Floating IP: Neutron support for "ip floating list" command
Change-Id: I253f66f6bc64470e1a18ffea506048eb53f67d5c partial-Bug: 1519502 Related-to: blueprint neutron-client
This commit is contained in:
parent
6109dfcf63
commit
d8abec33ad
@ -68,23 +68,6 @@ class CreateFloatingIP(command.ShowOne):
|
|||||||
return zip(*sorted(six.iteritems(info)))
|
return zip(*sorted(six.iteritems(info)))
|
||||||
|
|
||||||
|
|
||||||
class ListFloatingIP(command.Lister):
|
|
||||||
"""List floating IP addresses"""
|
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
|
||||||
compute_client = self.app.client_manager.compute
|
|
||||||
|
|
||||||
columns = ('ID', 'Pool', 'IP', 'Fixed IP', 'Instance ID')
|
|
||||||
|
|
||||||
data = compute_client.floating_ips.list()
|
|
||||||
|
|
||||||
return (columns,
|
|
||||||
(utils.get_item_properties(
|
|
||||||
s, columns,
|
|
||||||
formatters={},
|
|
||||||
) for s in data))
|
|
||||||
|
|
||||||
|
|
||||||
class RemoveFloatingIP(command.Command):
|
class RemoveFloatingIP(command.Command):
|
||||||
"""Remove floating IP address from server"""
|
"""Remove floating IP address from server"""
|
||||||
|
|
||||||
|
@ -38,3 +38,29 @@ class DeleteFloatingIP(common.NetworkAndComputeCommand):
|
|||||||
parsed_args.floating_ip,
|
parsed_args.floating_ip,
|
||||||
)
|
)
|
||||||
client.floating_ips.delete(obj.id)
|
client.floating_ips.delete(obj.id)
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
query = {}
|
||||||
|
data = client.ips(**query)
|
||||||
|
|
||||||
|
return (self.column_headers,
|
||||||
|
(utils.get_item_properties(
|
||||||
|
s, self.columns,
|
||||||
|
formatters={},
|
||||||
|
) for s in data))
|
||||||
|
|
||||||
|
def take_action_compute(self, client, parsed_args):
|
||||||
|
data = client.floating_ips.list()
|
||||||
|
|
||||||
|
return (self.column_headers,
|
||||||
|
(utils.get_item_properties(
|
||||||
|
s, self.columns,
|
||||||
|
formatters={},
|
||||||
|
) for s in data))
|
||||||
|
@ -566,12 +566,15 @@ class FakeFloatingIP(object):
|
|||||||
:param Dictionary methods:
|
:param Dictionary methods:
|
||||||
A dictionary with all methods
|
A dictionary with all methods
|
||||||
:return:
|
:return:
|
||||||
A FakeResource object, with id, ip
|
A FakeResource object, with id, ip, and so on
|
||||||
"""
|
"""
|
||||||
# Set default attributes.
|
# Set default attributes.
|
||||||
floating_ip_attrs = {
|
floating_ip_attrs = {
|
||||||
'id': 'floating-ip-id-' + uuid.uuid4().hex,
|
'id': 'floating-ip-id-' + uuid.uuid4().hex,
|
||||||
'ip': '1.0.9.0',
|
'ip': '1.0.9.0',
|
||||||
|
'fixed_ip': '2.0.9.0',
|
||||||
|
'instance_id': 'server-id-' + uuid.uuid4().hex,
|
||||||
|
'pool': 'public',
|
||||||
}
|
}
|
||||||
|
|
||||||
# Overwrite default attributes.
|
# Overwrite default attributes.
|
||||||
|
@ -59,6 +59,43 @@ class TestDeleteFloatingIPNetwork(TestFloatingIPNetwork):
|
|||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
data = []
|
||||||
|
for ip in floating_ips:
|
||||||
|
data.append((
|
||||||
|
ip.id,
|
||||||
|
ip.ip,
|
||||||
|
ip.fixed_ip,
|
||||||
|
ip.instance_id,
|
||||||
|
ip.pool,
|
||||||
|
))
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestListFloatingIPNetwork, self).setUp()
|
||||||
|
|
||||||
|
self.network.ips = mock.Mock(return_value=self.floating_ips)
|
||||||
|
|
||||||
|
# Get the command object to test
|
||||||
|
self.cmd = floating_ip.ListFloatingIP(self.app, self.namespace)
|
||||||
|
|
||||||
|
def test_floating_ip_list(self):
|
||||||
|
arglist = []
|
||||||
|
verifylist = []
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.network.ips.assert_called_with(**{})
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.data, list(data))
|
||||||
|
|
||||||
|
|
||||||
# Tests for Nova network
|
# Tests for Nova network
|
||||||
#
|
#
|
||||||
class TestFloatingIPCompute(compute_fakes.TestComputev2):
|
class TestFloatingIPCompute(compute_fakes.TestComputev2):
|
||||||
@ -103,3 +140,42 @@ class TestDeleteFloatingIPCompute(TestFloatingIPCompute):
|
|||||||
self.floating_ip.id
|
self.floating_ip.id
|
||||||
)
|
)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
|
class TestListFloatingIPCompute(TestFloatingIPCompute):
|
||||||
|
|
||||||
|
# The floating ips to be list up
|
||||||
|
floating_ips = network_fakes.FakeFloatingIP.create_floating_ips(count=3)
|
||||||
|
|
||||||
|
columns = ('ID', 'Floating IP', 'Fixed IP', 'Server ID', 'Pool')
|
||||||
|
|
||||||
|
data = []
|
||||||
|
for ip in floating_ips:
|
||||||
|
data.append((
|
||||||
|
ip.id,
|
||||||
|
ip.ip,
|
||||||
|
ip.fixed_ip,
|
||||||
|
ip.instance_id,
|
||||||
|
ip.pool,
|
||||||
|
))
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestListFloatingIPCompute, self).setUp()
|
||||||
|
|
||||||
|
self.app.client_manager.network_endpoint_enabled = False
|
||||||
|
|
||||||
|
self.compute.floating_ips.list.return_value = self.floating_ips
|
||||||
|
|
||||||
|
# Get the command object to test
|
||||||
|
self.cmd = floating_ip.ListFloatingIP(self.app, None)
|
||||||
|
|
||||||
|
def test_floating_ip_list(self):
|
||||||
|
arglist = []
|
||||||
|
verifylist = []
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.compute.floating_ips.list.assert_called_with()
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(self.data, list(data))
|
||||||
|
@ -91,7 +91,6 @@ openstack.compute.v2 =
|
|||||||
|
|
||||||
ip_floating_add = openstackclient.compute.v2.floatingip:AddFloatingIP
|
ip_floating_add = openstackclient.compute.v2.floatingip:AddFloatingIP
|
||||||
ip_floating_create = openstackclient.compute.v2.floatingip:CreateFloatingIP
|
ip_floating_create = openstackclient.compute.v2.floatingip:CreateFloatingIP
|
||||||
ip_floating_list = openstackclient.compute.v2.floatingip:ListFloatingIP
|
|
||||||
ip_floating_remove = openstackclient.compute.v2.floatingip:RemoveFloatingIP
|
ip_floating_remove = openstackclient.compute.v2.floatingip:RemoveFloatingIP
|
||||||
ip_floating_pool_list = openstackclient.compute.v2.floatingippool:ListFloatingIPPool
|
ip_floating_pool_list = openstackclient.compute.v2.floatingippool:ListFloatingIPPool
|
||||||
|
|
||||||
@ -326,6 +325,7 @@ openstack.image.v2 =
|
|||||||
|
|
||||||
openstack.network.v2 =
|
openstack.network.v2 =
|
||||||
ip_floating_delete = openstackclient.network.v2.floating_ip:DeleteFloatingIP
|
ip_floating_delete = openstackclient.network.v2.floating_ip:DeleteFloatingIP
|
||||||
|
ip_floating_list = openstackclient.network.v2.floating_ip:ListFloatingIP
|
||||||
network_create = openstackclient.network.v2.network:CreateNetwork
|
network_create = openstackclient.network.v2.network:CreateNetwork
|
||||||
network_delete = openstackclient.network.v2.network:DeleteNetwork
|
network_delete = openstackclient.network.v2.network:DeleteNetwork
|
||||||
network_list = openstackclient.network.v2.network:ListNetwork
|
network_list = openstackclient.network.v2.network:ListNetwork
|
||||||
|
Loading…
x
Reference in New Issue
Block a user