Revision 0bbe448c lib/cli.py

b/lib/cli.py
41 41
                      Option, OptionValueError, SUPPRESS_HELP)
42 42

  
43 43
__all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain",
44
           "SubmitOpCode", "SubmitJob", "SubmitQuery",
44
           "SubmitOpCode",
45 45
           "cli_option", "GenerateTable", "AskUser",
46 46
           "ARGS_NONE", "ARGS_FIXED", "ARGS_ATLEAST", "ARGS_ANY", "ARGS_ONE",
47 47
           "USEUNITS_OPT", "FIELDS_OPT", "FORCE_OPT",
......
370 370

  
371 371

  
372 372
def SubmitOpCode(op, proc=None, feedback_fn=None):
373
  """Function to submit an opcode.
373
  """Legacy function to submit an opcode.
374 374

  
375 375
  This is just a simple wrapper over the construction of the processor
376 376
  instance. It should be extended to better handle feedback and
......
379 379
  """
380 380
  # TODO: Fix feedback_fn situation.
381 381
  cl = luxi.Client()
382
  job = opcodes.Job(op_list=[op])
383
  jid = SubmitJob(job, cl)
384 382

  
385
  query = {
386
    "object": "jobs",
387
    "fields": ["status"],
388
    "names": [jid],
389
    }
383
  job_id = cl.SubmitJob([op])
390 384

  
391 385
  while True:
392
    jdata = SubmitQuery(query, cl)
393
    if not jdata:
386
    jobs = cl.QueryJobs([job_id], ["status"])
387
    if not jobs:
394 388
      # job not found, go away!
395
      raise errors.JobLost("Job with id %s lost" % jid)
389
      raise errors.JobLost("Job with id %s lost" % job_id)
396 390

  
397
    status = jdata[0][0]
398
    if status in (opcodes.Job.STATUS_SUCCESS, opcodes.Job.STATUS_FAIL):
391
    # TODO: Handle canceled and archived jobs
392
    status = jobs[0][0]
393
    if status in (constants.JOB_STATUS_SUCCESS, constants.JOB_STATUS_ERROR):
399 394
      break
400 395
    time.sleep(1)
401 396

  
402
  query["fields"].extend(["op_list", "op_status", "op_result"])
403
  jdata = SubmitQuery(query, cl)
404
  if not jdata:
405
    raise errors.JobLost("Job with id %s lost" % jid)
406
  status, op_list, op_status, op_result = jdata[0]
407
  if status != opcodes.Job.STATUS_SUCCESS:
408
    raise errors.OpExecError(op_result[0])
409
  return op_result[0]
397
  jobs = cl.QueryJobs([job_id], ["status", "result"])
398
  if not jobs:
399
    raise errors.JobLost("Job with id %s lost" % job_id)
410 400

  
411

  
412
def SubmitJob(job, cl=None):
413
  if cl is None:
414
    cl = luxi.Client()
415
  return cl.SubmitJob(job)
416

  
417

  
418
def SubmitQuery(data, cl=None):
419
  if cl is None:
420
    cl = luxi.Client()
421
  return cl.Query(data)
401
  status, result = jobs[0]
402
  if status == constants.JOB_STATUS_SUCCESS:
403
    return result[0]
404
  else:
405
    raise errors.OpExecError(result)
422 406

  
423 407

  
424 408
def FormatError(err):

Also available in: Unified diff