Implement an identifier stack_path()

This returns stack_name/stack_id, which is the form that needs to be
used with heatclient to avoid doing an extra stack lookup API call.

See the next change in this series to see this in use.

Change-Id: I41dcb732d36d702b7583b5e877fd074f86445a03
Related-Bug: #1291097
This commit is contained in:
Steve Baker 2014-03-17 13:31:47 +13:00
parent a63ba7db5b
commit acdc77e1c9
2 changed files with 16 additions and 4 deletions

View File

@ -115,10 +115,18 @@ class HeatIdentifier(collections.Mapping):
in the form:
stacks/<stack_name>/<stack_id><path>
'''
return 'stacks/%s/%s%s' % (urlutils.quote(self.stack_name, ''),
urlutils.quote(self.stack_id, ''),
urlutils.quote(strutils.safe_encode(
self.path)))
return 'stacks/%s%s' % (self.stack_path(),
urlutils.quote(strutils.safe_encode(
self.path)))
def stack_path(self):
'''
Return a URL-encoded path segment of a URL,
in the form:
<stack_name>/<stack_id>
'''
return '%s/%s' % (urlutils.quote(self.stack_name, ''),
urlutils.quote(self.stack_id, ''))
def _path_components(self):
'''Return a list of the path components.'''

View File

@ -48,6 +48,10 @@ class IdentifierTest(testtools.TestCase):
hi.identity['foo'] = 'bar'
self.assertRaises(KeyError, lambda o, k: o[k], hi, 'foo')
def test_stack_path(self):
hi = identifier.HeatIdentifier('t', 's', 'i', 'p')
self.assertEqual('s/i', hi.stack_path())
def test_arn(self):
hi = identifier.HeatIdentifier('t', 's', 'i', 'p')
self.assertEqual('arn:openstack:heat::t:stacks/s/i/p', hi.arn())