|
34 | 34 | set_neutron_runtime_properties, |
35 | 35 | create_object_dict, |
36 | 36 | COMMON_RUNTIME_PROPERTIES_KEYS, |
| 37 | + OPENSTACK_ID_PROPERTY, |
37 | 38 | is_external_relationship_not_conditionally_created) |
38 | 39 |
|
39 | 40 | from neutron_plugin.network import NETWORK_OPENSTACK_TYPE |
|
42 | 43 | from openstack_plugin_common.floatingip import get_server_floating_ip |
43 | 44 |
|
44 | 45 | PORT_OPENSTACK_TYPE = 'port' |
| 46 | +PORT_ADDRESS_REL_TYPE = 'cloudify.openstack.port_connected_to_floating_ip' |
45 | 47 |
|
46 | 48 | # Runtime properties |
47 | 49 | FIXED_IP_ADDRESS_PROPERTY = 'fixed_ip_address' # the fixed ip address |
@@ -111,25 +113,34 @@ def attach(nova_client, neutron_client, **kwargs): |
111 | 113 | 'external port and server are being used') |
112 | 114 | return |
113 | 115 |
|
114 | | - port_id = get_openstack_id(ctx.target) |
115 | 116 | server_id = get_openstack_id(ctx.source) |
| 117 | + port_id = get_openstack_id(ctx.target) |
116 | 118 | port = neutron_client.show_port(port_id) |
| 119 | + server = nova_client.servers.get(server_id) |
117 | 120 | network = neutron_client.show_network(port['port']['network_id']) |
118 | 121 | network_name = network['network']['name'] |
119 | | - 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'] |
| 122 | + |
| 123 | + floating_ip_address = None |
| 124 | + for target in ctx.target.instance.relationships: |
| 125 | + if target.type == PORT_ADDRESS_REL_TYPE: |
| 126 | + target_instance = target.target.instance |
| 127 | + floatingip_id = \ |
| 128 | + target_instance.runtime_properties[OPENSTACK_ID_PROPERTY] |
| 129 | + floating_ip = neutron_client.show_floatingip(floatingip_id) |
| 130 | + floating_ip_address = \ |
| 131 | + floating_ip['floatingip']['floating_ip_address'] |
| 132 | + |
122 | 133 | server_addresses = \ |
123 | 134 | [addr['addr'] for addr in server.addresses[network_name]] |
124 | 135 |
|
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']) |
| 136 | + if floating_ip_address and floating_ip_address not in server_addresses: |
| 137 | + ctx.logger.info('We will attach floating ip {0} to server {1}' |
| 138 | + .format(floating_ip_address, server_id)) |
| 139 | + server.add_floating_ip(floating_ip_address) |
129 | 140 | return ctx.operation.retry( |
130 | 141 | message='Waiting for the floating ip {0} to ' |
131 | 142 | 'attach to server {1}..' |
132 | | - .format(server_floating_ip['floating_ip_address'], |
| 143 | + .format(floating_ip_address, |
133 | 144 | server_id), |
134 | 145 | retry_after=10) |
135 | 146 | change = { |
|
0 commit comments