create new ip address before checking list of allocated ips

This will help prevent a race condition of all cloud servers being built in
parallel trying to build with the same floating ip address.
This commit is contained in:
Daniel Wallace 2017-08-15 08:21:25 -06:00
parent c0ff69f88c
commit bd63074e7a

View File

@ -726,12 +726,18 @@ def request_instance(vm_=None, call=None):
else:
pool = floating_ip_conf.get('pool', 'public')
for fl_ip, opts in six.iteritems(conn.floating_ip_list()):
if opts['fixed_ip'] is None and opts['pool'] == pool:
floating_ip = fl_ip
break
if floating_ip is None:
try:
floating_ip = conn.floating_ip_create(pool)['ip']
except Exception:
log.info('A new ip address was unable to be allocated. '
'An ip address will be pulled from the already allocated list, '
'This will cause a race condition when building in parallel.')
for fl_ip, opts in six.iteritems(conn.floating_ip_list()):
if opts['fixed_ip'] is None and opts['pool'] == pool:
floating_ip = fl_ip
break
if floating_ip is None:
log.error('No ip addresses available to allocate for this server: {0}'.format(vm_['name']))
def __query_node_data(vm_):
try: