Implement "address scope show" command
This patch add a command that supports showing address scope details Change-Id: Ic0b41c1cab8c618904c7a6046d7493db5b74b430 Partial-Bug: #1566269
This commit is contained in:
parent
aa5ff67e3f
commit
32da111c17
@ -72,3 +72,19 @@ List address scopes
|
||||
.. code:: bash
|
||||
|
||||
os address scope list
|
||||
|
||||
address scope show
|
||||
------------------
|
||||
|
||||
Display address scope details
|
||||
|
||||
.. program:: address scope show
|
||||
.. code:: bash
|
||||
|
||||
os address scope show
|
||||
<address-scope>
|
||||
|
||||
.. _address_scope_show-address-scope:
|
||||
.. describe:: <address-scope>
|
||||
|
||||
Address scope to display (name or ID)
|
||||
|
@ -140,3 +140,27 @@ class ListAddressScope(command.Lister):
|
||||
(utils.get_item_properties(
|
||||
s, columns, formatters={},
|
||||
) for s in data))
|
||||
|
||||
|
||||
class ShowAddressScope(command.ShowOne):
|
||||
"""Display address scope details"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowAddressScope, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'address_scope',
|
||||
metavar="<address-scope>",
|
||||
help=_("Address scope to display (name or ID)")
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
client = self.app.client_manager.network
|
||||
obj = client.find_address_scope(
|
||||
parsed_args.address_scope,
|
||||
ignore_missing=False)
|
||||
columns = _get_columns(obj)
|
||||
data = utils.get_item_properties(obj, columns, formatters={})
|
||||
|
||||
return columns, data
|
||||
|
@ -235,3 +235,56 @@ class TestListAddressScope(TestAddressScope):
|
||||
self.network.address_scopes.assert_called_once_with(**{})
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(self.data, list(data))
|
||||
|
||||
|
||||
class TestShowAddressScope(TestAddressScope):
|
||||
|
||||
# The address scope to show.
|
||||
_address_scope = (
|
||||
network_fakes.FakeAddressScope.create_one_address_scope())
|
||||
columns = (
|
||||
'id',
|
||||
'ip_version',
|
||||
'name',
|
||||
'project_id',
|
||||
'shared',
|
||||
)
|
||||
data = (
|
||||
_address_scope.id,
|
||||
_address_scope.ip_version,
|
||||
_address_scope.name,
|
||||
_address_scope.project_id,
|
||||
_address_scope.shared,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestShowAddressScope, self).setUp()
|
||||
self.network.find_address_scope = mock.Mock(
|
||||
return_value=self._address_scope)
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = address_scope.ShowAddressScope(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._address_scope.name,
|
||||
]
|
||||
verifylist = [
|
||||
('address_scope', self._address_scope.name),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.network.find_address_scope.assert_called_once_with(
|
||||
self._address_scope.name, ignore_missing=False)
|
||||
self.assertEqual(self.columns, columns)
|
||||
self.assertEqual(list(self.data), list(data))
|
||||
|
@ -322,6 +322,7 @@ openstack.network.v2 =
|
||||
address_scope_create = openstackclient.network.v2.address_scope:CreateAddressScope
|
||||
address_scope_delete = openstackclient.network.v2.address_scope:DeleteAddressScope
|
||||
address_scope_list = openstackclient.network.v2.address_scope:ListAddressScope
|
||||
address_scope_show = openstackclient.network.v2.address_scope:ShowAddressScope
|
||||
|
||||
ip_floating_create = openstackclient.network.v2.floating_ip:CreateFloatingIP
|
||||
ip_floating_delete = openstackclient.network.v2.floating_ip:DeleteFloatingIP
|
||||
|
Loading…
Reference in New Issue
Block a user