Merge "Support 'with_attr' parameter for resource-show"
This commit is contained in:
@@ -80,6 +80,19 @@ class ResourceManagerTest(testtools.TestCase):
|
|||||||
manager.get(**fields)
|
manager.get(**fields)
|
||||||
self.m.VerifyAll()
|
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):
|
def test_get_with_unicode_resource_name(self):
|
||||||
fields = {'stack_id': 'teststack',
|
fields = {'stack_id': 'teststack',
|
||||||
'resource_name': u'\u5de5\u4f5c'}
|
'resource_name': u'\u5de5\u4f5c'}
|
||||||
|
@@ -3271,7 +3271,7 @@ class ShellTestResources(ShellBase):
|
|||||||
for field in required:
|
for field in required:
|
||||||
self.assertRegexpMatches(resource_list_text, field)
|
self.assertRegexpMatches(resource_list_text, field)
|
||||||
|
|
||||||
def test_resource_show(self):
|
def test_resource_show_with_attrs(self):
|
||||||
self.register_keystone_auth_fixture()
|
self.register_keystone_auth_fixture()
|
||||||
resp_dict = {"resource":
|
resp_dict = {"resource":
|
||||||
{"description": "",
|
{"description": "",
|
||||||
@@ -3287,7 +3287,11 @@ class ShellTestResources(ShellBase):
|
|||||||
"resource_status": "CREATE_COMPLETE",
|
"resource_status": "CREATE_COMPLETE",
|
||||||
"resource_status_reason": "state changed",
|
"resource_status_reason": "state changed",
|
||||||
"resource_type": "OS::Nova::Server",
|
"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(
|
resp = fakes.FakeHTTPResponse(
|
||||||
200,
|
200,
|
||||||
'OK',
|
'OK',
|
||||||
@@ -3296,7 +3300,7 @@ class ShellTestResources(ShellBase):
|
|||||||
stack_id = 'teststack/1'
|
stack_id = 'teststack/1'
|
||||||
resource_name = 'aResource'
|
resource_name = 'aResource'
|
||||||
http.SessionClient.request(
|
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(stack_id, ''),
|
||||||
parse.quote(encodeutils.safe_encode(
|
parse.quote(encodeutils.safe_encode(
|
||||||
@@ -3305,7 +3309,9 @@ class ShellTestResources(ShellBase):
|
|||||||
|
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
resource_show_text = self.shell('resource-show {0} {1}'.format(
|
resource_show_text = self.shell(
|
||||||
|
'resource-show {0} {1} --with-attr attr_a '
|
||||||
|
'--with-attr attr_b'.format(
|
||||||
stack_id, resource_name))
|
stack_id, resource_name))
|
||||||
|
|
||||||
required = [
|
required = [
|
||||||
|
@@ -57,16 +57,21 @@ class ResourceManager(stacks.StackChildManager):
|
|||||||
url += '?nested_depth=%s' % nested_depth
|
url += '?nested_depth=%s' % nested_depth
|
||||||
return self._list(url, "resources")
|
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.
|
"""Get the details for a specific resource.
|
||||||
|
|
||||||
:param stack_id: ID of stack containing the resource
|
:param stack_id: ID of stack containing the resource
|
||||||
:param resource_name: ID of resource to get the details for
|
: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)
|
stack_id = self._resolve_stack_id(stack_id)
|
||||||
url_str = '/stacks/%s/resources/%s' % (
|
url_str = '/stacks/%s/resources/%s' % (
|
||||||
parse.quote(stack_id, ''),
|
parse.quote(stack_id, ''),
|
||||||
parse.quote(encodeutils.safe_encode(resource_name), ''))
|
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)
|
resp = self.client.get(url_str)
|
||||||
body = utils.get_response_body(resp)
|
body = utils.get_response_body(resp)
|
||||||
return Resource(self, body.get('resource'))
|
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.'))
|
help=_('Name or ID of stack to show the resource for.'))
|
||||||
@utils.arg('resource', metavar='<RESOURCE>',
|
@utils.arg('resource', metavar='<RESOURCE>',
|
||||||
help=_('Name of the resource to show the details for.'))
|
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):
|
def do_resource_show(hc, args):
|
||||||
'''Describe the resource.'''
|
'''Describe the resource.'''
|
||||||
fields = {'stack_id': args.id,
|
fields = {'stack_id': args.id,
|
||||||
'resource_name': args.resource}
|
'resource_name': args.resource}
|
||||||
|
if args.with_attr:
|
||||||
|
fields['with_attr'] = list(args.with_attr)
|
||||||
try:
|
try:
|
||||||
resource = hc.resources.get(**fields)
|
resource = hc.resources.get(**fields)
|
||||||
except exc.HTTPNotFound:
|
except exc.HTTPNotFound:
|
||||||
|
Reference in New Issue
Block a user