diff --git a/doc/source/command-objects/router.rst b/doc/source/command-objects/router.rst index e881065dd4..2a5bf0539c 100644 --- a/doc/source/command-objects/router.rst +++ b/doc/source/command-objects/router.rst @@ -16,6 +16,7 @@ Create new router [--project [--project-domain ]] [--enable | --disable] [--distributed] + [--availability-zone-hint ] .. option:: --project @@ -39,6 +40,11 @@ Create new router Create a distributed router +.. option:: --availability-zone-hint + + Availability Zone in which to create this router (requires the Router + Availability Zone extension, this option can be repeated). + .. _router_create-name: .. describe:: diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index 09e0fe4c84..06e086db00 100644 --- a/openstackclient/network/v2/router.py +++ b/openstackclient/network/v2/router.py @@ -39,6 +39,8 @@ def _format_external_gateway_info(info): _formatters = { 'admin_state_up': _format_admin_state, 'external_gateway_info': _format_external_gateway_info, + 'availability_zones': utils.format_list, + 'availability_zone_hints': utils.format_list, } @@ -50,6 +52,9 @@ def _get_attrs(client_manager, parsed_args): attrs['admin_state_up'] = parsed_args.admin_state_up if parsed_args.distributed is not None: attrs['distributed'] = parsed_args.distributed + if ('availability_zone_hints' in parsed_args + and parsed_args.availability_zone_hints is not None): + attrs['availability_zone_hints'] = parsed_args.availability_zone_hints # "router set" command doesn't support setting project. if 'project' in parsed_args and parsed_args.project is not None: identity_client = client_manager.identity @@ -105,6 +110,16 @@ class CreateRouter(show.ShowOne): metavar='', help="Owner's project (name or ID)", ) + parser.add_argument( + '--availability-zone-hint', + metavar='', + action='append', + dest='availability_zone_hints', + help='Availability Zone in which to create this router ' + '(requires the Router Availability Zone extension, ' + 'this option can be repeated).', + ) + identity_common.add_project_domain_option_to_parser(parser) return parser @@ -189,10 +204,12 @@ class ListRouter(lister.Lister): columns = columns + ( 'routes', 'external_gateway_info', + 'availability_zones' ) column_headers = column_headers + ( 'Routes', 'External gateway info', + 'Availability zones' ) data = client.routers() diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py index 80760a7792..2bddf17e58 100644 --- a/openstackclient/tests/network/v2/fakes.py +++ b/openstackclient/tests/network/v2/fakes.py @@ -171,6 +171,8 @@ class FakeRouter(object): 'tenant_id': 'project-id-' + uuid.uuid4().hex, 'routes': [], 'external_gateway_info': {}, + 'availability_zone_hints': [], + 'availability_zones': [], } # Overwrite default attributes. diff --git a/openstackclient/tests/network/v2/test_router.py b/openstackclient/tests/network/v2/test_router.py index fba6e192c5..98e9f17a8f 100644 --- a/openstackclient/tests/network/v2/test_router.py +++ b/openstackclient/tests/network/v2/test_router.py @@ -14,6 +14,7 @@ import mock from openstackclient.common import exceptions +from openstackclient.common import utils as osc_utils from openstackclient.network.v2 import router from openstackclient.tests.network.v2 import fakes as network_fakes from openstackclient.tests import utils as tests_utils @@ -88,6 +89,31 @@ class TestCreateRouter(TestRouter): self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) + def test_create_with_AZ_hints(self): + arglist = [ + self.new_router.name, + '--availability-zone-hint', 'fake-az', + '--availability-zone-hint', 'fake-az2', + ] + verifylist = [ + ('name', self.new_router.name), + ('availability_zone_hints', ['fake-az', 'fake-az2']), + ('admin_state_up', True), + ('distributed', False), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = (self.cmd.take_action(parsed_args)) + self.network.create_router.assert_called_with(**{ + 'admin_state_up': True, + 'name': self.new_router.name, + 'distributed': False, + 'availability_zone_hints': ['fake-az', 'fake-az2'], + }) + + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, data) + class TestDeleteRouter(TestRouter): @@ -135,6 +161,7 @@ class TestListRouter(TestRouter): columns_long = columns + ( 'Routes', 'External gateway info', + 'Availability zones' ) data = [] @@ -155,6 +182,7 @@ class TestListRouter(TestRouter): data[i] + ( r.routes, router._format_external_gateway_info(r.external_gateway_info), + osc_utils.format_list(r.availability_zones), ) )