Merge "Floating IP: Neutron support for "ip floating show" command"

This commit is contained in:
Jenkins 2016-02-25 21:15:47 +00:00 committed by Gerrit Code Review
commit fbc03104f6
7 changed files with 175 additions and 2 deletions

View File

@ -82,3 +82,17 @@ Remove floating IP address from server
.. describe:: <server>
Server to remove the IP address from (name or ID)
ip floating show
----------------
Display floating IP details
.. program:: ip floating show
.. code:: bash
os ip floating show <floating-ip>
.. describe:: <floating-ip>
Floating IP to display (IP address or ID)

View File

@ -17,6 +17,14 @@ from openstackclient.common import utils
from openstackclient.network import common
def _get_columns(item):
columns = item.keys()
if 'tenant_id' in columns:
columns.remove('tenant_id')
columns.append('project_id')
return tuple(sorted(columns))
class DeleteFloatingIP(common.NetworkAndComputeCommand):
"""Delete floating IP"""
@ -89,3 +97,30 @@ class ListFloatingIP(common.NetworkAndComputeLister):
s, columns,
formatters={},
) for s in data))
class ShowFloatingIP(common.NetworkAndComputeShowOne):
"""Show floating IP details"""
def update_parser_common(self, parser):
parser.add_argument(
'floating_ip',
metavar="<floating-ip>",
help=("Floating IP to display (IP address or ID)")
)
return parser
def take_action_network(self, client, parsed_args):
obj = client.find_ip(parsed_args.floating_ip, ignore_missing=False)
columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns)
return (columns, data)
def take_action_compute(self, client, parsed_args):
obj = utils.find_resource(
client.floating_ips,
parsed_args.floating_ip,
)
columns = _get_columns(obj._info)
data = utils.get_dict_properties(obj._info, columns)
return (columns, data)

View File

@ -630,6 +630,7 @@ class FakeFloatingIP(object):
info=copy.deepcopy(floating_ip_attrs),
methods=copy.deepcopy(floating_ip_methods),
loaded=True)
return floating_ip
@staticmethod

View File

@ -637,14 +637,24 @@ class FakeFloatingIP(object):
'id': 'floating-ip-id-' + uuid.uuid4().hex,
'floating_ip_address': '1.0.9.0',
'fixed_ip_address': '2.0.9.0',
'dns_domain': None,
'dns_name': None,
'status': 'DOWN',
'floating_network_id': 'network-id-' + uuid.uuid4().hex,
'router_id': 'router-id-' + uuid.uuid4().hex,
'port_id': 'port-id-' + uuid.uuid4().hex,
'tenant_id': 'project-id-' + uuid.uuid4().hex,
}
# Overwrite default attributes.
floating_ip_attrs.update(attrs)
# Set default methods.
floating_ip_methods = {}
floating_ip_methods = {
'keys': ['id', 'floating_ip_address', 'fixed_ip_address',
'dns_domain', 'dns_name', 'status', 'router_id',
'floating_network_id', 'port_id', 'tenant_id']
}
# Overwrite default methods.
floating_ip_methods.update(methods)
@ -652,7 +662,12 @@ class FakeFloatingIP(object):
floating_ip = fakes.FakeResource(
info=copy.deepcopy(floating_ip_attrs),
methods=copy.deepcopy(floating_ip_methods),
loaded=True)
loaded=True
)
# Set attributes with special mappings in OpenStack SDK.
floating_ip.project_id = floating_ip_attrs['tenant_id']
return floating_ip
@staticmethod

View File

@ -100,6 +100,64 @@ class TestListFloatingIPNetwork(TestFloatingIPNetwork):
self.assertEqual(self.data, list(data))
class TestShowFloatingIPNetwork(TestFloatingIPNetwork):
# The floating ip to display.
floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip()
columns = (
'dns_domain',
'dns_name',
'fixed_ip_address',
'floating_ip_address',
'floating_network_id',
'id',
'port_id',
'project_id',
'router_id',
'status',
)
data = (
floating_ip.dns_domain,
floating_ip.dns_name,
floating_ip.fixed_ip_address,
floating_ip.floating_ip_address,
floating_ip.floating_network_id,
floating_ip.id,
floating_ip.port_id,
floating_ip.tenant_id,
floating_ip.router_id,
floating_ip.status,
)
def setUp(self):
super(TestShowFloatingIPNetwork, self).setUp()
self.network.find_ip = mock.Mock(return_value=self.floating_ip)
# Get the command object to test
self.cmd = floating_ip.ShowFloatingIP(self.app, self.namespace)
def test_floating_ip_show(self):
arglist = [
self.floating_ip.id,
]
verifylist = [
('floating_ip', self.floating_ip.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.network.find_ip.assert_called_with(
self.floating_ip.id,
ignore_missing=False
)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
# Tests for Nova network
#
class TestFloatingIPCompute(compute_fakes.TestComputev2):
@ -189,3 +247,50 @@ class TestListFloatingIPCompute(TestFloatingIPCompute):
self.compute.floating_ips.list.assert_called_with()
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
class TestShowFloatingIPCompute(TestFloatingIPCompute):
# The floating ip to display.
floating_ip = compute_fakes.FakeFloatingIP.create_one_floating_ip()
columns = (
'fixed_ip',
'id',
'instance_id',
'ip',
'pool',
)
data = (
floating_ip.fixed_ip,
floating_ip.id,
floating_ip.instance_id,
floating_ip.ip,
floating_ip.pool,
)
def setUp(self):
super(TestShowFloatingIPCompute, self).setUp()
self.app.client_manager.network_endpoint_enabled = False
# Return value of utils.find_resource()
self.compute.floating_ips.get.return_value = self.floating_ip
# Get the command object to test
self.cmd = floating_ip.ShowFloatingIP(self.app, None)
def test_floating_ip_show(self):
arglist = [
self.floating_ip.id,
]
verifylist = [
('floating_ip', self.floating_ip.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)

View File

@ -4,3 +4,5 @@ features:
[Bug `1519502 <https://bugs.launchpad.net/python-openstackclient/+bug/1519502>`_]
- Command ``ip floating list`` is now available for neutron network.
[Bug `1519502 <https://bugs.launchpad.net/python-openstackclient/+bug/1519502>`_]
- Add command ``ip floating show`` for neutron and nova network.
[Bug `1519502 <https://bugs.launchpad.net/python-openstackclient/+bug/1519502>`_]

View File

@ -326,6 +326,7 @@ openstack.image.v2 =
openstack.network.v2 =
ip_floating_delete = openstackclient.network.v2.floating_ip:DeleteFloatingIP
ip_floating_list = openstackclient.network.v2.floating_ip:ListFloatingIP
ip_floating_show = openstackclient.network.v2.floating_ip:ShowFloatingIP
network_create = openstackclient.network.v2.network:CreateNetwork
network_delete = openstackclient.network.v2.network:DeleteNetwork
network_list = openstackclient.network.v2.network:ListNetwork