Merge "osc resource-type-list description option"
This commit is contained in:
commit
b8407bd941
@ -90,6 +90,13 @@ class ResourceTypeList(lister.Lister):
|
||||
'name, version or support_status'),
|
||||
action='append'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help=_('Show resource types with corresponding description of '
|
||||
'each resource type.')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -101,7 +108,13 @@ class ResourceTypeList(lister.Lister):
|
||||
|
||||
def _list_resourcetypes(heat_client, parsed_args):
|
||||
resource_types = heat_client.resource_types.list(
|
||||
filters=heat_utils.format_parameters(parsed_args.filter))
|
||||
columns = ['Resource Type']
|
||||
rows = sorted([r.resource_type] for r in resource_types)
|
||||
return (columns, rows)
|
||||
filters=heat_utils.format_parameters(parsed_args.filter),
|
||||
with_description=parsed_args.long
|
||||
)
|
||||
if parsed_args.long:
|
||||
columns = ['Resource Type', 'Description']
|
||||
rows = sorted([r.resource_type, r.description] for r in resource_types)
|
||||
else:
|
||||
columns = ['Resource Type']
|
||||
rows = sorted([r.resource_type] for r in resource_types)
|
||||
return columns, rows
|
||||
|
@ -101,9 +101,13 @@ class TestTypeList(TestResourceType):
|
||||
|
||||
expected_columns = ['Resource Type']
|
||||
list_response = [
|
||||
resource_types.ResourceType(None, 'BBB'),
|
||||
resource_types.ResourceType(None, 'AAA'),
|
||||
resource_types.ResourceType(None, 'CCC')
|
||||
resource_types.ResourceType(None, {'resource_type': 'BBB',
|
||||
'description': 'This is BBB'}),
|
||||
resource_types.ResourceType(None, {'resource_type': 'AAA',
|
||||
'description': 'Well done'}),
|
||||
resource_types.ResourceType(None,
|
||||
{'resource_type': 'CCC',
|
||||
'description': 'No description given'})
|
||||
]
|
||||
expected_rows = [
|
||||
['AAA'],
|
||||
@ -122,7 +126,7 @@ class TestTypeList(TestResourceType):
|
||||
columns, rows = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.mock_client.resource_types.list.assert_called_with(
|
||||
filters={})
|
||||
filters={}, with_description=False)
|
||||
self.assertEqual(self.expected_columns, columns)
|
||||
self.assertEqual(self.expected_rows, rows)
|
||||
|
||||
@ -132,7 +136,7 @@ class TestTypeList(TestResourceType):
|
||||
columns, rows = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.mock_client.resource_types.list.assert_called_once_with(
|
||||
filters={'name': 'B'})
|
||||
filters={'name': 'B'}, with_description=False)
|
||||
self.assertEqual(self.expected_columns, columns)
|
||||
self.assertEqual(self.expected_rows, rows)
|
||||
|
||||
@ -142,6 +146,19 @@ class TestTypeList(TestResourceType):
|
||||
columns, rows = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.mock_client.resource_types.list.assert_called_once_with(
|
||||
filters={'name': 'B', 'version': '123'})
|
||||
filters={'name': 'B', 'version': '123'}, with_description=False)
|
||||
self.assertEqual(self.expected_columns, columns)
|
||||
self.assertEqual(self.expected_rows, rows)
|
||||
|
||||
def test_resourcetype_list_with_description(self):
|
||||
arglist = ['--long']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
columns, rows = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.mock_client.resource_types.list.assert_called_once_with(
|
||||
filters={}, with_description=True)
|
||||
self.assertEqual(['Resource Type', 'Description'], columns)
|
||||
self.assertEqual([['AAA', 'Well done'],
|
||||
['BBB', 'This is BBB'],
|
||||
['CCC', 'No description given']],
|
||||
rows)
|
||||
|
@ -10,6 +10,9 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from heatclient.common import utils
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
@ -20,13 +23,20 @@ from heatclient.openstack.common.apiclient import base
|
||||
|
||||
class ResourceType(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<ResourceType %s>" % self._info
|
||||
if isinstance(self._info, six.string_types):
|
||||
return "<ResourceType %s>" % self._info
|
||||
else:
|
||||
return "<ResourceType %s>" % self._info.get('resource_type')
|
||||
|
||||
def data(self, **kwargs):
|
||||
return self.manager.data(self, **kwargs)
|
||||
|
||||
def _add_details(self, info):
|
||||
self.resource_type = info
|
||||
if isinstance(info, six.string_types):
|
||||
self.resource_type = info
|
||||
elif isinstance(info, dict):
|
||||
self.resource_type = info.get('resource_type')
|
||||
self.description = info.get('description')
|
||||
|
||||
|
||||
class ResourceTypeManager(base.BaseManager):
|
||||
@ -44,6 +54,10 @@ class ResourceTypeManager(base.BaseManager):
|
||||
if 'filters' in kwargs:
|
||||
filters = kwargs.pop('filters')
|
||||
params.update(filters)
|
||||
if 'with_description' in kwargs:
|
||||
with_description = kwargs.pop('with_description')
|
||||
params.update({'with_description': with_description})
|
||||
if params:
|
||||
url += '?%s' % parse.urlencode(params, True)
|
||||
|
||||
return self._list(url, self.KEY)
|
||||
|
Loading…
Reference in New Issue
Block a user