Commit af30b2fd authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

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", "GetClient",
"cli_option", "GenerateTable", "AskUser",
......@@ -394,7 +394,7 @@ def SubmitOpCode(op, proc=None, feedback_fn=None):
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()
def GetInput(self):
"""Returns the original opcode.
return self.input
def SetStatus(self, status, result):
"""Update the opcode status and result.
......@@ -228,9 +235,12 @@ class JobQueue:
elif fname == "status":
elif fname == "result":
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])
raise errors.OpExecError("Invalid job query field '%s'" % fname)
return row
......@@ -35,6 +35,14 @@ from ganeti import errors
_LIST_DEF_FIELDS = ["id", "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):
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",
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]
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