Commit 591e5103 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

RAPI client: Rename Get{Node,Instance}Info, add new GetInstanceInfo



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: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent f961e2ba
......@@ -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
......
......@@ -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"])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment