def get_types_info(client: EC2Client) -> Dict[str, NodeTypeInfo]: instances = { i["InstanceType"]: i for page in client.get_paginator("describe_instance_types").paginate() for i in page["InstanceTypes"] } def is_cluster_group(d): if "PlacementGroupInfo" not in d: return False return "cluster" in d["PlacementGroupInfo"]["SupportedStrategies"] return { s: { "memory": d["MemoryInfo"]["SizeInMiB"] - int(math.pow(d["MemoryInfo"]["SizeInMiB"], 0.7) * 0.9 + 500), "cores_per_socket": d["VCpuInfo"].get( "DefaultCores", d["VCpuInfo"]["DefaultVCpus"] ), "threads_per_core": d["VCpuInfo"].get("DefaultThreadsPerCore", 1), "arch": d["ProcessorInfo"]["SupportedArchitectures"][0], "cluster_group": is_cluster_group(d), } for s, d in instances.items() }
def update_route_tables(client: EC2Client, vpc_id: str, vgw: str, cidr: str, log: logging.Logger) -> None: try: log.info(f"Getting all route tables in VPC {vpc_id}") route_tables = { table["RouteTableId"]: table["Routes"] for page in client.get_paginator("describe_route_tables").paginate( Filters=[{ 'Name': 'vpc-id', 'Values': [vpc_id] }]) for table in page["RouteTables"] } for route_table_id, routes in route_tables.items(): log.info( f"Will create route to {cidr} via {vgw} in route table {route_table_id} if not present" ) if not route_is_present(cidr, routes, log): client.create_route(DestinationCidrBlock=cidr, RouteTableId=route_table_id, GatewayId=vgw) except Exception as e: log.exception(f"Error updating VPC {vpc_id}: {e}")