Commit af30b2fd authored by Michael Hanselmann's avatar Michael Hanselmann

Make "gnt-job list" work again

"gnt-job list" was broken after my recent changes in the RPC
between clients and the master. This patch makes it work again.

Reviewed-by: iustinp
parent 8c229cc7
......@@ -41,7 +41,7 @@ from optparse import (OptionParser, make_option, TitledHelpFormatter,
Option, OptionValueError, SUPPRESS_HELP)
__all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain",
"SubmitOpCode",
"SubmitOpCode", "GetClient",
"cli_option", "GenerateTable", "AskUser",
"ARGS_NONE", "ARGS_FIXED", "ARGS_ATLEAST", "ARGS_ANY", "ARGS_ONE",
"USEUNITS_OPT", "FIELDS_OPT", "FORCE_OPT",
......@@ -394,7 +394,7 @@ def SubmitOpCode(op, proc=None, feedback_fn=None):
break
time.sleep(1)
jobs = cl.QueryJobs([job_id], ["status", "result"])
jobs = cl.QueryJobs([job_id], ["status", "opresult"])
if not jobs:
raise errors.JobLost("Job with id %s lost" % job_id)
......@@ -405,6 +405,11 @@ def SubmitOpCode(op, proc=None, feedback_fn=None):
raise errors.OpExecError(result)
def GetClient():
# TODO: Cache object?
return luxi.Client()
def FormatError(err):
"""Return a formatted error message for a given error.
......
......@@ -46,6 +46,13 @@ class _QueuedOpCode(object):
self.result = None
self._lock = threading.Lock()
@utils.LockedMethod
def GetInput(self):
"""Returns the original opcode.
"""
return self.input
@utils.LockedMethod
def SetStatus(self, status, result):
"""Update the opcode status and result.
......@@ -228,9 +235,12 @@ class JobQueue:
row.append(job.id)
elif fname == "status":
row.append(job.GetStatus())
elif fname == "result":
# TODO
elif fname == "ops":
row.append([op.GetInput().__getstate__() for op in job._ops])
elif fname == "opresult":
row.append([op.GetResult() for op in job._ops])
elif fname == "opstatus":
row.append([op.GetStatus() for op in job._ops])
else:
raise errors.OpExecError("Invalid job query field '%s'" % fname)
return row
......
......@@ -35,6 +35,14 @@ from ganeti import errors
_LIST_DEF_FIELDS = ["id", "status"]
_USER_JOB_STATUS = {
constants.JOB_STATUS_QUEUED: "queued",
constants.JOB_STATUS_RUNNING: "running",
constants.JOB_STATUS_CANCELED: "canceled",
constants.JOB_STATUS_SUCCESS: "success",
constants.JOB_STATUS_ERROR: "error",
}
def ListJobs(opts, args):
"""List the jobs
......@@ -46,20 +54,15 @@ def ListJobs(opts, args):
else:
selected_fields = opts.output.split(",")
query = {
"object": "jobs",
"fields": selected_fields,
"names": [],
}
output = SubmitQuery(query)
output = GetClient().QueryJobs(None, selected_fields)
if not opts.no_headers:
# TODO: Implement more fields
headers = {
"id": "ID",
"status": "Status",
"op_list": "OpCodes",
"op_status": "OpStatus",
"op_result": "OpResult",
"ops": "OpCodes",
"opresult": "OpCode_result",
"opstatus": "OpCode_status",
}
else:
headers = None
......@@ -73,16 +76,8 @@ def ListJobs(opts, args):
for idx, field in enumerate(selected_fields):
val = row[idx]
if field == "status":
if val == opcodes.Job.STATUS_PENDING:
val = "pending"
elif val == opcodes.Job.STATUS_RUNNING:
val = "running"
elif val == opcodes.Job.STATUS_SUCCESS:
val = "finished"
elif val == opcodes.Job.STATUS_FAIL:
val = "failed"
elif val == opcodes.Job.STATUS_ABORT:
val = "aborted"
if val in _USER_JOB_STATUS:
val = _USER_JOB_STATUS[val]
else:
raise errors.ProgrammerError("Unknown job status code '%s'" % val)
......
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