|
39 | 39 | from neutron_plugin.network import NETWORK_OPENSTACK_TYPE |
40 | 40 | from neutron_plugin.subnet import SUBNET_OPENSTACK_TYPE |
41 | 41 | from neutron_plugin.security_group import SG_OPENSTACK_TYPE |
| 42 | +from neutron_plugin.floatingip import FLOATINGIP_OPENSTACK_TYPE |
42 | 43 | from openstack_plugin_common.floatingip import get_server_floating_ip |
43 | 44 |
|
44 | 45 | PORT_OPENSTACK_TYPE = 'port' |
@@ -117,19 +118,22 @@ def attach(nova_client, neutron_client, **kwargs): |
117 | 118 | network = neutron_client.show_network(port['port']['network_id']) |
118 | 119 | network_name = network['network']['name'] |
119 | 120 | 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'] |
122 | 126 | server_addresses = \ |
123 | 127 | [addr['addr'] for addr in server.addresses[network_name]] |
124 | 128 |
|
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) |
129 | 133 | return ctx.operation.retry( |
130 | 134 | message='Waiting for the floating ip {0} to ' |
131 | 135 | 'attach to server {1}..' |
132 | | - .format(server_floating_ip['floating_ip_address'], |
| 136 | + .format(floating_ip_address, |
133 | 137 | server_id), |
134 | 138 | retry_after=10) |
135 | 139 | change = { |
|
0 commit comments