8484 OPENSTACK_PORT_ID ,
8585 OPENSTACK_NETWORK_ID ,
8686 OPENSTACK_TYPE_PROPERTY ,
87- USE_EXTERNAL_RESOURCE_PROPERTY )
87+ USE_EXTERNAL_RESOURCE_PROPERTY ,
88+ SERVER_PUBLIC_IP_PROPERTY ,
89+ SERVER_IP_PROPERTY )
8890
8991from openstack_plugin .utils import \
9092 (handle_userdata ,
@@ -209,8 +211,8 @@ def _set_server_ips_runtime_properties(server):
209211
210212 # Only set the first "ip" as runtime property
211213 if ipv4 ['type' ] == 'fixed' \
212- and 'ip' not in ctx .instance .runtime_properties :
213- ctx .instance .runtime_properties ['ip' ] = ip
214+ and SERVER_IP_PROPERTY not in ctx .instance .runtime_properties :
215+ ctx .instance .runtime_properties [SERVER_IP_PROPERTY ] = ip
214216
215217 # Only set the first "public_ip_address" as runtime property
216218 elif ipv4 ['type' ] == 'floating' \
@@ -226,8 +228,8 @@ def _set_server_ips_runtime_properties(server):
226228 ctx .instance .runtime_properties ['ipv6' ] = ip_v6
227229 # If "ip" is not set at this point, then the only address used
228230 # is ipv6
229- if 'ip' not in ctx .instance .runtime_properties :
230- ctx .instance .runtime_properties ['ip' ] = ip_v6
231+ if SERVER_IP_PROPERTY not in ctx .instance .runtime_properties :
232+ ctx .instance .runtime_properties [SERVER_IP_PROPERTY ] = ip_v6
231233
232234 # Only set the first "public_ip6_address" as runtime property
233235 elif ipv6 ['type' ] == 'floating' \
@@ -240,11 +242,12 @@ def _set_server_ips_runtime_properties(server):
240242 if ctx .node .properties .get ('use_public_ip' ):
241243 pip = ctx .instance .runtime_properties .get ('public_ip_address' )
242244 if pip :
243- ctx .instance .runtime_properties ['ip' ] = pip
245+ ctx .instance .runtime_properties [SERVER_IP_PROPERTY ] = pip
246+ ctx .instance .runtime_properties [SERVER_PUBLIC_IP_PROPERTY ] = pip
244247
245248 elif ctx .node .properties .get ('use_ipv6_ip' , False ) and ipv6_addresses :
246249 ip_v6 = ctx .instance .runtime_properties ['ipv6' ]
247- ctx .instance .runtime_properties ['ip' ] = ip_v6
250+ ctx .instance .runtime_properties [SERVER_IP_PROPERTY ] = ip_v6
248251
249252 # Get list of all ipv4 associated with server
250253 ipv4_list = map (lambda ipv4_conf : ipv4_conf ['addr' ], ipv4_addresses )
@@ -2003,6 +2006,14 @@ def connect_floating_ip(openstack_resource, floating_ip, fixed_ip=''):
20032006 fixed_ip = fixed_ip or None
20042007 openstack_resource .add_floating_ip_to_server (floating_ip ,
20052008 fixed_ip = fixed_ip )
2009+ # set public ip property inside server runtime_properties
2010+ ctx .source .instance .runtime_properties [SERVER_PUBLIC_IP_PROPERTY ] = \
2011+ floating_ip
2012+ if ctx .source .node .properties .get ('use_public_ip' , False ):
2013+ ctx .source .instance .runtime_properties ['last_ip' ] = \
2014+ ctx .source .instance .runtime_properties .get (SERVER_IP_PROPERTY )
2015+ ctx .source .instance .runtime_properties [SERVER_IP_PROPERTY ] = \
2016+ floating_ip
20062017
20072018
20082019@with_compat_node
@@ -2022,6 +2033,11 @@ def disconnect_floating_ip(openstack_resource, floating_ip):
20222033 '' .format (openstack_resource .resource_id ))
20232034
20242035 openstack_resource .remove_floating_ip_from_server (floating_ip )
2036+ # remove public ip property from server runtime_properties
2037+ ctx .source .instance .runtime_properties .pop (SERVER_PUBLIC_IP_PROPERTY , None )
2038+ if ctx .source .node .properties .get ('use_public_ip' , False ):
2039+ ctx .source .instance .runtime_properties [SERVER_IP_PROPERTY ] = \
2040+ ctx .source .instance .runtime_properties .pop ('last_ip' , None )
20252041
20262042
20272043@with_compat_node
0 commit comments