def get_unallocated_public_ips(module, cp_driver, lb_driver, network_domain, reuse_free, count=0):
 free_ips = []
 if (reuse_free is True):
  blocks_with_unallocated = get_blocks_with_unallocated(module, cp_driver, lb_driver, network_domain)
  free_ips = blocks_with_unallocated['unallocated_addresses']
 if (len(free_ips) < count):
  num_needed = (count - len(free_ips))
  for i in range(num_needed):
   block = cp_driver.ex_add_public_ip_block_to_network_domain(network_domain)
   block_dict = get_block_allocation(module, cp_driver, lb_driver, network_domain, block)
   for addr in block_dict['addresses']:
    free_ips.append(addr['address'])
   if (len(free_ips) >= count):
    break
  return {'changed': True, 'msg': 'Allocated public IP block(s)', 'addresses': free_ips[:count]}
 else:
  return {'changed': False, 'msg': ('Found enough unallocated IPs' + ' without provisioning.'), 'addresses': free_ips}

def get_unallocated_public_ips ( module , cp_driver , lb_driver , network_domain , reuse_free , count = 0 ) : free_ips = [ ] if ( reuse_free is True ) : blocks_with_unallocated = get_blocks_with_unallocated ( module , cp_driver , lb_driver , network_domain ) free_ips = blocks_with_unallocated [ 'unallocated_addresses' ] if ( len ( free_ips ) < count ) : num_needed = ( count - len ( free_ips ) ) for i in range ( num_needed ) : block = cp_driver . ex_add_public_ip_block_to_network_domain ( network_domain ) block_dict = get_block_allocation ( module , cp_driver , lb_driver , network_domain , block ) for addr in block_dict [ 'addresses' ] : free_ips . append ( addr [ 'address' ] ) if ( len ( free_ips ) >= count ) : break return { 'changed' : True , 'msg' : 'Allocated public IP block(s)' , 'addresses' : free_ips [ : count ] } else : return { 'changed' : False , 'msg' : ( 'Found enough unallocated IPs' + ' without provisioning.' ) , 'addresses' : free_ips }
get and/or provision unallocated public ips .