diff options
| author | reedip <reedip.banerjee@nectechnologies.in> | 2016-04-15 15:27:18 +0900 |
|---|---|---|
| committer | Reedip <reedip.banerjee@nectechnologies.in> | 2016-06-30 08:14:58 +0000 |
| commit | 063c722a110031883e9615064092644de6df8da2 (patch) | |
| tree | fcdf62fb46ac2543163369ee33d39c374ab21a1e | |
| parent | 4b61efe3f9f6158c6062ff3c56bb5116b7f08d87 (diff) | |
| download | python-openstackclient-063c722a110031883e9615064092644de6df8da2.tar.gz | |
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
| -rw-r--r-- | doc/source/command-objects/subnet-pool.rst | 22 | ||||
| -rw-r--r-- | openstackclient/network/v2/subnet_pool.py | 41 | ||||
| -rw-r--r-- | openstackclient/tests/network/v2/test_subnet_pool.py | 39 | ||||
| -rw-r--r-- | releasenotes/notes/unset-subnet-pool-333052dd85b95653.yaml | 6 | ||||
| -rw-r--r-- | setup.cfg | 1 |
5 files changed, 109 insertions, 0 deletions
diff --git a/doc/source/command-objects/subnet-pool.rst b/doc/source/command-objects/subnet-pool.rst index 516b9bf4..005b8357 100644 --- a/doc/source/command-objects/subnet-pool.rst +++ b/doc/source/command-objects/subnet-pool.rst @@ -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) diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py index 55dfed83..ed2bb0ef 100644 --- a/openstackclient/network/v2/subnet_pool.py +++ b/openstackclient/network/v2/subnet_pool.py @@ -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) diff --git a/openstackclient/tests/network/v2/test_subnet_pool.py b/openstackclient/tests/network/v2/test_subnet_pool.py index 7a96b30f..41b6170f 100644 --- a/openstackclient/tests/network/v2/test_subnet_pool.py +++ b/openstackclient/tests/network/v2/test_subnet_pool.py @@ -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) diff --git a/releasenotes/notes/unset-subnet-pool-333052dd85b95653.yaml b/releasenotes/notes/unset-subnet-pool-333052dd85b95653.yaml new file mode 100644 index 00000000..7fbda240 --- /dev/null +++ b/releasenotes/notes/unset-subnet-pool-333052dd85b95653.yaml @@ -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 |
