From ca34aa1587212ce5ac456a988fd6b442e646ed16 Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Tue, 16 Feb 2016 14:33:31 +0800 Subject: [PATCH] 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 --- openstackclient/network/v2/floating_ip.py | 39 +++++++++++++++---- openstackclient/tests/network/v2/fakes.py | 7 ++-- .../tests/network/v2/test_floating_ip.py | 22 ++++++++--- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py index 488950485..23b83201f 100644 --- a/openstackclient/network/v2/floating_ip.py +++ b/openstackclient/network/v2/floating_ip.py @@ -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)) diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py index b48cde3eb..ae205a2d5 100644 --- a/openstackclient/tests/network/v2/fakes.py +++ b/openstackclient/tests/network/v2/fakes.py @@ -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. diff --git a/openstackclient/tests/network/v2/test_floating_ip.py b/openstackclient/tests/network/v2/test_floating_ip.py index 031dcdac3..a29d69133 100644 --- a/openstackclient/tests/network/v2/test_floating_ip.py +++ b/openstackclient/tests/network/v2/test_floating_ip.py @@ -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: