Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Add GovCloud region(s)
Browse files Browse the repository at this point in the history
[Issue(s) #50]
  • Loading branch information
sopel committed Nov 7, 2013
1 parent 79a054a commit 744564c
Show file tree
Hide file tree
Showing 38 changed files with 129 additions and 41 deletions.
22 changes: 20 additions & 2 deletions botocross/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def build_common_parser():
def build_region_parser():
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("-r", "--region", help="A region substring selector (e.g. 'us-west')")
parser.add_argument("--include_govcloud", action='store_true', help="Include 'GovCloud' regions. [default: False]")
parser.add_argument("--only_govcloud", action='store_true', help="Return only 'GovCloud' region(s). [default: False]")
return parser

def build_filter_parser(resource_name, add_ids=True):
Expand Down Expand Up @@ -114,11 +116,18 @@ def parse_credentials(args):
def is_region_selected(region, name):
return True if region.name.find(name) != -1 else False

def is_govcloud(region):
return True if region.name.find('gov') != -1 else False

def filter_list_by_attribute(includes, excludes, attribute):
excluded_ids = set([getattr(exclude, attribute) for exclude in excludes])
return [include for include in includes if getattr(include, attribute) not in excluded_ids]

def filter_regions(regions, region):
def filter_regions(regions, region, include_govcloud=False, only_govcloud=False):
if not (include_govcloud or only_govcloud):
regions = filter(lambda x: not is_govcloud(x), regions)
if only_govcloud:
regions = filter(lambda x: is_govcloud(x), regions)
if region:
botocross_log.info("... (filtered by region '" + region + "')")
regions = filter(lambda x: is_region_selected(x, region), regions)
Expand All @@ -130,7 +139,16 @@ def is_region_selected_s3(region, name):
return True if RegionMap[region].find(name) != -1 else False

# REVIEW: remove this S3 legacy induced partial duplication, if possible.
def filter_regions_s3(regions, region):
def is_govcloud_s3(region):
from botocross.s3 import RegionMap
return True if RegionMap[region].find('gov') != -1 else False

# REVIEW: remove this S3 legacy induced partial duplication, if possible.
def filter_regions_s3(regions, region, include_govcloud=False, only_govcloud=False):
if not (include_govcloud or only_govcloud):
regions = filter(lambda x: not is_govcloud_s3(x), regions)
if only_govcloud:
regions = filter(lambda x: is_govcloud_s3(x), regions)
if region:
botocross_log.info("... (filtered by S3 region '" + region + "')")
regions = filter(lambda x: is_region_selected_s3(x, region), regions)
Expand Down
3 changes: 2 additions & 1 deletion botocross/s3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
'EU': 'eu-west-1',
'APNortheast': 'ap-northeast-1',
'APSoutheast': 'ap-southeast-1',
'APSoutheast2': 'ap-southeast-2'}
'APSoutheast2': 'ap-southeast-2',
'USGovWest': 'us-gov-west-1'}

# NOTE: S3 region handling differs in an unfortunate way (likely a legacy issue) and requires special treatment.
def class_iterator(Class):
Expand Down
2 changes: 1 addition & 1 deletion scripts/authorize-securitygroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def authorizeIp():
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
group_name = args.name if args.name else ""
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
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)
locations = bc.filter_regions_s3(class_iterator(Location), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Creating S3 buckets named '" + args.bucket + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)

# execute business logic
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-securitygroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Creating EC2 security groups named '" + args.group + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)

# execute business logic
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.cloudformation.regions(), args.region)
regions = bc.filter_regions(boto.cloudformation.regions(), args.region, args.include_govcloud, args.only_govcloud)

def processParameter(parameter, region_name, account_id):
replacement = parameter[1].replace('{REGION}', region_name).replace('{ACCOUNT}', account_id)
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.sns.regions(), args.region)
regions = bc.filter_regions(boto.sns.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Creating SNS topics named '" + args.topic + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/delete-buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
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)
locations = bc.filter_regions_s3(class_iterator(Location), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Deleting S3 buckets named '" + args.bucket + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/delete-keypairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Deleting key pair named '" + args.key_name + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/delete-keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
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)
locations = bc.filter_regions_s3(class_iterator(Location), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Deleting from S3 buckets named '" + args.bucket + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/delete-securitygroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
groupname = args.name if args.name else ""
Expand Down
2 changes: 1 addition & 1 deletion scripts/delete-snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)
log.info(args.resource_ids)

