Support OptInStatus for EC2 describe_region calls
This commit is contained in:
parent
eb17288503
commit
908468edb6
@ -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": [
|
||||
|
@ -22,6 +22,7 @@ DESCRIBE_REGIONS_RESPONSE = """<DescribeRegionsResponse xmlns="http://ec2.amazon
|
||||
<item>
|
||||
<regionName>{{ region.name }}</regionName>
|
||||
<regionEndpoint>{{ region.endpoint }}</regionEndpoint>
|
||||
<optInStatus>{{ region.opt_in_status }}</optInStatus>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</regionInfo>
|
||||
|
@ -40,6 +40,13 @@ def test_boto3_describe_regions():
|
||||
resp = ec2.describe_regions(RegionNames=[test_region])
|
||||
resp["Regions"].should.have.length_of(1)
|
||||
resp["Regions"][0].should.have.key("RegionName").which.should.equal(test_region)
|
||||
resp["Regions"][0].should.have.key("OptInStatus").which.should.equal("opt-in-not-required")
|
||||
|
||||
test_region = "ap-east-1"
|
||||
resp = ec2.describe_regions(RegionNames=[test_region])
|
||||
resp["Regions"].should.have.length_of(1)
|
||||
resp["Regions"][0].should.have.key("RegionName").which.should.equal(test_region)
|
||||
resp["Regions"][0].should.have.key("OptInStatus").which.should.equal("not-opted-in")
|
||||
|
||||
|
||||
@mock_ec2
|
||||
|
Loading…
Reference in New Issue
Block a user