Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws: add default regions in aws-china and aws-us-gov #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions cloudwash/providers/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
from cloudwash.utils import dry_data
from cloudwash.utils import echo_dry
from cloudwash.utils import total_running_time

import sys

def cleanup(**kwargs):

is_dry_run = kwargs["dry_run"]
data = ['VMS', 'NICS', 'DISCS', 'PIPS', 'RESOURCES', 'STACKS']
regions = settings.aws.auth.regions
if "all" in regions:
with compute_client("aws", aws_region="us-west-2") as client:
regions = client.list_regions()
default_regions = ['us-west-2', 'cn-northwest-1', 'us-gov-west-1']
for region in default_regions:
try:
with compute_client("aws", aws_region=region) as client:
regions = client.list_regions()
if regions:
break
except Exception as e:
pass
if "all" in regions:
logger.error(f"Unable to retrive region list using currrent token!")
sys.exit(1)
Comment on lines +16 to +27
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default_regions = ['us-west-2', 'cn-northwest-1', 'us-gov-west-1']
for region in default_regions:
try:
with compute_client("aws", aws_region=region) as client:
regions = client.list_regions()
if regions:
break
except Exception as e:
pass
if "all" in regions:
logger.error(f"Unable to retrive region list using currrent token!")
sys.exit(1)
default_regions = ['us-west-2', 'cn-northwest-1', 'us-gov-west-1']
regions = []
for region in default_regions:
try:
with compute_client("aws", aws_region=region) as client:
_regions = client.list_regions()
if _regions:
regions += _regions
break
except Exception as e:
pass
else:
logger.error(f"Unable to retrive region list using currrent token!")
sys.exit(1)

You should append the list of regions from all default regions to iterate over.

Also, the error should only be thrown when break is not hit in any cycle of the loop. That is else.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should append the list of regions from all default regions to iterate over.

That's not what the proposed patch does, afaics, because of the break.
Does .list_regions() return all the regions, or just some?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .list_regions() can only retrieve the regions your account belongs. That means the default region lists(['us-west-2', 'cn-northwest-1', 'us-gov-west-1']) is isolated physically and managed by standalone IAM manage systems.

for region in regions:
dry_data['VMS']['stop'] = []
dry_data['VMS']['skip'] = []
Expand Down
Loading