Subnet Pool: Add "subnet pool show" command

Change-Id: I8dda7bbf1e27b0ac773f62a5cd293387da96f8df
Closes-Bug: 1544590
Implements: blueprint neutron-client
This commit is contained in:
Tang Chen 2016-02-13 10:13:14 +08:00
parent a04012c3d5
commit 3c8bb16513
6 changed files with 147 additions and 1 deletions

View File

@ -34,3 +34,19 @@ List subnet pools
.. option:: --long
List additional fields in output
subnet pool show
----------------
Show subnet pool details
.. program:: subnet pool show
.. code:: bash
os subnet pool show
<subnet-pool>
.. _subnet_pool_show-subnet-pool:
.. describe:: <subnet-pool>
Subnet pool to show (name or ID)

View File

@ -17,6 +17,19 @@ from openstackclient.common import command
from openstackclient.common import utils
def _get_columns(item):
columns = item.keys()
if 'tenant_id' in columns:
columns.remove('tenant_id')
columns.append('project_id')
return tuple(sorted(columns))
_formatters = {
'prefixes': utils.format_list,
}
class DeleteSubnetPool(command.Command):
"""Delete subnet pool"""
@ -83,3 +96,26 @@ class ListSubnetPool(command.Lister):
s, columns,
formatters={},
) for s in data))
class ShowSubnetPool(command.ShowOne):
"""Show subnet pool details"""
def get_parser(self, prog_name):
parser = super(ShowSubnetPool, self).get_parser(prog_name)
parser.add_argument(
'subnet_pool',
metavar="<subnet-pool>",
help=("Subnet pool to show (name or ID)")
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
obj = client.find_subnet_pool(
parsed_args.subnet_pool,
ignore_missing=False
)
columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
return (columns, data)

View File

@ -696,12 +696,24 @@ class FakeSubnetPool(object):
A FakeResource object faking the subnet pool
"""
# Set default attributes.
project_id = 'project-id-' + uuid.uuid4().hex
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,
'tenant_id': project_id,
'is_default': False,
'shared': False,
'max_prefixlen': 32,
'min_prefixlen': 8,
'default_quota': None,
'ip_version': 4,
# OpenStack SDK automatically translates project_id to tenant_id.
# So we need an additional attr to simulate this behavior.
'project_id': project_id,
}
# Overwrite default attributes.
@ -710,7 +722,9 @@ class FakeSubnetPool(object):
# Set default methods.
subnet_pool_methods = {
'keys': ['id', 'name', 'prefixes', 'default_prefixlen',
'address_scope_id']
'address_scope_id', 'tenant_id', 'is_default',
'shared', 'max_prefixlen', 'min_prefixlen',
'default_quota', 'ip_version']
}
# Overwrite default methods.

View File

@ -13,8 +13,10 @@
import mock
from openstackclient.common import utils
from openstackclient.network.v2 import subnet_pool
from openstackclient.tests.network.v2 import fakes as network_fakes
from openstackclient.tests import utils as tests_utils
class TestSubnetPool(network_fakes.TestNetworkV2):
@ -124,3 +126,76 @@ class TestListSubnetPool(TestSubnetPool):
self.network.subnet_pools.assert_called_with()
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))
class TestShowSubnetPool(TestSubnetPool):
# The subnet_pool to set.
_subnet_pool = network_fakes.FakeSubnetPool.create_one_subnet_pool()
columns = (
'address_scope_id',
'default_prefixlen',
'default_quota',
'id',
'ip_version',
'is_default',
'max_prefixlen',
'min_prefixlen',
'name',
'prefixes',
'project_id',
'shared',
)
data = (
_subnet_pool.address_scope_id,
_subnet_pool.default_prefixlen,
_subnet_pool.default_quota,
_subnet_pool.id,
_subnet_pool.ip_version,
_subnet_pool.is_default,
_subnet_pool.max_prefixlen,
_subnet_pool.min_prefixlen,
_subnet_pool.name,
utils.format_list(_subnet_pool.prefixes),
_subnet_pool.tenant_id,
_subnet_pool.shared,
)
def setUp(self):
super(TestShowSubnetPool, self).setUp()
self.network.find_subnet_pool = mock.Mock(
return_value=self._subnet_pool
)
# Get the command object to test
self.cmd = subnet_pool.ShowSubnetPool(self.app, self.namespace)
def test_show_no_options(self):
arglist = []
verifylist = []
# Missing required args should bail here
self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist)
def test_show_all_options(self):
arglist = [
self._subnet_pool.name,
]
verifylist = [
('subnet_pool', self._subnet_pool.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.network.find_subnet_pool.assert_called_with(
self._subnet_pool.name,
ignore_missing=False
)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)

View File

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

View File

@ -343,6 +343,7 @@ openstack.network.v2 =
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
subnet_pool_show = openstackclient.network.v2.subnet_pool:ShowSubnetPool
openstack.object_store.v1 =
object_store_account_set = openstackclient.object.v1.account:SetAccount