Revision 7a1ecaed lib/jqueue.py

b/lib/jqueue.py
25 25
import Queue
26 26

  
27 27
from ganeti import opcodes
28
from ganeti import errors
28 29

  
29 30
class JobObject:
30 31
  """In-memory job representation.
......
90 91
    result = self.job_queue.get(rid, None)
91 92
    self.lock.release()
92 93
    return result
94

  
95
  def query_jobs(self, fields, names):
96
    """Query all jobs.
97

  
98
    The fields and names parameters are similar to the ones passed to
99
    the OpQueryInstances.
100

  
101
    """
102
    result = []
103
    self.lock.acquire()
104
    try:
105
      for jobj in self.job_queue.itervalues():
106
        row = []
107
        jdata = jobj.data
108
        for fname in fields:
109
          if fname == "id":
110
            row.append(jdata.job_id)
111
          elif fname == "status":
112
            row.append(jdata.status)
113
          elif fname == "opcodes":
114
            row.append(",".join([op.OP_ID for op in jdata.op_list]))
115
          else:
116
            raise errors.OpExecError("Invalid job query field '%s'" %
117
                                           fname)
118
        result.append(row)
119
    finally:
120
      self.lock.release()
121
    return result

Also available in: Unified diff