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.
-
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
-
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
= {'stop': 'Stop nomad jobs.', 'run': 'Start nomad jobs.', 'plan': 'Plan nomad jobs.', 'status': 'Stop nomad jobs.'}¶ The list of job commands and their descriptions.
-
template_dir
= None¶ Where to find the Nomad templates for the jobs.
-
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
-
JOBS
= None¶ The list of available jobs
-
services
= None¶ The supervisor services installer.
-
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.
-
Changed in version 1.21.0:
Adjusted to use the new
ConsulTemplateTool
.
-
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, **kwargs)¶ Run or plan a Nomad job directly from a template.
-
run_nomad_jobs
(action, *jobs, **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
.
-
plan_jobs
(*jobs, **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, **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, **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, **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.
-
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 ofadd_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 ofadd_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:
-
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 ofadd_runtime_commands()
.Returns: If the command was handled and the result if it was.
-
-
class
runtime.
RuntimeTool
¶ Implementation of
genvid.toolbox.RuntimeTool