in network-load-balancer-copy-utility/copy_network_load_balancer.py [0:0]
def create_nlb(nlb_data, eipalloc):
"""
Create the NLB
"""
if debug:
logger.debug("Creating the Network Load Balancer")
# If EIPs are not specified
if eipalloc is None:
request = {'Name': nlb_data['Nlb_name'], 'Subnets': nlb_data['Subnets'],
'Scheme': nlb_data['Scheme'], 'Type': nlb_data['Type']}
else:
# If the number of subnets and EIPs matches
if len(nlb_data['Subnets']) == len(eipalloc):
subnetmappings = []
for i, j in zip(nlb_data['Subnets'], eipalloc):
subnetmappings.append({'SubnetId': i, 'AllocationId': j})
request = {'Name': nlb_data['Nlb_name'], 'SubnetMappings': subnetmappings,
'Scheme': nlb_data['Scheme'], 'Type': nlb_data['Type']}
else:
logger.error("The number of EIPs and Subnets does not match")
sys.exit(1)
if len(nlb_data['Tags']) >= 1:
request['Tags'] = nlb_data['Tags']
try:
response = client.create_load_balancer(**request)
except botocore.exceptions.ParamValidationError as exception:
logger.error("Failed to create Network Load Balancer")
logger.error(exception)
sys.exit(1)
if debug:
logger.debug("Create Network Load Balancer response:")
logger.debug(response)
return response['LoadBalancers'][0]['LoadBalancerArn']