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 <vm> <network> --fixed-ip-address <ip>

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
This commit is contained in:
Cedric Brandily 2017-03-31 16:53:20 +02:00 committed by Dean Troyer
parent c7e7f2b730
commit 7f9814860a
4 changed files with 32 additions and 7 deletions

View File

@ -13,9 +13,14 @@ Add fixed IP address to server
.. code:: bash
openstack server add fixed ip
[--fixed-ip-address <ip-address>]
<server>
<network>
.. option:: --fixed-ip-address <ip-address>
Requested fixed IP address
.. describe:: <server>
Server to receive the fixed IP address (name or ID)

View File

@ -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="<ip-address>",
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):

View File

@ -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):

View File

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