From fa2ef99a80b1bfb85b0dc6471e52d02f44660e62 Mon Sep 17 00:00:00 2001 From: Xiao Liang Date: Thu, 9 Feb 2023 15:33:55 +0800 Subject: [PATCH] aws: add default regions in aws-china and aws-us-gov Handle failures When pass "all" in regions, us-west-2 is not proper when token is for aws-china and aws-us-gov. Signed-off-by: Xiao Liang --- cloudwash/providers/aws.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cloudwash/providers/aws.py b/cloudwash/providers/aws.py index 89579050a..e251d6711 100644 --- a/cloudwash/providers/aws.py +++ b/cloudwash/providers/aws.py @@ -5,7 +5,7 @@ from cloudwash.utils import dry_data from cloudwash.utils import echo_dry from cloudwash.utils import total_running_time - +import sys def cleanup(**kwargs): @@ -13,8 +13,18 @@ def cleanup(**kwargs): 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) for region in regions: dry_data['VMS']['stop'] = [] dry_data['VMS']['skip'] = []