genvid.toolbox.ClusterAPI

class genvid.toolbox.ClusterAPI(cluster_id='', use_wan=False, **kwargs)

Bases: BaseHttpApiTool, ConsulTool

Handles the communication with a cluster.

Changed in version 1.20.0: Now, have a use_wan parameter to replace the service address with the TaggedAddress “wan”. The default is now to use the internal registered address.

Changed in version 1.33.0: Moved as_bitrate() to ClusterTool.

NAME = 'cluster-api'

The name of the logger for this tool. Must be redefined in children.

cluster_id

Base URL for Genvid Cluster Service API.

GENVID_CLUSTER_API_BASEURL

Base URL from bastion server, to access the cluster API.

Deprecated since version 1.12.0: This value is no longer used by get_base_url(). Override the method instead.

jobs

Get the JobsAPI

logs

Get the LogsAPI

get_proxied_url(service: str = 'cluster-api', timeout=0.0) str

Get the cluster service proxied url

Changed in version 1.12.0: The URL is now always returned without a slash.

get_base_url(timeout=0.0) str

Get the base url

is_bastion_running(timeout=0.0) bool

Check whether the bastion instance is running.

New in version 1.20.0.

get_cluster_id_tag() str
: returns: the cluster_id of the current object prepended

with “CLUSTER_ID:” so it can be used as a tag filter for the consulate client

is_cluster_running(timeout=0.0) bool
Returns

True if and only if the cluster instance is running.

Changed in version 1.30.0: Use the cluster-api to check if a cluster is connected.

get_cluster_version(timeout=0.0)

Get the version of this cluster instance.

Parameters

timeout – Timeout to wait for the service to be available.

New in version 1.20.0.

load_project_definition(definition)

Load a project definition into the cluster.

Deprecated since version 1.29.0: no longer used

get_project_config(timeout=0.0)

Get the project configuration.

Parameters

timeout – The timeout in seconds.

Returns

The project configuration.

set_project_config(config: dict, timeout=0.0)

Set the project configuration. The keys genvid, bastion, and vault are omitted.

Parameters
  • config – The project configuration.

  • timeout – The timeout in seconds.

delete_project_config(timeout=0.0)

Delete the configuration. The keys genvid, bastion, and vault are omitted.

Parameters

timeout – The timeout in seconds.

do_consul_template(template: str, timeout=0.0) dict

Execute a consul-template on the server site and return the result.

Parameters
  • template – The template.

  • timeout – The timeout in seconds.

Returns

Ex: { “data”: “result”, “stderr”: “message”}

Deprecated since version 1.33.0: Replaced by render_template()

get_project_log_list(timeout=0.0) List[dict]

Get the list of logs.

Returns

The list of logs.

Deprecated since version 1.12: Use logs and LogsAPI.get_logs()

set_project_log_list(logs: list, timeout=0.0)

Return the list of logs.

Parameters
  • logs – Configure the list of logs.

  • timeout – The timeout in seconds.

Deprecated since version 1.12: Use logs and LogsAPI.set_logs()

delete_project_log_list(timeout=0.0)

Delete the list of logs.

Parameters

timeout – The timeout in seconds.

Deprecated since version 1.12: Use logs and LogsAPI.delete_logs()

delete_project_log(log_id: str, timeout=0.0)

Delete the specified log.

Parameters
  • log_id – The log ID.

  • timeout – The timeout in seconds.

Deprecated since version 1.12: Use logs and LogsAPI.delete_log()

get_project_log_meta(name: str, timeout=0.0) dict

Return the meta data associated with the project log.

Parameters
  • name – The log name.

  • timeout – The timeout in seconds.

Deprecated since version 1.12: Use logs and LogsAPI.get_log_meta()

get_project_log_stream(meta: dict, origin: str, offset: int, timeout=0.0)

Return the log stream for the log specified in the meta.

Parameters
  • meta – The log meta information.

  • origin – The origin of the log. Either ‘start’ or ‘end’.

  • offset – The offset to the origin.

  • timeout – The timeout in seconds.

Deprecated since version 1.12: Use logs and LogsAPI.get_log_stream()

print_project_log(name, output=None, tail=False, follow=False, lines=10, timeout=0.0)

Print project logs on output.

Parameters
  • name – The name of the log.

  • output – If None, defaults to stdout.

  • tail – If True, prints the end of the log.

  • follow – If True, continues to show the log as it runs.

  • lines – An approximate number of lines to show.

  • timeout – The timeout in seconds.

Deprecated since version 1.12: Use logs and LogsAPI.print_log()

get_project_jobs(timeout=0.0)

Return currently running jobs in the process.

Deprecated since version 1.12.0: Use jobs and JobsAPI.get_job_definitions()

get_events_defs(timeout=0.0)

Get the events definitions.

Parameters

timeout – The timeout in seconds.

set_events_defs(events_defs: dict, timeout=0.0) dict

Set the events definition.

Parameters
  • events_defs – The events.

  • timeout – The timeout in seconds.

delete_events_def(event_id: str, timeout=0.0)

Delete an events definition.

Parameters
  • event_id – The events definition to delete.

  • timeout – The timeout in seconds.

delete_events_defs(timeout=0.0)

Delete the multiple event definitions.

Parameters

timeout – The timeout in seconds.

get_secrets(timeout=0.0) dict

Get the list of secrets in the database.

Parameters

timeout – The timeout in seconds.

Returns

The list of secrets. Ex: { “keys”: [“command”, “disco”]}

get_secret(path: str, timeout=0.0) dict

Retrieve a secret.

Parameters
  • path – The path to the secret.

  • timeout – The timeout in seconds.

