Skip to content

Commit a4b05b4

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add availability zone support for network commands"
2 parents 9734586 + 67ecf4e commit a4b05b4

4 files changed

Lines changed: 51 additions & 3 deletions

File tree

doc/source/command-objects/network.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Create new network
1616
[--project <project> [--project-domain <project-domain>]]
1717
[--enable | --disable]
1818
[--share | --no-share]
19+
[--availability-zone-hint <availability-zone>]
1920
<name>
2021
2122
.. option:: --project <project>
@@ -43,6 +44,11 @@ Create new network
4344
4445
Do not share the network between projects
4546
47+
.. option:: --availability-zone-hint <availability-zone>
48+
49+
Availability Zone in which to create this network (requires the Network
50+
Availability Zone extension, this option can be repeated).
51+
4652
.. _network_create-name:
4753
.. describe:: <name>
4854

openstackclient/network/v2/network.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def _format_router_external(item):
3636
'subnets': utils.format_list,
3737
'admin_state_up': _format_admin_state,
3838
'router_external': _format_router_external,
39+
'availability_zones': utils.format_list,
40+
'availability_zone_hints': utils.format_list,
3941
}
4042

4143

@@ -93,8 +95,19 @@ def get_parser(self, prog_name):
9395
parser.add_argument(
9496
'--project',
9597
metavar='<project>',
96-
help="Owner's project (name or ID)")
98+
help="Owner's project (name or ID)"
99+
)
97100
identity_common.add_project_domain_option_to_parser(parser)
101+
102+
parser.add_argument(
103+
'--availability-zone-hint',
104+
action='append',
105+
dest='availability_zone_hints',
106+
metavar='<availability-zone>',
107+
help='Availability Zone in which to create this network '
108+
'(requires the Network Availability Zone extension, '
109+
'this option can be repeated).',
110+
)
98111
return parser
99112

100113
def take_action(self, parsed_args):
@@ -119,6 +132,10 @@ def get_body(self, parsed_args):
119132
parsed_args.project_domain,
120133
).id
121134
body['tenant_id'] = project_id
135+
if parsed_args.availability_zone_hints is not None:
136+
body['availability_zone_hints'] = \
137+
parsed_args.availability_zone_hints
138+
122139
return body
123140

124141

@@ -181,6 +198,7 @@ def take_action(self, parsed_args):
181198
'subnets',
182199
'provider_network_type',
183200
'router_external',
201+
'availability_zones',
184202
)
185203
column_headers = (
186204
'ID',
@@ -192,6 +210,7 @@ def take_action(self, parsed_args):
192210
'Subnets',
193211
'Network Type',
194212
'Router Type',
213+
'Availability Zones',
195214
)
196215
else:
197216
columns = (

openstackclient/tests/network/v2/fakes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def create_one_network(attrs={}, methods={}):
8585
'provider_network_type': 'vlan',
8686
'router_external': True,
8787
'is_dirty': True,
88+
'availability_zones': [],
89+
'availability_zone_hints': [],
8890
}
8991

9092
# Overwrite default attributes.
@@ -93,7 +95,8 @@ def create_one_network(attrs={}, methods={}):
9395
# Set default methods.
9496
network_methods = {
9597
'keys': ['id', 'name', 'admin_state_up', 'router_external',
96-
'status', 'subnets', 'tenant_id'],
98+
'status', 'subnets', 'tenant_id', 'availability_zones',
99+
'availability_zone_hints'],
97100
}
98101

99102
# Overwrite default methods.

openstackclient/tests/network/v2/test_network.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ class TestCreateNetworkIdentityV3(TestNetwork):
3737

3838
# The new network created.
3939
_network = network_fakes.FakeNetwork.create_one_network(
40-
attrs={'tenant_id': identity_fakes_v3.project_id}
40+
attrs={
41+
'tenant_id': identity_fakes_v3.project_id,
42+
'availability_zone_hints': ["nova"],
43+
}
4144
)
4245

4346
columns = (
4447
'admin_state_up',
48+
'availability_zone_hints',
49+
'availability_zones',
4550
'id',
4651
'name',
4752
'project_id',
@@ -52,6 +57,8 @@ class TestCreateNetworkIdentityV3(TestNetwork):
5257

5358
data = (
5459
network._format_admin_state(_network.admin_state_up),
60+
utils.format_list(_network.availability_zone_hints),
61+
utils.format_list(_network.availability_zones),
5562
_network.id,
5663
_network.name,
5764
_network.project_id,
@@ -129,13 +136,15 @@ def test_create_all_options(self):
129136
"--share",
130137
"--project", identity_fakes_v3.project_name,
131138
"--project-domain", identity_fakes_v3.domain_name,
139+
"--availability-zone-hint", "nova",
132140
self._network.name,
133141
]
134142
verifylist = [
135143
('admin_state', False),
136144
('shared', True),
137145
('project', identity_fakes_v3.project_name),
138146
('project_domain', identity_fakes_v3.domain_name),
147+
('availability_zone_hints', ["nova"]),
139148
('name', self._network.name),
140149
]
141150

@@ -144,6 +153,7 @@ def test_create_all_options(self):
144153

145154
self.network.create_network.assert_called_with(**{
146155
'admin_state_up': False,
156+
'availability_zone_hints': ["nova"],
147157
'name': self._network.name,
148158
'shared': True,
149159
'tenant_id': identity_fakes_v3.project_id,
@@ -184,6 +194,8 @@ class TestCreateNetworkIdentityV2(TestNetwork):
184194

185195
columns = (
186196
'admin_state_up',
197+
'availability_zone_hints',
198+
'availability_zones',
187199
'id',
188200
'name',
189201
'project_id',
@@ -194,6 +206,8 @@ class TestCreateNetworkIdentityV2(TestNetwork):
194206

195207
data = (
196208
network._format_admin_state(_network.admin_state_up),
209+
utils.format_list(_network.availability_zone_hints),
210+
utils.format_list(_network.availability_zones),
197211
_network.id,
198212
_network.name,
199213
_network.project_id,
@@ -324,6 +338,7 @@ class TestListNetwork(TestNetwork):
324338
'Subnets',
325339
'Network Type',
326340
'Router Type',
341+
'Availability Zones',
327342
)
328343

329344
data = []
@@ -346,6 +361,7 @@ class TestListNetwork(TestNetwork):
346361
utils.format_list(net.subnets),
347362
net.provider_network_type,
348363
network._format_router_external(net.router_external),
364+
utils.format_list(net.availability_zones),
349365
))
350366

351367
def setUp(self):
@@ -483,6 +499,8 @@ class TestShowNetwork(TestNetwork):
483499

484500
columns = (
485501
'admin_state_up',
502+
'availability_zone_hints',
503+
'availability_zones',
486504
'id',
487505
'name',
488506
'project_id',
@@ -493,6 +511,8 @@ class TestShowNetwork(TestNetwork):
493511

494512
data = (
495513
network._format_admin_state(_network.admin_state_up),
514+
utils.format_list(_network.availability_zone_hints),
515+
utils.format_list(_network.availability_zones),
496516
_network.id,
497517
_network.name,
498518
_network.project_id,

0 commit comments

Comments
 (0)