add basic zone and region endpoints
This commit is contained in:
parent
351aca3c68
commit
fbd9206f23
@ -152,7 +152,48 @@ class AmiBackend(object):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class EC2Backend(BaseBackend, InstanceBackend, TagBackend, AmiBackend):
|
|
||||||
|
class Region(object):
|
||||||
|
def __init__(self, name, endpoint):
|
||||||
|
self.name = name
|
||||||
|
self.endpoint = endpoint
|
||||||
|
|
||||||
|
|
||||||
|
class Zone(object):
|
||||||
|
def __init__(self, name, region_name):
|
||||||
|
self.name = name
|
||||||
|
self.region_name = region_name
|
||||||
|
|
||||||
|
|
||||||
|
class RegionsAndZonesBackend(object):
|
||||||
|
regions = [
|
||||||
|
Region("eu-west-1", "ec2.eu-west-1.amazonaws.com"),
|
||||||
|
Region("sa-east-1", "ec2.sa-east-1.amazonaws.com"),
|
||||||
|
Region("us-east-1", "ec2.us-east-1.amazonaws.com"),
|
||||||
|
Region("ap-northeast-1", "ec2.ap-northeast-1.amazonaws.com"),
|
||||||
|
Region("us-west-2", "ec2.us-west-2.amazonaws.com"),
|
||||||
|
Region("us-west-1", "ec2.us-west-1.amazonaws.com"),
|
||||||
|
Region("ap-southeast-1", "ec2.ap-southeast-1.amazonaws.com"),
|
||||||
|
Region("ap-southeast-2", "ec2.ap-southeast-2.amazonaws.com"),
|
||||||
|
]
|
||||||
|
|
||||||
|
# TODO: cleanup. For now, pretend everything is us-east-1. 'merica.
|
||||||
|
zones = [
|
||||||
|
Zone("us-east-1a", "us-east-1"),
|
||||||
|
Zone("us-east-1b", "us-east-1"),
|
||||||
|
Zone("us-east-1c", "us-east-1"),
|
||||||
|
Zone("us-east-1d", "us-east-1"),
|
||||||
|
Zone("us-east-1e", "us-east-1"),
|
||||||
|
]
|
||||||
|
|
||||||
|
def describe_regions(self):
|
||||||
|
return self.regions
|
||||||
|
|
||||||
|
def describe_availability_zones(self):
|
||||||
|
return self.zones
|
||||||
|
|
||||||
|
|
||||||
|
class EC2Backend(BaseBackend, InstanceBackend, TagBackend, AmiBackend, RegionsAndZonesBackend):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ from moto.ec2.utils import camelcase_to_underscores, method_namess_from_class
|
|||||||
|
|
||||||
from .amazon_dev_pay import AmazonDevPay
|
from .amazon_dev_pay import AmazonDevPay
|
||||||
from .amis import AmisResponse
|
from .amis import AmisResponse
|
||||||
from .availability_zonesand_regions import AvailabilityZonesandRegions
|
from .availability_zones_and_regions import AvailabilityZonesAndRegions
|
||||||
from .customer_gateways import CustomerGateways
|
from .customer_gateways import CustomerGateways
|
||||||
from .dhcp_options import DHCPOptions
|
from .dhcp_options import DHCPOptions
|
||||||
from .elastic_block_store import ElasticBlockStore
|
from .elastic_block_store import ElasticBlockStore
|
||||||
@ -35,7 +35,7 @@ from .tags import TagResponse
|
|||||||
|
|
||||||
class EC2Response(object):
|
class EC2Response(object):
|
||||||
|
|
||||||
sub_responses = [InstanceResponse, TagResponse, AmisResponse]
|
sub_responses = [InstanceResponse, TagResponse, AmisResponse, AvailabilityZonesAndRegions]
|
||||||
|
|
||||||
def dispatch(self, uri, body, headers):
|
def dispatch(self, uri, body, headers):
|
||||||
if body:
|
if body:
|
||||||
|
45
moto/ec2/responses/availability_zones_and_regions.py
Normal file
45
moto/ec2/responses/availability_zones_and_regions.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from jinja2 import Template
|
||||||
|
|
||||||
|
from moto.ec2.models import ec2_backend
|
||||||
|
from moto.ec2.utils import resource_ids_from_querystring
|
||||||
|
|
||||||
|
|
||||||
|
class AvailabilityZonesAndRegions(object):
|
||||||
|
def __init__(self, querystring):
|
||||||
|
self.querystring = querystring
|
||||||
|
|
||||||
|
def describe_availability_zones(self):
|
||||||
|
zones = ec2_backend.describe_availability_zones()
|
||||||
|
template = Template(DESCRIBE_ZONES_RESPONSE)
|
||||||
|
return template.render(zones=zones)
|
||||||
|
|
||||||
|
def describe_regions(self):
|
||||||
|
regions = ec2_backend.describe_regions()
|
||||||
|
template = Template(DESCRIBE_REGIONS_RESPONSE)
|
||||||
|
return template.render(regions=regions)
|
||||||
|
|
||||||
|
DESCRIBE_REGIONS_RESPONSE = """<DescribeRegionsResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||||
|
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||||
|
<regionInfo>
|
||||||
|
{% for region in regions %}
|
||||||
|
<item>
|
||||||
|
<regionName>{{ region.name }}</regionName>
|
||||||
|
<regionEndpoint>{{ region.endpoint }}</regionEndpoint>
|
||||||
|
</item>
|
||||||
|
{% endfor %}
|
||||||
|
</regionInfo>
|
||||||
|
</DescribeRegionsResponse>"""
|
||||||
|
|
||||||
|
DESCRIBE_ZONES_RESPONSE = """<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||||
|
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||||
|
<availabilityZoneInfo>
|
||||||
|
{% for zone in zones %}
|
||||||
|
<item>
|
||||||
|
<zoneName>{{ zone.name }}</zoneName>
|
||||||
|
<zoneState>available</zoneState>
|
||||||
|
<regionName>{{ zone.region_name }}</regionName>
|
||||||
|
<messageSet/>
|
||||||
|
</item>
|
||||||
|
{% endfor %}
|
||||||
|
</availabilityZoneInfo>
|
||||||
|
</DescribeAvailabilityZonesResponse>"""
|
@ -1,13 +0,0 @@
|
|||||||
from jinja2 import Template
|
|
||||||
|
|
||||||
from moto.ec2.models import ec2_backend
|
|
||||||
from moto.ec2.utils import resource_ids_from_querystring
|
|
||||||
|
|
||||||
|
|
||||||
class AvailabilityZonesandRegions(object):
|
|
||||||
def describe_availability_zones(self):
|
|
||||||
raise NotImplementedError('AvailabilityZonesandRegions.describe_availability_zones is not yet implemented')
|
|
||||||
|
|
||||||
def describe_regions(self):
|
|
||||||
raise NotImplementedError('AvailabilityZonesandRegions.describe_regions is not yet implemented')
|
|
||||||
|
|
23
tests/test_ec2/test_availability_zones_and_regions.py
Normal file
23
tests/test_ec2/test_availability_zones_and_regions.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import boto
|
||||||
|
from sure import expect
|
||||||
|
|
||||||
|
from moto import mock_ec2
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_describe_regions():
|
||||||
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
|
regions = conn.get_all_regions()
|
||||||
|
regions.should.have.length_of(8)
|
||||||
|
regions[0].name.should.equal('eu-west-1')
|
||||||
|
regions[0].endpoint.should.equal('ec2.eu-west-1.amazonaws.com')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_availability_zones():
|
||||||
|
# Just testing us-east-1 for now
|
||||||
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
|
zones = conn.get_all_zones()
|
||||||
|
zones.should.have.length_of(5)
|
||||||
|
zones[0].name.should.equal('us-east-1a')
|
||||||
|
zones[0].region_name.should.equal('us-east-1')
|
@ -1,9 +0,0 @@
|
|||||||
import boto
|
|
||||||
from sure import expect
|
|
||||||
|
|
||||||
from moto import mock_ec2
|
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
|
||||||
def test_availability_zonesand_regions():
|
|
||||||
pass
|
|
Loading…
Reference in New Issue
Block a user