Skip to content

Commit d1f9ea3

Browse files
Tang ChenDean Troyer
andcommitted
Transfer "ip floating add/remove" to "server add/remove
floating ip" This patch does the following things to transfer "ip floating add/remove" to "server add/remove floating ip": * Add new command "server add/remove floating ip", and unit tests and doc. * Deprecate "ip floating add/remove" command. compute/v2/floatingip.py is not removed because the arguments' positions are different between the new and old commands. * ip floating add <ip-address> <server> server add floating ip <server> <ip-address> * ip floating remove <ip-address> <server> server remove floating ip <server> <ip-address> Change-Id: Ic0dd22ca6fb7b7bc3e820fd5a14d7c551e7ab963 Implements: blueprint rework-ip-commands Partial-bug: 1555990 Co-Authored-By: Dean Troyer <dtroyer@gmail.com>
1 parent 50bd56d commit d1f9ea3

8 files changed

Lines changed: 202 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ip floating add
88
---------------
99

1010
Add floating IP address to server
11+
(Deprecated, please use ``server add floating ip`` instead)
1112

1213
.. program:: ip floating add
1314
.. code:: bash
@@ -92,6 +93,7 @@ ip floating remove
9293
------------------
9394

9495
Remove floating IP address from server
96+
(Deprecated, please use ``server remove floating ip`` instead)
9597

9698
.. program:: ip floating remove
9799
.. code:: bash

doc/source/command-objects/server.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ server
44

55
Compute v2
66

7+
server add floating ip
8+
----------------------
9+
10+
Add floating IP address to server
11+
12+
.. program:: server add floating ip
13+
.. code:: bash
14+
15+
os server add floating ip
16+
<server>
17+
<ip-address>
18+
19+
.. describe:: <server>
20+
21+
Server (name or ID) to receive the floating IP address
22+
23+
.. describe:: <ip-address>
24+
25+
Floating IP address (IP address only) to assign to server
26+
727
server add security group
828
-------------------------
929

@@ -418,6 +438,26 @@ Rebuild server
418438
419439
Server (name or ID)
420440
441+
server remove floating ip
442+
-------------------------
443+
444+
Remove floating IP address from server
445+
446+
.. program:: server remove floating ip
447+
.. code:: bash
448+
449+
os server remove floating ip
450+
<server>
451+
<ip-address>
452+
453+
.. describe:: <server>
454+
455+
Server (name or ID) to remove the floating IP address from
456+
457+
.. describe:: <ip-address>
458+
459+
Floating IP address (IP address only) to remove from server
460+
421461
server remove security group
422462
----------------------------
423463

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``: (**Compute**, **Network**) - a public IP address that can be mapped to a server
9495
* ``floating ip pool``: (**Compute**, **Network**) - a pool of public IP addresses
9596
* ``group``: (**Identity**) a grouping of users
9697
* ``host``: (**Compute**) - the physical computer running compute services

openstackclient/compute/v2/floatingip.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,43 @@
1515

1616
"""Floating IP action implementations"""
1717

18+
import logging
19+
1820
from osc_lib.command import command
1921
from osc_lib import utils
2022

23+
from openstackclient.i18n import _
24+
2125

2226
class AddFloatingIP(command.Command):
2327
"""Add floating IP address to server"""
2428

29+
# TODO(tangchen): Remove this class and ``ip floating add`` command
30+
# two cycles after Mitaka.
31+
32+
# This notifies cliff to not display the help for this command
33+
deprecated = True
34+
35+
log = logging.getLogger('deprecated')
36+
2537
def get_parser(self, prog_name):
2638
parser = super(AddFloatingIP, self).get_parser(prog_name)
2739
parser.add_argument(
2840
"ip_address",
2941
metavar="<ip-address>",
30-
help="IP address to add to server (name only)",
42+
help=_("IP address to add to server (name only)"),
3143
)
3244
parser.add_argument(
3345
"server",
3446
metavar="<server>",
35-
help="Server to receive the IP address (name or ID)",
47+
help=_("Server to receive the IP address (name or ID)"),
3648
)
3749
return parser
3850

