コード例 #1
0
ファイル: EC2.py プロジェクト: zenoss/ZenPacks.zenoss.AWS
            # Zones
            maps['zones'].append(
                zones_rm(
                    region_id, ec2regionconn.get_all_zones())
            )

            # VPCs
            maps['VPCs'].append(
                vpcs_rm(
                    region_id, vpcregionconn.get_all_vpcs())
            )

            # VPNGateways
            maps['VPNGateways'].append(
                vpn_gateways_rm(
                    region_id, vpcregionconn.get_all_vpn_gateways()
                )
            )

            if sqsconnection:
                maps['queues'].append(vpn_queues_rm(
                    region_id, sqsconnection.get_all_queues()
                ))
            else:
                log.error(
                    'Cannot initiate SQSConnection to %s region, '
                    'VPN Queues will not be populated for this region',
                    region.name)

            maps['VPC subnets'].append(vpc_subnets_rm(
                region_id, vpcregionconn.get_all_subnets()
コード例 #2
0
ファイル: EC2.py プロジェクト: ifosch/ZenPacks.zenoss.AWS
    def process(self, device, results, log):
        log.info(
            'Modeler %s processing data for device %s',
            self.name(), device.id)

        accesskey = getattr(device, 'ec2accesskey', None)
        secretkey = getattr(device, 'ec2secretkey', None)

        old_logger = boto.log.error
        boto.log.error = lambda x: x
        try:
            if not secretkey or not accesskey:
                raise EC2ResponseError('', '', '')
            ec2conn = EC2Connection(accesskey, secretkey)
            s3connection = S3Connection(accesskey, secretkey)
            ec2_regions = ec2conn.get_all_regions()
        except EC2ResponseError:
            log.error('Invalid Keys. '
                      'Check your EC2 Access Key and EC2 Secret Key.')
            return
        finally:
            boto.log.error = old_logger

        maps = collections.OrderedDict([
            ('regions', []),
            ('s3buckets', []),
            ('instance types', []),
            ('zones', []),
            ('VPCs', []),
            ('VPC subnets', []),
            ('VPNGateways', []),
            ('images', []),
            ('instances', []),
            ('volumes', []),
            ('snapshots', []),
            ('queues', []),
            ('elastic_ips', []),
            ('reservations', []),
            ('account', []),
            ('reserved_instances', []),
        ])

        image_filters = []

        region_oms = []
        for region in ec2_regions:
            region_id = prepId(region.name)

            region_oms.append(ObjectMap(data={
                'id': region_id,
                'title': region.name,
            }))

            ec2regionconn = EC2Connection(accesskey, secretkey, region=region)
            vpcregionconn = VPCConnection(accesskey, secretkey, region=region)
            sqsconnection = boto.sqs.connect_to_region(
                region.name,
                aws_access_key_id=accesskey,
                aws_secret_access_key=secretkey
            )
            # Zones
            maps['zones'].append(
                zones_rm(
                    region_id, ec2regionconn.get_all_zones())
            )

            # VPCs
            maps['VPCs'].append(
                vpcs_rm(
                    region_id, vpcregionconn.get_all_vpcs())
            )

            # VPNGateways
            maps['VPNGateways'].append(
                vpn_gateways_rm(
                    region_id, vpcregionconn.get_all_vpn_gateways()
                )
            )

            maps['queues'].append(vpn_queues_rm(
                region_id, sqsconnection.get_all_queues()
            ))

            maps['VPC subnets'].append(vpc_subnets_rm(
                region_id, vpcregionconn.get_all_subnets()
            ))

            # Instances
            maps['instances'].append(instances_rm(
                region_id,
                device,
                ec2regionconn.get_only_instances(filters=INSTANCE_FILTERS),
                image_filters
            ))

            # Images
            if image_filters:
                maps['images'].append(
                    images_rm(region_id, ec2regionconn.get_all_images(
                        image_ids=image_filters))
                )
                image_filters = []

            maps['volumes'].append(volumes_rm(
                region_id, ec2regionconn.get_all_volumes()
            ))

            maps['snapshots'].append(snapshots_rm(
                region_id, ec2regionconn.get_all_snapshots(
                    owner="self"
                )
            ))

            # Elastic IPs
            maps['elastic_ips'].append(
                elastic_ips_rm(
                    region_id, ec2regionconn.get_all_addresses())
            )

            maps['reserved_instances'].append(
                reserved_instances_rm(
                    region_id,
                    ec2regionconn.get_all_reserved_instances(),
                )
            )

        # Regions
        maps['regions'].append(RelationshipMap(
            relname='regions',
            modname=MODULE_NAME['EC2Region'],
            objmaps=region_oms))

        # S3Buckets
        maps['s3buckets'].append(
            s3buckets_rm(s3connection.get_all_buckets())
        )

        # Trigger discovery of instance guest devices.
        maps['account'].append(ObjectMap(data={
            'setDiscoverGuests': True,
        }))

        return list(chain.from_iterable(maps.itervalues()))