Support "network show" command in nova network
"network show" command is not implemented in nova network. This patch implements it. Change-Id: I1fadd890fe36c4e3ac5c9ed389b20c5b2fff8aca partial-Bug: 1543672
This commit is contained in:
parent
ddc97c6dc5
commit
d9d1809907
@ -316,7 +316,7 @@ class SetNetwork(command.Command):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
class ShowNetwork(command.ShowOne):
|
class ShowNetwork(common.NetworkAndComputeShowOne):
|
||||||
"""Show network details"""
|
"""Show network details"""
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
@ -328,9 +328,17 @@ class ShowNetwork(command.ShowOne):
|
|||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action_network(self, client, parsed_args):
|
||||||
client = self.app.client_manager.network
|
|
||||||
obj = client.find_network(parsed_args.network, ignore_missing=False)
|
obj = client.find_network(parsed_args.network, ignore_missing=False)
|
||||||
columns = _get_columns(obj)
|
columns = _get_columns(obj)
|
||||||
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
||||||
return (columns, data)
|
return (columns, data)
|
||||||
|
|
||||||
|
def take_action_compute(self, client, parsed_args):
|
||||||
|
network = utils.find_resource(
|
||||||
|
client.networks,
|
||||||
|
parsed_args.network,
|
||||||
|
)
|
||||||
|
columns = sorted(network._info.keys())
|
||||||
|
data = utils.get_dict_properties(network._info, columns)
|
||||||
|
return (columns, data)
|
||||||
|
@ -539,13 +539,42 @@ class FakeNetwork(object):
|
|||||||
:param Dictionary methods:
|
:param Dictionary methods:
|
||||||
A dictionary with all methods
|
A dictionary with all methods
|
||||||
:return:
|
:return:
|
||||||
A FakeResource object, with id, label, cidr
|
A FakeResource object, with id, label, cidr and so on
|
||||||
"""
|
"""
|
||||||
# Set default attributes.
|
# Set default attributes.
|
||||||
network_attrs = {
|
network_attrs = {
|
||||||
'id': 'network-id-' + uuid.uuid4().hex,
|
'bridge': 'br100',
|
||||||
'label': 'network-label-' + uuid.uuid4().hex,
|
'bridge_interface': None,
|
||||||
|
'broadcast': '10.0.0.255',
|
||||||
'cidr': '10.0.0.0/24',
|
'cidr': '10.0.0.0/24',
|
||||||
|
'cidr_v6': None,
|
||||||
|
'created_at': '2016-02-11T11:17:37.000000',
|
||||||
|
'deleted': False,
|
||||||
|
'deleted_at': None,
|
||||||
|
'dhcp_server': '10.0.0.1',
|
||||||
|
'dhcp_start': '10.0.0.2',
|
||||||
|
'dns1': '8.8.4.4',
|
||||||
|
'dns2': None,
|
||||||
|
'enable_dhcp': True,
|
||||||
|
'gateway': '10.0.0.1',
|
||||||
|
'gateway_v6': None,
|
||||||
|
'host': None,
|
||||||
|
'id': 'network-id-' + uuid.uuid4().hex,
|
||||||
|
'injected': False,
|
||||||
|
'label': 'network-label-' + uuid.uuid4().hex,
|
||||||
|
'mtu': None,
|
||||||
|
'multi_host': False,
|
||||||
|
'netmask': '255.255.255.0',
|
||||||
|
'netmask_v6': None,
|
||||||
|
'priority': None,
|
||||||
|
'project_id': 'project-id-' + uuid.uuid4().hex,
|
||||||
|
'rxtx_base': None,
|
||||||
|
'share_address': False,
|
||||||
|
'updated_at': None,
|
||||||
|
'vlan': None,
|
||||||
|
'vpn_private_address': None,
|
||||||
|
'vpn_public_address': None,
|
||||||
|
'vpn_public_port': None,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Overwrite default attributes.
|
# Overwrite default attributes.
|
||||||
|
@ -654,3 +654,112 @@ class TestListNetworkCompute(TestNetworkCompute):
|
|||||||
self.compute.networks.list.assert_called_with()
|
self.compute.networks.list.assert_called_with()
|
||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(self.data, list(data))
|
self.assertEqual(self.data, list(data))
|
||||||
|
|
||||||
|
|
||||||
|
class TestShowNetworkCompute(TestNetworkCompute):
|
||||||
|
|
||||||
|
# The network to show.
|
||||||
|
_network = compute_fakes.FakeNetwork.create_one_network()
|
||||||
|
|
||||||
|
columns = (
|
||||||
|
'bridge',
|
||||||
|
'bridge_interface',
|
||||||
|
'broadcast',
|
||||||
|
'cidr',
|
||||||
|
'cidr_v6',
|
||||||
|
'created_at',
|
||||||
|
'deleted',
|
||||||
|
'deleted_at',
|
||||||
|
'dhcp_server',
|
||||||
|
'dhcp_start',
|
||||||
|
'dns1',
|
||||||
|
'dns2',
|
||||||
|
'enable_dhcp',
|
||||||
|
'gateway',
|
||||||
|
'gateway_v6',
|
||||||
|
'host',
|
||||||
|
'id',
|
||||||
|
'injected',
|
||||||
|
'label',
|
||||||
|
'mtu',
|
||||||
|
'multi_host',
|
||||||
|
'netmask',
|
||||||
|
'netmask_v6',
|
||||||
|
'priority',
|
||||||
|
'project_id',
|
||||||
|
'rxtx_base',
|
||||||
|
'share_address',
|
||||||
|
'updated_at',
|
||||||
|
'vlan',
|
||||||
|
'vpn_private_address',
|
||||||
|
'vpn_public_address',
|
||||||
|
'vpn_public_port',
|
||||||
|
)
|
||||||
|
|
||||||
|
data = (
|
||||||
|
_network.bridge,
|
||||||
|
_network.bridge_interface,
|
||||||
|
_network.broadcast,
|
||||||
|
_network.cidr,
|
||||||
|
_network.cidr_v6,
|
||||||
|
_network.created_at,
|
||||||
|
_network.deleted,
|
||||||
|
_network.deleted_at,
|
||||||
|
_network.dhcp_server,
|
||||||
|
_network.dhcp_start,
|
||||||
|
_network.dns1,
|
||||||
|
_network.dns2,
|
||||||
|
_network.enable_dhcp,
|
||||||
|
_network.gateway,
|
||||||
|
_network.gateway_v6,
|
||||||
|
_network.host,
|
||||||
|
_network.id,
|
||||||
|
_network.injected,
|
||||||
|
_network.label,
|
||||||
|
_network.mtu,
|
||||||
|
_network.multi_host,
|
||||||
|
_network.netmask,
|
||||||
|
_network.netmask_v6,
|
||||||
|
_network.priority,
|
||||||
|
_network.project_id,
|
||||||
|
_network.rxtx_base,
|
||||||
|
_network.share_address,
|
||||||
|
_network.updated_at,
|
||||||
|
_network.vlan,
|
||||||
|
_network.vpn_private_address,
|
||||||
|
_network.vpn_public_address,
|
||||||
|
_network.vpn_public_port,
|
||||||
|
)
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShowNetworkCompute, self).setUp()
|
||||||
|
|
||||||
|
self.app.client_manager.network_endpoint_enabled = False
|
||||||
|
|
||||||
|
# Return value of utils.find_resource()
|
||||||
|
self.compute.networks.get.return_value = self._network
|
||||||
|
|
||||||
|
# Get the command object to test
|
||||||
|
self.cmd = network.ShowNetwork(self.app, None)
|
||||||
|
|
||||||
|
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._network.label,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('network', self._network.label),
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, tuple(columns))
|
||||||
|
self.assertEqual(self.data, data)
|
||||||
|
@ -4,3 +4,5 @@ features:
|
|||||||
[Bug `1543672 <https://bugs.launchpad.net/python-openstackclient/+bug/1543672>`_]
|
[Bug `1543672 <https://bugs.launchpad.net/python-openstackclient/+bug/1543672>`_]
|
||||||
- Command ``network list`` is now available for nova network.
|
- Command ``network list`` is now available for nova network.
|
||||||
[Bug `1543672 <https://bugs.launchpad.net/python-openstackclient/+bug/1543672>`_]
|
[Bug `1543672 <https://bugs.launchpad.net/python-openstackclient/+bug/1543672>`_]
|
||||||
|
- Command ``network show`` is now available for nova network.
|
||||||
|
[Bug `1543672 <https://bugs.launchpad.net/python-openstackclient/+bug/1543672>`_]
|
||||||
|
Loading…
Reference in New Issue
Block a user