Some command line scripts fixes
[ganeti-local] / scripts / gnt-job
index 5b9caa7..ce81709 100755 (executable)
@@ -28,6 +28,7 @@ import sys
 from ganeti.cli import *
 from ganeti import constants
 from ganeti import errors
+from ganeti import utils
 
 
 #: default list of fields for L{ListJobs}
@@ -63,7 +64,7 @@ def ListJobs(opts, args):
   else:
     selected_fields = opts.output.split(",")
 
-  output = GetClient().QueryJobs(None, selected_fields)
+  output = GetClient().QueryJobs(args, selected_fields)
   if not opts.no_headers:
     # TODO: Implement more fields
     headers = {
@@ -83,10 +84,6 @@ def ListJobs(opts, args):
   else:
     headers = None
 
-  # we don't have yet unitfields here
-  unitfields = None
-  numfields = None
-
   # change raw values to nicer strings
   for row in output:
     for idx, field in enumerate(selected_fields):
@@ -106,8 +103,7 @@ def ListJobs(opts, args):
       row[idx] = str(val)
 
   data = GenerateTable(separator=opts.separator, headers=headers,
-                       fields=selected_fields, unitfields=unitfields,
-                       numfields=numfields, data=output, units=opts.units)
+                       fields=selected_fields, data=output)
   for line in data:
     ToStdout(line)
 
@@ -307,15 +303,16 @@ def ShowJobs(opts, args):
       format(3, "Execution log:")
       for serial, log_ts, log_type, log_msg in log:
         time_txt = FormatTimestamp(log_ts)
-        encoded = str(log_msg).encode('string_escape')
+        encoded = utils.SafeEncode(log_msg)
         format(4, "%s:%s:%s %s" % (serial, time_txt, log_type, encoded))
   return 0
 
 
 commands = {
-  'list': (ListJobs, ARGS_NONE,
-            [DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
-            "", "List the jobs and their status. The available fields are"
+  'list': (ListJobs, ARGS_ANY,
+            [DEBUG_OPT, NOHDR_OPT, SEP_OPT, FIELDS_OPT],
+            "[job_id ...]",
+           "List the jobs and their status. The available fields are"
            " (see the man page for details): id, status, op_list,"
            " op_status, op_result."
            " The default field"