]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add an RPC API to list resource types
authorZane Bitter <zbitter@redhat.com>
Fri, 14 Dec 2012 21:23:44 +0000 (22:23 +0100)
committerZane Bitter <zbitter@redhat.com>
Fri, 14 Dec 2012 21:26:31 +0000 (22:26 +0100)
Change-Id: I0218dcebf9213887e9b7883e6bba9b6b54a6e6ad
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/resource.py
heat/engine/service.py
heat/rpc/client.py
heat/tests/test_engine_service.py

index bfca7a53e000ed4ae646e7adb8c9e9492ee88f95..a9f580363cd23d1ac719810093529592ff7006c8 100644 (file)
@@ -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)
 
 
index d13a6357a18e128de598314a70736c03c86a0079..565258a2098ff0451edbd7ebb64cbfe3821e0db2 100644 (file)
@@ -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):
         """
index 9036ed4efe76e9f13025b4e19722fb717c4230c8..5fa837477b8b3a9c687ca5b2884c96089083f0d8 100644 (file)
@@ -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.
index 8f4f831df6f8da09daa3c41670121b066578cce0..d94d6b5147302d118cacb68ed3af1da813f0634b 100644 (file)
@@ -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')