From 88c92bf71ae026b90b07411772c66b718a7d59e1 Mon Sep 17 00:00:00 2001 From: reedip Date: Tue, 1 Mar 2016 10:46:04 +0900 Subject: [PATCH] Subnet: Add "subnet delete" command using SDK This patch adds "subnet delete" command to osc using sdk. Change-Id: I6be27406b16909c6db2b95417355be302e218a8d Implements: blueprint neutron-client Closes-bug: #1542362 --- doc/source/command-objects/subnet.rst | 16 ++++++++++ openstackclient/network/v2/subnet.py | 18 ++++++++++++ .../tests/network/v2/test_subnet.py | 29 +++++++++++++++++++ .../notes/bug-1542362-ddad607f6d3025f0.yaml | 5 ++++ setup.cfg | 1 + 5 files changed, 69 insertions(+) create mode 100644 releasenotes/notes/bug-1542362-ddad607f6d3025f0.yaml diff --git a/doc/source/command-objects/subnet.rst b/doc/source/command-objects/subnet.rst index 12b056658d..9520a22d6a 100644 --- a/doc/source/command-objects/subnet.rst +++ b/doc/source/command-objects/subnet.rst @@ -34,3 +34,19 @@ Show subnet details .. describe:: Subnet to show (name or ID) + +subnet delete +------------- + +Delete a subnet + +.. program:: subnet delete +.. code:: bash + + os subnet delete + + +.. _subnet_delete-subnet: +.. describe:: + + Subnet to delete (name or ID) diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py index 7ed02a3a30..96ab35ae74 100644 --- a/openstackclient/network/v2/subnet.py +++ b/openstackclient/network/v2/subnet.py @@ -89,3 +89,21 @@ class ShowSubnet(command.ShowOne): columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (columns, data) + + +class DeleteSubnet(command.Command): + """Delete subnet""" + + def get_parser(self, prog_name): + parser = super(DeleteSubnet, self).get_parser(prog_name) + parser.add_argument( + 'subnet', + metavar="", + help=("Subnet to delete (name or ID)") + ) + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.network + client.delete_subnet( + client.find_subnet(parsed_args.subnet)) diff --git a/openstackclient/tests/network/v2/test_subnet.py b/openstackclient/tests/network/v2/test_subnet.py index e1e663f462..e844c1388b 100644 --- a/openstackclient/tests/network/v2/test_subnet.py +++ b/openstackclient/tests/network/v2/test_subnet.py @@ -181,3 +181,32 @@ class TestShowSubnet(TestSubnet): self.assertEqual(self.columns, columns) self.assertEqual(list(self.data), list(data)) + + +class TestDeleteSubnet(TestSubnet): + + # The subnet to delete. + _subnet = network_fakes.FakeSubnet.create_one_subnet() + + def setUp(self): + super(TestDeleteSubnet, self).setUp() + + self.network.delete_subnet = mock.Mock(return_value=None) + + self.network.find_subnet = mock.Mock(return_value=self._subnet) + + # Get the command object to test + self.cmd = subnet_v2.DeleteSubnet(self.app, self.namespace) + + def test_delete(self): + arglist = [ + self._subnet.name, + ] + verifylist = [ + ('subnet', self._subnet.name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + self.network.delete_subnet.assert_called_with(self._subnet) + self.assertIsNone(result) diff --git a/releasenotes/notes/bug-1542362-ddad607f6d3025f0.yaml b/releasenotes/notes/bug-1542362-ddad607f6d3025f0.yaml new file mode 100644 index 0000000000..f405522164 --- /dev/null +++ b/releasenotes/notes/bug-1542362-ddad607f6d3025f0.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``subnet delete`` command to openstack-client. + [Bug `1542362 `_] diff --git a/setup.cfg b/setup.cfg index 0750d7ef7a..136510bf3a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -342,6 +342,7 @@ openstack.network.v2 = security_group_delete = openstackclient.network.v2.security_group:DeleteSecurityGroup security_group_rule_delete = openstackclient.network.v2.security_group_rule:DeleteSecurityGroupRule security_group_rule_show = openstackclient.network.v2.security_group_rule:ShowSecurityGroupRule + subnet_delete = openstackclient.network.v2.subnet:DeleteSubnet subnet_list = openstackclient.network.v2.subnet:ListSubnet subnet_show = openstackclient.network.v2.subnet:ShowSubnet subnet_pool_delete = openstackclient.network.v2.subnet_pool:DeleteSubnetPool