Skip to content

Commit 50bd56d

Browse files
Tang ChenDean Troyer
andcommitted
Transfer "ip floating pool list" to "floating ip pool list"
This patch does the following things to transfer "ip floating pool list" to "floating ip pool list": * Add a new command "floating ip pool list" to deprecate "ip floating pool list". The source code is in network/v2 dir. * Add doc for "floating ip pool list". * Add floating ip pool unit tests. Change-Id: Id410f4e4a96cf589a6e8def209574da71395b55f Implements: blueprint rework-ip-commands Partial-bug: 1555990 Co-Authored-By: Dean Troyer <dtroyer@gmail.com>
1 parent 605efe6 commit 50bd56d

9 files changed

Lines changed: 244 additions & 37 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
================
2+
floating ip pool
3+
================
4+
5+
Compute v2, Network v2
6+
7+
floating ip pool list
8+
---------------------
9+
10+
List pools of floating IP addresses
11+
12+
.. program:: floating ip pool list
13+
.. code:: bash
14+
15+
os floating ip pool list

doc/source/command-objects/ip-floating-pool.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ip floating pool list
88
---------------------
99

1010
List pools of floating IP addresses
11+
(Deprecated, please use ``floating ip pool list`` instead)
1112

1213
.. program:: ip floating pool list
1314
.. code:: bash

doc/source/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ referring to both Compute and Volume quotas.
9191
* ``extension``: (**Compute**, **Identity**, **Network**, **Volume**) OpenStack server API extensions
9292
* ``federation protocol``: (**Identity**) the underlying protocol used while federating identities
9393
* ``flavor``: (**Compute**) predefined server configurations: ram, root disk and so on
94+
* ``floating ip pool``: (**Compute**, **Network**) - a pool of public IP addresses
9495
* ``group``: (**Identity**) a grouping of users
9596
* ``host``: (**Compute**) - the physical computer running compute services
9697
* ``hypervisor``: (**Compute**) the virtual machine manager

openstackclient/compute/v2/floatingippool.py

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
14+
"""Floating IP Pool action implementations"""
15+
16+
import logging
17+
18+
from osc_lib import exceptions
19+
from osc_lib import utils
20+
21+
from openstackclient.i18n import _
22+
from openstackclient.network import common
23+
24+
25+
class ListFloatingIPPool(common.NetworkAndComputeLister):
26+
"""List pools of floating IP addresses"""
27+
28+
def take_action_network(self, client, parsed_args):
29+
msg = _("Floating ip pool operations are only available for "
30+
"Compute v2 network.")
31+
raise exceptions.CommandError(msg)
32+
33+
def take_action_compute(self, client, parsed_args):
34+
columns = (
35+
'Name',
36+
)
37+
data = client.floating_ip_pools.list()
38+
39+
return (columns,
40+
(utils.get_item_properties(
41+
s, columns,
42+
) for s in data))
43+
44+
45+
class ListIPFloatingPool(ListFloatingIPPool):
46+
"""List pools of floating IP addresses"""
47+
48+
# TODO(tangchen): Remove this class and ``ip floating pool list`` command
49+
# two cycles after Mitaka.
50+
51+
# This notifies cliff to not display the help for this command
52+
deprecated = True
53+
54+
log = logging.getLogger('deprecated')
55+
56+
def take_action_network(self, client, parsed_args):
57+
self.log.warning(_('This command has been deprecated. '
58+
'Please use "floating ip pool list" instead.'))
59+
return super(ListIPFloatingPool, self).take_action_network(
60+
client, parsed_args)
61+
62+
def take_action_compute(self, client, parsed_args):
63+
self.log.warning(_('This command has been deprecated. '
64+
'Please use "floating ip pool list" instead.'))
65+
return super(ListIPFloatingPool, self).take_action_compute(
66+
client, parsed_args)

openstackclient/tests/compute/v2/fakes.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ def __init__(self, **kwargs):
178178
self.floating_ips = mock.Mock()
179179
self.floating_ips.resource_class = fakes.FakeResource(None, {})
180180

181+
self.floating_ip_pools = mock.Mock()
182+
self.floating_ip_pools.resource_class = fakes.FakeResource(None, {})
183+
181184
self.networks = mock.Mock()
182185
self.networks.resource_class = fakes.FakeResource(None, {})
183186

@@ -971,6 +974,54 @@ def get_floating_ips(floating_ips=None, count=2):
971974
return mock.MagicMock(side_effect=floating_ips)
972975

973976

