From f5527877bb6dab09757b6692460bcc376b7d5ec3 Mon Sep 17 00:00:00 2001 From: Cedric Brandily Date: Fri, 16 Sep 2016 22:00:23 +0200 Subject: [PATCH] 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 --fixed-ip-address Closes-Bug: #1624524 Change-Id: I2ddb68c5873bfed7293b0e661d1adbe111681136 --- doc/source/command-objects/server.rst | 5 +++++ openstackclient/compute/v2/server.py | 9 ++++++++- .../tests/unit/compute/v2/test_server.py | 15 ++++++++++++--- ...specify-vm-ip-to-publish-85f7207740c0cc8d.yaml | 5 +++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/allow-to-specify-vm-ip-to-publish-85f7207740c0cc8d.yaml diff --git a/doc/source/command-objects/server.rst b/doc/source/command-objects/server.rst index b2ae965a7b..047bf1810b 100644 --- a/doc/source/command-objects/server.rst +++ b/doc/source/command-objects/server.rst @@ -33,9 +33,14 @@ Add floating IP address to server .. code:: bash openstack server add floating ip + [--fixed-ip-address ] +.. option:: --fixed-ip-address + + Fixed IP address to associate with this floating IP address + .. describe:: Server (name or ID) to receive the floating IP address diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index d33c631a17..3cffa0a94a 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -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="", + 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): diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 249902bca4..cdda6a97bc 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -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): diff --git a/releasenotes/notes/allow-to-specify-vm-ip-to-publish-85f7207740c0cc8d.yaml b/releasenotes/notes/allow-to-specify-vm-ip-to-publish-85f7207740c0cc8d.yaml new file mode 100644 index 0000000000..3d0a48016b --- /dev/null +++ b/releasenotes/notes/allow-to-specify-vm-ip-to-publish-85f7207740c0cc8d.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``--fixed-ip-address`` option to the ``server add floating ip`` command + [Bug `1624524 `_]