Expose bulk parameter for GetJobs in RAPI client
authorLeon Handreke <lhandreke@google.com>
Wed, 10 Jul 2013 13:46:04 +0000 (14:46 +0100)
committerKlaus Aehlig <aehlig@google.com>
Wed, 10 Jul 2013 14:21:00 +0000 (16:21 +0200)
This patch exposes the bulk argument of the jobs resource on
the RAPI python wrapper, making it possible to retrieve status
information about all jobs with a single call.

Signed-off-by: Leon Handreke <lhandreke@google.com>
Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/rapi/client.py
test/py/ganeti.rapi.client_unittest.py

index eb3c21e..35b1191 100644 (file)
@@ -1294,17 +1294,28 @@ class GanetiRapiClient(object): # pylint: disable=R0904
                              ("/%s/instances/%s/console" %
                               (GANETI_RAPI_VERSION, instance)), None, None)
 
-  def GetJobs(self):
+  def GetJobs(self, bulk=False):
     """Gets all jobs for the cluster.
 
+    @type bulk: bool
+    @param bulk: Whether to return detailed information about jobs.
     @rtype: list of int
-    @return: job ids for the cluster
+    @return: List of job ids for the cluster or list of dicts with detailed
+             information about the jobs if bulk parameter was true.
 
     """
-    return [int(j["id"])
-            for j in self._SendRequest(HTTP_GET,
-                                       "/%s/jobs" % GANETI_RAPI_VERSION,
-                                       None, None)]
+    query = []
+    _AppendIf(query, bulk, ("bulk", 1))
+
+    if bulk:
+      return self._SendRequest(HTTP_GET,
+                               "/%s/jobs" % GANETI_RAPI_VERSION,
+                               query, None)
+    else:
+      return [int(j["id"])
+              for j in self._SendRequest(HTTP_GET,
+                                         "/%s/jobs" % GANETI_RAPI_VERSION,
+                                         None, None)]
 
   def GetJobStatus(self, job_id):
     """Gets the status of a job.
index 555ee21..a219673 100755 (executable)
@@ -837,6 +837,14 @@ class GanetiRapiClientTests(testutils.GanetiTestCase):
     self.assertEqual([123, 124], self.client.GetJobs())
     self.assertHandler(rlib2.R_2_jobs)
 
+    self.rapi.AddResponse('[ { "id": "123", "uri": "\\/2\\/jobs\\/123" },'
+                          '  { "id": "124", "uri": "\\/2\\/jobs\\/124" } ]')
+    self.assertEqual([{"id": "123", "uri": "/2/jobs/123"},
+                      {"id": "124", "uri": "/2/jobs/124"}],
+                      self.client.GetJobs(bulk=True))
+    self.assertHandler(rlib2.R_2_jobs)
+    self.assertBulk()
+
   def testGetJobStatus(self):
     self.rapi.AddResponse("{\"foo\": \"bar\"}")
     self.assertEqual({"foo": "bar"}, self.client.GetJobStatus(1234))