Merge "Support 'with_attr' parameter for resource-show"
This commit is contained in:
@@ -80,6 +80,19 @@ class ResourceManagerTest(testtools.TestCase):
|
||||
manager.get(**fields)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_get_with_attr(self):
|
||||
fields = {'stack_id': 'teststack',
|
||||
'resource_name': 'testresource',
|
||||
'with_attr': ['attr_a', 'attr_b']}
|
||||
expect = ('GET',
|
||||
'/stacks/teststack%2Fabcd1234/resources'
|
||||
'/testresource?with_attr=attr_a&with_attr=attr_b')
|
||||
key = 'resource'
|
||||
|
||||
manager = self._base_test(expect, key)
|
||||
manager.get(**fields)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_get_with_unicode_resource_name(self):
|
||||
fields = {'stack_id': 'teststack',
|
||||
'resource_name': u'\u5de5\u4f5c'}
|
||||
|
@@ -3271,7 +3271,7 @@ class ShellTestResources(ShellBase):
|
||||
for field in required:
|
||||
self.assertRegexpMatches(resource_list_text, field)
|
||||
|
||||
def test_resource_show(self):
|
||||
def test_resource_show_with_attrs(self):
|
||||
self.register_keystone_auth_fixture()
|
||||
resp_dict = {"resource":
|
||||
{"description": "",
|
||||
@@ -3287,7 +3287,11 @@ class ShellTestResources(ShellBase):
|
||||
"resource_status": "CREATE_COMPLETE",
|
||||
"resource_status_reason": "state changed",
|
||||
"resource_type": "OS::Nova::Server",
|
||||
"updated_time": "2014-01-06T16:14:26Z"}}
|
||||
"updated_time": "2014-01-06T16:14:26Z",
|
||||
"creation_time": "2014-01-06T16:14:26Z",
|
||||
"attributes": {
|
||||
"attr_a": "value_of_attr_a",
|
||||
"attr_b": "value_of_attr_b"}}}
|
||||
resp = fakes.FakeHTTPResponse(
|
||||
200,
|
||||
'OK',
|
||||
@@ -3296,7 +3300,7 @@ class ShellTestResources(ShellBase):
|
||||
stack_id = 'teststack/1'
|
||||
resource_name = 'aResource'
|
||||
http.SessionClient.request(
|
||||
'/stacks/%s/resources/%s' %
|
||||
'/stacks/%s/resources/%s?with_attr=attr_a&with_attr=attr_b' %
|
||||
(
|
||||
parse.quote(stack_id, ''),
|
||||
parse.quote(encodeutils.safe_encode(
|
||||
@@ -3305,8 +3309,10 @@ class ShellTestResources(ShellBase):
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
resource_show_text = self.shell('resource-show {0} {1}'.format(
|
||||
stack_id, resource_name))
|
||||
resource_show_text = self.shell(
|
||||
'resource-show {0} {1} --with-attr attr_a '
|
||||
'--with-attr attr_b'.format(
|
||||
stack_id, resource_name))
|
||||
|
||||
required = [
|
||||
'description',
|
||||
|
@@ -57,16 +57,21 @@ class ResourceManager(stacks.StackChildManager):
|
||||
url += '?nested_depth=%s' % nested_depth
|
||||
return self._list(url, "resources")
|
||||
|
||||
def get(self, stack_id, resource_name):
|
||||
def get(self, stack_id, resource_name, with_attr=None):
|
||||
"""Get the details for a specific resource.
|
||||
|
||||
:param stack_id: ID of stack containing the resource
|
||||
:param resource_name: ID of resource to get the details for
|
||||
:param with_attr: Attributes to show
|
||||
"""
|
||||
stack_id = self._resolve_stack_id(stack_id)
|
||||
url_str = '/stacks/%s/resources/%s' % (
|
||||
parse.quote(stack_id, ''),
|
||||
parse.quote(encodeutils.safe_encode(resource_name), ''))
|
||||
if with_attr:
|
||||
params = {'with_attr': with_attr}
|
||||
url_str += '?%s' % parse.urlencode(params, True)
|
||||
|
||||
resp = self.client.get(url_str)
|
||||
body = utils.get_response_body(resp)
|
||||
return Resource(self, body.get('resource'))
|
||||
|
@@ -764,10 +764,16 @@ def do_resource_list(hc, args):
|
||||
help=_('Name or ID of stack to show the resource for.'))
|
||||
@utils.arg('resource', metavar='<RESOURCE>',
|
||||
help=_('Name of the resource to show the details for.'))
|
||||
@utils.arg('-a', '--with-attr', metavar='<ATTRIBUTE>',
|
||||
help=_('Attribute to show, it can be specified '
|
||||
'multiple times.'),
|
||||
action='append')
|
||||
def do_resource_show(hc, args):
|
||||
'''Describe the resource.'''
|
||||
fields = {'stack_id': args.id,
|
||||
'resource_name': args.resource}
|
||||
if args.with_attr:
|
||||
fields['with_attr'] = list(args.with_attr)
|
||||
try:
|
||||
resource = hc.resources.get(**fields)
|
||||
except exc.HTTPNotFound:
|
||||
|
Reference in New Issue
Block a user