summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReedip <reedip.banerjee@nectechnologies.in>2016-11-16 14:22:44 +0530
committerReedip <reedip.banerjee@nectechnologies.in>2016-11-28 05:49:21 +0000
commitabfcd7810cb5937060fd9ae290f07a48226c9ced (patch)
tree3bbfe9186e0e78564171757a029f1400003e266b
parent4cd336b1285fdd0455ce1fcc4544ae81a7756e0b (diff)
downloadpython-openstackclient-abfcd7810cb5937060fd9ae290f07a48226c9ced.tar.gz
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
-rw-r--r--doc/source/command-objects/subnet.rst7
-rw-r--r--openstackclient/network/v2/subnet.py14
-rw-r--r--openstackclient/tests/unit/network/v2/test_subnet.py8
-rw-r--r--releasenotes/notes/add-dns-nameserver-overwrite-option-b866baeae12f9460.yaml7
4 files changed, 34 insertions, 2 deletions
diff --git a/doc/source/command-objects/subnet.rst b/doc/source/command-objects/subnet.rst
index e2059875..a88b8103 100644
--- a/doc/source/command-objects/subnet.rst
+++ b/doc/source/command-objects/subnet.rst
@@ -231,6 +231,7 @@ Set subnet properties
[--no-allocation-pool]
[--dhcp | --no-dhcp]
[--dns-nameserver <dns-nameserver>]
+ [--no-dns-nameserver]
[--gateway <gateway-ip>]
[--host-route destination=<subnet>,gateway=<ip-address>]
[--no-host-route]
@@ -263,6 +264,12 @@ Set subnet properties
DNS server for this subnet (repeat option to set multiple DNS servers)
+.. option:: --no-dns-nameservers
+
+ Clear existing information of DNS servers.
+ Specify both --dns-nameserver and --no-dns-nameservers
+ to overwrite the current DNS server information.
+
.. option:: --gateway <gateway>
Specify a gateway for the subnet. The options are:
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py
index f1ecb5a7..dc504b32 100644
--- a/openstackclient/network/v2/subnet.py
+++ b/openstackclient/network/v2/subnet.py
@@ -84,6 +84,15 @@ def _get_common_parse_arguments(parser, is_create=True):
help=_("DNS server for this subnet "
"(repeat option to set multiple DNS servers)")
)
+
+ if not is_create:
+ parser.add_argument(
+ '--no-dns-nameservers',
+ action='store_true',
+ help=_("Clear existing information of DNS Nameservers. "
+ "Specify both --dns-nameserver and --no-dns-nameserver "
+ "to overwrite the current DNS Nameserver information.")
+ )
parser.add_argument(
'--host-route',
metavar='destination=<subnet>,gateway=<ip-address>',
@@ -532,7 +541,10 @@ class SetSubnet(command.Command):
attrs = _get_attrs(self.app.client_manager, parsed_args,
is_create=False)
if 'dns_nameservers' in attrs:
- attrs['dns_nameservers'] += obj.dns_nameservers
+ if not parsed_args.no_dns_nameservers:
+ attrs['dns_nameservers'] += obj.dns_nameservers
+ elif parsed_args.no_dns_nameservers:
+ attrs['dns_nameservers'] = []
if 'host_routes' in attrs:
if not parsed_args.no_host_route:
attrs['host_routes'] += obj.host_routes
diff --git a/openstackclient/tests/unit/network/v2/test_subnet.py b/openstackclient/tests/unit/network/v2/test_subnet.py
index 2d51aa4a..e7406575 100644
--- a/openstackclient/tests/unit/network/v2/test_subnet.py
+++ b/openstackclient/tests/unit/network/v2/test_subnet.py
@@ -925,13 +925,16 @@ class TestSetSubnet(TestSubnet):
{'host_routes': [{'destination': '10.20.20.0/24',
'nexthop': '10.20.20.1'}],
'allocation_pools': [{'start': '8.8.8.200',
- 'end': '8.8.8.250'}], })
+ 'end': '8.8.8.250'}],
+ 'dns_nameservers': ["10.0.0.1"], })
self.network.find_subnet = mock.Mock(return_value=_testsubnet)
arglist = [
'--host-route', 'destination=10.30.30.30/24,gateway=10.30.30.1',
'--no-host-route',
'--allocation-pool', 'start=8.8.8.100,end=8.8.8.150',
'--no-allocation-pool',
+ '--dns-nameserver', '10.1.10.1',
+ '--no-dns-nameservers',
_testsubnet.name,
]
verifylist = [
@@ -939,6 +942,8 @@ class TestSetSubnet(TestSubnet):
"destination": "10.30.30.30/24", "gateway": "10.30.30.1"}]),
('allocation_pools', [{
'start': '8.8.8.100', 'end': '8.8.8.150'}]),
+ ('dns_nameservers', ['10.1.10.1']),
+ ('no_dns_nameservers', True),
('no_host_route', True),
('no_allocation_pool', True),
]
@@ -948,6 +953,7 @@ class TestSetSubnet(TestSubnet):
'host_routes': [{
"destination": "10.30.30.30/24", "nexthop": "10.30.30.1"}],
'allocation_pools': [{'start': '8.8.8.100', 'end': '8.8.8.150'}],
+ 'dns_nameservers': ["10.1.10.1"],
}
self.network.update_subnet.assert_called_once_with(
_testsubnet, **attrs)
diff --git a/releasenotes/notes/add-dns-nameserver-overwrite-option-b866baeae12f9460.yaml b/releasenotes/notes/add-dns-nameserver-overwrite-option-b866baeae12f9460.yaml
new file mode 100644
index 00000000..04f0638d
--- /dev/null
+++ b/releasenotes/notes/add-dns-nameserver-overwrite-option-b866baeae12f9460.yaml
@@ -0,0 +1,7 @@
+---
+features:
+ - |
+ ``subnet set`` command now allows the user to overwrite/clear dns-nameserver information
+ of a subnet by using the option ``no-dns-nameserver``.
+ [ Blueprint `allow-overwrite-set-options <https://blueprints.launchpad.net/python-openstackclient/+spec/allow-overwrite-set-options>` _]
+