Merge "SDK Refactor: Prepare subnet pool commands"

This commit is contained in:
Jenkins 2016-11-08 19:47:49 +00:00 committed by Gerrit Code Review
commit 6bba1f0008
3 changed files with 33 additions and 15 deletions

View File

@ -22,17 +22,21 @@ from osc_lib import utils
from openstackclient.i18n import _
from openstackclient.identity import common as identity_common
from openstackclient.network import sdk_utils
LOG = logging.getLogger(__name__)
def _get_columns(item):
columns = list(item.keys())
if 'tenant_id' in columns:
columns.remove('tenant_id')
columns.append('project_id')
return tuple(sorted(columns))
column_map = {
'default_prefix_length': 'default_prefixlen',
'is_shared': 'shared',
'maximum_prefix_length': 'max_prefixlen',
'minimum_prefix_length': 'min_prefixlen',
'tenant_id': 'project_id',
}
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
_formatters = {
@ -134,6 +138,8 @@ def _add_default_options(parser):
)
# TODO(rtheis): Use the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
class CreateSubnetPool(command.ShowOne):
"""Create subnet pool"""
@ -184,9 +190,9 @@ class CreateSubnetPool(command.ShowOne):
if "prefixes" not in attrs:
attrs['prefixes'] = []
obj = client.create_subnet_pool(**attrs)
columns = _get_columns(obj)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
return (columns, data)
return (display_columns, data)
class DeleteSubnetPool(command.Command):
@ -223,6 +229,8 @@ class DeleteSubnetPool(command.Command):
raise exceptions.CommandError(msg)
# TODO(rtheis): Use only the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
class ListSubnetPool(command.Lister):
"""List subnet pools"""
@ -283,8 +291,10 @@ class ListSubnetPool(command.Lister):
filters = {}
if parsed_args.share:
filters['shared'] = True
filters['is_shared'] = True
elif parsed_args.no_share:
filters['shared'] = False
filters['is_shared'] = False
if parsed_args.default:
filters['is_default'] = True
elif parsed_args.no_default:
@ -296,6 +306,7 @@ class ListSubnetPool(command.Lister):
parsed_args.project_domain,
).id
filters['tenant_id'] = project_id
filters['project_id'] = project_id
if parsed_args.name is not None:
filters['name'] = parsed_args.name
if parsed_args.address_scope:
@ -310,8 +321,8 @@ class ListSubnetPool(command.Lister):
if parsed_args.long:
headers += ('Default Prefix Length', 'Address Scope',
'Default Subnet Pool', 'Shared')
columns += ('default_prefixlen', 'address_scope_id',
'is_default', 'shared')
columns += ('default_prefix_length', 'address_scope_id',
'is_default', 'is_shared')
return (headers,
(utils.get_item_properties(
@ -320,6 +331,8 @@ class ListSubnetPool(command.Lister):
) for s in data))
# TODO(rtheis): Use the SDK resource mapped attribute names once the
# OSC minimum requirements include SDK 1.0.
class SetSubnetPool(command.Command):
"""Set subnet pool properties"""
@ -390,9 +403,9 @@ class ShowSubnetPool(command.ShowOne):
parsed_args.subnet_pool,
ignore_missing=False
)
columns = _get_columns(obj)
display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
return (columns, data)
return (display_columns, data)
class UnsetSubnetPool(command.Command):

View File

@ -1217,6 +1217,11 @@ class FakeSubnetPool(object):
)
# Set attributes with special mapping in OpenStack SDK.
subnet_pool.default_prefix_length = \
subnet_pool_attrs['default_prefixlen']
subnet_pool.is_shared = subnet_pool_attrs['shared']
subnet_pool.maximum_prefix_length = subnet_pool_attrs['max_prefixlen']
subnet_pool.minimum_prefix_length = subnet_pool_attrs['min_prefixlen']
subnet_pool.project_id = subnet_pool_attrs['tenant_id']
return subnet_pool

View File

@ -435,7 +435,7 @@ class TestListSubnetPool(TestSubnetPool):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {'shared': False}
filters = {'shared': False, 'is_shared': False}
self.network.subnet_pools.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
@ -451,7 +451,7 @@ class TestListSubnetPool(TestSubnetPool):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {'shared': True}
filters = {'shared': True, 'is_shared': True}
self.network.subnet_pools.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
@ -501,7 +501,7 @@ class TestListSubnetPool(TestSubnetPool):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {'tenant_id': project.id}
filters = {'tenant_id': project.id, 'project_id': project.id}
self.network.subnet_pools.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)
@ -521,7 +521,7 @@ class TestListSubnetPool(TestSubnetPool):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
filters = {'tenant_id': project.id}
filters = {'tenant_id': project.id, 'project_id': project.id}
self.network.subnet_pools.assert_called_once_with(**filters)
self.assertEqual(self.columns, columns)