From 7f9814860ad739e25b82898176d26c7b788e8e33 Mon Sep 17 00:00:00 2001 From: Cedric Brandily Date: Fri, 31 Mar 2017 16:53:20 +0200 Subject: [PATCH] Enable to specify which fixed-ip to add to a vm. This change enables to specify which fixed-ip will be added to a vm using: openstack server add fixed ip --fixed-ip-address This change uses interface_attach instead of add_fixed_ip[1] which is less flexible and uses a deprecated API. [1] https://review.openstack.org/384261 Closes-Bug: #1678140 Change-Id: I7fe4621439ef0d8dca080551ffaeb614c5a91174 --- doc/source/command-objects/server.rst | 5 +++++ openstackclient/compute/v2/server.py | 8 +++++++- .../tests/unit/compute/v2/test_server.py | 20 +++++++++++++------ ...llow-to-vm-ip-to-add-7721ba64b863fa77.yaml | 6 ++++++ 4 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/allow-to-vm-ip-to-add-7721ba64b863fa77.yaml diff --git a/doc/source/command-objects/server.rst b/doc/source/command-objects/server.rst index 4ac05c70f7..55b39ef57d 100644 --- a/doc/source/command-objects/server.rst +++ b/doc/source/command-objects/server.rst @@ -13,9 +13,14 @@ Add fixed IP address to server .. code:: bash openstack server add fixed ip + [--fixed-ip-address ] +.. option:: --fixed-ip-address + + Requested fixed IP address + .. describe:: Server to receive the fixed IP address (name or ID) diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index edb066031a..ae83967767 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -206,6 +206,11 @@ class AddFixedIP(command.Command): "Network to allocate the fixed IP address from (name or ID)" ), ) + parser.add_argument( + "--fixed-ip-address", + metavar="", + help=_("Requested fixed IP address"), + ) return parser def take_action(self, parsed_args): @@ -217,7 +222,8 @@ class AddFixedIP(command.Command): network = utils.find_resource( compute_client.networks, parsed_args.network) - server.add_fixed_ip(network.id) + server.interface_attach(port_id=None, net_id=network.id, + fixed_ip=parsed_args.fixed_ip_address) class AddFloatingIP(command.Command): diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 0e3bb28f32..fed847f1da 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -104,10 +104,10 @@ class TestServerAddFixedIP(TestServer): # Set add_fixed_ip method to be tested. self.methods = { - 'add_fixed_ip': None, + 'interface_attach': None, } - def test_server_add_fixed_ip(self): + def _test_server_add_fixed_ip(self, extralist, fixed_ip_address): servers = self.setup_servers_mock(count=1) network = compute_fakes.FakeNetwork.create_one_network() self.networks_mock.get.return_value = network @@ -115,20 +115,28 @@ class TestServerAddFixedIP(TestServer): arglist = [ servers[0].id, network.id, - ] + ] + extralist verifylist = [ ('server', servers[0].id), - ('network', network.id) + ('network', network.id), + ('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_fixed_ip.assert_called_once_with( - network.id, + servers[0].interface_attach.assert_called_once_with( + port_id=None, net_id=network.id, fixed_ip=fixed_ip_address ) self.assertIsNone(result) + def test_server_add_fixed_ip(self): + self._test_server_add_fixed_ip([], None) + + def test_server_add_specific_fixed_ip(self): + extralist = ['--fixed-ip-address', '5.6.7.8'] + self._test_server_add_fixed_ip(extralist, '5.6.7.8') + class TestServerAddFloatingIP(TestServer): diff --git a/releasenotes/notes/allow-to-vm-ip-to-add-7721ba64b863fa77.yaml b/releasenotes/notes/allow-to-vm-ip-to-add-7721ba64b863fa77.yaml new file mode 100644 index 0000000000..9b7de99dec --- /dev/null +++ b/releasenotes/notes/allow-to-vm-ip-to-add-7721ba64b863fa77.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add ``--fixed-ip-address`` option to the ``server add fixed ip`` command + [Bug `1678140 `_] +