The logic for this is currently mixed up with describe_stack_resources.
Change-Id: I14dadfc3ae6cde337dfb1bdee011cb7b32e5e4d9
Signed-off-by: Zane Bitter <zbitter@redhat.com>
return api.format_stack_resource(stack[resource_name])
+ @request_context
+ def find_physical_resource(self, context, physical_resource_id):
+ """
+ Return an identifier for the resource with the specified physical
+ resource ID.
+ arg1 -> RPC context.
+ arg2 -> The physical resource ID to look up.
+ """
+ rs = db_api.resource_get_by_physical_resource_id(context,
+ physical_resource_id)
+ if not rs:
+ msg = "The specified PhysicalResourceId doesn't exist"
+ raise AttributeError(msg)
+
+ stack = parser.Stack.load(context, stack=rs.stack)
+ resource = stack[rs.name]
+
+ return dict(resource.identifier())
+
@request_context
def describe_stack_resources(self, context, stack_identity,
physical_resource_id, logical_resource_id):
resource_name=resource_name),
topic=_engine_topic(self.topic, ctxt, None))
+ def find_physical_resource(self, ctxt, physical_resource_id):
+ """
+ Return an identifier for the resource with the specified physical
+ resource ID.
+ :param ctxt RPC context.
+ :param physcial_resource_id The physical resource ID to look up.
+ """
+ return self.call(ctxt,
+ self.make_msg(
+ 'find_physical_resource',
+ physical_resource_id=physical_resource_id),
+ topic=_engine_topic(self.topic, ctxt, None))
+
def describe_stack_resources(self, ctxt, stack_identity,
physical_resource_id, logical_resource_id):
return self.call(ctxt, self.make_msg('describe_stack_resources',
from heat.tests.v1_1 import fakes
import heat.engine.api as engine_api
import heat.db as db_api
+from heat.common import identifier
from heat.common import template_format
from heat.engine import parser
from heat.engine import service
self.man.describe_stack_resources,
self.ctx, None, 'foo', 'WebServer')
+ def test_find_physical_resource(self):
+ resources = self.man.describe_stack_resources(self.ctx,
+ self.stack_identity,
+ None, None)
+ phys_id = resources[0]['physical_resource_id']
+
+ result = self.man.find_physical_resource(self.ctx, phys_id)
+ self.assertTrue(isinstance(result, dict))
+ resource_identity = identifier.ResourceIdentifier(**result)
+ self.assertEqual(resource_identity.stack(), self.stack_identity)
+ self.assertEqual(resource_identity.resource_name, 'WebServer')
+
+ def test_find_physical_resource_nonexist(self):
+ self.assertRaises(AttributeError,
+ self.man.find_physical_resource,
+ self.ctx, 'foo')
+
def test_stack_resources_list(self):
resources = self.man.list_stack_resources(self.ctx,
self.stack_identity)
stack_identity=self.identity,
resource_name='LogicalResourceId')
+ def test_find_physical_resource(self):
+ self._test_engine_api('find_physical_resource', 'call',
+ physical_resource_id=u'404d-a85b-5315293e67de')
+
def test_describe_stack_resources(self):
self._test_engine_api('describe_stack_resources', 'call',
stack_identity=self.identity,