genvid.toolbox.RuntimeTool

class genvid.toolbox.RuntimeTool(services_dir='services', **kwargs)

Bases: genvid.toolbox.nomad.NomadTool, genvid.toolbox.consul_template.ConsulTemplateTool

Common tool for managing the different environments.

Changed in version 1.30.0: Make it derived from ProjectTool instead of ConsulTemplateTool.

Changed in version 1.33.0: Removed dependency on EventsTool.

Changed in version 1.33.0: Removed dependency on ConfigTool.

Changed in version 1.33.0: Replace ProjectTool with ConfigurationLoader.

VaultInitializationErrors = (<class 'requests.exceptions.ConnectionError'>, <class 'hvac.exceptions.VaultDown'>, <class 'hvac.exceptions.Forbidden'>, <class 'hvac.exceptions.InternalServerError'>, <class 'hvac.exceptions.InvalidPath'>, <class 'genvid.toolbox.consul.ServiceIsNotRunningError'>)

Vault Initialization Errors that are allowed to retry.

New in version 1.15.0.

NomadInitializationErrors = (<class 'nomad.api.exceptions.BaseNomadException'>, <class 'nomad.api.exceptions.URLNotFoundNomadException'>, <class 'genvid.toolbox.consul.ServiceIsNotRunningError'>, <class 'requests.exceptions.ConnectionError'>)

Nomad Initialization Errors that are allowed to retry.

New in version 1.15.0.

MUST_HAVE_CONFIGURATION = ('genvid/encode/stream/service', 'genvid/encode/stream/addr', 'genvid/encode/stream/key', 'genvid/encode/stream/channel')

List of mandatory configuration keys

Deprecated since version 1.33.0: No longer valid.

STARTUP_TIMEOUT = 60

Default value for GENVID_STARTUP_TIMEOUT.

STOP_TIMEOUT = 15

Maximum waiting time before giving up on terminating a Nomad job.

JOBS_ACTIONS = {'plan': 'Plan nomad jobs.', 'run': 'Start nomad jobs.', 'stop': 'Stop nomad jobs.', 'status': 'Stop nomad jobs.'}

The list of job commands and their descriptions.

jobs_dir = None

The folder where the jobs template is output.

GENVID_STARTUP_TIMEOUT = None

A mirror of GENVID_STARTUP_TIMEOUT containing the default timeout for startup jobs

services = None

The supervisor services installer.

GENVID_BASTION_CONFIG_FOLDER = None

A mirror of GENVID_BASTION_CONFIG_FOLDER that contains the bastion configuration.

New in version 1.31.0.

GENVID_BASTION_JOB_TEMPLATE_FOLDER = None

A mirror of GENVID_BASTION_JOB_TEMPLATE_FOLDER that contains the bastion configuration.

New in version 1.31.0.

template_dir

Where to find the Nomad templates for the jobs.

Deprecated since version 1.31.0: This property is now a mirror of GENVID_BASTION_JOB_TEMPLATE_FOLDER.

JOBS

The list of available jobs.

add_job(name, dependencies=None)

Add a new Nomad job to run.

We create the job description for the environment using consul-template and run the jobs using Nomad. For the local environment, all jobs are run using the rawexec driver. Please, consult the Nomad and consul-template websites for more information.

Args:

name: The name of the job.

dependencies: A list of service names which the job depends on.

nomad_template(name, template)

Set up a Nomad job file with consul-template.

get_template_job(job)

Return the template path for job.

get_nomad_file(job)
install(node_class: str = 'game', vault_enabled: bool = False, reconfigure: bool = False, **kwargs)

Install the supervisor services locally.

This method checks if the services are already installed and running first, then corrects any missing elements. If the services are already installed, it won’t change their configuration. Use uninstall() to remove the old configuration.

Changed in version 1.15.0: If reconfigure is True, the service will be always restarted.

uninstall(clean: bool = False)

Uninstall the supervisor services locally.

