Skip to content

Commit 00a1ddd

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Subnet Pool: Add "subnet pool delete" command"
2 parents 088f244 + 79fd6d3 commit 00a1ddd

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
@@ -679,3 +679,64 @@ def get_floating_ips(floating_ips=None, count=2):
679679
if floating_ips is None:
680680
floating_ips = FakeFloatingIP.create_floating_ips(count)
681681
return mock.MagicMock(side_effect=floating_ips)
682+
683+
684+
class FakeSubnetPool(object):
685+
"""Fake one or more subnet pools."""
686+
687+
@staticmethod
688+
def create_one_subnet_pool(attrs={}, methods={}):
689+
"""Create a fake subnet pool.
690+
691+
:param Dictionary attrs:
692+
A dictionary with all attributes
693+
:param Dictionary methods:
694+
A dictionary with all methods
695+
:return:
696+
A FakeResource object faking the subnet pool
697+
"""
698+
# Set default attributes.
699+
subnet_pool_attrs = {
700+
'id': 'subnet-pool-id-' + uuid.uuid4().hex,
701+
'name': 'subnet-pool-name-' + uuid.uuid4().hex,
702+
}
703+
704+
# Overwrite default attributes.
705+
subnet_pool_attrs.update(attrs)
706+
707+
# Set default methods.
708+
subnet_pool_methods = {
709+
'keys': ['id', 'name']
710+
}
711+
712+
# Overwrite default methods.
713+
subnet_pool_methods.update(methods)
714+
715+
subnet_pool = fakes.FakeResource(
716+
info=copy.deepcopy(subnet_pool_attrs),
717+
methods=copy.deepcopy(subnet_pool_methods),
718+
loaded=True
719+
)
720+
721+
return subnet_pool
722+
723+
@staticmethod
724+
def create_subnet_pools(attrs={}, methods={}, count=2):
725+
"""Create multiple fake subnet pools.
726+
727+
:param Dictionary attrs:
728+
A dictionary with all attributes
729+
:param Dictionary methods:
730+
A dictionary with all methods
731+
:param int count:
732+
The number of subnet pools to fake
733+
:return:
734+
A list of FakeResource objects faking the subnet pools
735+
"""
736+
subnet_pools = []
737+
for i in range(0, count):
738+
subnet_pools.append(
739+
FakeSubnetPool.create_one_subnet_pool(attrs, methods)
740+
)
741+
742+
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
security_group_delete = openstackclient.network.v2.security_group:DeleteSecurityGroup
342342
security_group_rule_delete = openstackclient.network.v2.security_group_rule:DeleteSecurityGroupRule
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)