Skip to content

Commit 49e8661

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Enable to specify which vm fixed-ip to publish"
2 parents fe3bbf6 + f552787 commit 49e8661

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

doc/source/command-objects/server.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ Add floating IP address to server
3333
.. code:: bash
3434
3535
openstack server add floating ip
36+
[--fixed-ip-address <fixed-ip-address>]
3637
<server>
3738
<ip-address>
3839
40+
.. option:: --fixed-ip-address <fixed-ip-address>
41+
42+
Fixed IP address to associate with this floating IP address
43+
3944
.. describe:: <server>
4045

4146
Server (name or ID) to receive the floating IP address

openstackclient/compute/v2/server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ def get_parser(self, prog_name):
235235
help=_("Floating IP address (IP address only) to assign "
236236
"to server"),
237237
)
238+
parser.add_argument(
239+
"--fixed-ip-address",
240+
metavar="<fixed-ip-address>",
241+
help=_("Fixed IP address to associate with this floating IP "
242+
"address"),
243+
)
238244
return parser
239245

240246
def take_action(self, parsed_args):
@@ -243,7 +249,8 @@ def take_action(self, parsed_args):
243249
server = utils.find_resource(
244250
compute_client.servers, parsed_args.server)
245251

246-
server.add_floating_ip(parsed_args.ip_address)
252+
server.add_floating_ip(parsed_args.ip_address,
253+
parsed_args.fixed_ip_address)
247254

248255

249256
class AddServerSecurityGroup(command.Command):

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,33 @@ def setUp(self):
146146
'add_floating_ip': None,
147147
}
148148

149-
def test_server_add_floating_ip(self):
149+
def _test_server_add_floating_ip(self, extralist, fixed_ip_address):
150150
servers = self.setup_servers_mock(count=1)
151151

152152
arglist = [
153153
servers[0].id,
154154
'1.2.3.4',
155-
]
155+
] + extralist
156156
verifylist = [
157157
('server', servers[0].id),
158158
('ip_address', '1.2.3.4'),
159+
('fixed_ip_address', fixed_ip_address),
159160
]
160161
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
161162

162163
result = self.cmd.take_action(parsed_args)
163164

164-
servers[0].add_floating_ip.assert_called_once_with('1.2.3.4')
165+
servers[0].add_floating_ip.assert_called_once_with('1.2.3.4',
166+
fixed_ip_address)
165167
self.assertIsNone(result)
166168

169+
def test_server_add_floating_ip(self):
170+
self._test_server_add_floating_ip([], None)
171+
172+
def test_server_add_floating_ip_to_fixed_ip(self):
173+
extralist = ['--fixed-ip-address', '5.6.7.8']
174+
self._test_server_add_floating_ip(extralist, '5.6.7.8')
175+
167176

168177
class TestServerAddSecurityGroup(TestServer):
169178

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add ``--fixed-ip-address`` option to the ``server add floating ip`` command
5+
[Bug `1624524 <https://bugs.launchpad.net/python-openstackclient/+bug/1624524>`_]

0 commit comments

Comments
 (0)