update ec2 calls for boto 2.5 compat
This commit is contained in:
parent
6989f7ee59
commit
98fc1eeab9
@ -1,6 +1,6 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from boto.ec2.instance import Instance, InstanceState, Reservation
|
from boto.ec2.instance import Instance as BotoInstance, Reservation
|
||||||
|
|
||||||
from moto.core import BaseBackend
|
from moto.core import BaseBackend
|
||||||
from .utils import (
|
from .utils import (
|
||||||
@ -13,6 +13,13 @@ from .utils import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Instance(BotoInstance):
|
||||||
|
def __init__(self):
|
||||||
|
self._state_name = None
|
||||||
|
self._state_code = None
|
||||||
|
super(Instance, self).__init__()
|
||||||
|
|
||||||
|
|
||||||
class InstanceBackend(object):
|
class InstanceBackend(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -30,7 +37,8 @@ class InstanceBackend(object):
|
|||||||
for index in range(count):
|
for index in range(count):
|
||||||
new_instance = Instance()
|
new_instance = Instance()
|
||||||
new_instance.id = random_instance_id()
|
new_instance.id = random_instance_id()
|
||||||
new_instance._state = InstanceState(0, "pending")
|
new_instance._state_name = "pending"
|
||||||
|
new_instance._state_code = 0
|
||||||
new_reservation.instances.append(new_instance)
|
new_reservation.instances.append(new_instance)
|
||||||
self.reservations[new_reservation.id] = new_reservation
|
self.reservations[new_reservation.id] = new_reservation
|
||||||
return new_reservation
|
return new_reservation
|
||||||
@ -39,7 +47,8 @@ class InstanceBackend(object):
|
|||||||
started_instances = []
|
started_instances = []
|
||||||
for instance in self.all_instances():
|
for instance in self.all_instances():
|
||||||
if instance.id in instance_ids:
|
if instance.id in instance_ids:
|
||||||
instance._state = InstanceState(0, 'pending')
|
instance._state_name = "pending"
|
||||||
|
instance._state_code = 0
|
||||||
started_instances.append(instance)
|
started_instances.append(instance)
|
||||||
|
|
||||||
return started_instances
|
return started_instances
|
||||||
@ -48,7 +57,8 @@ class InstanceBackend(object):
|
|||||||
stopped_instances = []
|
stopped_instances = []
|
||||||
for instance in self.all_instances():
|
for instance in self.all_instances():
|
||||||
if instance.id in instance_ids:
|
if instance.id in instance_ids:
|
||||||
instance._state = InstanceState(64, 'stopping')
|
instance._state_name = "stopping"
|
||||||
|
instance._state_code = 64
|
||||||
stopped_instances.append(instance)
|
stopped_instances.append(instance)
|
||||||
|
|
||||||
return stopped_instances
|
return stopped_instances
|
||||||
@ -57,7 +67,8 @@ class InstanceBackend(object):
|
|||||||
terminated_instances = []
|
terminated_instances = []
|
||||||
for instance in self.all_instances():
|
for instance in self.all_instances():
|
||||||
if instance.id in instance_ids:
|
if instance.id in instance_ids:
|
||||||
instance._state = InstanceState(32, 'shutting-down')
|
instance._state_name = "shutting-down"
|
||||||
|
instance._state_code = 32
|
||||||
terminated_instances.append(instance)
|
terminated_instances.append(instance)
|
||||||
|
|
||||||
return terminated_instances
|
return terminated_instances
|
||||||
@ -67,7 +78,8 @@ class InstanceBackend(object):
|
|||||||
for instance in self.all_instances():
|
for instance in self.all_instances():
|
||||||
if instance.id in instance_ids:
|
if instance.id in instance_ids:
|
||||||
# TODO double check instances go to pending when reboot
|
# TODO double check instances go to pending when reboot
|
||||||
instance._state = InstanceState(0, 'pending')
|
instance._state_name = "pending"
|
||||||
|
instance._state_code = 0
|
||||||
rebooted_instances.append(instance)
|
rebooted_instances.append(instance)
|
||||||
|
|
||||||
return rebooted_instances
|
return rebooted_instances
|
||||||
|
@ -57,7 +57,7 @@ class InstanceResponse(object):
|
|||||||
value = self.querystring.get(key)[0]
|
value = self.querystring.get(key)[0]
|
||||||
normalized_attribute = camelcase_to_underscores(key.split(".")[0])
|
normalized_attribute = camelcase_to_underscores(key.split(".")[0])
|
||||||
instance_id = self.instance_ids[0]
|
instance_id = self.instance_ids[0]
|
||||||
instance = ec2_backend.modify_instance_attribute(instance_id, normalized_attribute, value)
|
ec2_backend.modify_instance_attribute(instance_id, normalized_attribute, value)
|
||||||
return EC2_MODIFY_INSTANCE_ATTRIBUTE
|
return EC2_MODIFY_INSTANCE_ATTRIBUTE
|
||||||
|
|
||||||
|
|
||||||
@ -77,8 +77,8 @@ EC2_RUN_INSTANCES = """<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc
|
|||||||
<instanceId>{{ instance.id }}</instanceId>
|
<instanceId>{{ instance.id }}</instanceId>
|
||||||
<imageId>ami-60a54009</imageId>
|
<imageId>ami-60a54009</imageId>
|
||||||
<instanceState>
|
<instanceState>
|
||||||
<code>0</code>
|
<code>{{ instance._state_code }}</code>
|
||||||
<name>pending</name>
|
<name>{{ instance._state_name }}</name>
|
||||||
</instanceState>
|
</instanceState>
|
||||||
<privateDnsName/>
|
<privateDnsName/>
|
||||||
<dnsName/>
|
<dnsName/>
|
||||||
@ -129,8 +129,8 @@ EC2_DESCRIBE_INSTANCES = """<DescribeInstancesResponse xmlns='http://ec2.amazona
|
|||||||
<instanceId>{{ instance.id }}</instanceId>
|
<instanceId>{{ instance.id }}</instanceId>
|
||||||
<imageId>ami-1a2b3c4d</imageId>
|
<imageId>ami-1a2b3c4d</imageId>
|
||||||
<instanceState>
|
<instanceState>
|
||||||
<code>16</code>
|
<code>{{ instance._state_code }}</code>
|
||||||
<name>{{ instance.state }}</name>
|
<name>{{ instance._state_name }}</name>
|
||||||
</instanceState>
|
</instanceState>
|
||||||
<privateDnsName/>
|
<privateDnsName/>
|
||||||
<dnsName/>
|
<dnsName/>
|
||||||
@ -163,74 +163,12 @@ EC2_DESCRIBE_INSTANCES = """<DescribeInstancesResponse xmlns='http://ec2.amazona
|
|||||||
<architecture>x86_64</architecture>
|
<architecture>x86_64</architecture>
|
||||||
<rootDeviceType>ebs</rootDeviceType>
|
<rootDeviceType>ebs</rootDeviceType>
|
||||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||||
<blockDeviceMapping>
|
<blockDeviceMapping />
|
||||||
<item>
|
|
||||||
<deviceName>/dev/sda1</deviceName>
|
|
||||||
<ebs>
|
|
||||||
<volumeId>vol-1a2b3c4d</volumeId>
|
|
||||||
<status>attached</status>
|
|
||||||
<attachTime>YYYY-MM-DDTHH:MM:SS.SSSZ</attachTime>
|
|
||||||
<deleteOnTermination>true</deleteOnTermination>
|
|
||||||
</ebs>
|
|
||||||
</item>
|
|
||||||
</blockDeviceMapping>
|
|
||||||
<virtualizationType>hvm</virtualizationType>
|
<virtualizationType>hvm</virtualizationType>
|
||||||
<clientToken>ABCDE1234567890123</clientToken>
|
<clientToken>ABCDE1234567890123</clientToken>
|
||||||
<tagSet>
|
<tagSet />
|
||||||
<item>
|
|
||||||
<key>Name</key>
|
|
||||||
<value>Windows Instance</value>
|
|
||||||
</item>
|
|
||||||
</tagSet>
|
|
||||||
<hypervisor>xen</hypervisor>
|
<hypervisor>xen</hypervisor>
|
||||||
<networkInterfaceSet>
|
<networkInterfaceSet />
|
||||||
<item>
|
|
||||||
<networkInterfaceId>eni-1a2b3c4d</networkInterfaceId>
|
|
||||||
<subnetId>subnet-1a2b3c4d</subnetId>
|
|
||||||
<vpcId>vpc-1a2b3c4d</vpcId>
|
|
||||||
<description>Primary network interface</description>
|
|
||||||
<ownerId>111122223333</ownerId>
|
|
||||||
<status>in-use</status>
|
|
||||||
<privateIpAddress>10.0.0.12</privateIpAddress>
|
|
||||||
<macAddress>1b:2b:3c:4d:5e:6f</macAddress>
|
|
||||||
<sourceDestCheck>true</sourceDestCheck>
|
|
||||||
<groupSet>
|
|
||||||
<item>
|
|
||||||
<groupId>sg-1a2b3c4d</groupId>
|
|
||||||
<groupName>my-security-group</groupName>
|
|
||||||
</item>
|
|
||||||
</groupSet>
|
|
||||||
<attachment>
|
|
||||||
<attachmentId>eni-attach-1a2b3c4d</attachmentId>
|
|
||||||
<deviceIndex>0</deviceIndex>
|
|
||||||
<status>attached</status>
|
|
||||||
<attachTime>YYYY-MM-DDTHH:MM:SS+0000</attachTime>
|
|
||||||
<deleteOnTermination>true</deleteOnTermination>
|
|
||||||
</attachment>
|
|
||||||
<association>
|
|
||||||
<publicIp>46.51.219.63</publicIp>
|
|
||||||
<ipOwnerId>111122223333</ipOwnerId>
|
|
||||||
</association>
|
|
||||||
<privateIpAddressesSet>
|
|
||||||
<item>
|
|
||||||
<privateIpAddress>10.0.0.12</privateIpAddress>
|
|
||||||
<primary>true</primary>
|
|
||||||
<association>
|
|
||||||
<publicIp>46.51.219.63</publicIp>
|
|
||||||
<ipOwnerId>111122223333</ipOwnerId>
|
|
||||||
</association>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<privateIpAddress>10.0.0.14</privateIpAddress>
|
|
||||||
<primary>false</primary>
|
|
||||||
<association>
|
|
||||||
<publicIp>46.51.221.177</publicIp>
|
|
||||||
<ipOwnerId>111122223333</ipOwnerId>
|
|
||||||
</association>
|
|
||||||
</item>
|
|
||||||
</privateIpAddressesSet>
|
|
||||||
</item>
|
|
||||||
</networkInterfaceSet>
|
|
||||||
</item>
|
</item>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</instancesSet>
|
</instancesSet>
|
||||||
@ -246,14 +184,14 @@ EC2_TERMINATE_INSTANCES = """
|
|||||||
{% for instance in instances %}
|
{% for instance in instances %}
|
||||||
<item>
|
<item>
|
||||||
<instanceId>{{ instance.id }}</instanceId>
|
<instanceId>{{ instance.id }}</instanceId>
|
||||||
<currentState>
|
|
||||||
<code>32</code>
|
|
||||||
<name>shutting-down</name>
|
|
||||||
</currentState>
|
|
||||||
<previousState>
|
<previousState>
|
||||||
<code>16</code>
|
<code>16</code>
|
||||||
<name>running</name>
|
<name>running</name>
|
||||||
</previousState>
|
</previousState>
|
||||||
|
<currentState>
|
||||||
|
<code>{{ instance._state_code }}</code>
|
||||||
|
<name>{{ instance._state_name }}</name>
|
||||||
|
</currentState>
|
||||||
</item>
|
</item>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</instancesSet>
|
</instancesSet>
|
||||||
@ -266,14 +204,14 @@ EC2_STOP_INSTANCES = """
|
|||||||
{% for instance in instances %}
|
{% for instance in instances %}
|
||||||
<item>
|
<item>
|
||||||
<instanceId>{{ instance.id }}</instanceId>
|
<instanceId>{{ instance.id }}</instanceId>
|
||||||
<currentState>
|
|
||||||
<code>32</code>
|
|
||||||
<name>{{ instance.state }}</name>
|
|
||||||
</currentState>
|
|
||||||
<previousState>
|
<previousState>
|
||||||
<code>16</code>
|
<code>16</code>
|
||||||
<name>running</name>
|
<name>running</name>
|
||||||
</previousState>
|
</previousState>
|
||||||
|
<currentState>
|
||||||
|
<code>{{ instance._state_code }}</code>
|
||||||
|
<name>{{ instance._state_name }}</name>
|
||||||
|
</currentState>
|
||||||
</item>
|
</item>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</instancesSet>
|
</instancesSet>
|
||||||
@ -286,14 +224,14 @@ EC2_START_INSTANCES = """
|
|||||||
{% for instance in instances %}
|
{% for instance in instances %}
|
||||||
<item>
|
<item>
|
||||||
<instanceId>{{ instance.id }}</instanceId>
|
<instanceId>{{ instance.id }}</instanceId>
|
||||||
<currentState>
|
|
||||||
<code>32</code>
|
|
||||||
<name>{{ instance.state }}</name>
|
|
||||||
</currentState>
|
|
||||||
<previousState>
|
<previousState>
|
||||||
<code>16</code>
|
<code>16</code>
|
||||||
<name>running</name>
|
<name>running</name>
|
||||||
</previousState>
|
</previousState>
|
||||||
|
<currentState>
|
||||||
|
<code>{{ instance._state_code }}</code>
|
||||||
|
<name>{{ instance._state_name }}</name>
|
||||||
|
</currentState>
|
||||||
</item>
|
</item>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</instancesSet>
|
</instancesSet>
|
||||||
|
@ -11,7 +11,7 @@ def test_ami_create_and_delete():
|
|||||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
reservation = conn.run_instances('<ami-image-id>')
|
reservation = conn.run_instances('<ami-image-id>')
|
||||||
instance = reservation.instances[0]
|
instance = reservation.instances[0]
|
||||||
image = instance.create_image("test-ami", "this is a test ami")
|
image = conn.create_image(instance.id, "test-ami", "this is a test ami")
|
||||||
|
|
||||||
all_images = conn.get_all_images()
|
all_images = conn.get_all_images()
|
||||||
all_images[0].id.should.equal(image)
|
all_images[0].id.should.equal(image)
|
||||||
@ -33,6 +33,6 @@ def test_ami_pulls_attributes_from_instance():
|
|||||||
instance = reservation.instances[0]
|
instance = reservation.instances[0]
|
||||||
instance.modify_attribute("kernel", "test-kernel")
|
instance.modify_attribute("kernel", "test-kernel")
|
||||||
|
|
||||||
image_id = instance.create_image("test-ami", "this is a test ami")
|
image_id = conn.create_image(instance.id, "test-ami", "this is a test ami")
|
||||||
image = conn.get_image(image_id)
|
image = conn.get_image(image_id)
|
||||||
image.kernel_id.should.equal('test-kernel')
|
expect(image.kernel_id).should.equal('test-kernel')
|
||||||
|
@ -21,7 +21,7 @@ def test_instance_launch_and_terminate():
|
|||||||
instances[0].id.should.equal(instance.id)
|
instances[0].id.should.equal(instance.id)
|
||||||
instances[0].state.should.equal('pending')
|
instances[0].state.should.equal('pending')
|
||||||
|
|
||||||
conn.terminate_instances(instances[0].id)
|
conn.terminate_instances([instances[0].id])
|
||||||
|
|
||||||
reservations = conn.get_all_instances()
|
reservations = conn.get_all_instances()
|
||||||
instance = reservations[0].instances[0]
|
instance = reservations[0].instances[0]
|
||||||
@ -40,7 +40,7 @@ def test_instance_start_and_stop():
|
|||||||
for instance in stopped_instances:
|
for instance in stopped_instances:
|
||||||
instance.state.should.equal('stopping')
|
instance.state.should.equal('stopping')
|
||||||
|
|
||||||
started_instances = conn.start_instances(instances[0].id)
|
started_instances = conn.start_instances([instances[0].id])
|
||||||
started_instances[0].state.should.equal('pending')
|
started_instances[0].state.should.equal('pending')
|
||||||
|
|
||||||
|
|
||||||
@ -76,4 +76,4 @@ def test_instance_attribute_user_data():
|
|||||||
|
|
||||||
instance_attribute = instance.get_attribute("userData")
|
instance_attribute = instance.get_attribute("userData")
|
||||||
instance_attribute.should.be.a(InstanceAttribute)
|
instance_attribute.should.be.a(InstanceAttribute)
|
||||||
instance_attribute.get("userData").should.equal("this is my user data")
|
expect(instance_attribute.get("userData")).should.equal("this is my user data")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user