Skip to content

Commit 79fd6d3

Browse files
author
Tang Chen
committed
Subnet Pool: Add "subnet pool delete" command
Change-Id: Ic5ba5effcaea2410421a81da8ffce7c0295179e7 Closes-Bug: 1544587 Partially implements: blueprint neutron-client
1 parent 272ac55 commit 79fd6d3

7 files changed

Lines changed: 179 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
===========
2+
subnet pool
3+
===========
4+
5+
Network v2
6+
7+
subnet pool delete
8+
------------------
9+
10+
Delete subnet pool
11+
12+
.. program:: subnet pool delete
13+
.. code:: bash
14+
15+
os subnet pool delete
16+
<subnet-pool>
17+
18+
.. _subnet_pool_delete-subnet-pool:
19+
.. describe:: <subnet-pool>
20+
21+
Subnet pool to delete (name or ID)

doc/source/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ referring to both Compute and Volume quotas.
118118
* ``service provider``: (**Identity**) a resource that consumes assertions from an ``identity provider``
119119
* ``snapshot``: (**Volume**) a point-in-time copy of a volume
120120
* ``subnet``: (**Network**) - a contiguous range of IP addresses assigned to a network
121+
* ``subnet pool``: (**Network**) - a pool of subnets
121122
* ``token``: (**Identity**) a bearer token managed by Identity service
122123
* ``usage``: (**Compute**) display host resources being consumed
123124
* ``user``: (**Identity**) individual cloud resources users
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
14+
"""Subnet pool action implementations"""
15+
16+
from openstackclient.common import command
17+
18+
19+
class DeleteSubnetPool(command.Command):
20+
"""Delete subnet pool"""
21+
22+
def get_parser(self, prog_name):
23+
parser = super(DeleteSubnetPool, self).get_parser(prog_name)
24+
parser.add_argument(
25+
'subnet_pool',
26+
metavar="<subnet-pool>",
27+
help=("Subnet pool to delete (name or ID)")
28+
)
29+
return parser
30+
31+
def take_action(self, parsed_args):
32+
client = self.app.client_manager.network
33+
obj = client.find_subnet_pool(parsed_args.subnet_pool)
34+
client.delete_subnet_pool(obj)

openstackclient/tests/network/v2/fakes.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,64 @@ def get_floating_ips(floating_ips=None, count=2):
631631
if floating_ips is None:
632632
floating_ips = FakeFloatingIP.create_floating_ips(count)
633633
return mock.MagicMock(side_effect=floating_ips)
634+
635+
636+
class FakeSubnetPool(object):
637+
"""Fake one or more subnet pools."""
638+
639+
@staticmethod
640+
def create_one_subnet_pool(attrs={}, methods={}):
641+
"""Create a fake subnet pool.
642+
643+
:param Dictionary attrs:
644+
A dictionary with all attributes
645+
:param Dictionary methods:
646+
A dictionary with all methods
647+
:return:
648+
A FakeResource object faking the subnet pool
649+
"""
650+
# Set default attributes.
651+
subnet_pool_attrs = {
652+
'id': 'subnet-pool-id-' + uuid.uuid4().hex,
653+
'name': 'subnet-pool-name-' + uuid.uuid4().hex,
654+
}
655+
656+
# Overwrite default attributes.
657+
subnet_pool_attrs.update(attrs)
658+
659+
# Set default methods.
660+
subnet_pool_methods = {
661+
'keys': ['id', 'name']
662+
}
663+
664+
# Overwrite default methods.
665+
subnet_pool_methods.update(methods)
666+
667+
subnet_pool = fakes.FakeResource(
668+
info=copy.deepcopy(subnet_pool_attrs),
669+
methods=copy.deepcopy(subnet_pool_methods),
670+
loaded=True
671+
)
672+
673+
return subnet_pool
674+
675+
@staticmethod
676+
def create_subnet_pools(attrs={}, methods={}, count=2):
677+
"""Create multiple fake subnet pools.
678+
679+
:param Dictionary attrs:
680+
A dictionary with all attributes
681+
:param Dictionary methods:
682+
A dictionary with all methods
683+
:param int count:
684+
The number of subnet pools to fake
685+
:return:
686+
A list of FakeResource objects faking the subnet pools
687+
"""
688+
subnet_pools = []
689+
for i in range(0, count):
690+
subnet_pools.append(
691+
FakeSubnetPool.create_one_subnet_pool(attrs, methods)
692+
)
693+
694+
return subnet_pools
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
14+
import mock
15+
16+
from openstackclient.network.v2 import subnet_pool
17+
from openstackclient.tests.network.v2 import fakes as network_fakes
18+
19+
20+
class TestSubnetPool(network_fakes.TestNetworkV2):
21+
def setUp(self):
22+
super(TestSubnetPool, self).setUp()
23+
24+
# Get a shortcut to the network client
25+
self.network = self.app.client_manager.network
26+
27+
28+
class TestDeleteSubnetPool(TestSubnetPool):
29+
30+
# The subnet pool to delete.
31+
_subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
32+
33+
def setUp(self):
34+
super(TestDeleteSubnetPool, self).setUp()
35+
36+
self.network.delete_subnet_pool = mock.Mock(return_value=None)
37+
38+
self.network.find_subnet_pool = mock.Mock(
39+
return_value=self._subnet_pool
40+
)
41+
42+
# Get the command object to test
43+
self.cmd = subnet_pool.DeleteSubnetPool(self.app, self.namespace)
44+
45+
def test_delete(self):
46+
arglist = [
47+
self._subnet_pool.name,
48+
]
49+
verifylist = [
50+
('subnet_pool', self._subnet_pool.name),
51+
]
52+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
53+
54+
result = self.cmd.take_action(parsed_args)
55+
56+
self.network.delete_subnet_pool.assert_called_with(self._subnet_pool)
57+
self.assertIsNone(result)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- Add support for ``subnet pool delete`` command.
4+
[Bug `1544587 <https://bugs.launchpad.net/python-openstackclient/+bug/1544587>`_]

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ openstack.network.v2 =
341341
router_show = openstackclient.network.v2.router:ShowRouter
342342
security_group_delete = openstackclient.network.v2.security_group:DeleteSecurityGroup
343343
subnet_list = openstackclient.network.v2.subnet:ListSubnet
344+
subnet_pool_delete = openstackclient.network.v2.subnet_pool:DeleteSubnetPool
344345

345346
openstack.object_store.v1 =
346347
object_store_account_set = openstackclient.object.v1.account:SetAccount

0 commit comments

Comments
 (0)