예제 #1
0
import logging
import os

# configure command line argument parsing
parser = argparse.ArgumentParser(
    description='Upload a file to a S3 bucket in all/some available S3 regions',
    parents=[bc.build_region_parser(),
             bc.build_common_parser()])
parser.add_argument("bucket", help="A bucket name (will get region suffix)")
parser.add_argument("file", help="A local file (e.g. ./test.txt)")
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)
locations = bc.filter_regions_s3(class_iterator(Location), args.region)

# execute business logic
log.info("Uploading to S3 buckets named '" + args.bucket + "':")

file = open(args.file, 'r')
filePath, fileName = os.path.split(file.name)
log.debug(filePath)
log.debug(fileName)

s3 = boto.connect_s3(**credentials)

for location in locations:
    region = RegionMap[location]
    pprint(region, indent=2)
예제 #2
0
import boto
import boto.ec2
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"