Include node name in hypervisor validation errors
[ganeti-local] / scripts / gnt-debug
index ed2d476..ff7e01b 100755 (executable)
@@ -30,6 +30,7 @@ import time
 from optparse import make_option
 
 from ganeti.cli import *
+from ganeti import cli
 from ganeti import opcodes
 from ganeti import constants
 from ganeti import utils
@@ -39,6 +40,13 @@ from ganeti import errors
 def Delay(opts, args):
   """Sleeps for a while
 
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: should contain only one element, the duration
+      the sleep
+  @rtype: int
+  @return: the desired exit code
+
   """
   delay = float(args[0])
   op = opcodes.OpTestDelay(duration=delay,
@@ -50,54 +58,38 @@ def Delay(opts, args):
 
 
 def GenericOpCodes(opts, args):
-  """Send any opcode to the master
+  """Send any opcode to the master.
+
+  @todo: The function is broken and needs to be converted to the
+      current job queue API
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: should contain only one element, the path of
+      the file with the opcode definition
+  @rtype: int
+  @return: the desired exit code
 
   """
+  cl = cli.GetClient()
   fname = args[0]
   op_data = simplejson.loads(open(fname).read())
   op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data]
-  job = opcodes.Job(op_list=op_list)
-  jid = SubmitJob(job)
+  jid = cli.SendJob(op_list, cl=cl)
   ToStdout("Job id: %s", jid)
-  query = {
-    "object": "jobs",
-    "fields": ["status"],
-    "names": [jid],
-    }
-
-  # wait for job to complete (either by success or failure)
-  while True:
-    jdata = SubmitQuery(query)
-    if not jdata:
-      # job not found, gone away!
-      ToStderr("Job lost!")
-      return 1
-
-    status = jdata[0][0]
-    ToStdout(status)
-    if status in (opcodes.Job.STATUS_SUCCESS, opcodes.Job.STATUS_FAIL):
-      break
-
-    # sleep between checks
-    time.sleep(0.5)
-
-  # job has finished, get and process its results
-  query["fields"].extend(["op_list", "op_status", "op_result"])
-  jdata = SubmitQuery(query)
-  if not jdata:
-    # job not found, gone away!
-    ToStderr("Job lost!")
-    return 1
-  ToStdout(jdata[0])
-  status, op_list, op_status, op_result = jdata[0]
-  for idx, op in enumerate(op_list):
-    ToStdout("%s %s %s %s", idx, op.OP_ID, op_status[idx], op_result[idx])
+  cli.PollJob(jid, cl=cl)
   return 0
 
 
 def TestAllocator(opts, args):
-  """Runs the test allocator opcode"""
+  """Runs the test allocator opcode.
 
+  @param opts: the command line options selected by the user
+  @type args: list
+  @param args: should contain only one element, the iallocator name
+  @rtype: int
+  @return: the desired exit code
+
+  """
   try:
     disks = [{"size": utils.ParseUnit(val), "mode": 'w'}
              for val in opts.disks.split(",")]
@@ -164,7 +156,7 @@ commands = {
                  make_option("-m", "--mode", default="relocate",
                              choices=["relocate", "allocate"],
                              help="Request mode, either allocate or"
-                             "relocate"),
+                             " relocate"),
                  cli_option("--mem", default=128, type="unit",
                             help="Memory size for the instance (MiB)"),
                  make_option("--disks", default="4096,4096",