Subnet Pool: Add "subnet pool list" command

Change-Id: I7935be2488fb728ced9680d75880870e5d315655
Closes-Bug: 1544589
Implements: blueprint neutron-client
This commit is contained in:
Tang Chen 2016-02-13 09:49:46 +08:00
parent 444fc6149d
commit a04012c3d5
6 changed files with 145 additions and 1 deletions

View File

@ -19,3 +19,18 @@ Delete subnet pool
.. describe:: <subnet-pool>
Subnet pool to delete (name or ID)
subnet pool list
----------------
List subnet pools
.. program:: subnet pool list
.. code:: bash
os subnet pool list
[--long]
.. option:: --long
List additional fields in output

View File

@ -14,6 +14,7 @@
"""Subnet pool action implementations"""
from openstackclient.common import command
from openstackclient.common import utils
class DeleteSubnetPool(command.Command):
@ -32,3 +33,53 @@ class DeleteSubnetPool(command.Command):
client = self.app.client_manager.network
obj = client.find_subnet_pool(parsed_args.subnet_pool)
client.delete_subnet_pool(obj)
class ListSubnetPool(command.Lister):
"""List subnet pools"""
def get_parser(self, prog_name):
parser = super(ListSubnetPool, self).get_parser(prog_name)
parser.add_argument(
'--long',
action='store_true',
default=False,
help='List additional fields in output',
)
return parser
def take_action(self, parsed_args):
data = self.app.client_manager.network.subnet_pools()
if parsed_args.long:
headers = (
'ID',
'Name',
'Prefixes',
'Default Prefix Length',
'Address Scope',
)
columns = (
'id',
'name',
'prefixes',
'default_prefixlen',
'address_scope_id',
)
else:
headers = (
'ID',
'Name',
'Prefixes',
)
columns = (
'id',
'name',
'prefixes',
)
return (headers,
(utils.get_item_properties(
s, columns,
formatters={},
) for s in data))

View File

@ -699,6 +699,9 @@ class FakeSubnetPool(object):
subnet_pool_attrs = {
'id': 'subnet-pool-id-' + uuid.uuid4().hex,
'name': 'subnet-pool-name-' + uuid.uuid4().hex,
'prefixes': ['10.0.0.0/24', '10.1.0.0/24'],
'default_prefixlen': 8,
'address_scope_id': 'address-scope-id-' + uuid.uuid4().hex,
}
# Overwrite default attributes.
@ -706,7 +709,8 @@ class FakeSubnetPool(object):
# Set default methods.
subnet_pool_methods = {
'keys': ['id', 'name']
'keys': ['id', 'name', 'prefixes', 'default_prefixlen',
'address_scope_id']
}
# Overwrite default methods.

View File

@ -55,3 +55,72 @@ class TestDeleteSubnetPool(TestSubnetPool):
self.network.delete_subnet_pool.assert_called_with(self._subnet_pool)
self.assertIsNone(result)
class TestListSubnetPool(TestSubnetPool):
# The subnet pools going to be listed up.
_subnet_pools = network_fakes.FakeSubnetPool.create_subnet_pools(count=3)
columns = (
'ID',
'Name',
'Prefixes',
)
columns_long = columns + (
'Default Prefix Length',
'Address Scope',
)
data = []
for pool in _subnet_pools:
data.append((
pool.id,
pool.name,
pool.prefixes,
))
data_long = []
for pool in _subnet_pools:
data_long.append((
pool.id,
pool.name,
pool.prefixes,
pool.default_prefixlen,
pool.address_scope_id,
))
def setUp(self):
super(TestListSubnetPool, self).setUp()
# Get the command object to test
self.cmd = subnet_pool.ListSubnetPool(self.app, self.namespace)
self.network.subnet_pools = mock.Mock(return_value=self._subnet_pools)
def test_subnet_pool_list_no_option(self):
arglist = []
verifylist = [
('long', False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.network.subnet_pools.assert_called_with()
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
def test_subnet_pool_list_long(self):
arglist = [
'--long',
]
verifylist = [
('long', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.network.subnet_pools.assert_called_with()
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))

View File

@ -0,0 +1,4 @@
---
features:
- Add support for ``subnet pool list`` command.
[Bug `1544589 <https://bugs.launchpad.net/python-openstackclient/+bug/1544589>`_]

View File

@ -342,6 +342,7 @@ openstack.network.v2 =
security_group_rule_delete = openstackclient.network.v2.security_group_rule:DeleteSecurityGroupRule
subnet_list = openstackclient.network.v2.subnet:ListSubnet
subnet_pool_delete = openstackclient.network.v2.subnet_pool:DeleteSubnetPool
subnet_pool_list = openstackclient.network.v2.subnet_pool:ListSubnetPool
openstack.object_store.v1 =
object_store_account_set = openstackclient.object.v1.account:SetAccount