genvid.toolbox.ConsulTool¶
-
class
genvid.toolbox.
ConsulTool
(use_wan=False, **kwargs)¶ Bases:
genvid.toolbox.network.NetworkTool
This class allows you to access different Consul services.
-
NAME
= 'consul'¶
-
DESCRIPTION
= 'An interface to the consul discovery service.'¶
-
CONSUL_KEY_SEP
= '/'¶ Consul KV store folder separator
-
UI_NAMES
= ('consul-ui',)¶ List of UI services name
-
CONSUL_HTTP_ADDR
= None¶ A mirror of
CONSUL_HTTP_ADDR
. It specifies the IP address and port the toolbox uses to connect to Consul.Changed in version 1.34.0: If
GENVID_BASTION_URL
(a fully parsable URI) orCONSUL_HTTP_ADDR
(a combination of an hostname/ip and a port, with no scheme) are set but invalid, this will returns aValueError
.
-
connect_consul
(ip=None)¶ Return a connection to a specific Consul node.
-
consulate
¶ A connected Consul client, from the consulate package.
-
consul_kv
¶ The Consul KV store.
-
consul_catalog
¶ The Consul catalog.
-
consul_health
¶ The Consul Health API.
New in version 1.15.0.
-
consul_agent
¶ The Consul agent API.
-
consul_join
(ip)¶ Join a Consul cluster.
-
get_consul_ip
()¶ Returns the IP of the default Consul service.
This method will return the host part of the environment variable
CONSUL_HTTP_ADDR
if it is set.If not and the
GENVID_BASTION_URL
environment variable is set, the host of the url will be used.Otherwise it will default to the environment variable
GENVID_DEFAULT_IP
which defaults to127.0.0.1
.Changed in version 1.28.0: The returned value now depends on the environment variables
CONSUL_HTTP_ADDR
andGENVID_BASTION_URL
in addition toGENVID_DEFAULT_IP
. See description for details.Changed in version 1.34.0: Raise a
ValueError
ifCONSUL_HTTP_ADDR
is malformed. In particular, it should failed if the scheme is included.
-
get_consul_address
()¶ Returns the address of the default Consul service.
The address returned only contains the
address:port
, no protocol prefixes.This method will return the environment variable
CONSUL_HTTP_ADDR
if it is set.If not and the
GENVID_BASTION_URL
environment variable is set, the host of the url will be used appended with the default port8500
.If not, it will default to the environment variable
GENVID_DEFAULT_IP
(which defaults to127.0.0.1
) appended with:8500
.Changed in version 1.28.0: The returned value now depends on the environment variables
CONSUL_HTTP_ADDR
andGENVID_BASTION_URL
in addition toGENVID_DEFAULT_IP
. See description for details.
-
get_service
(name, timeout=0.0, tag: typing.Union[str, NoneType] = None, passing: bool = True)¶ Return the status of the service name.
Parameters: - timeout – The service will retry for at least that many seconds or that a good service is found.
- tag – If not empty, return only the service with this tag.
- passing – If true (the default), returns only passing services.
Raises a
ServiceIsNotRunningError
if the service is unavailable.Changed in version 1.15.0: Used /v1/health/service instead of catalog to only returns healty services. Set the new passing parameter to False to get the old behaviour.
-
static
get_service_address_port
(svc: dict, use_wan: bool = False)¶ Return the address and port of the service.
Parameters: - svc – A dictionary of service description, as returned by
get_service()
. - use_wan – Either to use the WAN TaggedAdressed if present.
New in version 1.19.0.
- svc – A dictionary of service description, as returned by
-
start_service_ui
(ui, use_wan=False)¶ Start a web browser on the service named ui, specifying if we should use_wan for the service.
-
start_consul_ui
()¶ Start a web browser on the Consul UI.
-
start_ui
(*uis)¶ Open a web page on the services specified by uis.
-
add_consul_commands
()¶ Add the Consul commands to the parser.
Run from
add_commands()
to add the events commands to the parser.
-
run_consul_command
(command, options)¶ Detect if the command is a Consul command and execute it.
Call it from
run_command()
to handle Consul commands. Consul commands are added with the help ofadd_consul_commands()
.Returns:
- handled, result: A tuple with a boolean saying if the
- command were handled and it’s result if it was.
-
-
class
consul.
ConsulTool
¶ Implementation of
genvid.toolbox.ConsulTool
.