Optimize get_by_instance_uuid

Previously this method was issuing two requests: One filtering the node
by instance_uuid and another to get all the informations about that
node. This patch optimize it by using the /detail flag which will filter
the node by the instance_uuid and return all informations in one request.

Change-Id: Ia22c5012af12b131d5a6601653d704b5a9f39d82
This commit is contained in:
Lucas Alvares Gomes 2014-08-12 10:21:00 +01:00
parent 8160da5b3b
commit 68e24fd5db
2 changed files with 6 additions and 8 deletions
ironicclient

@ -130,7 +130,7 @@ fake_responses = {
{"nodes": [NODE2]},
)
},
'/v1/nodes/?instance_uuid=%s' % NODE2['instance_uuid']:
'/v1/nodes/detail?instance_uuid=%s' % NODE2['instance_uuid']:
{
'GET': (
{},
@ -383,9 +383,8 @@ class NodeManagerTest(testtools.TestCase):
def test_node_show_by_instance(self):
node = self.mgr.get_by_instance_uuid(NODE2['instance_uuid'])
expect = [
('GET', '/v1/nodes/?instance_uuid=%s' % NODE2['instance_uuid'],
{}, None),
('GET', '/v1/nodes/%s' % NODE2['uuid'], {}, None),
('GET', '/v1/nodes/detail?instance_uuid=%s' %
NODE2['instance_uuid'], {}, None),
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(NODE2['uuid'], node.uuid)

@ -130,14 +130,13 @@ class NodeManager(base.Manager):
return None
def get_by_instance_uuid(self, instance_uuid):
path = "?instance_uuid=%s" % instance_uuid
path = "detail?instance_uuid=%s" % instance_uuid
nodes = self._list(self._path(path), 'nodes')
# get all the details of the node assuming that
# filtering by instance_uuid returns a collection
# of one node if successful.
if len(nodes) > 0:
uuid = getattr(nodes[0], 'uuid')
return self.get(uuid)
if len(nodes) == 1:
return nodes[0]
else:
raise exc.NotFound()