def parse_elb(self, global_params, region, lb): """ :param global_params: :param region: :param elb: :return: """ elb = {} elb['name'] = lb.pop('LoadBalancerName') vpc_id = lb['VPCId'] if 'VPCId' in lb and lb['VPCId'] else ec2_classic manage_dictionary(self.vpcs, vpc_id, ELBv2VPCConfig()) get_keys(lb, elb, [ 'DNSName', 'CreatedTime', 'AvailabilityZones', 'Subnets', 'Policies', 'Scheme' ]) elb['security_groups'] = [] for sg in lb['SecurityGroups']: elb['security_groups'].append({'GroupId': sg}) #manage_dictionary(elb, 'listeners', {}) #for l in lb['ListenerDescriptions']: # listener = l['Listener'] # manage_dictionary(listener, 'policies', {}) # for policy_name in l['PolicyNames']: # manage_dictionary(listener['policies'], policy_name, {}) # elb['listeners'][l['Listener']['LoadBalancerPort']] = listener #manage_dictionary(elb, 'instances', []) #for i in lb['Instances']: # elb['instances'].append(i['InstanceId']) self.vpcs[vpc_id].elbs[self.get_non_aws_id(elb['name'])] = elb
def parse_instance(self, global_params, region, reservation): """ Parse a single EC2 instance :param global_params: Parameters shared for all regions :param region: Name of the AWS region :param instance: Cluster """ for i in reservation['Instances']: instance = {} vpc_id = i['VpcId'] if 'VpcId' in i and i['VpcId'] else ec2_classic manage_dictionary(self.vpcs, vpc_id, EC2VPCConfig()) instance['reservation_id'] = reservation['ReservationId'] instance['id'] = i['InstanceId'] get_name(i, instance, 'InstanceId') get_keys(i, instance, [ 'KeyName', 'LaunchTime', 'InstanceType', 'State', 'IamInstanceProfile' ]) # Network interfaces & security groups manage_dictionary(instance, 'network_interfaces', {}) for eni in i['NetworkInterfaces']: nic = {} get_keys(eni, nic, ['Association', 'Groups', 'PrivateIpAddresses']) instance['network_interfaces'][eni['NetworkInterfaceId']] = nic self.vpcs[vpc_id].instances[i['InstanceId']] = instance
def parse_route_table(self, global_params, region, rt): route_table = {} vpc_id = rt['VpcId'] get_name(rt, route_table, 'VpcId') # TODO: change get_name to have src then dst get_keys(rt, route_table, ['Routes', 'Associations', 'PropagatingVgws']) # Save manage_dictionary(self.vpcs, vpc_id, SingleVPCConfig(self.vpc_resource_types)) self.vpcs[vpc_id].route_tables[rt['RouteTableId']] = route_table
def parse_route_table(self, global_params, region, rt): route_table = {} vpc_id = rt['VpcId'] get_name(rt, route_table, 'VpcId') # TODO: change get_name to have src then dst get_keys(rt, route_table, ['Routes', 'Associations', 'PropagatingVgws']) # Save manage_dictionary(self.vpcs, vpc_id, SingleVPCConfig()) self.vpcs[vpc_id].route_tables[rt['RouteTableId']] = route_table
def parse_elb(self, global_params, region, lb): """ :param global_params: :param region: :param elb: :return: """ elb = {} elb['name'] = lb.pop('LoadBalancerName') vpc_id = lb['VPCId'] if 'VPCId' in lb and lb['VPCId'] else ec2_classic manage_dictionary(self.vpcs, vpc_id, VPCConfig(self.vpc_resource_types)) get_keys(lb, elb, [ 'DNSName', 'CreatedTime', 'AvailabilityZones', 'Subnets', 'Scheme' ]) elb['security_groups'] = [] for sg in lb['SecurityGroups']: elb['security_groups'].append({'GroupId': sg}) manage_dictionary(elb, 'listeners', {}) policy_names = [] for l in lb['ListenerDescriptions']: listener = l['Listener'] manage_dictionary(listener, 'policies', []) for policy_name in l['PolicyNames']: policy_id = self.get_non_aws_id(policy_name) listener['policies'].append(policy_id) if policy_id not in self.elb_policies: policy_names.append(policy_name) elb['listeners'][l['Listener']['LoadBalancerPort']] = listener # Fetch LB policies here. This is not ideal, but the alternative is to download all policies and clean up after... if len(policy_names): policies = api_clients[region].describe_load_balancer_policies( LoadBalancerName=elb['name'], PolicyNames=policy_names)['PolicyDescriptions'] for policy in policies: policy['name'] = policy.pop('PolicyName') policy_id = self.get_non_aws_id(policy['name']) self.elb_policies[policy_id] = policy manage_dictionary(elb, 'instances', []) for i in lb['Instances']: elb['instances'].append(i['InstanceId']) self.vpcs[vpc_id].elbs[self.get_non_aws_id(elb['name'])] = elb
def parse_elb(self, global_params, region, lb): """ :param global_params: :param region: :param elb: :return: """ elb = {} elb['name'] = lb.pop('LoadBalancerName') vpc_id = lb['VPCId'] if 'VPCId' in lb and lb['VPCId'] else ec2_classic manage_dictionary(self.vpcs, vpc_id, VPCConfig(self.vpc_resource_types)) get_keys(lb, elb, ['DNSName', 'CreatedTime', 'AvailabilityZones', 'Subnets', 'Scheme']) elb['security_groups'] = [] for sg in lb['SecurityGroups']: elb['security_groups'].append({'GroupId': sg}) manage_dictionary(elb, 'listeners', {}) policy_names = [] for l in lb['ListenerDescriptions']: listener = l['Listener'] manage_dictionary(listener, 'policies', []) for policy_name in l['PolicyNames']: policy_id = self.get_non_aws_id(policy_name) listener['policies'].append(policy_id) if policy_id not in self.elb_policies: policy_names.append(policy_name) elb['listeners'][l['Listener']['LoadBalancerPort']] = listener # Fetch LB policies here. This is not ideal, but the alternative is to download all policies and clean up after... if len(policy_names): policies = api_clients[region].describe_load_balancer_policies(LoadBalancerName = elb['name'], PolicyNames = policy_names)['PolicyDescriptions'] for policy in policies: policy['name'] = policy.pop('PolicyName') policy_id = self.get_non_aws_id(policy['name']) self.elb_policies[policy_id] = policy manage_dictionary(elb, 'instances', []) for i in lb['Instances']: elb['instances'].append(i['InstanceId']) # Get attributes elb['attributes'] = api_clients[region].describe_load_balancer_attributes(LoadBalancerName=elb['name'])['LoadBalancerAttributes'] self.vpcs[vpc_id].elbs[self.get_non_aws_id(elb['name'])] = elb
def parse_instance(self, global_params, region, reservation): """ Parse a single EC2 instance :param global_params: Parameters shared for all regions :param region: Name of the AWS region :param instance: Cluster """ for i in reservation['Instances']: instance = {} vpc_id = i['VpcId'] if 'VpcId' in i and i['VpcId'] else ec2_classic manage_dictionary(self.vpcs, vpc_id, VPCConfig(self.vpc_resource_types)) instance['reservation_id'] = reservation['ReservationId'] instance['id'] = i['InstanceId'] get_name(i, instance, 'InstanceId') get_keys(i, instance, ['KeyName', 'LaunchTime', 'InstanceType', 'State', 'IamInstanceProfile', 'SubnetId']) # Network interfaces & security groups manage_dictionary(instance, 'network_interfaces', {}) for eni in i['NetworkInterfaces']: nic = {} get_keys(eni, nic, ['Association', 'Groups', 'PrivateIpAddresses', 'SubnetId', 'Ipv6Addresses']) instance['network_interfaces'][eni['NetworkInterfaceId']] = nic self.vpcs[vpc_id].instances[i['InstanceId']] = instance