|
43 | 43 | from openstack_plugin_common.floatingip import get_server_floating_ip |
44 | 44 |
|
45 | 45 | PORT_OPENSTACK_TYPE = 'port' |
| 46 | +PORT_ADDRESS_REL_TYPE = 'cloudify.openstack.port_connected_to_floating_ip' |
46 | 47 |
|
47 | 48 | # Runtime properties |
48 | 49 | FIXED_IP_ADDRESS_PROPERTY = 'fixed_ip_address' # the fixed ip address |
@@ -112,20 +113,26 @@ def attach(nova_client, neutron_client, **kwargs): |
112 | 113 | 'external port and server are being used') |
113 | 114 | return |
114 | 115 |
|
115 | | - port_id = get_openstack_id(ctx.target) |
116 | 116 | server_id = get_openstack_id(ctx.source) |
| 117 | + port_id = get_openstack_id(ctx.target) |
117 | 118 | port = neutron_client.show_port(port_id) |
| 119 | + server = nova_client.servers.get(server_id) |
118 | 120 | network = neutron_client.show_network(port['port']['network_id']) |
119 | 121 | 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 | + |
125 | 132 | server_addresses = \ |
126 | 133 | [addr['addr'] for addr in server.addresses[network_name]] |
127 | 134 |
|
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: |
129 | 136 | ctx.logger.info('We will attach floating ip {0} to server {1}' |
130 | 137 | .format(floating_ip_address, server_id)) |
131 | 138 | server.add_floating_ip(floating_ip_address) |
|
0 commit comments