Enable to specify which vm fixed-ip to publish

This change enables to specify which vm fixed-ip will be associated to a
floating ip using:

 openstack server add floating ip <vm> <fip> --fixed-ip-address <ip>

Closes-Bug: #1624524
Change-Id: I2ddb68c5873bfed7293b0e661d1adbe111681136
This commit is contained in:
Cedric Brandily 2016-09-16 22:00:23 +02:00
parent 98d5641ac5
commit f5527877bb
4 changed files with 30 additions and 4 deletions

View File

@ -33,9 +33,14 @@ Add floating IP address to server
.. code:: bash
openstack server add floating ip
[--fixed-ip-address <fixed-ip-address>]
<server>
<ip-address>
.. option:: --fixed-ip-address <fixed-ip-address>
Fixed IP address to associate with this floating IP address
.. describe:: <server>
Server (name or ID) to receive the floating IP address

View File

@ -235,6 +235,12 @@ class AddFloatingIP(command.Command):
help=_("Floating IP address (IP address only) to assign "
"to server"),
)
parser.add_argument(
"--fixed-ip-address",
metavar="<fixed-ip-address>",
help=_("Fixed IP address to associate with this floating IP "
"address"),
)
return parser
def take_action(self, parsed_args):
@ -243,7 +249,8 @@ class AddFloatingIP(command.Command):
server = utils.find_resource(
compute_client.servers, parsed_args.server)
server.add_floating_ip(parsed_args.ip_address)
server.add_floating_ip(parsed_args.ip_address,
parsed_args.fixed_ip_address)
class AddServerSecurityGroup(command.Command):

View File

@ -146,24 +146,33 @@ class TestServerAddFloatingIP(TestServer):
'add_floating_ip': None,
}
def test_server_add_floating_ip(self):
def _test_server_add_floating_ip(self, extralist, fixed_ip_address):
servers = self.setup_servers_mock(count=1)
arglist = [
servers[0].id,
'1.2.3.4',
]
] + extralist
verifylist = [
('server', servers[0].id),
('ip_address', '1.2.3.4'),
('fixed_ip_address', fixed_ip_address),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
servers[0].add_floating_ip.assert_called_once_with('1.2.3.4')
servers[0].add_floating_ip.assert_called_once_with('1.2.3.4',
fixed_ip_address)
self.assertIsNone(result)
def test_server_add_floating_ip(self):
self._test_server_add_floating_ip([], None)
def test_server_add_floating_ip_to_fixed_ip(self):
extralist = ['--fixed-ip-address', '5.6.7.8']
self._test_server_add_floating_ip(extralist, '5.6.7.8')
class TestServerAddSecurityGroup(TestServer):

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``--fixed-ip-address`` option to the ``server add floating ip`` command
[Bug `1624524 <https://bugs.launchpad.net/python-openstackclient/+bug/1624524>`_]