Esempio n. 1
0
# 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("Imaging EC2 instances:")

# REVIEW: For backup purposes it seems reasonable to only consider all OK vs. FAIL?!
exit_code = bc.ExitCodes.OK
for region in regions:
    try:
        ec2 = boto.connect_ec2(region=region, **credentials)
        reservations = ec2.get_all_instances(instance_ids=args.resource_ids,
                                             filters=filter['filters'])
        if filter['excludes']:
            exclusions = ec2.get_all_instances(filters=filter['excludes'])
            reservations = bc.filter_list_by_attribute(reservations,
                                                       exclusions, 'id')
        instances = [
            instance for reservation in reservations
            for instance in reservation.instances
        ]

        print region.name + ": " + str(len(instances)) + " instances"
        images = create_images(ec2,
                               instances,
                               args.backup_set,
                               args.description,
                               no_reboot=args.no_reboot)
Esempio n. 2
0
# 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("Imaging EC2 instances:")

# REVIEW: For backup purposes it seems reasonable to only consider all OK vs. FAIL?!
exit_code = bc.ExitCodes.OK
for region in regions:
    try:
        ec2 = boto.connect_ec2(region=region, **credentials)
        reservations = ec2.get_all_instances(instance_ids=args.resource_ids, filters=filter["filters"])
        if filter["excludes"]:
            exclusions = ec2.get_all_instances(filters=filter["excludes"])
            reservations = bc.filter_list_by_attribute(reservations, exclusions, "id")
        instances = [instance for reservation in reservations for instance in reservation.instances]

        print region.name + ": " + str(len(instances)) + " instances"
        images = create_images(ec2, instances, args.backup_set, args.description, no_reboot=args.no_reboot)

        if args.backup_timeout:
            try:
                states = await_images(ec2, images, timeout=args.backup_timeout)
                if not bc.ec2.IMAGE_STATES_SUCCEEDED.issuperset(states):
                    message = "FAILED to create some images: {0}!".format(format_states(states))
                    log.error(message)
                    exit_code = bc.ExitCodes.FAIL
Esempio n. 3
0
# 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 EC2 images:")

for region in regions:
    try:
        ec2 = boto.connect_ec2(region=region, **credentials)
        # NOTE: Not filtering by id allows expiring images of terminated instances as well.
        reservations = ec2.get_all_instances(filters=filter['filters'])
        if filter['excludes']:
            exclusions = ec2.get_all_instances(filters=filter['excludes'])
            reservations = bc.filter_list_by_attribute(reservations,
                                                       exclusions, 'id')
        instance_ids = [
            instance.id for reservation in reservations
            for instance in reservation.instances
        ]
        num_instances = len(instance_ids)
        if args.resource_ids:
            instance_ids.extend(args.resource_ids)
        print region.name + ": " + str(num_instances) + " instances / " + str(
            len(instance_ids)) + " instance IDs"
        expire_images(ec2, instance_ids, args.backup_set,
                      args.backup_retention, args.no_origin_safeguard)