Add availability zone support for router commands
This patch allows the adding of availability_zone_hints during router create. Also allows for the display of availability_zones during list and and show commands. Change-Id: Ifbc5c218bc7103d28076d726212ce25321bcf7f1 Partial-bug: #1519503 Partially-implements: blueprint neutron-client
This commit is contained in:
		| @@ -16,6 +16,7 @@ Create new router | ||||
|         [--project <project> [--project-domain <project-domain>]] | ||||
|         [--enable | --disable] | ||||
|         [--distributed] | ||||
| 	[--availability-zone-hint <availability-zone>] | ||||
|         <name> | ||||
|  | ||||
| .. option:: --project <project> | ||||
| @@ -39,6 +40,11 @@ Create new router | ||||
|  | ||||
|     Create a distributed router | ||||
|  | ||||
| .. option:: --availability-zone-hint <availability-zone> | ||||
|  | ||||
|     Availability Zone in which to create this router (requires the Router | ||||
|     Availability Zone extension, this option can be repeated). | ||||
|  | ||||
| .. _router_create-name: | ||||
| .. describe:: <name> | ||||
|  | ||||
|   | ||||
| @@ -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='<poroject>', | ||||
|             help="Owner's project (name or ID)", | ||||
|         ) | ||||
|         parser.add_argument( | ||||
|             '--availability-zone-hint', | ||||
|             metavar='<availability-zone>', | ||||
|             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() | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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), | ||||
|             ) | ||||
|         ) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jas
					Jas