Commit 94428652 authored by Iustin Pop's avatar Iustin Pop
Browse files

Implement job submission for scripts

This patch adds the infrastructure for executing a job in background,
instead of foreground, via a new “--submit” option. The behaviour is
that the job ID is printed and the script will immediately exit.

The patch also converts gnt-node list to this model (yes, this will be a
query in the future).

Reviewed-by: imsnah
parent 17dc2da0
......@@ -44,9 +44,9 @@ __all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain",
"SubmitOpCode", "GetClient",
"cli_option", "GenerateTable", "AskUser",
"ListTags", "AddTags", "RemoveTags", "TAG_SRC_OPT",
"FormatError", "SplitNodeOption"
"FormatError", "SplitNodeOption", "SubmitOrSend",
......@@ -180,6 +180,11 @@ FORCE_OPT = make_option("-f", "--force", dest="force", action="store_true",
TAG_SRC_OPT = make_option("--from", dest="tags_source",
default=None, help="File with tag names")
SUBMIT_OPT = make_option("--submit", dest="submit_only",
default=False, action="store_true",
help="Submit the job and return the job ID, but"
" don't wait for the job to finish")
def ARGS_FIXED(val):
"""Macro-like function denoting a fixed number of arguments"""
......@@ -447,6 +452,22 @@ def SubmitOpCode(op, cl=None, feedback_fn=None):
return PollJob(job_id, cl)
def SubmitOrSend(op, opts, cl=None, feedback_fn=None):
"""Wrapper around SubmitOpCode or SendJob.
This function will decide, based on the 'opts' parameter, whether to
submit and wait for the result of the opcode (and return it), or
whether to just send the job and print its identifier. It is used in
order to simplify the implementation of the '--submit' option.
if opts and opts.submit_only:
print SendJob([op], cl=cl)
return SubmitOpCode(op, cl=cl, feedback_fn=feedback_fn)
def GetClient():
# TODO: Cache object?
......@@ -79,7 +79,7 @@ def ListNodes(opts, args):
selected_fields = opts.output.split(",")
op = opcodes.OpQueryNodes(output_fields=selected_fields, names=[])
output = SubmitOpCode(op)
output = SubmitOrSend(op, opts)
if not opts.no_headers:
headers = {
......@@ -335,7 +335,8 @@ commands = {
'info': (ShowNodeConfig, ARGS_ANY, [DEBUG_OPT],
"[<node_name>...]", "Show information about the node(s)"),
'list': (ListNodes, ARGS_NONE,
"", "Lists the nodes in the cluster. The available fields"
" are (see the man page for details): name, pinst_cnt, pinst_list,"
" sinst_cnt, sinst_list, pip, sip, dtotal, dfree, mtotal, mnode,"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment