Add command to unset information from Subnet-pools
This patch introduces the ``subnet pool unset`` command to clear the pool prefix information from the subnet-pools. Change-Id: I84b7259d6e26e695343d41cea6d807396faaf69a Implements: blueprint network-property-unset
This commit is contained in:
parent
4b61efe3f9
commit
063c722a11
@ -185,3 +185,25 @@ Display subnet pool details
|
||||
.. describe:: <subnet-pool>
|
||||
|
||||
Subnet pool to display (name or ID)
|
||||
|
||||
subnet pool unset
|
||||
-----------------
|
||||
|
||||
Unset subnet pool properties
|
||||
|
||||
.. program:: subnet pool unset
|
||||
.. code:: bash
|
||||
|
||||
os subnet pool unset
|
||||
[--pool-prefix <pool-prefix> [...]]
|
||||
<subnet-pool>
|
||||
|
||||
.. option:: --pool-prefix <pool-prefix>
|
||||
|
||||
Remove subnet pool prefixes (in CIDR notation).
|
||||
(repeat option to unset multiple prefixes).
|
||||
|
||||
.. _subnet_pool_unset-subnet-pool:
|
||||
.. describe:: <subnet-pool>
|
||||
|
||||
Subnet pool to modify (name or ID)
|
||||
|
@ -12,6 +12,7 @@
|
||||
#
|
||||
|
||||
"""Subnet pool action implementations"""
|
||||
import copy
|
||||
|
||||
import logging
|
||||
|
||||
@ -337,3 +338,43 @@ class ShowSubnetPool(command.ShowOne):
|
||||
columns = _get_columns(obj)
|
||||
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
||||
return (columns, data)
|
||||
|
||||
|
||||
class UnsetSubnetPool(command.Command):
|
||||
"""Unset subnet pool properties"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(UnsetSubnetPool, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--pool-prefix',
|
||||
metavar='<pool-prefix>',
|
||||
action='append',
|
||||
dest='prefixes',
|
||||
help=_('Remove subnet pool prefixes (in CIDR notation). '
|
||||
'(repeat option to unset multiple prefixes).'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'subnet_pool',
|
||||
metavar="<subnet-pool>",
|
||||
help=_("Subnet pool to modify (name or ID)")
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.network
|
||||
obj = client.find_subnet_pool(
|
||||
parsed_args.subnet_pool, ignore_missing=False)
|
||||
tmp_prefixes = copy.deepcopy(obj.prefixes)
|
||||
attrs = {}
|
||||
if parsed_args.prefixes:
|
||||
for prefix in parsed_args.prefixes:
|
||||
try:
|
||||
tmp_prefixes.remove(prefix)
|
||||
except ValueError:
|
||||
msg = _(
|
||||
"Subnet pool does not "
|
||||
"contain prefix %s") % prefix
|
||||
raise exceptions.CommandError(msg)
|
||||
attrs['prefixes'] = tmp_prefixes
|
||||
if attrs:
|
||||
client.update_subnet_pool(obj, **attrs)
|
||||
|
@ -698,3 +698,42 @@ class TestShowSubnetPool(TestSubnetPool):
|
||||
)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, data)
|
||||
|
||||
|
||||
class TestUnsetSubnetPool(TestSubnetPool):
|
||||
|
||||
def setUp(self):
|
||||
super(TestUnsetSubnetPool, self).setUp()
|
||||
self._subnetpool = network_fakes.FakeSubnetPool.create_one_subnet_pool(
|
||||
{'prefixes': ['10.0.10.0/24', '10.1.10.0/24',
|
||||
'10.2.10.0/24'], })
|
||||
self.network.find_subnet_pool = mock.Mock(
|
||||
return_value=self._subnetpool)
|
||||
self.network.update_subnet_pool = mock.Mock(return_value=None)
|
||||
# Get the command object to test
|
||||
self.cmd = subnet_pool.UnsetSubnetPool(self.app, self.namespace)
|
||||
|
||||
def test_unset_subnet_pool(self):
|
||||
arglist = [
|
||||
'--pool-prefix', '10.0.10.0/24',
|
||||
'--pool-prefix', '10.1.10.0/24',
|
||||
self._subnetpool.name,
|
||||
]
|
||||
verifylist = [('prefixes', ['10.0.10.0/24', '10.1.10.0/24'])]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
attrs = {'prefixes': ['10.2.10.0/24']}
|
||||
self.network.update_subnet_pool.assert_called_once_with(
|
||||
self._subnetpool, **attrs)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_unset_subnet_pool_prefix_not_existent(self):
|
||||
arglist = [
|
||||
'--pool-prefix', '10.100.1.1/25',
|
||||
self._subnetpool.name,
|
||||
]
|
||||
verifylist = [('prefixes', ['10.100.1.1/25'])]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add a new command ``subnet pool unset`` to clear the information
|
||||
of pool-prefixes from the subnet pools.
|
||||
[ Blueprint `network-property-unset <https://blueprints.launchpad.net/python-openstackclient/+spec/network-property-unset>`_]
|
@ -390,6 +390,7 @@ openstack.network.v2 =
|
||||
subnet_pool_list = openstackclient.network.v2.subnet_pool:ListSubnetPool
|
||||
subnet_pool_set = openstackclient.network.v2.subnet_pool:SetSubnetPool
|
||||
subnet_pool_show = openstackclient.network.v2.subnet_pool:ShowSubnetPool
|
||||
subnet_pool_unset = openstackclient.network.v2.subnet_pool:UnsetSubnetPool
|
||||
|
||||
openstack.object_store.v1 =
|
||||
object_store_account_set = openstackclient.object.v1.account:SetAccount
|
||||
|
Loading…
Reference in New Issue
Block a user