genvid.toolbox.RuntimeTool

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

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

Common tool for managing the different environments.

GENVID_STARTUP_TIMEOUT = None

A mirror of GENVID_STARTUP_TIMEOUT containing the default timeout for startup jobs

GENVID_VAULT_TOKEN_ROLES_FOLDER = None

The folder where the vault roles can be found.

JOBS = None

The list of available jobs

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

The list of job commands and their descriptions.

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

List of mandatory configuration keys

STARTUP_TIMEOUT = 30

Default value for GENVID_STARTUP_TIMEOUT.

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.

add_jobs_commands()

Add the job commands to the parser.

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

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:

add_services_commands()

Add the commands for services to the parser.

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

check_config()

Validate that all configurations are set up correctly.

Returns:True if everything is OK, False otherwise.
check_services(timeout: float = None) → bool

Check if the supervisor services are responding.

get_nomad_file(job)
get_template_job(job)

Return the template path for job.

install(node_class='game', **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.

jobs_dir = None

The folder where the jobs template is output.

nomad_template(name, template)

Set up a Nomad job file with consul-template.

plan_jobs(*jobs, **kwargs)

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

Refresh configuration, if necessary.

run_jobs(*jobs, **kwargs)

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.
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.
run_nomad_job(action, job, **kwargs)

Run or plan a Nomad job directly from a template.

run_nomad_jobs(action, *jobs, **kwargs)

Execute an available Nomad command on the list of jobs.

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.
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.
services = None

The supervisor services installer.

status(*jobs)

Print the status of all services and jobs.

status_jobs(*jobs, **kwargs)

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

stop_jobs(*jobs, **kwargs)

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

template_dir = None

Where to find the Nomad templates for the jobs.

uninstall(clean: bool = False)

Uninstall the supervisor services locally.

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

class runtime.RuntimeTool

Implementation of genvid.toolbox.RuntimeTool