Skip to content

Commit abfcd78

Browse files
author
Reedip
committed
Introduce overwrite functionality in osc subnet set
The overwrite functionality allows user to overwrite the dns-nameservers of a specific subnet. Change-Id: I421808a3bdeb4565668f627b7929c4762cf40212 partially-implements: blueprint allow-overwrite-set-options partially-implements: blueprint network-commands-options
1 parent 4cd336b commit abfcd78

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

doc/source/command-objects/subnet.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ Set subnet properties
231231
[--no-allocation-pool]
232232
[--dhcp | --no-dhcp]
233233
[--dns-nameserver <dns-nameserver>]
234+
[--no-dns-nameserver]
234235
[--gateway <gateway-ip>]
235236
[--host-route destination=<subnet>,gateway=<ip-address>]
236237
[--no-host-route]
@@ -263,6 +264,12 @@ Set subnet properties
263264
264265
DNS server for this subnet (repeat option to set multiple DNS servers)
265266
267+
.. option:: --no-dns-nameservers
268+
269+
Clear existing information of DNS servers.
270+
Specify both --dns-nameserver and --no-dns-nameservers
271+
to overwrite the current DNS server information.
272+
266273
.. option:: --gateway <gateway>
267274
268275
Specify a gateway for the subnet. The options are:

openstackclient/network/v2/subnet.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ def _get_common_parse_arguments(parser, is_create=True):
8484
help=_("DNS server for this subnet "
8585
"(repeat option to set multiple DNS servers)")
8686
)
87+
88+
if not is_create:
89+
parser.add_argument(
90+
'--no-dns-nameservers',
91+
action='store_true',
92+
help=_("Clear existing information of DNS Nameservers. "
93+
"Specify both --dns-nameserver and --no-dns-nameserver "
94+
"to overwrite the current DNS Nameserver information.")
95+
)
8796
parser.add_argument(
8897
'--host-route',
8998
metavar='destination=<subnet>,gateway=<ip-address>',
@@ -532,7 +541,10 @@ def take_action(self, parsed_args):
532541
attrs = _get_attrs(self.app.client_manager, parsed_args,
533542
is_create=False)
534543
if 'dns_nameservers' in attrs:
535-
attrs['dns_nameservers'] += obj.dns_nameservers
544+
if not parsed_args.no_dns_nameservers:
545+
attrs['dns_nameservers'] += obj.dns_nameservers
546+
elif parsed_args.no_dns_nameservers:
547+
attrs['dns_nameservers'] = []
536548
if 'host_routes' in attrs:
537549
if not parsed_args.no_host_route:
538550
attrs['host_routes'] += obj.host_routes

openstackclient/tests/unit/network/v2/test_subnet.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,20 +925,25 @@ def test_overwrite_options(self):
925925
{'host_routes': [{'destination': '10.20.20.0/24',
926926
'nexthop': '10.20.20.1'}],
927927
'allocation_pools': [{'start': '8.8.8.200',
928-
'end': '8.8.8.250'}], })
928+
'end': '8.8.8.250'}],
929+
'dns_nameservers': ["10.0.0.1"], })
929930
self.network.find_subnet = mock.Mock(return_value=_testsubnet)
930931
arglist = [
931932
'--host-route', 'destination=10.30.30.30/24,gateway=10.30.30.1',
932933
'--no-host-route',
933934
'--allocation-pool', 'start=8.8.8.100,end=8.8.8.150',
934935
'--no-allocation-pool',
936+
'--dns-nameserver', '10.1.10.1',
937+
'--no-dns-nameservers',
935938
_testsubnet.name,
936939
]
937940
verifylist = [
938941
('host_routes', [{
939942
"destination": "10.30.30.30/24", "gateway": "10.30.30.1"}]),
940943
('allocation_pools', [{
941944
'start': '8.8.8.100', 'end': '8.8.8.150'}]),
945+
('dns_nameservers', ['10.1.10.1']),
946+
('no_dns_nameservers', True),
942947
('no_host_route', True),
943948
('no_allocation_pool', True),
944949
]
@@ -948,6 +953,7 @@ def test_overwrite_options(self):
948953
'host_routes': [{
949954
"destination": "10.30.30.30/24", "nexthop": "10.30.30.1"}],
950955
'allocation_pools': [{'start': '8.8.8.100', 'end': '8.8.8.150'}],
956+
'dns_nameservers': ["10.1.10.1"],
951957
}
952958
self.network.update_subnet.assert_called_once_with(
953959
_testsubnet, **attrs)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
``subnet set`` command now allows the user to overwrite/clear dns-nameserver information
5+
of a subnet by using the option ``no-dns-nameserver``.
6+
[ Blueprint `allow-overwrite-set-options <https://blueprints.launchpad.net/python-openstackclient/+spec/allow-overwrite-set-options>` _]
7+

0 commit comments

Comments
 (0)