Overwrite/Clear support for subnets
This patch adds the overwrite/clear functionality for allocation-pool and host-routes in subnets. Change-Id: Idfa41173d0c054c5bfb4eda8c5f614928012555a implements: blueprint allow-overwrite-set-options
This commit is contained in:
parent
43f6b95229
commit
7f12b745ce
@ -232,10 +232,12 @@ Set subnet properties
|
|||||||
|
|
||||||
os subnet set
|
os subnet set
|
||||||
[--allocation-pool start=<ip-address>,end=<ip-address>]
|
[--allocation-pool start=<ip-address>,end=<ip-address>]
|
||||||
|
[--no-allocation-pool]
|
||||||
[--dhcp | --no-dhcp]
|
[--dhcp | --no-dhcp]
|
||||||
[--dns-nameserver <dns-nameserver>]
|
[--dns-nameserver <dns-nameserver>]
|
||||||
[--gateway <gateway-ip>]
|
[--gateway <gateway-ip>]
|
||||||
[--host-route destination=<subnet>,gateway=<ip-address>]
|
[--host-route destination=<subnet>,gateway=<ip-address>]
|
||||||
|
[--no-host-route]
|
||||||
[--service-type <service-type>]
|
[--service-type <service-type>]
|
||||||
[--name <new-name>]
|
[--name <new-name>]
|
||||||
[--description <description>]
|
[--description <description>]
|
||||||
@ -247,6 +249,12 @@ Set subnet properties
|
|||||||
``start=192.168.199.2,end=192.168.199.254``
|
``start=192.168.199.2,end=192.168.199.254``
|
||||||
(repeat option to add multiple IP addresses)
|
(repeat option to add multiple IP addresses)
|
||||||
|
|
||||||
|
.. option:: --no-allocation-pool
|
||||||
|
|
||||||
|
Clear associated allocation pools from this subnet.
|
||||||
|
Specify both --allocation-pool and --no-allocation-pool
|
||||||
|
to overwrite the current allocation pool information.
|
||||||
|
|
||||||
.. option:: --dhcp
|
.. option:: --dhcp
|
||||||
|
|
||||||
Enable DHCP
|
Enable DHCP
|
||||||
@ -272,7 +280,12 @@ Set subnet properties
|
|||||||
``destination=10.10.0.0/16,gateway=192.168.71.254``
|
``destination=10.10.0.0/16,gateway=192.168.71.254``
|
||||||
destination: destination subnet (in CIDR notation)
|
destination: destination subnet (in CIDR notation)
|
||||||
gateway: nexthop IP address
|
gateway: nexthop IP address
|
||||||
(repeat option to add multiple routes)
|
|
||||||
|
.. option:: --no-host-route
|
||||||
|
|
||||||
|
Clear associated host routes from this subnet.
|
||||||
|
Specify both --host-route and --no-host-route
|
||||||
|
to overwrite the current host route information.
|
||||||
|
|
||||||
.. option:: --service-type <service-type>
|
.. option:: --service-type <service-type>
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ _formatters = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _get_common_parse_arguments(parser):
|
def _get_common_parse_arguments(parser, is_create=True):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--allocation-pool',
|
'--allocation-pool',
|
||||||
metavar='start=<ip-address>,end=<ip-address>',
|
metavar='start=<ip-address>,end=<ip-address>',
|
||||||
@ -68,6 +68,14 @@ def _get_common_parse_arguments(parser):
|
|||||||
"e.g.: start=192.168.199.2,end=192.168.199.254 "
|
"e.g.: start=192.168.199.2,end=192.168.199.254 "
|
||||||
"(repeat option to add multiple IP addresses)")
|
"(repeat option to add multiple IP addresses)")
|
||||||
)
|
)
|
||||||
|
if not is_create:
|
||||||
|
parser.add_argument(
|
||||||
|
'--no-allocation-pool',
|
||||||
|
action='store_true',
|
||||||
|
help=_("Clear associated allocation-pools from the subnet. "
|
||||||
|
"Specify both --allocation-pool and --no-allocation-pool "
|
||||||
|
"to overwrite the current allocation pool information.")
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--dns-nameserver',
|
'--dns-nameserver',
|
||||||
metavar='<dns-nameserver>',
|
metavar='<dns-nameserver>',
|
||||||
@ -88,6 +96,14 @@ def _get_common_parse_arguments(parser):
|
|||||||
"gateway: nexthop IP address "
|
"gateway: nexthop IP address "
|
||||||
"(repeat option to add multiple routes)")
|
"(repeat option to add multiple routes)")
|
||||||
)
|
)
|
||||||
|
if not is_create:
|
||||||
|
parser.add_argument(
|
||||||
|
'--no-host-route',
|
||||||
|
action='store_true',
|
||||||
|
help=_("Clear associated host-routes from the subnet. "
|
||||||
|
"Specify both --host-route and --no-host-route "
|
||||||
|
"to overwrite the current host route information.")
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--service-type',
|
'--service-type',
|
||||||
metavar='<service-type>',
|
metavar='<service-type>',
|
||||||
@ -508,7 +524,7 @@ class SetSubnet(command.Command):
|
|||||||
metavar='<description>',
|
metavar='<description>',
|
||||||
help=_("Set subnet description")
|
help=_("Set subnet description")
|
||||||
)
|
)
|
||||||
_get_common_parse_arguments(parser)
|
_get_common_parse_arguments(parser, is_create=False)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@ -519,9 +535,15 @@ class SetSubnet(command.Command):
|
|||||||
if 'dns_nameservers' in attrs:
|
if 'dns_nameservers' in attrs:
|
||||||
attrs['dns_nameservers'] += obj.dns_nameservers
|
attrs['dns_nameservers'] += obj.dns_nameservers
|
||||||
if 'host_routes' in attrs:
|
if 'host_routes' in attrs:
|
||||||
attrs['host_routes'] += obj.host_routes
|
if not parsed_args.no_host_route:
|
||||||
|
attrs['host_routes'] += obj.host_routes
|
||||||
|
elif parsed_args.no_host_route:
|
||||||
|
attrs['host_routes'] = ''
|
||||||
if 'allocation_pools' in attrs:
|
if 'allocation_pools' in attrs:
|
||||||
attrs['allocation_pools'] += obj.allocation_pools
|
if not parsed_args.no_allocation_pool:
|
||||||
|
attrs['allocation_pools'] += obj.allocation_pools
|
||||||
|
elif parsed_args.no_allocation_pool:
|
||||||
|
attrs['allocation_pools'] = ''
|
||||||
if 'service_types' in attrs:
|
if 'service_types' in attrs:
|
||||||
attrs['service_types'] += obj.service_types
|
attrs['service_types'] += obj.service_types
|
||||||
client.update_subnet(obj, **attrs)
|
client.update_subnet(obj, **attrs)
|
||||||
|
@ -938,6 +938,39 @@ class TestSetSubnet(TestSubnet):
|
|||||||
self.network.update_subnet.assert_called_with(self._subnet, **attrs)
|
self.network.update_subnet.assert_called_with(self._subnet, **attrs)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_overwrite_options(self):
|
||||||
|
_testsubnet = network_fakes.FakeSubnet.create_one_subnet(
|
||||||
|
{'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'}], })
|
||||||
|
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',
|
||||||
|
_testsubnet.name,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('host_routes', [{
|
||||||
|
"destination": "10.30.30.30/24", "gateway": "10.30.30.1"}]),
|
||||||
|
('allocation_pools', [{
|
||||||
|
'start': '8.8.8.100', 'end': '8.8.8.150'}]),
|
||||||
|
('no_host_route', True),
|
||||||
|
('no_allocation_pool', True),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
attrs = {
|
||||||
|
'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'}],
|
||||||
|
}
|
||||||
|
self.network.update_subnet.assert_called_once_with(
|
||||||
|
_testsubnet, **attrs)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
class TestShowSubnet(TestSubnet):
|
class TestShowSubnet(TestSubnet):
|
||||||
# The subnets to be shown
|
# The subnets to be shown
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
``subnet set`` command now allows the user to clear and overwrite
|
||||||
|
allocation-pool or host-route of a subnet.
|
||||||
|
[ Blueprint `allow-overwrite-set-options <https://blueprints.launchpad.net/python-openstackclient/+spec/allow-overwrite-set-options>` _]
|
Loading…
Reference in New Issue
Block a user