]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add a resource type list to the ReST API
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:27:28 +0000 (22:27 +0100)
Change-Id: I09f5e9fc97ef095c7ab8def8adf4dcc79c6fcd48
Signed-off-by: Zane Bitter <zbitter@redhat.com>
docs/api.md
heat/api/openstack/v1/__init__.py
heat/api/openstack/v1/stacks.py
heat/tests/test_api_openstack_v1.py

index 7631124bf44d3902ee9354a0fe3b9148d37cae6e..c5535ea079803f946807265d3ea6f025038c6cae 100644 (file)
@@ -158,6 +158,17 @@ Parameters:
 * `template_url` The URL of the template to validate
 * `template` A JSON template to validate - this takes precendence over the `template_url` if both are supplied.
 
+List Valid Resource Types
+-------------------------
+
+```
+GET /v1/{tenant_id}/resource_types
+```
+
+Parameters:
+
+* `tenant_id` The unique identifier of the tenant or account
+
 List Stack Resources
 --------------------
 
index 5600b51ac94c2dacf419ed28a555f039f1c5089f..b819ecce33eee6a77ba4c21a8ed20f40fc2ab410 100644 (file)
@@ -47,6 +47,10 @@ class API(wsgi.Router):
                                  "/validate",
                                  action="validate_template",
                                  conditions={'method': 'POST'})
+            stack_mapper.connect("resource_types",
+                                 "/resource_types",
+                                 action="list_resource_types",
+                                 conditions={'method': 'GET'})
 
             # Stack collection
             stack_mapper.connect("stack_index",
index c5717a91562e4b9dfbe7219f6ff58a7b5a7ac0fd..b6d693ec9db95551f4774e392c113f08404c03c3 100644 (file)
@@ -305,6 +305,19 @@ class StackController(object):
 
         return result
 
+    @util.tenant_local
+    def list_resource_types(self, req):
+        """
+        Returns a list of valid resource types that may be used in a template.
+        """
+
+        try:
+            types = self.engine.list_resource_types(req.context)
+        except rpc_common.RemoteError as ex:
+            raise exc.HTTPInternalServerError(explanation=str(ex))
+
+        return types
+
 
 def create_resource(options):
     """
index c48f8e8b69db6c54bee507c498403ef17063b305..4511762aaad776ea4c49dd8a0694cefb3709aed3 100644 (file)
@@ -793,6 +793,45 @@ class StackControllerTest(ControllerTest, unittest.TestCase):
                           req, tenant_id=self.tenant, body=body)
         self.m.VerifyAll()
 
+    def test_list_resource_types(self):
+        req = self._get('/resource_types')
+
+        engine_response = ['AWS::EC2::Instance',
+                           'AWS::EC2::EIP',
+                           'AWS::EC2::EIPAssociation']
+
+        self.m.StubOutWithMock(rpc, 'call')
+        rpc.call(req.context, self.topic,
+                 {'method': 'list_resource_types',
+                  'args': {},
+                  'version': self.api_version},
+                 None).AndReturn(engine_response)
+        self.m.ReplayAll()
+        response = self.controller.list_resource_types(req,
+                                                       tenant_id=self.tenant)
+        self.assertEqual(response, engine_response)
+        self.m.VerifyAll()
+
+    def test_list_resource_types_error(self):
+        req = self._get('/resource_types')
+
+        engine_response = ['AWS::EC2::Instance',
+                           'AWS::EC2::EIP',
+                           'AWS::EC2::EIPAssociation']
+
+        self.m.StubOutWithMock(rpc, 'call')
+        rpc.call(req.context, self.topic,
+                 {'method': 'list_resource_types',
+                  'args': {},
+                  'version': self.api_version},
+                 None).AndRaise(rpc_common.RemoteError("ValueError"))
+        self.m.ReplayAll()
+
+        self.assertRaises(webob.exc.HTTPInternalServerError,
+                          self.controller.list_resource_types,
+                          req, tenant_id=self.tenant)
+        self.m.VerifyAll()
+
 
 @attr(tag=['unit', 'api-openstack-v1', 'ResourceController'])
 @attr(speed='fast')