From af30b2fd23712b6df246b8209066f4d572b8dc3f Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 11 Jul 2008 10:25:15 +0000 Subject: [PATCH] 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 --- lib/cli.py | 9 +++++++-- lib/jqueue.py | 14 ++++++++++++-- scripts/gnt-job | 35 +++++++++++++++-------------------- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index befcb2c04..1f89be361 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -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. diff --git a/lib/jqueue.py b/lib/jqueue.py index 3ba41afff..67054aefc 100644 --- a/lib/jqueue.py +++ b/lib/jqueue.py @@ -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 diff --git a/scripts/gnt-job b/scripts/gnt-job index 748a11c58..a4341d642 100755 --- a/scripts/gnt-job +++ b/scripts/gnt-job @@ -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) -- GitLab