Skip to content

Commit efcf3b2

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Fix Nova-net netowrk commands"
2 parents dd7da49 + 589a65c commit efcf3b2

7 files changed

Lines changed: 299 additions & 143 deletions

File tree

doc/source/backwards-incompatible.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ Backwards Incompatible Changes
3030
Release 3.10
3131
------------
3232

33-
1. The positional argument ``<snapshot-name>`` of the ``volume snapshot create``
33+
1. The ``network create`` command now requires the ``--subnet`` option when used
34+
with Nova-network clouds.
35+
36+
* As of: 3.10
37+
* Commit: https://review.openstack.org/460679
38+
39+
2. The positional argument ``<snapshot-name>`` of the ``volume snapshot create``
3440
command is no longer optional.
3541

3642
Previously when the ``--volume`` option was

doc/source/command-objects/network.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Create new network
7171
7272
Set network description
7373
74+
*Network version 2 only*
75+
7476
.. option:: --availability-zone-hint <availability-zone>
7577
7678
Availability Zone in which to create this network

openstackclient/api/compute_v2.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,25 @@ def network_create(
202202
):
203203
"""Create a new network
204204
205-
https://developer.openstack.org/api-ref/compute/#create-project-network
205+
https://developer.openstack.org/api-ref/compute/#create-network
206206
207207
:param string name:
208-
Network label
208+
Network label (required)
209209
:param integer subnet:
210-
Subnet for IPv4 fixed addresses in CIDR notation
210+
Subnet for IPv4 fixed addresses in CIDR notation (required)
211211
:param integer share_subnet:
212212
Shared subnet between projects, True or False
213213
:returns: A dict of the network attributes
214214
"""
215215

216-
url = "/os-tenant-networks"
216+
url = "/os-networks"
217217

218218
params = {
219219
'label': name,
220220
'cidr': subnet,
221-
'share_address': share_subnet,
222221
}
222+
if share_subnet is not None:
223+
params['share_address'] = share_subnet
223224

