Add option to ignore offline node on instance start/stop
[ganeti-local] / scripts / gnt-job
index 3088a14..9d58528 100755 (executable)
@@ -61,12 +61,7 @@ def ListJobs(opts, args):
   @return: the desired exit code
 
   """
-  if opts.output is None:
-    selected_fields = _LIST_DEF_FIELDS
-  elif opts.output.startswith("+"):
-    selected_fields = _LIST_DEF_FIELDS + opts.output[1:].split(",")
-  else:
-    selected_fields = opts.output.split(",")
+  selected_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
 
   output = GetClient().QueryJobs(args, selected_fields)
   if not opts.no_headers:
@@ -74,6 +69,7 @@ def ListJobs(opts, args):
     headers = {
       "id": "ID",
       "status": "Status",
+      "priority": "Prio",
       "ops": "OpCodes",
       "opresult": "OpCode_result",
       "opstatus": "OpCode_status",
@@ -82,6 +78,7 @@ def ListJobs(opts, args):
       "opstart": "OpCode_start",
       "opexec": "OpCode_exec",
       "opend": "OpCode_end",
+      "oppriority": "OpCode_prio",
       "start_ts": "Start",
       "end_ts": "End",
       "received_ts": "Received",
@@ -89,6 +86,8 @@ def ListJobs(opts, args):
   else:
     headers = None
 
+  numfields = ["priority"]
+
   # change raw values to nicer strings
   for row_id, row in enumerate(output):
     if row is None:
@@ -112,7 +111,8 @@ def ListJobs(opts, args):
       row[idx] = str(val)
 
   data = GenerateTable(separator=opts.separator, headers=headers,
-                       fields=selected_fields, data=output)
+                       fields=selected_fields, data=output,
+                       numfields=numfields)
   for line in data:
     ToStdout(line)
 
@@ -181,13 +181,17 @@ def CancelJobs(opts, args):
 
   """
   client = GetClient()
+  result = constants.EXIT_SUCCESS
 
   for job_id in args:
-    (_, msg) = client.CancelJob(job_id)
+    (success, msg) = client.CancelJob(job_id)
+
+    if not success:
+      result = constants.EXIT_FAILURE
+
     ToStdout(msg)
 
-  # TODO: Different exit value if not all jobs were canceled?
-  return 0
+  return result
 
 
 def ShowJobs(opts, args):
@@ -295,9 +299,10 @@ def ShowJobs(opts, args):
       else:
         format_msg(3, "No processing end time")
       format_msg(3, "Input fields:")
-      for key, val in opcode.iteritems():
+      for key in utils.NiceSort(opcode.keys()):
         if key == "OP_ID":
           continue
+        val = opcode[key]
         if isinstance(val, (tuple, list)):
           val = ",".join([str(item) for item in val])
         format_msg(4, "%s: %s" % (key, val))