Skip to content

Commit 7cf7412

Browse files
committed
Network: Add onboard_network_subnets
Depends-On: https://review.opendev.org/995969 Assisted-By: claude-opus-4.8 Signed-off-by: lajoskatona <lajos.katona@est.tech> Change-Id: I8060005332d2c8af91986b86cef4dfe42dd7d048
1 parent 926da72 commit 7cf7412

6 files changed

Lines changed: 143 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (c) 2019 SUSE Linux Products GmbH
2+
# All Rights Reserved
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
#
16+
17+
"""Subnet onboard action implementation"""
18+
19+
import argparse
20+
import logging
21+
22+
from openstackclient.i18n import _
23+
from openstackclient.network.v2 import subnet_pool
24+
25+
26+
LOG = logging.getLogger(__name__)
27+
28+
29+
class NetworkOnboardSubnets(subnet_pool.AddNetworkSubnetPool):
30+
"""Onboard network subnets into a subnet pool"""
31+
32+
_description = _("DEPRECATED: Use 'subnet pool add network' instead.")
33+
34+
def take_action(self, parsed_args: argparse.Namespace) -> None:
35+
self.log.warning(
36+
_(
37+
'The "network onboard subnet" command is deprecated '
38+
'in favour of "subnet pool add network". '
39+
'It will be removed in a future release.'
40+
)
41+
)
42+
super().take_action(parsed_args)

openstackclient/network/v2/subnet_pool.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,38 @@ def take_action(self, parsed_args: argparse.Namespace) -> None:
522522
)
523523
# tags is a subresource and it needs to be updated separately.
524524
_tag.update_tags_for_unset(client, obj, parsed_args)
525+
526+
527+
class AddNetworkSubnetPool(command.Command):
528+
"""Onboard network subnets into a subnet pool"""
529+
530+
def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
531+
parser = super().get_parser(prog_name)
532+
parser.add_argument(
533+
'network',
534+
metavar="<network>",
535+
help=_("Onboard all subnets associated with this network"),
536+
)
537+
parser.add_argument(
538+
'subnetpool',
539+
metavar="<subnetpool>",
540+
help=_("Target subnet pool for onboarding subnets"),
541+
)
542+
return parser
543+
544+
def take_action(self, parsed_args: argparse.Namespace) -> None:
545+
client = self.app.client_manager.network
546+
subnet_pool = client.find_subnet_pool(
547+
parsed_args.subnetpool, ignore_missing=False
548+
)
549+
network = client.find_network(
550+
parsed_args.network, ignore_missing=False
551+
)
552+
try:
553+
client.onboard_network_subnets(subnet_pool, network)
554+
except Exception as e:
555+
msg = _("Failed to onboard subnets for network '%(n)s': %(e)s") % {
556+
'n': parsed_args.network,
557+
'e': e,
558+
}
559+
raise exceptions.CommandError(msg)

openstackclient/shell.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
'neutronclient.osc.v2.taas',
3838
'neutronclient.osc.v2.networking_bgpvpn',
3939
'neutronclient.osc.v2.dynamic_routing',
40+
'neutronclient.osc.v2.subnet_onboard',
4041
'neutronclient.osc.v2.vpnaas',
4142
# FIXME(stephenfin): this is ignored temporarily while we complete
4243
# implementation. This should be dropped once completed.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2019 SUSE Linux Products GmbH
2+
# All Rights Reserved
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
#
16+
17+
from openstack.network.v2 import network as _network
18+
from openstack.network.v2 import subnet_pool as _subnet_pool
19+
20+
from openstackclient.network.v2 import subnet_onboard
21+
from openstackclient.tests.unit.network.v2 import fakes as network_fakes
22+
23+
24+
class TestNetworkOnboardSubnets(network_fakes.TestNetworkV2):
25+
def setUp(self):
26+
super().setUp()
27+
28+
self._subnet_pool = _subnet_pool.SubnetPool(
29+
id='my_subnetpool_id', name='my_subnetpool'
30+
)
31+
self._network = _network.Network(id='my_network_id', name='my_network')
32+
33+
self.network_client.find_subnet_pool.return_value = self._subnet_pool
34+
self.network_client.find_network.return_value = self._network
35+
36+
self.cmd = subnet_onboard.NetworkOnboardSubnets(self.app, None)
37+
38+
def test_onboard_subnets(self):
39+
arglist = ['my_network', 'my_subnetpool']
40+
verifylist = [
41+
('network', 'my_network'),
42+
('subnetpool', 'my_subnetpool'),
43+
]
44+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
45+
self.cmd.take_action(parsed_args)
46+
47+
self.network_client.find_network.assert_called_once_with(
48+
'my_network', ignore_missing=False
49+
)
50+
self.network_client.find_subnet_pool.assert_called_once_with(
51+
'my_subnetpool', ignore_missing=False
52+
)
53+
self.network_client.onboard_network_subnets.assert_called_once_with(
54+
self._subnet_pool, self._network
55+
)

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ network_segment_range_list = "openstackclient.network.v2.network_segment_range:L
482482
network_segment_range_set = "openstackclient.network.v2.network_segment_range:SetNetworkSegmentRange"
483483
network_segment_range_show = "openstackclient.network.v2.network_segment_range:ShowNetworkSegmentRange"
484484
network_service_provider_list = "openstackclient.network.v2.network_service_provider:ListNetworkServiceProvider"
485+
network_onboard_subnet = "openstackclient.network.v2.subnet_onboard:NetworkOnboardSubnets"
485486
network_subport_list = "openstackclient.network.v2.network_trunk:ListNetworkSubport"
486487
network_trunk_create = "openstackclient.network.v2.network_trunk:CreateNetworkTrunk"
487488
network_trunk_delete = "openstackclient.network.v2.network_trunk:DeleteNetworkTrunk"
@@ -548,6 +549,7 @@ subnet_pool_list = "openstackclient.network.v2.subnet_pool:ListSubnetPool"
548549
subnet_pool_set = "openstackclient.network.v2.subnet_pool:SetSubnetPool"
549550
subnet_pool_show = "openstackclient.network.v2.subnet_pool:ShowSubnetPool"
550551
subnet_pool_unset = "openstackclient.network.v2.subnet_pool:UnsetSubnetPool"
552+
subnet_pool_add_network = "openstackclient.network.v2.subnet_pool:AddNetworkSubnetPool"
551553

552554
[project.entry-points."openstack.network.v2.bgpvpn"]
553555
bgpvpn_create = "openstackclient.network.v2.bgpvpn.bgpvpn:CreateBgpvpn"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
features:
3+
- |
4+
OSC command for ``subnet onboard`` moved from
5+
``python-neutronclient``. The following command is now
6+
available from openstackclient:
7+
8+
* ``network onboard subnets``

0 commit comments

Comments
 (0)