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
This commit is contained in:
reedip 2016-03-01 10:46:04 +09:00
parent 3372de6f3b
commit 88c92bf71a
5 changed files with 69 additions and 0 deletions

View File

@ -34,3 +34,19 @@ Show subnet details
.. describe:: <subnet>
Subnet to show (name or ID)
subnet delete
-------------
Delete a subnet
.. program:: subnet delete
.. code:: bash
os subnet delete
<subnet>
.. _subnet_delete-subnet:
.. describe:: <subnet>
Subnet to delete (name or ID)

View File

@ -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="<subnet>",
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))

View File

@ -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)

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``subnet delete`` command to openstack-client.
[Bug `1542362 <https://bugs.launchpad.net/python-openstackclient/+bug/1542362>`_]

View File

@ -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