in python/gwlb/create_gwlb_tg_listener_sample.py [0:0]
def main():
"""
Creates Appliance Gateway (GWLB) and associated Target Group (TG) and
Listener and registers target(s)
Accepts:
--tg_name: TG name
--gwlb_name: GWLB name
--vpc_id: VPC id to associate TG with
--subnet_ids: Subnet ids to be assocated with GWLB
--target_ids: Target ids to be registered with GWLB's TG
Usage:
./create_gwlb_tg_listener.py \
--tg_name provider-gwlb-tg1 \
--gwlb_name provider-gwlb1 \
--vpc_id vpc-xxxx \
--subnet_ids subnet-xxxx subnet-yyyy \
--target_ids i-xxxx i-yyyy
"""
parser = argparse.ArgumentParser()
parser.add_argument('--tg_name', required=True,
help='specify target group name', type=str)
parser.add_argument('--gwlb_name', required=True,
help='specify gateway load balancer name', type=str)
parser.add_argument('--vpc_id', required=True,
help='specify vpc id', type=str)
parser.add_argument('--subnet_ids', nargs='+', required=True,
help='specify subnet ids')
parser.add_argument('--target_ids', nargs='+', required=True,
help='specify target ids')
args = parser.parse_args()
############################
# Define script variables:
############################
tg_name = args.tg_name
gwlb_name = args.gwlb_name
vpc_id = args.vpc_id
subnet_ids = args.subnet_ids
target_ids = args.target_ids
tg1_args = {
'name': tg_name,
'protocol': 'GENEVE',
'port': 6081,
'healthchkproto': 'HTTP',
'healthchkport': '80',
'healthchkpath': '/',
'vpc_id': vpc_id,
'type': 'instance'
}
#############################
# Target Group:
tg1 = create_tg(**tg1_args)
print(f"TG ARN: {tg1[1]}")
# GWLB:
gwlb1 = create_gwlb(gwlb_name, subnet_ids)
print(f"GWLB ARN: {gwlb1[1]}")
# Listener:
listener1 = create_fwd_listener(gwlb1[1], tg1[1])
print(f"LISTENER ARN: {listener1[1]}")
# Register Targets:
register_targets(tg1[1], target_ids[0])