SDK Refactor: Prepare router commands
Prepare the OSC "router" commands for the SDK refactor. See [1] for details. [1] https://etherpad.openstack.org/p/osc-network-command-sdk-support Change-Id: I2fa12943a65e3981b924e6cea9ed041682ec54b2 Partially-Implements: blueprint network-command-sdk-support
This commit is contained in:
parent
29587eaa66
commit
083e155ae5
openstackclient
@ -52,6 +52,7 @@ def _format_routes(routes):
|
||||
|
||||
_formatters = {
|
||||
'admin_state_up': _format_admin_state,
|
||||
'is_admin_state_up': _format_admin_state,
|
||||
'external_gateway_info': _format_external_gateway_info,
|
||||
'availability_zones': utils.format_list,
|
||||
'availability_zone_hints': utils.format_list,
|
||||
@ -62,6 +63,9 @@ _formatters = {
|
||||
def _get_columns(item):
|
||||
column_map = {
|
||||
'tenant_id': 'project_id',
|
||||
'is_ha': 'ha',
|
||||
'is_distributed': 'distributed',
|
||||
'is_admin_state_up': 'admin_state_up',
|
||||
}
|
||||
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
|
||||
|
||||
@ -150,6 +154,8 @@ class AddSubnetToRouter(command.Command):
|
||||
subnet_id=subnet.id)
|
||||
|
||||
|
||||
# TODO(yanxing'an): Use the SDK resource mapped attribute names once the
|
||||
# OSC minimum requirements include SDK 1.0.
|
||||
class CreateRouter(command.ShowOne):
|
||||
_description = _("Create a new router")
|
||||
|
||||
@ -255,6 +261,8 @@ class DeleteRouter(command.Command):
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
|
||||
# TODO(yanxing'an): Use the SDK resource mapped attribute names once the
|
||||
# OSC minimum requirements include SDK 1.0.
|
||||
class ListRouter(command.Lister):
|
||||
_description = _("List routers")
|
||||
|
||||
@ -297,10 +305,10 @@ class ListRouter(command.Lister):
|
||||
'id',
|
||||
'name',
|
||||
'status',
|
||||
'admin_state_up',
|
||||
'distributed',
|
||||
'ha',
|
||||
'tenant_id',
|
||||
'is_admin_state_up',
|
||||
'is_distributed',
|
||||
'is_ha',
|
||||
'project_id',
|
||||
)
|
||||
column_headers = (
|
||||
'ID',
|
||||
@ -319,8 +327,10 @@ class ListRouter(command.Lister):
|
||||
|
||||
if parsed_args.enable:
|
||||
args['admin_state_up'] = True
|
||||
args['is_admin_state_up'] = True
|
||||
elif parsed_args.disable:
|
||||
args['admin_state_up'] = False
|
||||
args['is_admin_state_up'] = False
|
||||
|
||||
if parsed_args.project:
|
||||
project_id = identity_common.find_project(
|
||||
@ -329,6 +339,7 @@ class ListRouter(command.Lister):
|
||||
parsed_args.project_domain,
|
||||
).id
|
||||
args['tenant_id'] = project_id
|
||||
args['project_id'] = project_id
|
||||
if parsed_args.long:
|
||||
columns = columns + (
|
||||
'routes',
|
||||
@ -407,6 +418,8 @@ class RemoveSubnetFromRouter(command.Command):
|
||||
subnet_id=subnet.id)
|
||||
|
||||
|
||||
# TODO(yanxing'an): Use the SDK resource mapped attribute names once the
|
||||
# OSC minimum requirements include SDK 1.0.
|
||||
class SetRouter(command.Command):
|
||||
_description = _("Set router properties")
|
||||
|
||||
|
@ -834,6 +834,9 @@ class FakeRouter(object):
|
||||
|
||||
# Set attributes with special mapping in OpenStack SDK.
|
||||
router.project_id = router_attrs['tenant_id']
|
||||
router.is_admin_state_up = router_attrs['admin_state_up']
|
||||
router.is_distributed = router_attrs['distributed']
|
||||
router.is_ha = router_attrs['ha']
|
||||
|
||||
return router
|
||||
|
||||
|
@ -459,7 +459,7 @@ class TestListRouter(TestRouter):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.routers.assert_called_once_with(
|
||||
**{'admin_state_up': True}
|
||||
**{'admin_state_up': True, 'is_admin_state_up': True}
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
@ -476,7 +476,7 @@ class TestListRouter(TestRouter):
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.routers.assert_called_once_with(
|
||||
**{'admin_state_up': False}
|
||||
**{'admin_state_up': False, 'is_admin_state_up': False}
|
||||
)
|
||||
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -494,7 +494,7 @@ class TestListRouter(TestRouter):
|
||||
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.routers.assert_called_once_with(**filters)
|
||||
self.assertEqual(self.columns, columns)
|
||||
@ -514,7 +514,7 @@ class TestListRouter(TestRouter):
|
||||
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.routers.assert_called_once_with(**filters)
|
||||
self.assertEqual(self.columns, columns)
|
||||
|
Loading…
x
Reference in New Issue
Block a user