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 `_]