Subnet Pool: Add "subnet pool delete" command
Change-Id: Ic5ba5effcaea2410421a81da8ffce7c0295179e7 Closes-Bug: 1544587 Partially implements: blueprint neutron-client
This commit is contained in:
parent
272ac55776
commit
79fd6d3f20
21
doc/source/command-objects/subnet_pool.rst
Normal file
21
doc/source/command-objects/subnet_pool.rst
Normal file
@ -0,0 +1,21 @@
|
||||
===========
|
||||
subnet pool
|
||||
===========
|
||||
|
||||
Network v2
|
||||
|
||||
subnet pool delete
|
||||
------------------
|
||||
|
||||
Delete subnet pool
|
||||
|
||||
.. program:: subnet pool delete
|
||||
.. code:: bash
|
||||
|
||||
os subnet pool delete
|
||||
<subnet-pool>
|
||||
|
||||
.. _subnet_pool_delete-subnet-pool:
|
||||
.. describe:: <subnet-pool>
|
||||
|
||||
Subnet pool to delete (name or ID)
|
@ -118,6 +118,7 @@ referring to both Compute and Volume quotas.
|
||||
* ``service provider``: (**Identity**) a resource that consumes assertions from an ``identity provider``
|
||||
* ``snapshot``: (**Volume**) a point-in-time copy of a volume
|
||||
* ``subnet``: (**Network**) - a contiguous range of IP addresses assigned to a network
|
||||
* ``subnet pool``: (**Network**) - a pool of subnets
|
||||
* ``token``: (**Identity**) a bearer token managed by Identity service
|
||||
* ``usage``: (**Compute**) display host resources being consumed
|
||||
* ``user``: (**Identity**) individual cloud resources users
|
||||
|
34
openstackclient/network/v2/subnet_pool.py
Normal file
34
openstackclient/network/v2/subnet_pool.py
Normal file
@ -0,0 +1,34 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
"""Subnet pool action implementations"""
|
||||
|
||||
from openstackclient.common import command
|
||||
|
||||
|
||||
class DeleteSubnetPool(command.Command):
|
||||
"""Delete subnet pool"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(DeleteSubnetPool, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'subnet_pool',
|
||||
metavar="<subnet-pool>",
|
||||
help=("Subnet pool to delete (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)
|
||||
client.delete_subnet_pool(obj)
|
@ -631,3 +631,64 @@ class FakeFloatingIP(object):
|
||||
if floating_ips is None:
|
||||
floating_ips = FakeFloatingIP.create_floating_ips(count)
|
||||
return mock.MagicMock(side_effect=floating_ips)
|
||||
|
||||
|
||||
class FakeSubnetPool(object):
|
||||
"""Fake one or more subnet pools."""
|
||||
|
||||
@staticmethod
|
||||
def create_one_subnet_pool(attrs={}, methods={}):
|
||||
"""Create a fake subnet pool.
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attributes
|
||||
:param Dictionary methods:
|
||||
A dictionary with all methods
|
||||
:return:
|
||||
A FakeResource object faking the subnet pool
|
||||
"""
|
||||
# Set default attributes.
|
||||
subnet_pool_attrs = {
|
||||
'id': 'subnet-pool-id-' + uuid.uuid4().hex,
|
||||
'name': 'subnet-pool-name-' + uuid.uuid4().hex,
|
||||
}
|
||||
|
||||
# Overwrite default attributes.
|
||||
subnet_pool_attrs.update(attrs)
|
||||
|
||||
# Set default methods.
|
||||
subnet_pool_methods = {
|
||||
'keys': ['id', 'name']
|
||||
}
|
||||
|
||||
# Overwrite default methods.
|
||||
subnet_pool_methods.update(methods)
|
||||
|
||||
subnet_pool = fakes.FakeResource(
|
||||
info=copy.deepcopy(subnet_pool_attrs),
|
||||
methods=copy.deepcopy(subnet_pool_methods),
|
||||
loaded=True
|
||||
)
|
||||
|
||||
return subnet_pool
|
||||
|
||||
@staticmethod
|
||||
def create_subnet_pools(attrs={}, methods={}, count=2):
|
||||
"""Create multiple fake subnet pools.
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attributes
|
||||
:param Dictionary methods:
|
||||
A dictionary with all methods
|
||||
:param int count:
|
||||
The number of subnet pools to fake
|
||||
:return:
|
||||
A list of FakeResource objects faking the subnet pools
|
||||
"""
|
||||
subnet_pools = []
|
||||
for i in range(0, count):
|
||||
subnet_pools.append(
|
||||
FakeSubnetPool.create_one_subnet_pool(attrs, methods)
|
||||
)
|
||||
|
||||
return subnet_pools
|
||||
|
57
openstackclient/tests/network/v2/test_subnet_pool.py
Normal file
57
openstackclient/tests/network/v2/test_subnet_pool.py
Normal file
@ -0,0 +1,57 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import mock
|
||||
|
||||
from openstackclient.network.v2 import subnet_pool
|
||||
from openstackclient.tests.network.v2 import fakes as network_fakes
|
||||
|
||||
|
||||
class TestSubnetPool(network_fakes.TestNetworkV2):
|
||||
def setUp(self):
|
||||
super(TestSubnetPool, self).setUp()
|
||||
|
||||
# Get a shortcut to the network client
|
||||
self.network = self.app.client_manager.network
|
||||
|
||||
|
||||
class TestDeleteSubnetPool(TestSubnetPool):
|
||||
|
||||
# The subnet pool to delete.
|
||||
_subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
|
||||
|
||||
def setUp(self):
|
||||
super(TestDeleteSubnetPool, self).setUp()
|
||||
|
||||
self.network.delete_subnet_pool = mock.Mock(return_value=None)
|
||||
|
||||
self.network.find_subnet_pool = mock.Mock(
|
||||
return_value=self._subnet_pool
|
||||
)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = subnet_pool.DeleteSubnetPool(self.app, self.namespace)
|
||||
|
||||
def test_delete(self):
|
||||
arglist = [
|
||||
self._subnet_pool.name,
|
||||
]
|
||||
verifylist = [
|
||||
('subnet_pool', self._subnet_pool.name),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.delete_subnet_pool.assert_called_with(self._subnet_pool)
|
||||
self.assertIsNone(result)
|
4
releasenotes/notes/bug-1544587-ec3ca453c1340b4e.yaml
Normal file
4
releasenotes/notes/bug-1544587-ec3ca453c1340b4e.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- Add support for ``subnet pool delete`` command.
|
||||
[Bug `1544587 <https://bugs.launchpad.net/python-openstackclient/+bug/1544587>`_]
|
@ -341,6 +341,7 @@ openstack.network.v2 =
|
||||
router_show = openstackclient.network.v2.router:ShowRouter
|
||||
security_group_delete = openstackclient.network.v2.security_group:DeleteSecurityGroup
|
||||
subnet_list = openstackclient.network.v2.subnet:ListSubnet
|
||||
subnet_pool_delete = openstackclient.network.v2.subnet_pool:DeleteSubnetPool
|
||||
|
||||
openstack.object_store.v1 =
|
||||
object_store_account_set = openstackclient.object.v1.account:SetAccount
|
||||
|
Loading…
Reference in New Issue
Block a user