Returns

The data associated with the secret.

set_secret(path: str, data: dict, timeout=0.0)

Set a secret.

Parameters
  • path – The path to the secret.

  • data – Data associated with the secret.

  • timeout – The timeout in seconds.

delete_secret(path: str, timeout=0.0)

Delete a secret.

Parameters
  • path – The path to the secret.

  • timeout – The timeout in seconds.

clear_secrets(timeout=0.0)

Delete a secret.

Parameters

timeout – The timeout in seconds.

run_project_job(job: str, timeout=0.0)

Start a project job by calling the cluster service.

Parameters
  • job – The job name.

  • timeout – The timeout in seconds.

Deprecated since version 1.12.0: Use jobs and JobsAPI.start_job()

stop_project_job(job: str, timeout=0.0)

Stop a project job by calling the cluster service.

Parameters
  • job – The job name.

  • timeout – The timeout in seconds.

Deprecated since version 1.12.0: Use jobs and JobsAPI.stop_job()

run_all_project_job(timeout=0.0)

Start all project jobs by calling the cluster service.

Parameters

timeout – The timeout in seconds.

Deprecated since version 1.12.0: Use jobs and JobsAPI.start_all_job()

stop_all_project_job(timeout=0.0)

Stop all project jobs by calling the cluster service.

Parameters

timeout – The timeout in seconds.

Deprecated since version 1.12.0: Use jobs and JobsAPI.stop_all_job()

Get the list of links.

Parameters
  • category – The link’s category.

  • link_id – The link’s ID.

  • timeout – The timeout in seconds.

Returns

A list of strings.

get_schema(schema: str)

Get the specified schema.

Parameters

schema – The schema file.

Returns

get_settings_schema() str

Get the schema for settings.

New in version 1.41.0.

set_settings_schema(schema: dict)

Update the schema for settings.

New in version 1.41.0.

get_default_settings() dict

Get the default settings.

Returns

A dictionary of settings.

get_settings() dict

Get the settings.

Returns

A dictionary of settings.

get_settings_validation() List[str]

Get the settings validation.

Returns

A list of warning messages.

set_settings(settings: dict)

Set multiple configuration settings.

Parameters

settings – The settings used for configuration. Values default to empty.

get_jobsdefs(timeout=0.0) dict

Retrieve multiple job definitions.

Parameters

timeout – The timeout in seconds.

Returns

The data associated with the job definitions.

Deprecated since version 1.12.0: Use jobs and JobsAPI.get_job_definitions()

set_jobsdefs(data: dict, timeout=0.0)

Set multiple job definitions.

Parameters
  • data – Data associated with the job definitions.

  • timeout – The timeout in seconds.

Deprecated since version 1.12.0: Use jobs and JobsAPI.update_job_definitions()

delete_jobsdefs(timeout=0.0)

Delete multiple job definitions.

Parameters

timeout – The timeout in seconds.

Deprecated since version 1.12.0: Use jobs and JobsAPI.delete_job_definitions()

delete_jobsdef(job_id: str, timeout=0.0)

Delete a job definition.

Parameters

timeout – The timeout in seconds.

Deprecated since version 1.12.0: Use jobs and JobsAPI.delete_job_definition()

get_linksdefs(timeout=0.0) dict

Retrieve multiple link definitions.

Parameters

timeout – The timeout in seconds.

Returns

The data associated with the link definitions.

set_linksdefs(data: dict, timeout=0.0)

Set multiple link definitions.

Parameters
  • data – Data associated with the link definitions.

  • timeout – The timeout in seconds.

delete_linksdefs(timeout=0.0)

Delete multiple link definitions.

Parameters

timeout – The timeout in seconds.

delete_linksdef(link_id: str, timeout=0.0)

Delete a link definition.

Parameters

timeout – The timeout in seconds.

get_service_addresses(service: str, timeout=0.0) List[str]

Get the service addresses

Parameters
  • service – The service name

  • timeout – The timeout in seconds

Returns

A list of ip addresses and ports.

get_health(service: str, timeout=0.0) dict

Return the heath definition of a service.

Parameters
  • service – The service name

  • timeout – The timeout in seconds

Returns

A dictionary with the properties of the service.

get_nodes(timeout=0.0) dict

Return the list of nodes.

Return a list of Nodes currently registered in Consul.

Each node have the following properties:

  • Name

  • Status

  • NodeClass

Parameters

timeout – The timeout in seconds

Returns

A list of dictionary of node properties.

get_node(nodeid: str, timeout=0.0) dict

Return the properties of a node.

Return the registered node properties.

Parameters

timeout – The timeout in seconds

Returns

A dictionary of node properties.

get_cluster_info(timeout=0.0, retry_request=False)

Returns result of query on: /v1/proxy/CLUSTER_ID/cluster-api/v1/cluster/info as dict

Changed in version 1.30.0: Add the retry_request parameter, allowing to retry on error.

render_template(content: Optional[str] = None, templatePath: Optional[str] = None, sources: Optional[str] = None, environment: Optional[Dict[str, str]] = None, timeout=5.0) dict

Execute a consul-template on the server site and return the result.

Parameters
  • content – The content of the template to render. Must be None or empty if templatePath is used.

  • templatePath – The path of the template inside the source. content must be None or empty if it is used and sources must be provided.

  • sources – A url for the sources. Must be provided if templatePath is set.

  • environment – A dictionary of environment variables. Keys and values must be string.

  • timeout – The timeout in seconds.

Returns

Ex: { “data”: “result”, “stderr”: “message”}

New in version 1.33.0.

class cluster_api.ClusterAPI

Implementation of genvid.toolbox.ClusterAPI