From: Zane Bitter Date: Fri, 14 Dec 2012 21:23:44 +0000 (+0100) Subject: Add an RPC API to list resource types X-Git-Tag: 2014.1~1071 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e2a67113c261c24b975bbb093bfbf64cdc0b9f2a;p=openstack-build%2Fheat-build.git Add an RPC API to list resource types Change-Id: I0218dcebf9213887e9b7883e6bba9b6b54a6e6ad Signed-off-by: Zane Bitter --- diff --git a/heat/engine/resource.py b/heat/engine/resource.py index bfca7a53..a9f58036 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -31,7 +31,13 @@ logger = logging.getLogger(__name__) _resource_classes = {} +def get_types(): + '''Return an iterator over the list of valid resource types''' + return iter(_resource_classes) + + def get_class(resource_type): + '''Return the Resource class for a given resource type''' return _resource_classes.get(resource_type) diff --git a/heat/engine/service.py b/heat/engine/service.py index d13a6357..565258a2 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -23,6 +23,7 @@ from heat.engine.event import Event from heat.common import exception from heat.common import identifier from heat.engine import parser +from heat.engine import resource from heat.engine import resources from heat.engine import watchrule @@ -336,6 +337,13 @@ class EngineService(service.Service): self.tg.add_thread(stack.delete) return None + def list_resource_types(self, context): + """ + Get a list of supported resource types. + arg1 -> RPC context. + """ + return list(resource.get_types()) + @request_context def list_events(self, context, stack_identity): """ diff --git a/heat/rpc/client.py b/heat/rpc/client.py index 9036ed4e..5fa83747 100644 --- a/heat/rpc/client.py +++ b/heat/rpc/client.py @@ -165,6 +165,15 @@ class EngineClient(heat.openstack.common.rpc.proxy.RpcProxy): stack_identity=stack_identity), topic=_engine_topic(self.topic, ctxt, None)) + def list_resource_types(self, ctxt): + """ + Get a list of valid resource types. + + :param ctxt: RPC context. + """ + return self.call(ctxt, self.make_msg('list_resource_types'), + topic=_engine_topic(self.topic, ctxt, None)) + def list_events(self, ctxt, stack_identity): """ The list_events method lists all events associated with a given stack. diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 8f4f831d..d94d6b51 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -505,6 +505,11 @@ class stackServiceTest(unittest.TestCase): self.assertNotEqual(s['description'].find('WordPress'), -1) self.assertTrue('parameters' in s) + def test_list_resource_types(self): + resources = self.man.list_resource_types(self.ctx) + self.assertTrue(isinstance(resources, list)) + self.assertTrue('AWS::EC2::Instance' in resources) + def test_stack_resource_describe(self): r = self.man.describe_stack_resource(self.ctx, self.stack_identity, 'WebServer')