From 591e5103f0d65c8e16eb9b7f9bddf8d1193276cc Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 14 May 2010 18:25:12 +0200 Subject: [PATCH] RAPI client: Rename Get{Node,Instance}Info, add new GetInstanceInfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GetInstanceInfo should return the resource /2/instances/$name/info, but so far it returns /2/instances/$name. The same applies to GetNodeInfo, which returns /2/nodes/$name. Both names are stripped of their βInfoβ suffix and a new method, GetInstanceInfo, is added for /2/instances/$name/info. There's no equivalent for nodes. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/rapi/client.py | 22 ++++++++++++++++++++-- test/ganeti.rapi.client_unittest.py | 27 +++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/lib/rapi/client.py b/lib/rapi/client.py index 8d2772aca..298640e08 100644 --- a/lib/rapi/client.py +++ b/lib/rapi/client.py @@ -552,7 +552,7 @@ class GanetiRapiClient(object): else: return [i["id"] for i in instances] - def GetInstanceInfo(self, instance): + def GetInstance(self, instance): """Gets information about an instance. @type instance: str @@ -566,6 +566,24 @@ class GanetiRapiClient(object): ("/%s/instances/%s" % (GANETI_RAPI_VERSION, instance)), None, None) + def GetInstanceInfo(self, instance, static=None): + """Gets information about an instance. + + @type instance: string + @param instance: Instance name + @rtype: string + @return: Job ID + + """ + if static is not None: + query = [("static", static)] + else: + query = None + + return self._SendRequest(HTTP_GET, + ("/%s/instances/%s/info" % + (GANETI_RAPI_VERSION, instance)), query, None) + def CreateInstance(self, mode, name, disk_template, disks, nics, **kwargs): """Creates a new instance. @@ -902,7 +920,7 @@ class GanetiRapiClient(object): else: return [n["id"] for n in nodes] - def GetNodeInfo(self, node): + def GetNode(self, node): """Gets information about a node. @type node: str diff --git a/test/ganeti.rapi.client_unittest.py b/test/ganeti.rapi.client_unittest.py index f06a5bf93..54fd5ff23 100755 --- a/test/ganeti.rapi.client_unittest.py +++ b/test/ganeti.rapi.client_unittest.py @@ -233,12 +233,31 @@ class GanetiRapiClientTests(testutils.GanetiTestCase): self.assertHandler(rlib2.R_2_instances) self.assertBulk() - def testGetInstanceInfo(self): + def testGetInstance(self): self.rapi.AddResponse("[]") - self.assertEqual([], self.client.GetInstanceInfo("instance")) + self.assertEqual([], self.client.GetInstance("instance")) self.assertHandler(rlib2.R_2_instances_name) self.assertItems(["instance"]) + def testGetInstanceInfo(self): + self.rapi.AddResponse("21291") + self.assertEqual(21291, self.client.GetInstanceInfo("inst3")) + self.assertHandler(rlib2.R_2_instances_name_info) + self.assertItems(["inst3"]) + self.assertQuery("static", None) + + self.rapi.AddResponse("3428") + self.assertEqual(3428, self.client.GetInstanceInfo("inst31", static=False)) + self.assertHandler(rlib2.R_2_instances_name_info) + self.assertItems(["inst31"]) + self.assertQuery("static", ["0"]) + + self.rapi.AddResponse("15665") + self.assertEqual(15665, self.client.GetInstanceInfo("inst32", static=True)) + self.assertHandler(rlib2.R_2_instances_name_info) + self.assertItems(["inst32"]) + self.assertQuery("static", ["1"]) + def testCreateInstanceOldVersion(self): self.rapi.AddResponse(serializer.DumpJson([])) self.assertRaises(NotImplementedError, self.client.CreateInstance, @@ -424,9 +443,9 @@ class GanetiRapiClientTests(testutils.GanetiTestCase): self.assertHandler(rlib2.R_2_nodes) self.assertBulk() - def testGetNodeInfo(self): + def testGetNode(self): self.rapi.AddResponse("{}") - self.assertEqual({}, self.client.GetNodeInfo("node-foo")) + self.assertEqual({}, self.client.GetNode("node-foo")) self.assertHandler(rlib2.R_2_nodes_name) self.assertItems(["node-foo"]) -- GitLab