genvid.toolbox.NomadTool¶
-
class
genvid.toolbox.
NomadTool
(use_wan=False, **kwargs)¶ Bases:
genvid.toolbox.consul.ConsulTool
A class for handling Nomad jobs.
Changed in version 1.19.0: Now, have a use_wan parameter to replace the service address with the TaggedAddress “wan”. The default is now to use the internal registered address.
-
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, nomad_url: str = None, **kwargs) → str¶ Query Consul for the Nomad client URL.
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_nomad
(action: str, *args, nomad_url: str = None, **kwargs)¶ Run Nomad with a specified action and other arguments.
This method ensurse the correct address from
get_nomad_client_url()
is passed to Nomad.Parameters: action – The action to do (‘run’, ‘plan’, ‘stop’, etc.).
-
static
check_alloc
(alloc, allocid=None, task=None, group=None, job=None, index=None, state=None)¶ Check if an allocation matches specific criteria.
Possible matches are:
allocid: Allocation ID starts with this prefix.
task: Task is part of the allocation.
group: Group is part of the allocation.
job: Job is the allocation Job ID.
index: Index of the allocation.
- state: If a task is specified, check if the task is in this state.
- If no tasks are specified, check if any task is in this state.
-
get_last_alloc
(**kwargs)¶ Get the last allocation that fits all the criteria.
-
show_alloc_log
(follow=False, tail=False, lines=10, logfilename=None, stdout=False, **kwargs)¶ Get the latest allocation which fits 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: For tail, 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 is specified, display stdout instead of
- stderr.
-
run_nomad_fs
(*args, **kwargs) → int¶ Run nomad fs with the arguments, and return the return code.
-
add_logs_commands
()¶ Add the log commands to the parser.
Run from
add_commands()
to add the log commands to the parser.
-
run_logs_command
(command, options)¶ Detect if the command is a log 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 was handled and its result if it was.
-
-
class
nomad.
NomadTool
¶ Implementation of
genvid.toolbox.NomadTool