Add a resource type list to the ReST API
Change-Id: I09f5e9fc97ef095c7ab8def8adf4dcc79c6fcd48 Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
parent
e2a67113c2
commit
19402ffe80
11
docs/api.md
11
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
|
||||
--------------------
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user