Skip to content

Commit

Permalink
Always use a fixed address when attaching a floating IP to a server
Browse files Browse the repository at this point in the history
When using Neutron, if the caller didn't specify a fixed_address when
assigning a floating IP to a server, automatically pick the fist IPv4 address
assigned to the fist port of the server.

This should fix the DreamHost use case: DH uses Neutron and automatically
assigns an IPv4 and an IPv6 fixed address. Even if it doesn't make sense to
attach a floating IPv4 address to a fixed IPv6 address, OpenStack returns an
error if we don't specify a fixed address when attacking a floating IP to a
server port when multiple IPs assigned to that port.

Change-Id: I4b91bf29366c4d8b5277d0d97cd9571770252961
  • Loading branch information
dguerri committed Jul 17, 2015
1 parent 4878e63 commit a9cf85b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions shade/__init__.py
Expand Up @@ -2092,6 +2092,15 @@ def _neutron_attach_ip_to_server(self, server_id, floating_ip_id,
port = None
if ports and fixed_address is None:
port = ports[0]
# Select the first available IPv4 address
for address in port.get('fixed_ips', list()):
if _utils.is_ipv4(address['ip_address']):
fixed_address = address['ip_address']
break
if fixed_address is None:
raise OpenStackCloudException(
"unable to find a suitable IPv4 address for server "
"{0}".format(server_id))
elif ports:
# unfortunately a port can have more than one fixed IP:
# we can't use the search_ports filtering for fixed_address as
Expand Down
4 changes: 3 additions & 1 deletion shade/tests/unit/test_floating_ip_neutron.py
Expand Up @@ -290,7 +290,9 @@ def test_attach_ip_to_server(
floatingip=self.mock_floating_ip_new_rep['floatingip']['id'],
body={
'floatingip': {
'port_id': self.mock_search_ports_rep[0]['id']
'port_id': self.mock_search_ports_rep[0]['id'],
'fixed_ip_address': self.mock_search_ports_rep[0][
'fixed_ips'][0]['ip_address']
}
}
)
Expand Down

0 comments on commit a9cf85b

Please sign in to comment.