224225
return self.create(
225226
url,
@@ -232,13 +233,13 @@ def network_delete(
232233
):
233234
"""Delete a network
234235
235-
https://developer.openstack.org/api-ref/compute/#delete-project-network
236+
https://developer.openstack.org/api-ref/compute/#delete-network
236237
237238
:param string network:
238239
Network name or ID
239240
"""
240241

241-
url = "/os-tenant-networks"
242+
url = "/os-networks"
242243

243244
network = self.find(
244245
url,
@@ -256,14 +257,14 @@ def network_find(
256257
):
257258
"""Return a network given name or ID
258259
259-
https://developer.openstack.org/api-ref/compute/#show-project-network-details
260+
https://developer.openstack.org/api-ref/compute/#show-network-details
260261
261262
:param string network:
262263
Network name or ID
263264
:returns: A dict of the network attributes
264265
"""
265266

266-
url = "/os-tenant-networks"
267+
url = "/os-networks"
267268

268269
return self.find(
269270
url,
@@ -276,13 +277,13 @@ def network_list(
276277
):
277278
"""Get networks
278279
279-
https://developer.openstack.org/api-ref/compute/#list-project-networks
280+
https://developer.openstack.org/api-ref/compute/#list-networks
280281
281282
:returns:
282283
list of networks
283284
"""
284285

285-
url = "/os-tenant-networks"
286+
url = "/os-networks"
286287

287288
return self.list(url)["networks"]
288289

openstackclient/network/v2/network.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _format_router_external(item):
4242
}
4343

4444

45-
def _get_network_columns(item):
45+
def _get_columns_network(item):
4646
column_map = {
4747
'subnet_ids': 'subnets',
4848
'is_admin_state_up': 'admin_state_up',
@@ -59,14 +59,14 @@ def _get_network_columns(item):
5959
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
6060

6161

62-
def _get_columns(item):
62+
def _get_columns_compute(item):
6363
column_map = {
6464
'tenant_id': 'project_id',
6565
}
6666
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
6767

6868

69-
def _get_attrs(client_manager, parsed_args):
69+
def _get_attrs_network(client_manager, parsed_args):
7070
attrs = {}
7171
if parsed_args.name is not None:
7272
attrs['name'] = str(parsed_args.name)
@@ -135,6 +135,19 @@ def _get_attrs(client_manager, parsed_args):
135135
return attrs
136136

137137

138+
def _get_attrs_compute(client_manager, parsed_args):
139+
attrs = {}
140+
if parsed_args.name is not None:
141+
attrs['name'] = str(parsed_args.name)
142+
if parsed_args.share:
143+
attrs['share_subnet'] = True
144+
if parsed_args.no_share:
145+
attrs['share_subnet'] = False
146+
if parsed_args.subnet is not None:
147+
attrs['subnet'] = parsed_args.subnet
148+
return attrs
149+
150+
138151
def _add_additional_network_options(parser):
139152
# Add additional network options
140153

@@ -168,19 +181,6 @@ def _add_additional_network_options(parser):
168181
help=_("Do not make the network VLAN transparent"))
169182

170183

171-
def _get_attrs_compute(client_manager, parsed_args):
172-
attrs = {}
173-
if parsed_args.name is not None:
174-
attrs['name'] = str(parsed_args.name)
175-
if parsed_args.share:
176-
attrs['share_subnet'] = True
177-
if parsed_args.no_share:
178-
attrs['share_subnet'] = False
179-
if parsed_args.subnet is not None:
180-
attrs['subnet'] = parsed_args.subnet
181-
return attrs
182-
183-
184184
# TODO(sindhu): Use the SDK resource mapped attribute names once the
185185
# OSC minimum requirements include SDK 1.0.
186186
class CreateNetwork(common.NetworkAndComputeShowOne):
@@ -289,21 +289,22 @@ def update_parser_compute(self, parser):
289289
parser.add_argument(
290290
'--subnet',
291291
metavar='<subnet>',
292+
required=True,
292293
help=_("IPv4 subnet for fixed IPs (in CIDR notation)")
293294
)
294295
return parser
295296

296297
def take_action_network(self, client, parsed_args):
297-
attrs = _get_attrs(self.app.client_manager, parsed_args)
298+
attrs = _get_attrs_network(self.app.client_manager, parsed_args)
298299
obj = client.create_network(**attrs)
299-
display_columns, columns = _get_network_columns(obj)
300+
display_columns, columns = _get_columns_network(obj)
300301
data = utils.get_item_properties(obj, columns, formatters=_formatters)
301302
return (display_columns, data)
302303

303304
def take_action_compute(self, client, parsed_args):
304305
attrs = _get_attrs_compute(self.app.client_manager, parsed_args)
305306
obj = client.api.network_create(**attrs)
306-
display_columns, columns = _get_columns(obj)
307+
display_columns, columns = _get_columns_compute(obj)
307308
data = utils.get_dict_properties(obj, columns)
308309
return (display_columns, data)
309310

@@ -660,7 +661,7 @@ def take_action(self, parsed_args):
660661
client = self.app.client_manager.network
661662
obj = client.find_network(parsed_args.network, ignore_missing=False)
662663

663-
attrs = _get_attrs(self.app.client_manager, parsed_args)
664+
attrs = _get_attrs_network(self.app.client_manager, parsed_args)
664665
client.update_network(obj, **attrs)
665666

666667

@@ -677,12 +678,12 @@ def update_parser_common(self, parser):
677678

678679
def take_action_network(self, client, parsed_args):
679680
obj = client.find_network(parsed_args.network, ignore_missing=False)
680-
display_columns, columns = _get_network_columns(obj)
681+
display_columns, columns = _get_columns_network(obj)
681682
data = utils.get_item_properties(obj, columns, formatters=_formatters)
682683
return (display_columns, data)
683684

684685
def take_action_compute(self, client, parsed_args):
685686
obj = client.api.network_find(parsed_args.network)
686-
display_columns, columns = _get_columns(obj)
687+
display_columns, columns = _get_columns_compute(obj)
687688
data = utils.get_dict_properties(obj, columns)
688689
return (display_columns, data)

0 commit comments

Comments
 (0)