Floating IP: Fix "ip floating list" in neutron network

The implementation of "ip floating list" in the commit below
is incorrect:

    Change-Id: I253f66f6bc64470e1a18ffea506048eb53f67d5c

This is because the FloatingIP objects returned from Nova and
Neutron network are different. They need different handling.

This patch fixes this problem.

The output for Neutron network would be:

+--------------------------------------+---------------------+------------------+------+
| ID                                   | Floating IP Address | Fixed IP Address | Port |
+--------------------------------------+---------------------+------------------+------+
| 1976df86-e66a-4f96-81bd-c6ffee6407f1 | 172.24.4.3          | None             | None |
+--------------------------------------+---------------------+------------------+------+

The output for Neutron network would be:

+----+---------------------+------------------+-----------+--------+
| ID | Floating IP Address | Fixed IP Address | Server ID | Pool   |
+----+---------------------+------------------+-----------+--------+
|  1 | 172.24.4.1          | None             | None      | public |
+----+---------------------+------------------+-----------+--------+

Change-Id: I1295e922df695414511d9a07ca4a8e2428040064
Partial-Bug: 1519502
Related-to: blueprint neutron-client
This commit is contained in:
Tang Chen 2016-02-16 14:33:31 +08:00
parent 444fc6149d
commit ca34aa1587
3 changed files with 51 additions and 17 deletions

View File

@ -43,24 +43,49 @@ class DeleteFloatingIP(common.NetworkAndComputeCommand):
class ListFloatingIP(common.NetworkAndComputeLister):
"""List floating IP(s)"""
columns = ('ID', 'IP', 'Fixed IP', 'Instance ID', 'Pool')
column_headers = ('ID', 'Floating IP', 'Fixed IP', 'Server ID', 'Pool')
def take_action_network(self, client, parsed_args):
columns = (
'id',
'floating_ip_address',
'fixed_ip_address',
'port_id',
)
headers = (
'ID',
'Floating IP Address',
'Fixed IP Address',
'Port',
)
query = {}
data = client.ips(**query)
return (self.column_headers,
return (headers,
(utils.get_item_properties(
s, self.columns,
s, columns,
formatters={},
) for s in data))
def take_action_compute(self, client, parsed_args):
columns = (
'ID',
'IP',
'Fixed IP',
'Instance ID',
'Pool',
)
headers = (
'ID',
'Floating IP Address',
'Fixed IP Address',
'Server',
'Pool',
)
data = client.floating_ips.list()
return (self.column_headers,
return (headers,
(utils.get_item_properties(
s, self.columns,
s, columns,
formatters={},
) for s in data))

View File

@ -619,10 +619,9 @@ class FakeFloatingIP(object):
# Set default attributes.
floating_ip_attrs = {
'id': 'floating-ip-id-' + uuid.uuid4().hex,
'ip': '1.0.9.0',
'fixed_ip': '2.0.9.0',
'instance_id': 'server-id-' + uuid.uuid4().hex,
'pool': 'public',
'floating_ip_address': '1.0.9.0',
'fixed_ip_address': '2.0.9.0',
'port_id': 'port-id-' + uuid.uuid4().hex,
}
# Overwrite default attributes.

View File

@ -64,16 +64,20 @@ class TestListFloatingIPNetwork(TestFloatingIPNetwork):
# The floating ips to list up
floating_ips = network_fakes.FakeFloatingIP.create_floating_ips(count=3)
columns = ('ID', 'Floating IP', 'Fixed IP', 'Server ID', 'Pool')
columns = (
'ID',
'Floating IP Address',
'Fixed IP Address',
'Port',
)
data = []
for ip in floating_ips:
data.append((
ip.id,
ip.ip,
ip.fixed_ip,
ip.instance_id,
ip.pool,
ip.floating_ip_address,
ip.fixed_ip_address,
ip.port_id,
))
def setUp(self):
@ -147,7 +151,13 @@ class TestListFloatingIPCompute(TestFloatingIPCompute):
# The floating ips to be list up
floating_ips = compute_fakes.FakeFloatingIP.create_floating_ips(count=3)
columns = ('ID', 'Floating IP', 'Fixed IP', 'Server ID', 'Pool')
columns = (
'ID',
'Floating IP Address',
'Fixed IP Address',
'Server',
'Pool',
)
data = []
for ip in floating_ips: