Skip to content

Commit 7f8999b

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Transfer "ip fixed add/remove" to "server add/remove fixed ip""
2 parents 2b8213d + 179ebe6 commit 7f8999b

8 files changed

Lines changed: 208 additions & 4 deletions

File tree

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

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

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

1213
.. program:: ip fixed add
1314
.. code:: bash
@@ -28,6 +29,7 @@ ip fixed remove
2829
---------------
2930

3031
Remove fixed IP address from server
32+
(Deprecated, please use ``server remove fixed ip`` instead)
3133

3234
.. program:: ip fixed remove
3335
.. 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 fixed ip
8+
-------------------
9+
10+
Add fixed IP address to server
11+
12+
.. program:: server add fixed ip
13+
.. code:: bash
14+
15+
os server add fixed ip
16+
<server>
17+
<network>
18+
19+
.. describe:: <server>
20+
21+
Server (name or ID) to receive the fixed IP address
22+
23+
.. describe:: <network>
24+
25+
Network (name or ID) to allocate the fixed IP address from
26+
727
server add floating ip
828
----------------------
929

@@ -438,6 +458,26 @@ Rebuild server
438458
439459
Server (name or ID)
440460
461+
server remove fixed ip
462+
----------------------
463+
464+
Remove fixed IP address from server
465+
466+
.. program:: server remove fixed ip
467+
.. code:: bash
468+
469+
os server remove fixed ip
470+
<server>
471+
<ip-address>
472+
473+
.. describe:: <server>
474+
475+
Server (name or ID) to remove the fixed IP address from
476+
477+
.. describe:: <ip-address>
478+
479+
Fixed IP address (IP address only) to remove from the server
480+
441481
server remove floating ip
442482
-------------------------
443483

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+
* ``fixed ip``: (**Compute**, **Network**) - an internal IP address assigned to a server
9495
* ``floating ip``: (**Compute**, **Network**) - a public IP address that can be mapped to a server
9596
* ``floating ip pool``: (**Compute**, **Network**) - a pool of public IP addresses
9697
* ``group``: (**Identity**) a grouping of users

openstackclient/compute/v2/fixedip.py

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

