Skip to content

Commit 66df8d1

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add availability zone support for router commands"
2 parents ca1eeaf + c0d2120 commit 66df8d1

4 files changed

Lines changed: 53 additions & 0 deletions

File tree

doc/source/command-objects/router.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Create new router
1616
[--project <project> [--project-domain <project-domain>]]
1717
[--enable | --disable]
1818
[--distributed]
19+
[--availability-zone-hint <availability-zone>]
1920
<name>
2021
2122
.. option:: --project <project>
@@ -39,6 +40,11 @@ Create new router
3940
4041
Create a distributed router
4142
43+
.. option:: --availability-zone-hint <availability-zone>
44+
45+
Availability Zone in which to create this router (requires the Router
46+
Availability Zone extension, this option can be repeated).
47+
4248
.. _router_create-name:
4349
.. describe:: <name>
4450

openstackclient/network/v2/router.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def _format_external_gateway_info(info):
3535
_formatters = {
3636
'admin_state_up': _format_admin_state,
3737
'external_gateway_info': _format_external_gateway_info,
38+
'availability_zones': utils.format_list,
39+
'availability_zone_hints': utils.format_list,
3840
}
3941

4042

@@ -46,6 +48,9 @@ def _get_attrs(client_manager, parsed_args):
4648
attrs['admin_state_up'] = parsed_args.admin_state_up
4749
if parsed_args.distributed is not None:
4850
attrs['distributed'] = parsed_args.distributed
51+
if ('availability_zone_hints' in parsed_args
52+
and parsed_args.availability_zone_hints is not None):
53+
attrs['availability_zone_hints'] = parsed_args.availability_zone_hints
4954
# "router set" command doesn't support setting project.
5055
if 'project' in parsed_args and parsed_args.project is not None:
5156
identity_client = client_manager.identity
@@ -99,6 +104,16 @@ def get_parser(self, prog_name):
99104
metavar='<poroject>',
100105
help="Owner's project (name or ID)",
101106
)
107+
parser.add_argument(
108+
'--availability-zone-hint',
109+
metavar='<availability-zone>',
110+
action='append',
111+
dest='availability_zone_hints',
112+
help='Availability Zone in which to create this router '
113+
'(requires the Router Availability Zone extension, '
114+
'this option can be repeated).',
115+
)
116+
102117
identity_common.add_project_domain_option_to_parser(parser)
103118
return parser
104119

@@ -176,10 +191,12 @@ def take_action(self, parsed_args):
176191
columns = columns + (
177192
'routes',
178193
'external_gateway_info',
194+
'availability_zones'
179195
)
180196
column_headers = column_headers + (
181197
'Routes',
182198
'External gateway info',
199+
'Availability zones'
183200
)
184201

185202
data = client.routers()

openstackclient/tests/network/v2/fakes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ def create_one_router(attrs={}, methods={}):
263263
'tenant_id': 'project-id-' + uuid.uuid4().hex,
264264
'routes': [],
265265
'external_gateway_info': {},
266+
'availability_zone_hints': [],
267+
'availability_zones': [],
266268
}
267269

268270
# Overwrite default attributes.

openstackclient/tests/network/v2/test_router.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import mock
1515

1616
from openstackclient.common import exceptions
17+
from openstackclient.common import utils as osc_utils
1718
from openstackclient.network.v2 import router
1819
from openstackclient.tests.network.v2 import fakes as network_fakes
1920
from openstackclient.tests import utils as tests_utils
@@ -88,6 +89,31 @@ def test_create_default_options(self):
8889
self.assertEqual(self.columns, columns)
8990
self.assertEqual(self.data, data)
9091

92+
def test_create_with_AZ_hints(self):
93+
arglist = [
94+
self.new_router.name,
95+
'--availability-zone-hint', 'fake-az',
96+
'--availability-zone-hint', 'fake-az2',
97+
]
98+
verifylist = [
99+
('name', self.new_router.name),
100+
('availability_zone_hints', ['fake-az', 'fake-az2']),
101+
('admin_state_up', True),
102+
('distributed', False),
103+
]
104+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
105+
106+
columns, data = (self.cmd.take_action(parsed_args))
107+
self.network.create_router.assert_called_with(**{
108+
'admin_state_up': True,
109+
'name': self.new_router.name,
110+
'distributed': False,
111+
'availability_zone_hints': ['fake-az', 'fake-az2'],
112+
})
113+
114+
self.assertEqual(self.columns, columns)
115+
self.assertEqual(self.data, data)
116+
91117

92118
class TestDeleteRouter(TestRouter):
93119

@@ -135,6 +161,7 @@ class TestListRouter(TestRouter):
135161
columns_long = columns + (
136162
'Routes',
137163
'External gateway info',
164+
'Availability zones'
138165
)
139166

140167
data = []
@@ -155,6 +182,7 @@ class TestListRouter(TestRouter):
155182
data[i] + (
156183
r.routes,
157184
router._format_external_gateway_info(r.external_gateway_info),
185+
osc_utils.format_list(r.availability_zones),
158186
)
159187
)
160188

0 commit comments

Comments
 (0)