def list_vpc_command(args): """ handle list vpcs command actions """ for vpc_env in DiscoVPC.list_vpcs(): line = u"{0}\t{1:<15}".format(vpc_env['id'], vpc_env['tags'].get("Name", "-")) if args.env_type: line += u"\t{0}".format(vpc_env['tags'].get("type", "-")) print(line)
def proxy_peerings_command(args): """ handle peerins command actions""" if args.vpc_name and args.vpc_id: logging.error("Don't use vpc_name and vpc_id at the same time.") sys.exit(2) if args.vpc_name: vpc_id = DiscoVPC.find_vpc_id_by_name(args.vpc_name) elif args.vpc_id: vpc_id = args.vpc_id else: vpc_id = None if args.list_peerings: vpc_map = {vpc.id: vpc for vpc in DiscoVPC.list_vpcs()} peerings = sorted( DiscoVPC.list_peerings(vpc_id, include_failed=True), key=lambda p: vpc_map.get(p.accepter_vpc_info.vpc_id).tags.get("Name")) for peering in peerings: vpc1 = vpc_map.get(peering.accepter_vpc_info.vpc_id) vpc2 = vpc_map.get(peering.requester_vpc_info.vpc_id) line = u"{0:<14} {1:<8} {2:<20} {3:<21}".format( peering.id, peering.status_code, "{}<->{}".format( vpc1.tags.get("Name"), vpc2.tags.get("Name")), "{}<->{}".format( peering.accepter_vpc_info.cidr_block, peering.requester_vpc_info.cidr_block)) print(line) elif args.delete_peerings: DiscoVPC.delete_peerings(vpc_id) elif args.create_peerings: peering_configs = DiscoVPC.parse_peerings_config(vpc_id) DiscoVPC.create_peering_connections(peering_configs)
def proxy_peerings_command(args): """ handle peerins command actions""" if args.vpc_name and args.vpc_id: logging.error("Don't use vpc_name and vpc_id at the same time.") sys.exit(2) if args.vpc_name: vpc_id = DiscoVPC.find_vpc_id_by_name(args.vpc_name) elif args.vpc_id: vpc_id = args.vpc_id else: vpc_id = None if args.list_peerings: vpc_map = {vpc.id: vpc for vpc in DiscoVPC.list_vpcs()} peerings = sorted(DiscoVPC.list_peerings(vpc_id, include_failed=True), key=lambda p: vpc_map.get(p.accepter_vpc_info.vpc_id) .tags.get("Name")) for peering in peerings: vpc1 = vpc_map.get(peering.accepter_vpc_info.vpc_id) vpc2 = vpc_map.get(peering.requester_vpc_info.vpc_id) line = u"{0:<14} {1:<8} {2:<20} {3:<21}".format( peering.id, peering.status_code, "{}<->{}".format(vpc1.tags.get("Name"), vpc2.tags.get("Name")), "{}<->{}".format(peering.accepter_vpc_info.cidr_block, peering.requester_vpc_info.cidr_block)) print(line) elif args.delete_peerings: DiscoVPC.delete_peerings(vpc_id) elif args.create_peerings: peering_configs = DiscoVPC.parse_peerings_config(vpc_id) DiscoVPC.create_peering_connections(peering_configs)
def proxy_peerings_command(args): """ handle peerings command actions""" if args.vpc_name and args.vpc_id: print("Don't use vpc_name and vpc_id at the same time.") sys.exit(2) vpc = None if args.vpc_name: vpc = DiscoVPC.fetch_environment(environment_name=args.vpc_name) elif args.vpc_id: vpc = DiscoVPC.fetch_environment(vpc_id=args.vpc_id) vpc_id = vpc.get_vpc_id() if vpc else None disco_peerings = DiscoVPCPeerings() if args.list_peerings: vpc_map = {vpc['id']: vpc for vpc in DiscoVPC.list_vpcs()} peerings = sorted( disco_peerings.list_peerings(vpc_id, include_failed=True), key=lambda p: vpc_map.get(p['AccepterVpcInfo']['VpcId'])['tags'].get("Name")) for peering in peerings: vpc1 = vpc_map.get(peering['AccepterVpcInfo']['VpcId']) vpc2 = vpc_map.get(peering['RequesterVpcInfo']['VpcId']) line = u"{0:<14} {1:<8} {2:<20} {3:<21}".format( peering['VpcPeeringConnectionId'], peering['Status']['Code'], "{}<->{}".format( vpc1['tags'].get("Name") if vpc1 is not None else "", vpc2['tags'].get("Name") if vpc2 is not None else ""), "{}<->{}".format( peering['AccepterVpcInfo'].get('CidrBlock'), peering['RequesterVpcInfo'].get('CidrBlock'))) print(line) elif args.delete_peerings: disco_peerings.delete_peerings(vpc_id) elif args.create_peerings: disco_peerings.update_peering_connections(vpc)