From: Zane Bitter Date: Fri, 14 Dec 2012 21:23:44 +0000 (+0100) Subject: Add a resource type list to the ReST API X-Git-Tag: 2014.1~1070 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=19402ffe8020ff6b2567a3554e61c0a691786b3b;p=openstack-build%2Fheat-build.git Add a resource type list to the ReST API Change-Id: I09f5e9fc97ef095c7ab8def8adf4dcc79c6fcd48 Signed-off-by: Zane Bitter --- diff --git a/docs/api.md b/docs/api.md index 7631124b..c5535ea0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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 -------------------- diff --git a/heat/api/openstack/v1/__init__.py b/heat/api/openstack/v1/__init__.py index 5600b51a..b819ecce 100644 --- a/heat/api/openstack/v1/__init__.py +++ b/heat/api/openstack/v1/__init__.py @@ -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", diff --git a/heat/api/openstack/v1/stacks.py b/heat/api/openstack/v1/stacks.py index c5717a91..b6d693ec 100644 --- a/heat/api/openstack/v1/stacks.py +++ b/heat/api/openstack/v1/stacks.py @@ -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): """ diff --git a/heat/tests/test_api_openstack_v1.py b/heat/tests/test_api_openstack_v1.py index c48f8e8b..4511762a 100644 --- a/heat/tests/test_api_openstack_v1.py +++ b/heat/tests/test_api_openstack_v1.py @@ -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')