Skip to content

Commit 29cbc36

Browse files
author
earthmant
committed
fixing
1 parent 71fdd8e commit 29cbc36

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

neutron_plugin/port.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from openstack_plugin_common.floatingip import get_server_floating_ip
4444

4545
PORT_OPENSTACK_TYPE = 'port'
46+
PORT_ADDRESS_REL_TYPE = 'cloudify.openstack.port_connected_to_floating_ip'
4647

4748
# Runtime properties
4849
FIXED_IP_ADDRESS_PROPERTY = 'fixed_ip_address' # the fixed ip address
@@ -112,20 +113,26 @@ def attach(nova_client, neutron_client, **kwargs):
112113
'external port and server are being used')
113114
return
114115

115-
port_id = get_openstack_id(ctx.target)
116116
server_id = get_openstack_id(ctx.source)
117+
port_id = get_openstack_id(ctx.target)
117118
port = neutron_client.show_port(port_id)
119+
server = nova_client.servers.get(server_id)
118120
network = neutron_client.show_network(port['port']['network_id'])
119121
network_name = network['network']['name']
120-
server = nova_client.servers.get(server_id)
121-
floating_ip_id = \
122-
ctx.target.instance.runtime_properties[OPENSTACK_ID_PROPERTY]
123-
floating_ip = neutron_client.show_floatingip(floating_ip_id)
124-
floating_ip_address = floating_ip['floating_ip_address']
122+
123+
floating_ip_address = None
124+
for target in ctx.target.instance.relationships:
125+
floatingip_id = \
126+
target.target.instance.runtime_properties[OPENSTACK_ID_PROPERTY]
127+
if target.type == PORT_ADDRESS_REL_TYPE:
128+
floating_ip = neutron_client.show_floatingip(floatingip_id)
129+
floating_ip_address = \
130+
floating_ip['floatingip']['floating_ip_address']
131+
125132
server_addresses = \
126133
[addr['addr'] for addr in server.addresses[network_name]]
127134

128-
if floating_ip_id and floating_ip_address not in server_addresses:
135+
if floating_ip_address and floating_ip_address not in server_addresses:
129136
ctx.logger.info('We will attach floating ip {0} to server {1}'
130137
.format(floating_ip_address, server_id))
131138
server.add_floating_ip(floating_ip_address)

0 commit comments

Comments
 (0)