in application-load-balancer-copy-utility/copy_classic_load_balancer.py [0:0]
def main():
"""
:rtype: int
"""
parser = argparse.ArgumentParser(
description='Create an Application Load Balancer '
'from a Classic load balancer', usage='%(prog)s --name <elb name> --region')
parser.add_argument(
"--name", help="The name of the Classic load balancer", required=True)
parser.add_argument(
"--profile", help="The credentials profile name to use", required=False, default=None)
parser.add_argument("--region", help="The region of the Classic load balancer "
"(will also be used for the Application Load Balancer)",
required=True)
parser.add_argument("--debug", help="debug mode", action='store_true')
parser.add_argument("--register-targets", help="Register the backend instances "
"of the Classic load balancer with the Application Load Balancer",
action='store_true')
parser.add_argument("--dry-run", help="Validate that "
"the current load balancer configuration is compatible "
"with Application Load Balancers, but do not perform create operations",
action='store_true')
# if no options, print help
if len(sys.argv[1:]) == 0:
parser.print_help()
parser.exit()
args = parser.parse_args()
load_balancer_name = args.name
region = args.region
# setting up debugging
global debug
debug = False
if args.debug:
debug = True
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s')
global client
session = botocore.session.get_session()
session.user_agent_name = 'CopyClassicLoadBalancer/' + VERSION
session.set_config_variable('profile', args.profile)
client = session.create_client('elbv2', region_name=region)
# Obtain ELB data
elb_data = get_elb_data(load_balancer_name, region, args.profile)
# validate that an existing Application Load Balancer with same name does not exist
if alb_exist(load_balancer_name, region):
print('An Application Load Balancer currently exists with the name {} in {}'.format(
load_balancer_name, region))
sys.exit(1)
# # validate known failure scenarios
if passed_hardfailure_detector(elb_data):
if passed_softfailure_detector(elb_data):
# quit early for dry run operation
if args.dry_run:
print(
'Your load balancer configuration is supported by this migration utility')
sys.exit(0)
alb_data = get_alb_data(elb_data, region, load_balancer_name)
alb_arn = create_alb(alb_data)
alb_target_group_arns = create_target_groups(alb_data)
create_listeners(alb_arn, alb_data, alb_target_group_arns)
load_attributes(alb_data, alb_arn)
target_group_attributes(alb_data, alb_arn)
add_tags(alb_data, alb_arn, alb_target_group_arns)
if args.register_targets:
register_backends(alb_target_group_arns, alb_data)
print("Your Application Load Balancer is ready!")
print("Application Load Balancer ARN:")
print(alb_arn)
print("Target group ARNs:")
for target_group in alb_target_group_arns:
print(target_group['arn'])
print("Considerations:")
print("1. If your Classic load balancer is attached to "
"an Auto Scaling group, attach the target groups to the Auto Scaling group.")
print("2. All HTTPS listeners use the predefined security policy.")
print(
"3. To use Amazon EC2 Container Service (Amazon ECS), "
"register your containers as targets.")
return
else:
return 1