1616
"""Fixed 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 AddFixedIP(command.Command):
2327
"""Add fixed IP address to server"""
2428

29+
# TODO(tangchen): Remove this class and ``ip fixed 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(AddFixedIP, self).get_parser(prog_name)
2739
parser.add_argument(
2840
"network",
2941
metavar="<network>",
30-
help="Network to fetch an IP address from (name or ID)",
42+
help=_("Network to fetch an IP address from (name or ID)"),
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 fixed ip" instead.'))
54+
4055
compute_client = self.app.client_manager.compute
4156

4257
network = utils.find_resource(
@@ -51,21 +66,32 @@ def take_action(self, parsed_args):
5166
class RemoveFixedIP(command.Command):
5267
"""Remove fixed IP address from server"""
5368

69+
# TODO(tangchen): Remove this class and ``ip fixed remove`` command
70+
# two cycles after Mitaka.
71+
72+
# This notifies cliff to not display the help for this command
73+
deprecated = True
74+
75+
log = logging.getLogger('deprecated')
76+
5477
def get_parser(self, prog_name):
5578
parser = super(RemoveFixedIP, self).get_parser(prog_name)
5679
parser.add_argument(
5780
"ip_address",
5881
metavar="<ip-address>",
59-
help="IP address to remove from server (name only)",
82+
help=_("IP address to remove from server (name only)"),
6083
)
6184
parser.add_argument(
6285
"server",
6386
metavar="<server>",
64-
help="Server to remove the IP address from (name or ID)",
87+
help=_("Server to remove the IP address from (name or ID)"),
6588
)
6689
return parser
6790

6891
def take_action(self, parsed_args):
92+
self.log.warning(_('This command has been deprecated. '
93+
'Please use "server remove fixed ip" instead.'))
94+
6995
compute_client = self.app.client_manager.compute
7096

7197
server = utils.find_resource(

openstackclient/compute/v2/server.py

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

176176

177+
class AddFixedIP(command.Command):
178+
"""Add fixed IP address to server"""
179+
180+
def get_parser(self, prog_name):
181+
parser = super(AddFixedIP, self).get_parser(prog_name)
182+
parser.add_argument(
183+
"server",
184+
metavar="<server>",
185+
help=_("Server (name or ID) to receive the fixed IP address"),
186+
)
187+
parser.add_argument(
188+
"network",
189+
metavar="<network>",
190+
help=_("Network (name or ID) to allocate "
191+
"the fixed IP address from"),
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+
network = utils.find_resource(
202+
compute_client.networks, parsed_args.network)
203+
204+
server.add_fixed_ip(network.id)
205+
206+
177207
class AddFloatingIP(command.Command):
178208
"""Add floating IP address to server"""
179209

@@ -1108,6 +1138,33 @@ def take_action(self, parsed_args):
11081138
return zip(*sorted(six.iteritems(details)))
11091139

11101140

1141+
class RemoveFixedIP(command.Command):
1142+
"""Remove fixed IP address from server"""
1143+
1144+
def get_parser(self, prog_name):
1145+
parser = super(RemoveFixedIP, self).get_parser(prog_name)
1146+
parser.add_argument(
1147+
"server",
1148+
metavar="<server>",
1149+
help=_("Server (name or ID) to remove the fixed IP address from"),
1150+
)
1151+
parser.add_argument(
1152+
"ip_address",
1153+
metavar="<ip-address>",
1154+
help=_("Fixed IP address (IP address only) to remove from the "
1155+
"server"),
1156+
)
1157+
return parser
1158+
1159+
def take_action(self, parsed_args):
1160+
compute_client = self.app.client_manager.compute
1161+
1162+
server = utils.find_resource(
1163+
compute_client.servers, parsed_args.server)
1164+
1165+
server.remove_fixed_ip(parsed_args.ip_address)
1166+
1167+
11111168
class RemoveFloatingIP(command.Command):
11121169
"""Remove floating IP address from server"""
11131170

openstackclient/tests/compute/v2/test_server.py

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

9090

91+
class TestServerAddFixedIP(TestServer):
92+
93+
def setUp(self):
94+
super(TestServerAddFixedIP, 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.AddFixedIP(self.app, None)
101+
102+
# Set add_fixed_ip method to be tested.
103+
self.methods = {
104+
'add_fixed_ip': None,
105+
}
106+
107+
def test_server_add_fixed_ip(self):
108+
servers = self.setup_servers_mock(count=1)
109+
network = compute_fakes.FakeNetwork.create_one_network()
110+
self.networks_mock.get.return_value = network
111+
112+
arglist = [
113+
servers[0].id,
114+
network.id,
115+
]
116+
verifylist = [
117+
('server', servers[0].id),
118+
('network', network.id)
119+
]
120+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
121+
122+
result = self.cmd.take_action(parsed_args)
123+
124+
servers[0].add_fixed_ip.assert_called_once_with(
125+
network.id,
126+
)
127+
self.assertIsNone(result)
128+
129+
91130
class TestServerAddFloatingIP(TestServer):
92131

93132
def setUp(self):
@@ -878,6 +917,38 @@ def test_rebuild_with_wait_fails(self, mock_wait_for_status):
878917
self.server.rebuild.assert_called_with(self.image, None)
879918

880919

920+
class TestServerRemoveFixedIP(TestServer):
921+
922+
def setUp(self):
923+
super(TestServerRemoveFixedIP, self).setUp()
924+
925+
# Get the command object to test
926+
self.cmd = server.RemoveFixedIP(self.app, None)
927+
928+
# Set unshelve method to be tested.
929+
self.methods = {
930+
'remove_fixed_ip': None,
931+
}
932+
933+
def test_server_remove_fixed_ip(self):
934+
servers = self.setup_servers_mock(count=1)
935+
936+
arglist = [
937+
servers[0].id,
938+
'1.2.3.4',
939+
]
940+
verifylist = [
941+
('server', servers[0].id),
942+
('ip_address', '1.2.3.4'),
943+
]
944+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
945+
946+
result = self.cmd.take_action(parsed_args)
947+
948+
servers[0].remove_fixed_ip.assert_called_once_with('1.2.3.4')
949+
self.assertIsNone(result)
950+
951+
881952
class TestServerRemoveFloatingIP(TestServer):
882953

883954
def setUp(self):

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ features:
77
- Add new commands ``server add/remove floating ip``. They are used to
88
replace the old commands ``ip floating add/remove``.
99
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
10+
- Add new commands ``server add/remove fixed ip``. They are used to
11+
replace the old commands ``ip fixed add/remove``.
12+
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
1013
deprecations:
1114
- Deprecate command ``ip floating pool list``.
1215
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
1316
- Deprecate commands ``ip floating add/remove``.
1417
[Blueprint rework-ip-commands `<https://blueprints.launchpad.net/python-openstackclient/+spec/rework-ip-commands>`_]
18+
- Deprecate commands ``ip fixed add/remove``.
19+
[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_fixed_ip = openstackclient.compute.v2.server:AddFixedIP
101102
server_add_floating_ip = openstackclient.compute.v2.server:AddFloatingIP
102103
server_add_security_group = openstackclient.compute.v2.server:AddServerSecurityGroup
103104
server_add_volume = openstackclient.compute.v2.server:AddServerVolume
@@ -109,6 +110,7 @@ openstack.compute.v2 =
109110
server_pause = openstackclient.compute.v2.server:PauseServer
110111
server_reboot = openstackclient.compute.v2.server:RebootServer
111112
server_rebuild = openstackclient.compute.v2.server:RebuildServer
113+
server_remove_fixed_ip = openstackclient.compute.v2.server:RemoveFixedIP
112114
server_remove_floating_ip = openstackclient.compute.v2.server:RemoveFloatingIP
113115
server_remove_security_group = openstackclient.compute.v2.server:RemoveServerSecurityGroup
114116
server_remove_volume = openstackclient.compute.v2.server:RemoveServerVolume

0 commit comments

Comments
 (0)