3951
def take_action(self, parsed_args):
52+
self.log.warning(_('This command has been deprecated. '
53+
'Please use "server add floating ip" instead.'))
54+
4055
compute_client = self.app.client_manager.compute
4156

4257
server = utils.find_resource(
@@ -48,21 +63,32 @@ def take_action(self, parsed_args):
4863
class RemoveFloatingIP(command.Command):
4964
"""Remove floating IP address from server"""
5065

66+
# TODO(tangchen): Remove this class and ``ip floating remove`` command
67+
# two cycles after Mitaka.
68+
69+
# This notifies cliff to not display the help for this command
70+
deprecated = True
71+
72+
log = logging.getLogger('deprecated')
73+
5174
def get_parser(self, prog_name):
5275
parser = super(RemoveFloatingIP, self).get_parser(prog_name)
5376
parser.add_argument(
5477
"ip_address",
5578
metavar="<ip-address>",
56-
help="IP address to remove from server (name only)",
79+
help=_("IP address to remove from server (name only)"),
5780
)
5881
parser.add_argument(
5982
"server",
6083
metavar="<server>",
61-
help="Server to remove the IP address from (name or ID)",
84+
help=_("Server to remove the IP address from (name or ID)"),
6285
)
6386
return parser
6487

6588
def take_action(self, parsed_args):
89+
self.log.warning(_('This command has been deprecated. '
90+
'Please use "server remove floating ip" instead.'))
91+
6692
compute_client = self.app.client_manager.compute
6793

6894
server = utils.find_resource(

openstackclient/compute/v2/server.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,33 @@ def _show_progress(progress):
174174
sys.stdout.flush()
175175

176176

177+
class AddFloatingIP(command.Command):
178+
"""Add floating IP address to server"""
179+
180+
def get_parser(self, prog_name):
181+
parser = super(AddFloatingIP, self).get_parser(prog_name)
182+
parser.add_argument(
183+
"server",
184+
metavar="<server>",
185+
help=_("Server (name or ID) to receive the floating IP address"),
186+
)
187+
parser.add_argument(
188+
"ip_address",
189+
metavar="<ip-address>",
190+
help=_("Floating IP address (IP address only) to assign "
191+
"to server"),
192+
)
193+
return parser
194+
195+
def take_action(self, parsed_args):
196+
compute_client = self.app.client_manager.compute
197+
198+
server = utils.find_resource(
199+
compute_client.servers, parsed_args.server)
200+
201+
server.add_floating_ip(parsed_args.ip_address)
202+
203+
177204
class AddServerSecurityGroup(command.Command):
178205
"""Add security group to server"""
179206

@@ -1081,6 +1108,34 @@ def take_action(self, parsed_args):
10811108
return zip(*sorted(six.iteritems(details)))
10821109

10831110

1111+
class RemoveFloatingIP(command.Command):
1112+
"""Remove floating IP address from server"""
1113+
1114+
def get_parser(self, prog_name):
1115+
parser = super(RemoveFloatingIP, self).get_parser(prog_name)
1116+
parser.add_argument(
1117+
"server",
1118+
metavar="<server>",
1119+
help=_("Server (name or ID) to remove the "
1120+
"floating IP address from"),
1121+
)
1122+
parser.add_argument(
1123+
"ip_address",
1124+
metavar="<ip-address>",
1125+
help=_("Floating IP address (IP address only) "
1126+
"to remove from server"),
1127+
)
1128+
return parser
1129+
1130+
def take_action(self, parsed_args):
1131+
compute_client = self.app.client_manager.compute
1132+
1133+
server = utils.find_resource(
1134+
compute_client.servers, parsed_args.server)
1135+
1136+
server.remove_floating_ip(parsed_args.ip_address)
1137+
1138+
10841139
class RemoveServerSecurityGroup(command.Command):
10851140
"""Remove security group from server"""
10861141

openstackclient/tests/compute/v2/test_server.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,41 @@ def run_method_with_servers(self, method_name, server_count):
8888
self.assertIsNone(result)
8989

9090

91+
class TestServerAddFloatingIP(TestServer):
92+
93+
def setUp(self):
94+
super(TestServerAddFloatingIP, self).setUp()
95+
96+
# Get a shortcut to the compute client ServerManager Mock
97+
self.networks_mock = self.app.client_manager.compute.networks
98+
99+
# Get the command object to test
100+
self.cmd = server.AddFloatingIP(self.app, None)
101+
102+
# Set add_floating_ip method to be tested.
103+
self.methods = {
104+
'add_floating_ip': None,
105+
}
106+
107+
def test_server_add_floating_ip(self):
108+
servers = self.setup_servers_mock(count=1)
109+
110+
arglist = [
111+
servers[0].id,
112+
'1.2.3.4',
113+
]
114+
verifylist = [
115+
('server', servers[0].id),
116+
('ip_address', '1.2.3.4'),
117+
]
118+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
119+
120+
result = self.cmd.take_action(parsed_args)
121+
122+
servers[0].add_floating_ip.assert_called_once_with('1.2.3.4')
123+
self.assertIsNone(result)
124+
125+
91126
class TestServerCreate(TestServer):
92127

93128
columns = (
@@ -843,6 +878,38 @@ def test_rebuild_with_wait_fails(self, mock_wait_for_status):
843878
self.server.rebuild.assert_called_with(self.image, None)
844879

845880

881+
class TestServerRemoveFloatingIP(TestServer):
882+
883+
def setUp(self):
884+
super(TestServerRemoveFloatingIP, self).setUp()
885+
886+
# Get the command object to test
887+
self.cmd = server.RemoveFloatingIP(self.app, None)
888+
889+
# Set unshelve method to be tested.
890+
self.methods = {
891+
'remove_floating_ip': None,
892+
}
893+
894+
def test_server_remove_floating_ip(self):
895+
servers = self.setup_servers_mock(count=1)
896+
897+
arglist = [
898+
servers[0].id,
899+
'1.2.3.4',
900+
]
901+
verifylist = [
902+
('server', servers[0].id),
903+
('ip_address', '1.2.3.4'),
904+
]
905+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
906+
907+
result = self.cmd.take_action(parsed_args)
908+
909+
servers[0].remove_floating_ip.assert_called_once_with('1.2.3.4')
910+
self.assertIsNone(result)
911+
912+
846913
class TestServerResize(TestServer):
847914

848915
def setUp(self):

releasenotes/notes/ip-command-rework-8d3fe0858f51e6b8.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ features:
44
pools. This command is used to replace the old command
55
``ip floating pool list``.
66
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
7+
- Add new commands ``server add/remove floating ip``. They are used to
8+
replace the old commands ``ip floating add/remove``.
9+
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
710
deprecations:
811
- Deprecate command ``ip floating pool list``.
912
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
13+
- Deprecate commands ``ip floating add/remove``.
14+
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ openstack.compute.v2 =
9898
keypair_list = openstackclient.compute.v2.keypair:ListKeypair
9999
keypair_show = openstackclient.compute.v2.keypair:ShowKeypair
100100

101+
server_add_floating_ip = openstackclient.compute.v2.server:AddFloatingIP
101102
server_add_security_group = openstackclient.compute.v2.server:AddServerSecurityGroup
102103
server_add_volume = openstackclient.compute.v2.server:AddServerVolume
103104
server_create = openstackclient.compute.v2.server:CreateServer
@@ -108,6 +109,7 @@ openstack.compute.v2 =
108109
server_pause = openstackclient.compute.v2.server:PauseServer
109110
server_reboot = openstackclient.compute.v2.server:RebootServer
110111
server_rebuild = openstackclient.compute.v2.server:RebuildServer
112+
server_remove_floating_ip = openstackclient.compute.v2.server:RemoveFloatingIP
111113
server_remove_security_group = openstackclient.compute.v2.server:RemoveServerSecurityGroup
112114
server_remove_volume = openstackclient.compute.v2.server:RemoveServerVolume
113115
server_rescue = openstackclient.compute.v2.server:RescueServer

0 commit comments

Comments
 (0)