From 908468edb6e9151d1607972c325f5e9dd22b6681 Mon Sep 17 00:00:00 2001 From: Matthew Gladney Date: Fri, 24 Apr 2020 14:15:22 -0400 Subject: [PATCH] Support OptInStatus for EC2 describe_region calls --- moto/ec2/models.py | 17 +++++++++++++---- .../responses/availability_zones_and_regions.py | 1 + .../test_availability_zones_and_regions.py | 7 +++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 332c8f030..7a9351209 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -1490,9 +1490,10 @@ class AmiBackend(object): class Region(object): - def __init__(self, name, endpoint): + def __init__(self, name, endpoint, opt_in_status): self.name = name self.endpoint = endpoint + self.opt_in_status = opt_in_status class Zone(object): @@ -1503,13 +1504,21 @@ class Zone(object): class RegionsAndZonesBackend(object): + regions_not_enabled_by_default = [ + 'ap-east-1', + 'me-south-1' + ] + regions = [] for region in Session().get_available_regions("ec2"): - regions.append(Region(region, "ec2.{}.amazonaws.com".format(region))) + if region in regions_not_enabled_by_default: + regions.append(Region(region, "ec2.{}.amazonaws.com".format(region), "not-opted-in")) + else: + regions.append(Region(region, "ec2.{}.amazonaws.com".format(region), "opt-in-not-required")) for region in Session().get_available_regions("ec2", partition_name="aws-us-gov"): - regions.append(Region(region, "ec2.{}.amazonaws.com".format(region))) + regions.append(Region(region, "ec2.{}.amazonaws.com".format(region), "opt-in-not-required")) for region in Session().get_available_regions("ec2", partition_name="aws-cn"): - regions.append(Region(region, "ec2.{}.amazonaws.com.cn".format(region))) + regions.append(Region(region, "ec2.{}.amazonaws.com.cn".format(region), "opt-in-not-required")) zones = { "af-south-1": [ diff --git a/moto/ec2/responses/availability_zones_and_regions.py b/moto/ec2/responses/availability_zones_and_regions.py index 28cc3a495..61d4eb1ae 100644 --- a/moto/ec2/responses/availability_zones_and_regions.py +++ b/moto/ec2/responses/availability_zones_and_regions.py @@ -22,6 +22,7 @@ DESCRIBE_REGIONS_RESPONSE = """