Skip to content

Commit

Permalink
create new ip address before checking list of allocated ips
Browse files Browse the repository at this point in the history
This will help prevent a race condition of all cloud servers being built in
parallel trying to build with the same floating ip address.
  • Loading branch information
gtmanfred committed Aug 15, 2017
1 parent c0ff69f commit bd63074
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions salt/cloud/clouds/nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bd63074

Please sign in to comment.