Skip to content

Commit d1acf3a

Browse files
author
earthmant
committed
another fix
1 parent 13a0166 commit d1acf3a

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

neutron_plugin/port.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from neutron_plugin.network import NETWORK_OPENSTACK_TYPE
4040
from neutron_plugin.subnet import SUBNET_OPENSTACK_TYPE
4141
from neutron_plugin.security_group import SG_OPENSTACK_TYPE
42+
from neutron_plugin.floatingip import FLOATINGIP_OPENSTACK_TYPE
4243
from openstack_plugin_common.floatingip import get_server_floating_ip
4344

4445
PORT_OPENSTACK_TYPE = 'port'
@@ -117,19 +118,22 @@ def attach(nova_client, neutron_client, **kwargs):
117118
network = neutron_client.show_network(port['port']['network_id'])
118119
network_name = network['network']['name']
119120
server = nova_client.servers.get(server_id)
120-
server_floating_ip = get_server_floating_ip(neutron_client, server_id)
121-
floating_ip = server_floating_ip['floating_ip_address']
121+
floating_ip_id = \
122+
get_openstack_id_of_single_connected_node_by_openstack_type(
123+
ctx, FLOATINGIP_OPENSTACK_TYPE, if_exists=True)
124+
floating_ip = neutron_client.show_floatingip(floating_ip_id)
125+
floating_ip_address = floating_ip['floating_ip_address']
122126
server_addresses = \
123127
[addr['addr'] for addr in server.addresses[network_name]]
124128

125-
if server_floating_ip and floating_ip not in server_addresses:
126-
ctx.logger.info('We will attach floating ip {0} to server'
127-
.format(server_floating_ip['floating_ip_address']))
128-
server.add_floating_ip(server_floating_ip['floating_ip_address'])
129+
if floating_ip_id and floating_ip_address not in server_addresses:
130+
ctx.logger.info('We will attach floating ip {0} to server {1}'
131+
.format(floating_ip_address, server_id))
132+
server.add_floating_ip(floating_ip_address)
129133
return ctx.operation.retry(
130134
message='Waiting for the floating ip {0} to '
131135
'attach to server {1}..'
132-
.format(server_floating_ip['floating_ip_address'],
136+
.format(floating_ip_address,
133137
server_id),
134138
retry_after=10)
135139
change = {

0 commit comments

Comments
 (0)