Expand Down
2 changes: 1 addition & 1 deletion scripts/delete-stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.cloudformation.regions(), args.region)
regions = bc.filter_regions(boto.cloudformation.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Deleting CloudFormation stacks named '" + args.stack_name_or_id + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/delete-topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.sns.regions(), args.region)
regions = bc.filter_regions(boto.sns.regions(), args.region, args.include_govcloud, args.only_govcloud)

def createTopicArn(region_name, topic_name):
from botocross.iam.accountinfo import AccountInfo
Expand Down
2 changes: 1 addition & 1 deletion scripts/deregister-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)
log.info(args.resource_ids)

Expand Down
2 changes: 1 addition & 1 deletion scripts/describe-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)
log.info(args.resource_ids)

Expand Down
2 changes: 1 addition & 1 deletion scripts/describe-instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)
log.info(args.resource_ids)

Expand Down
2 changes: 1 addition & 1 deletion scripts/describe-regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Describing regions for EC2:")
Expand Down
2 changes: 1 addition & 1 deletion scripts/describe-securitygroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)

# execute business logic
Expand Down
2 changes: 1 addition & 1 deletion scripts/describe-snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)
log.info(args.resource_ids)

Expand Down
2 changes: 1 addition & 1 deletion scripts/describe-stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.cloudformation.regions(), args.region)
regions = bc.filter_regions(boto.cloudformation.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Describing CloudFormation stacks:")
Expand Down
2 changes: 1 addition & 1 deletion scripts/describe-tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filters = bc.build_filter_params(args.filter)

# execute business logic
Expand Down
2 changes: 1 addition & 1 deletion scripts/describe-volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)
log.info(args.resource_ids)

Expand Down
2 changes: 1 addition & 1 deletion scripts/expire-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)

# execute business logic
Expand Down
2 changes: 1 addition & 1 deletion scripts/expire-snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)
filter = bc.build_filter(args.filter, args.exclude)

# execute business logic
Expand Down
2 changes: 1 addition & 1 deletion scripts/import-keypairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Importing key pair named '" + args.key_name + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/list-subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.sns.regions(), args.region)
regions = bc.filter_regions(boto.sns.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Describing SNS topics:")
Expand Down
2 changes: 1 addition & 1 deletion scripts/list-topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.sns.regions(), args.region)
regions = bc.filter_regions(boto.sns.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Describing SNS topics:")
Expand Down
2 changes: 1 addition & 1 deletion scripts/read-buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
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)
locations = bc.filter_regions_s3(class_iterator(Location), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Reading S3 buckets named '" + args.bucket + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/revoke-securitygroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def revokeIp():
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)
regions = bc.filter_regions(boto.ec2.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
group_name = args.name if args.name else ""
Expand Down
2 changes: 1 addition & 1 deletion scripts/subscribe-topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.sns.regions(), args.region)
regions = bc.filter_regions(boto.sns.regions(), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Subscribing to SNS topics named '" + args.topic + ' with protocol ' + args.protocol + ' and endpoint ' + args.endpoint + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-stacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.cloudformation.regions(), args.region)
regions = bc.filter_regions(boto.cloudformation.regions(), args.region, args.include_govcloud, args.only_govcloud)

def processParameter(parameter, region_name, account_id):
replacement = parameter[1].replace('{REGION}', region_name).replace('{ACCOUNT}', account_id)
Expand Down
2 changes: 1 addition & 1 deletion scripts/upload-keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
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)
locations = bc.filter_regions_s3(class_iterator(Location), args.region, args.include_govcloud, args.only_govcloud)

# execute business logic
log.info("Uploading to S3 buckets named '" + args.bucket + "':")
Expand Down
2 changes: 1 addition & 1 deletion scripts/validate-template.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
log = logging.getLogger('botocross')
bc.configure_logging(log, args.log_level)
credentials = bc.parse_credentials(args)
regions = bc.filter_regions(boto.cloudformation.regions(), args.region)
regions = bc.filter_regions(boto.cloudformation.regions(), args.region, args.include_govcloud, args.only_govcloud)

def processArgument(argument, region_name):
return argument.replace('{REGION}', region_name)
Expand Down
2 changes: 1 addition & 1 deletion tests/s3/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import unittest

class S3PackageTest(unittest.TestCase):
num_regions = 8;
num_regions = 9;

def test_region_map(self):
from botocross.s3 import RegionMap
Expand Down
Loading

0 comments on commit 744564c

Please sign in to comment.