977+
class FakeFloatingIPPool(object):
978+
"""Fake one or more floating ip pools."""
979+
980+
@staticmethod
981+
def create_one_floating_ip_pool(attrs=None):
982+
"""Create a fake floating ip pool.
983+
984+
:param Dictionary attrs:
985+
A dictionary with all attributes
986+
:return:
987+
A FakeResource object, with id, etc
988+
"""
989+
if attrs is None:
990+
attrs = {}
991+
992+
# Set default attributes.
993+
floating_ip_pool_attrs = {
994+
'name': 'floating-ip-pool-name-' + uuid.uuid4().hex,
995+
}
996+
997+
# Overwrite default attributes.
998+
floating_ip_pool_attrs.update(attrs)
999+
1000+
floating_ip_pool = fakes.FakeResource(
1001+
info=copy.deepcopy(floating_ip_pool_attrs),
1002+
loaded=True)
1003+
1004+
return floating_ip_pool
1005+
1006+
@staticmethod
1007+
def create_floating_ip_pools(attrs=None, count=2):
1008+
"""Create multiple fake floating ip pools.
1009+
1010+
:param Dictionary attrs:
1011+
A dictionary with all attributes
1012+
:param int count:
1013+
The number of floating ip pools to fake
1014+
:return:
1015+
A list of FakeResource objects faking the floating ip pools
1016+
"""
1017+
floating_ip_pools = []
1018+
for i in range(0, count):
1019+
floating_ip_pools.append(
1020+
FakeFloatingIPPool.create_one_floating_ip_pool(attrs)
1021+
)
1022+
return floating_ip_pools
1023+
1024+
9741025
class FakeNetwork(object):
9751026
"""Fake one or more networks."""
9761027

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
14+
from osc_lib import exceptions
15+
16+
from openstackclient.network.v2 import floating_ip_pool
17+
from openstackclient.tests.compute.v2 import fakes as compute_fakes
18+
from openstackclient.tests.network.v2 import fakes as network_fakes
19+
20+
21+
# Tests for Network API v2
22+
#
23+
class TestFloatingIPPoolNetwork(network_fakes.TestNetworkV2):
24+
25+
def setUp(self):
26+
super(TestFloatingIPPoolNetwork, self).setUp()
27+
28+
# Get a shortcut to the network client
29+
self.network = self.app.client_manager.network
30+
31+
32+
class TestListFloatingIPPoolNetwork(TestFloatingIPPoolNetwork):
33+
34+
def setUp(self):
35+
super(TestListFloatingIPPoolNetwork, self).setUp()
36+
37+
# Get the command object to test
38+
self.cmd = floating_ip_pool.ListFloatingIPPool(self.app,
39+
self.namespace)
40+
41+
def test_floating_ip_list(self):
42+
arglist = []
43+
verifylist = []
44+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
45+
46+
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
47+
parsed_args)
48+
49+
50+
# Tests for Compute network
51+
#
52+
class TestFloatingIPPoolCompute(compute_fakes.TestComputev2):
53+
54+
def setUp(self):
55+
super(TestFloatingIPPoolCompute, self).setUp()
56+
57+
# Get a shortcut to the compute client
58+
self.compute = self.app.client_manager.compute
59+
60+
61+
class TestListFloatingIPPoolCompute(TestFloatingIPPoolCompute):
62+
63+
# The floating ip pools to list up
64+
floating_ip_pools = \
65+
compute_fakes.FakeFloatingIPPool.create_floating_ip_pools(count=3)
66+
67+
columns = (
68+
'Name',
69+
)
70+
71+
data = []
72+
for pool in floating_ip_pools:
73+
data.append((
74+
pool.name,
75+
))
76+
77+
def setUp(self):
78+
super(TestListFloatingIPPoolCompute, self).setUp()
79+
80+
self.app.client_manager.network_endpoint_enabled = False
81+
82+
self.compute.floating_ip_pools.list.return_value = \
83+
self.floating_ip_pools
84+
85+
# Get the command object to test
86+
self.cmd = floating_ip_pool.ListFloatingIPPool(self.app, None)
87+
88+
def test_floating_ip_list(self):
89+
arglist = []
90+
verifylist = []
91+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
92+
93+
columns, data = self.cmd.take_action(parsed_args)
94+
95+
self.compute.floating_ip_pools.list.assert_called_once_with()
96+
self.assertEqual(self.columns, columns)
97+
self.assertEqual(self.data, list(data))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
features:
3+
- Add new command ``floating ip pool list`` to list up all floating ip
4+
pools. This command is used to replace the old command
5+
``ip floating pool list``.
6+
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
7+
deprecations:
8+
- Deprecate command ``ip floating pool list``.
9+
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]

setup.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ openstack.compute.v2 =
9292

9393
ip_floating_add = openstackclient.compute.v2.floatingip:AddFloatingIP
9494
ip_floating_remove = openstackclient.compute.v2.floatingip:RemoveFloatingIP
95-
ip_floating_pool_list = openstackclient.compute.v2.floatingippool:ListFloatingIPPool
9695

9796
keypair_create = openstackclient.compute.v2.keypair:CreateKeypair
9897
keypair_delete = openstackclient.compute.v2.keypair:DeleteKeypair
@@ -333,6 +332,8 @@ openstack.network.v2 =
333332
address_scope_set = openstackclient.network.v2.address_scope:SetAddressScope
334333
address_scope_show = openstackclient.network.v2.address_scope:ShowAddressScope
335334

335+
floating_ip_pool_list = openstackclient.network.v2.floating_ip_pool:ListFloatingIPPool
336+
336337
ip_availability_list = openstackclient.network.v2.ip_availability:ListIPAvailability
337338
ip_availability_show = openstackclient.network.v2.ip_availability:ShowIPAvailability
338339

@@ -341,6 +342,8 @@ openstack.network.v2 =
341342
ip_floating_list = openstackclient.network.v2.floating_ip:ListFloatingIP
342343
ip_floating_show = openstackclient.network.v2.floating_ip:ShowFloatingIP
343344

345+
ip_floating_pool_list = openstackclient.network.v2.floating_ip_pool:ListIPFloatingPool
346+
344347
network_create = openstackclient.network.v2.network:CreateNetwork
345348
network_delete = openstackclient.network.v2.network:DeleteNetwork
346349
network_list = openstackclient.network.v2.network:ListNetwork

0 commit comments

Comments
 (0)