import botocross as bc
import logging

# configure command line argument parsing
parser = argparse.ArgumentParser(
    description="Describe EBS snapshots in all/some available EC2 regions",
    parents=[bc.build_region_parser(), bc.build_filter_parser("EBS snapshots"), bc.build_common_parser()],
)
args = parser.parse_args()

# process common command line arguments
log = logging.getLogger("botocross")
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.ec2.regions(), args.region)
filter = bc.build_filter(args.filter, args.exclude)
log.info(args.resource_ids)

# execute business logic
log.info("Describing EBS snapshots:")

for region in regions:
    try:
        ec2 = boto.connect_ec2(region=region, **credentials)
        snapshots = ec2.get_all_snapshots(snapshot_ids=args.resource_ids, owner="self", filters=filter["filters"])
        if filter["excludes"]:
            exclusions = ec2.get_all_snapshots(owner="self", filters=filter["excludes"])
            snapshots = bc.filter_list_by_attribute(snapshots, exclusions, "id")
        print region.name + ": " + str(len(snapshots)) + " snapshots"
        for snapshot in snapshots:
            if args.verbose:
Exemple #2
0
    description=
    'Expire snapshots of EBS volumes in all/some available EC2 regions',
    parents=[
        bc.build_region_parser(),
        bc.build_filter_parser('EBS volume'),
        bc.build_backup_parser('EBS volume', True, 1),
        bc.build_common_parser()
    ])
args = parser.parse_args()

# process common command line arguments
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.ec2.regions(), args.region)
filter = bc.build_filter(args.filter, args.exclude)

# execute business logic
log.info("Expire EBS snapshots")

for region in regions:
    try:
        ec2 = boto.connect_ec2(region=region, **credentials)
        # NOTE: Not filtering by id allows expiring snapshots of deregistered volumes as well.
        volumes = ec2.get_all_volumes(filters=filter['filters'])
        if filter['excludes']:
            exclusions = ec2.get_all_volumes(filters=filter['excludes'])
            volumes = bc.filter_list_by_attribute(volumes, exclusions, 'id')
        volume_ids = [volume.id for volume in volumes]
        if args.resource_ids:
            volume_ids.extend(args.resource_ids)