Revision 3312709d
b/lib/rapi/client.py | ||
---|---|---|
1294 | 1294 |
("/%s/instances/%s/console" % |
1295 | 1295 |
(GANETI_RAPI_VERSION, instance)), None, None) |
1296 | 1296 |
|
1297 |
def GetJobs(self): |
|
1297 |
def GetJobs(self, bulk=False):
|
|
1298 | 1298 |
"""Gets all jobs for the cluster. |
1299 | 1299 |
|
1300 |
@type bulk: bool |
|
1301 |
@param bulk: Whether to return detailed information about jobs. |
|
1300 | 1302 |
@rtype: list of int |
1301 |
@return: job ids for the cluster |
|
1303 |
@return: List of job ids for the cluster or list of dicts with detailed |
|
1304 |
information about the jobs if bulk parameter was true. |
|
1302 | 1305 |
|
1303 | 1306 |
""" |
1304 |
return [int(j["id"]) |
|
1305 |
for j in self._SendRequest(HTTP_GET, |
|
1306 |
"/%s/jobs" % GANETI_RAPI_VERSION, |
|
1307 |
None, None)] |
|
1307 |
query = [] |
|
1308 |
_AppendIf(query, bulk, ("bulk", 1)) |
|
1309 |
|
|
1310 |
if bulk: |
|
1311 |
return self._SendRequest(HTTP_GET, |
|
1312 |
"/%s/jobs" % GANETI_RAPI_VERSION, |
|
1313 |
query, None) |
|
1314 |
else: |
|
1315 |
return [int(j["id"]) |
|
1316 |
for j in self._SendRequest(HTTP_GET, |
|
1317 |
"/%s/jobs" % GANETI_RAPI_VERSION, |
|
1318 |
None, None)] |
|
1308 | 1319 |
|
1309 | 1320 |
def GetJobStatus(self, job_id): |
1310 | 1321 |
"""Gets the status of a job. |
b/test/py/ganeti.rapi.client_unittest.py | ||
---|---|---|
837 | 837 |
self.assertEqual([123, 124], self.client.GetJobs()) |
838 | 838 |
self.assertHandler(rlib2.R_2_jobs) |
839 | 839 |
|
840 |
self.rapi.AddResponse('[ { "id": "123", "uri": "\\/2\\/jobs\\/123" },' |
|
841 |
' { "id": "124", "uri": "\\/2\\/jobs\\/124" } ]') |
|
842 |
self.assertEqual([{"id": "123", "uri": "/2/jobs/123"}, |
|
843 |
{"id": "124", "uri": "/2/jobs/124"}], |
|
844 |
self.client.GetJobs(bulk=True)) |
|
845 |
self.assertHandler(rlib2.R_2_jobs) |
|
846 |
self.assertBulk() |
|
847 |
|
|
840 | 848 |
def testGetJobStatus(self): |
841 | 849 |
self.rapi.AddResponse("{\"foo\": \"bar\"}") |
842 | 850 |
self.assertEqual({"foo": "bar"}, self.client.GetJobStatus(1234)) |
Also available in: Unified diff