* `stack_name` The name of the stack to look up
* `stack_id` The unique identifier of the stack to look up
+Find Stack Resources by Name
+----------------------------
+
+```
+GET /v1/{tenant_id}/stacks/{stack_name}/resources
+```
+
+Parameters:
+
+* `stack_name` The name of the stack to look up
+
+Result:
+
+```
+HTTP/1.1 302 Found
+Location: http://heat.example.com:8004/v1/{tenant_id}/stacks/{stack_name}/{stack_id}/resources
+```
+
+This is a shortcut to go directly to the list of stack resources when only the stack name is known.
+
Get Resource
------------
stack_mapper.connect("stack_lookup",
"/stacks/{stack_name}",
action="lookup")
+ stack_mapper.connect("stack_lookup_subpath",
+ "/stacks/{stack_name}/{path:resources}",
+ action="lookup",
+ conditions={'method': 'GET'})
stack_mapper.connect("stack_show",
"/stacks/{stack_name}/{stack_id}",
action="show",
raise exc.HTTPCreated(location=util.make_url(req, result))
@util.tenant_local
- def lookup(self, req, stack_name, body=None):
+ def lookup(self, req, stack_name, path='', body=None):
"""
Redirect to the canonical URL for a stack
"""
except rpc_common.RemoteError as ex:
return util.remote_error(ex)
- raise exc.HTTPFound(location=util.make_url(req, identity))
+ location = util.make_url(req, identity)
+ if path:
+ location = '/'.join([location, path])
+
+ raise exc.HTTPFound(location=location)
@util.identified_stack
def show(self, req, identity):
req, tenant_id=self.tenant, stack_name=stack_name)
self.m.VerifyAll()
+ def test_lookup_resource(self):
+ identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '1')
+
+ req = self._get('/stacks/%(stack_name)s/resources' % identity)
+
+ self.m.StubOutWithMock(rpc, 'call')
+ rpc.call(req.context, self.topic,
+ {'method': 'identify_stack',
+ 'args': {'stack_name': identity.stack_name},
+ 'version': self.api_version},
+ None).AndReturn(identity)
+
+ self.m.ReplayAll()
+
+ try:
+ result = self.controller.lookup(req, tenant_id=identity.tenant,
+ stack_name=identity.stack_name,
+ path='resources')
+ except webob.exc.HTTPFound as found:
+ self.assertEqual(found.location, self._url(identity) +
+ '/resources')
+ else:
+ self.fail('No redirect generated')
+ self.m.VerifyAll()
+
+ def test_lookup_resource_nonexistant(self):
+ stack_name = 'wibble'
+
+ req = self._get('/stacks/%(stack_name)s/resources' % locals())
+
+ self.m.StubOutWithMock(rpc, 'call')
+ rpc.call(req.context, self.topic,
+ {'method': 'identify_stack',
+ 'args': {'stack_name': stack_name},
+ 'version': self.api_version},
+ None).AndRaise(rpc_common.RemoteError("AttributeError"))
+ self.m.ReplayAll()
+
+ self.assertRaises(webob.exc.HTTPNotFound, self.controller.lookup,
+ req, tenant_id=self.tenant, stack_name=stack_name,
+ path='resources')
+ self.m.VerifyAll()
+
def test_show(self):
identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6')