This stops any running supervisor services and uninstalls their configuration and data files.

run_nomad_job(action, job, *, nomad_url: str = None, hcl1: bool = False, **kwargs)

Run or plan a Nomad job directly from a template.

Changed in version 1.34.0: Add -detach parameter to nomad run. Add hcl1 parameter to support -hcl1 jobs.

run_nomad_jobs(action, *jobs, skip_checks: bool = False, nomad_url: str = None, hcl1: bool = False, **kwargs) → bool

Execute an available Nomad command on the list of jobs.

Returns:False if Nomad service is not running. True otherwise.

Changed in version 1.20.0: Return nomad service check result.

Changed in version 1.20.1: Properly wait for Nomad jobs to terminate when action=stop.

Changed in version 1.34.0: Add the hcl1 option to support hcl1 job definition.

plan_jobs(*jobs, skip_checks: bool = False, nomad_url: str = None, hcl1: bool = False, **kwargs) → bool

Do a plan on the list of jobs, generating the Nomad file first.

Parameters:jobs – The list of jobs. Uses all known jobs if none provided.
Returns:False if Nomad service is not running. True otherwise.

Changed in version 1.20.0: Return nomad service check result.

run_jobs(*jobs, skip_checks: bool = False, nomad_url: str = None, hcl1: bool = False, **kwargs) → bool

Do a run on the list of jobs, generating the Nomad file first.

Parameters:jobs – The list of jobs. Uses all known jobs if none provided.
Returns:False if Nomad service is not running. True otherwise.

Changed in version 1.20.0: Return nomad service check result.

stop_jobs(*jobs, skip_checks: bool = False, nomad_url: str = None, hcl1: bool = False, **kwargs) → bool

Stop the jobs in the list. Uses all known jobs if none provided.

Returns:False if Nomad service is not running. True otherwise.

Changed in version 1.20.0: Return nomad service check result.

status_jobs(*jobs, skip_checks: bool = False, nomad_url: str = None, hcl1: bool = False, **kwargs) → bool

Return the status of the jobs in the list. Uses all known jobs if none provided.

Returns:False if Nomad service is not running. True otherwise.

Changed in version 1.20.0: Return nomad service check result.

status(*jobs)

Print the status of all services and jobs.

Changed in version 1.20.0: Will now display the version of the bastion and cluster instance.

check_config()

Validate that all configurations are set up correctly.

returns:True if everything is OK, False otherwise.

Deprecated since version 1.33.0: No longer used and not valid

refresh()

Refresh configuration, if necessary.

check_services(timeout: float = None) → bool

Check if the supervisor services are responding.

init_service_vault(timeout: float)
get_nomad_token()
init_service_nomad(timeout: float)
add_services_commands()

Add the commands for services to the parser.

Run from add_commands() to add the service commands to the parser.

run_services_command(command: str, options) → typing.Tuple[bool, typing.Any]

Detect if the command is a service command and execute it.

Call from run_command() to handle service commands. Job commands are added with the help of add_services_commands().

Returns:If the command was handled and the result if it was.
add_jobs_commands()

Add the job commands to the parser.

Run from add_commands() to add the job commands to the parser.

run_jobs_command(command: str, options) → typing.Tuple[bool, typing.Any]

Detect if the command is a job command and execute it.

Call from run_command() to handle job commands. Job commands are added with the help of add_jobs_commands().

Returns:If the command was handled and the result if it was.
add_runtime_commands()

Add all the commands available from RuntimeTool and its parents.

Run from add_commands() to add all the commands avaiable to the parser.

See the following methods for more information:

Changed in version 1.33.0: Remove events commands.

run_runtime_command(command: str, options) → typing.Tuple[bool, typing.Any]

Detect if the command is a runtime command and execute it.

Call from run_command() to handle runtime commands. Runtime commands are added with the help of add_runtime_commands().

Returns:If the command was handled and the result if it was.
class runtime.RuntimeTool

Implementation of genvid.toolbox.RuntimeTool