genvid.toolbox.NomadTool¶
-
class
genvid.toolbox.
NomadTool
(**kwargs)¶ Bases:
genvid.toolbox.consul.ConsulTool
A class for handling nomad jobs.
-
add_logs_commands
()¶ Add the logs commands to the parser.
Run it from
add_commands()
to add the logs commands to the parser.
-
static
check_alloc
(alloc, allocid=None, task=None, group=None, job=None, index=None, state=None)¶ Check if an alloc answer different conditions.
The conditions are the following:
allocid : if the allocation ID starts with this prefix.
task : if task is part of the allocation.
group : if group is part of the allocation.
job : if job is the allocation Job ID.
index : the index of the allocation.
state : if a task is specified, check if the task is in this state. If no task are specified, check if any task is in this state.
-
get_last_alloc
(**kwargs)¶ Get the last allocation that fits all the criteria.
-
get_nomad_client_addr
(*, timeout=0.0) → tuple¶ Get the nomad-client services address and port from consul.
Return the first service found.
Parameters: timeout – The timeout for the service.
-
get_nomad_client_url
(*, timeout=0.0) → str¶ Get the nomad client url.
Query consul to find it.
Parameters: timeout – timeout of the service to return. Returns: The url for nomad-client.
-
get_nomad_ip
() → str¶ Get the nomad IP address.
-
nomad
¶ A nomad client from the python-nomad package.
-
run_logs_command
(command, options)¶ Detect if the command is a logs command and execute it.
Call it from
run_command()
to handle logs commands. Job commands are added with the help ofadd_logs_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
(action: str, *args, **kwargs)¶ Run nomad with action and the other arguments.
This method ensure the correct address from
get_nomad_client_url()
are passed to nomad.Parameters: action – The action to do. Usually ‘run’, ‘plan’, ‘stop’, etc.
-
run_nomad_fs
(*args, **kwargs) → int¶ Run nomad fs with the arguments, and return the return code.
-
show_alloc_log
(follow=False, tail=False, lines=10, logfilename=None, stdout=False, **kwargs)¶ Get the latest alloc which fit all the criteria and show its logs.
The criteria are the same as
check_alloc()
. The other parameters do the following:follow: Don’t stop when end of file is reached, but instead wait for additional content. tail: Just display the last
lines
of text. lines: Fortail
, adjust the number of lines to display (default is 10). logfilename: The name of the file to display. Default is to show stderr. stdout: If no logfile are given, display stdout instead of stderr.
-
-
class
nomad.
NomadTool
¶ Implementation of
genvid.toolbox.NomadTool