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

Environment variable for the default timeout for startup jobs

JOBS = None

The list of available jobs

JOBS_ACTIONS = {'plan': 'Plan nomad jobs.', 'status': 'Stop nomad jobs.', 'run': 'Start 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.

Job are run by Nomad <https://nomadproject.io/> and we use consul-template <https://github.com/hashicorp/consul-template> for creating the job description to the environment. For the local environment, all jobs are run using the rawexec driver. Please, consult the nomad and consul-template website to find more information.

Args:

name: The name of the job.

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

add_jobs_commands()

Add the jobs commands to the parser.

Run it from add_commands() to add the jobs commands to the parser.

add_runtime_commands()

Add all the commands available from :class:RuntimeTool and its parents.

Run it 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 it from add_commands() to add the services commands to the parser.

check_config()

Validate if all configuration are setup 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 check if the services are already installed and running first correcting any missing elements. If the services are already installed, it will not try to change its configuration. Use uninstall() to remove the old configuration.

jobs_dir = None

The folder where the jobs template will be output.

nomad_template(name, template)

Setup a nomad job file with consul-template.

plan_jobs(*jobs, **kwargs)

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

Args:
jobs: The list of jobs. 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.

Args:
jobs: The list of jobs. All known jobs if none are provided.
run_jobs_command(command, options)

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

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

Returns:
handled, result: A tuple with a boolean saying if the command were handled, and it’s result if that the case.
run_nomad_job(action, job, **kwargs)

Run or plan directly a nomad job from a template.

run_nomad_jobs(action, *jobs, **kwargs)

Execute one of the existing nomad commands on the list of jobs.

run_runtime_command(command, options)

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

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

Returns:
handled, result: A tuple with a boolean saying if the command were handled, and it’s result if that the case.
run_services_command(command, options)

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

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

Returns:
handled, result: A tuple with a boolean saying if the command were handled, and its result if that is the case.
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 (or all if none are provided).

stop_jobs(*jobs, **kwargs)

Stop the jobs include in the list of jobs (or all of them if none are provided).

template_dir = None

Where to find the nomad templates for the jobs.

uninstall()

Uninstall the supervisor services locally.

This stops any running supervisor services and uninstall its configuration and data files.