def parse_instance(self, global_params, region, reservation): """ Parse a single EC2 instance :param reservation: :param global_params: Parameters shared for all regions :param region: Name of the AWS region """ 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'] instance['monitoring_enabled'] = i['Monitoring'][ 'State'] == 'enabled' instance['user_data'] = self._get_user_data(region, instance['id']) 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
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_flow_log(self, global_params, region, flow_log): """ :param global_params: :param region: :param flow_log: :return: """ get_name(flow_log, flow_log, 'FlowLogId') flow_log_id = flow_log.pop('FlowLogId') self.flow_logs[flow_log_id] = flow_log
def store_target(self, global_params, region, target): target_type = target.pop('scout2_target_type') if 'VpcId' in target: vpc_id = target.pop('VpcId') manage_dictionary(self.vpcs, vpc_id, VPCConfig(self.vpc_resource_types)) tmp = getattr(self, 'vpcs')[vpc_id] target_dict = getattr(tmp, target_type) else: target_dict = getattr(self, target_type) target_id = target[resource_id_map[target_type]] get_name(target, target, resource_id_map[target_type]) target_dict[target_id] = target
def parse_network_acl(self, global_params, region, network_acl): """ :param global_params: :param region: :param network_acl: :return: """ vpc_id = network_acl['VpcId'] network_acl['id'] = network_acl.pop('NetworkAclId') get_name(network_acl, network_acl, 'id') manage_dictionary(network_acl, 'rules', {}) network_acl['rules']['ingress'] = self.__parse_network_acl_entries(network_acl['Entries'], False) network_acl['rules']['egress'] = self.__parse_network_acl_entries(network_acl['Entries'], True) network_acl.pop('Entries') # Save manage_dictionary(self.vpcs, vpc_id, SingleVPCConfig(self.vpc_resource_types)) self.vpcs[vpc_id].network_acls[network_acl['id']] = network_acl
def parse_subnet(self, global_params, region, subnet): """ Parse subnet object. :param global_params: :param region: :param subnet: :return: """ vpc_id = subnet['VpcId'] manage_dictionary(self.vpcs, vpc_id, SingleVPCConfig(self.vpc_resource_types)) subnet_id = subnet['SubnetId'] get_name(subnet, subnet, 'SubnetId') # set flow logs that cover this subnet subnet['flow_logs'] = get_subnet_flow_logs_list(self, subnet) # Save manage_dictionary(self.vpcs, vpc_id, SingleVPCConfig(self.vpc_resource_types)) self.vpcs[vpc_id].subnets[subnet_id] = subnet
def parse_volume(self, global_params, region, volume): """ :param global_params: Parameters shared for all regions :param region: Name of the AWS region :param volume: Single EBS volume :return: """ volume['id'] = volume.pop('VolumeId') volume['name'] = get_name(volume, volume, 'id') self.volumes[volume['id']] = volume
def parse_vpc(self, global_params, region_name, vpc): """ :param global_params: :param region_name: :param vpc: :return: """ vpc_id = vpc['VpcId'] # Save manage_dictionary(self.vpcs, vpc_id, SingleVPCConfig(self.vpc_resource_types)) self.vpcs[vpc_id].name = get_name(vpc, {}, 'VpcId')
def parse_snapshot(self, global_params, region, snapshot): """ :param global_params: Parameters shared for all regions :param region: Name of the AWS region :param snapshot: Single snapshot :return: """ snapshot['id'] = snapshot.pop('SnapshotId') snapshot['name'] = get_name(snapshot, snapshot, 'id') self.snapshots[snapshot['id']] = snapshot # Get snapshot attribute snapshot['createVolumePermission'] = \ api_clients[region].describe_snapshot_attribute(Attribute='createVolumePermission', SnapshotId=snapshot['id'])[ 'CreateVolumePermissions'] snapshot['public'] = self._is_public(snapshot)