From: Zane Bitter Date: Wed, 5 Sep 2012 19:51:25 +0000 (+0200) Subject: Add an identify_stack RPC call X-Git-Tag: 2014.1~1472 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=052a6a431144f8d249c562e8a633e3e0afea12d5;p=openstack-build%2Fheat-build.git Add an identify_stack RPC call This call converts a stack name into a fully-qualified stack identifier. This allows us to, e.g., add support for keeping deleted stacks around in the database while still allowing stack names to be reused, since the deleted stacks can be referenced using this ID. Change-Id: Ide19841a92a25d2f6172f19c2627d24ab6d2fd63 Signed-off-by: Zane Bitter --- diff --git a/heat/engine/manager.py b/heat/engine/manager.py index a69564a1..65a0d85e 100644 --- a/heat/engine/manager.py +++ b/heat/engine/manager.py @@ -61,6 +61,22 @@ class EngineManager(manager.Manager): """Load configuration options and connect to the hypervisor.""" pass + def identify_stack(self, context, stack_name): + """ + The identify_stack method returns the full stack identifier for a + single, live stack given the stack name. + arg1 -> RPC context. + arg2 -> Name of the stack to look up. + """ + auth.authenticate(context) + + s = db_api.stack_get_by_name(context, stack_name) + if s: + stack = parser.Stack.load(context, s.id) + return stack.identifier() + else: + raise AttributeError('Unknown stack name') + def show_stack(self, context, stack_name, params): """ The show_stack method returns the attributes of one stack. diff --git a/heat/engine/rpcapi.py b/heat/engine/rpcapi.py index 3586b9c5..b731e7b0 100644 --- a/heat/engine/rpcapi.py +++ b/heat/engine/rpcapi.py @@ -57,6 +57,21 @@ class EngineAPI(heat.openstack.common.rpc.proxy.RpcProxy): topic=FLAGS.engine_topic, default_version=self.BASE_RPC_API_VERSION) + def identify_stack(self, ctxt, stack_name): + """ + The identify_stack method returns the full stack identifier for a + single, live stack given the stack name. + + :param ctxt: RPC context. + :param stack_name: Name of the stack you want to see, + or None to see all + """ + return self.call(ctxt, self.make_msg('identify_stack', + stack_name=stack_name, + topic=_engine_topic(self.topic, + ctxt, + None))) + def show_stack(self, ctxt, stack_name, params): """ The show_stack method returns the attributes of one stack. diff --git a/heat/tests/test_engine_manager.py b/heat/tests/test_engine_manager.py index e853f1a0..59e82791 100644 --- a/heat/tests/test_engine_manager.py +++ b/heat/tests/test_engine_manager.py @@ -142,6 +142,7 @@ class stackManagerTest(unittest.TestCase): stack.store() stack.create() cls.stack = stack + cls.stack_identity = stack.identifier() m.UnsetStubs() @@ -169,6 +170,14 @@ class stackManagerTest(unittest.TestCase): def tearDown(self): self.m.UnsetStubs() + def test_stack_identify(self): + identity = self.man.identify_stack(self.ctx, self.stack_name) + self.assertEqual(identity, self.stack_identity) + + def test_stack_identify_nonexist(self): + self.assertRaises(AttributeError, self.man.identify_stack, + self.ctx, 'wibble') + def test_stack_event_list(self): el = self.man.list_events(self.ctx, self.stack_name, {})