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

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()

Return the IP of the Consul service to connect to.

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.

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 of add_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.