Merge pull request #165 from andresriancho/master
Fix NotImplementedError: The describe_instance_status action has not been implemented
This commit is contained in:
commit
ca7a7c2dc3
@ -141,37 +141,33 @@ class InstanceBackend(object):
|
|||||||
|
|
||||||
def start_instances(self, instance_ids):
|
def start_instances(self, instance_ids):
|
||||||
started_instances = []
|
started_instances = []
|
||||||
for instance in self.all_instances():
|
for instance in self.get_multi_instances_by_id(instance_ids):
|
||||||
if instance.id in instance_ids:
|
instance.start()
|
||||||
instance.start()
|
started_instances.append(instance)
|
||||||
started_instances.append(instance)
|
|
||||||
|
|
||||||
return started_instances
|
return started_instances
|
||||||
|
|
||||||
def stop_instances(self, instance_ids):
|
def stop_instances(self, instance_ids):
|
||||||
stopped_instances = []
|
stopped_instances = []
|
||||||
for instance in self.all_instances():
|
for instance in self.get_multi_instances_by_id(instance_ids):
|
||||||
if instance.id in instance_ids:
|
instance.stop()
|
||||||
instance.stop()
|
stopped_instances.append(instance)
|
||||||
stopped_instances.append(instance)
|
|
||||||
|
|
||||||
return stopped_instances
|
return stopped_instances
|
||||||
|
|
||||||
def terminate_instances(self, instance_ids):
|
def terminate_instances(self, instance_ids):
|
||||||
terminated_instances = []
|
terminated_instances = []
|
||||||
for instance in self.all_instances():
|
for instance in self.get_multi_instances_by_id(instance_ids):
|
||||||
if instance.id in instance_ids:
|
instance.terminate()
|
||||||
instance.terminate()
|
terminated_instances.append(instance)
|
||||||
terminated_instances.append(instance)
|
|
||||||
|
|
||||||
return terminated_instances
|
return terminated_instances
|
||||||
|
|
||||||
def reboot_instances(self, instance_ids):
|
def reboot_instances(self, instance_ids):
|
||||||
rebooted_instances = []
|
rebooted_instances = []
|
||||||
for instance in self.all_instances():
|
for instance in self.get_multi_instances_by_id(instance_ids):
|
||||||
if instance.id in instance_ids:
|
instance.reboot()
|
||||||
instance.reboot()
|
rebooted_instances.append(instance)
|
||||||
rebooted_instances.append(instance)
|
|
||||||
|
|
||||||
return rebooted_instances
|
return rebooted_instances
|
||||||
|
|
||||||
@ -192,6 +188,20 @@ class InstanceBackend(object):
|
|||||||
instances.append(instance)
|
instances.append(instance)
|
||||||
return instances
|
return instances
|
||||||
|
|
||||||
|
def get_multi_instances_by_id(self, instance_ids):
|
||||||
|
"""
|
||||||
|
:param instance_ids: A string list with instance ids
|
||||||
|
:return: A list with instance objects
|
||||||
|
"""
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for reservation in self.all_reservations():
|
||||||
|
for instance in reservation.instances:
|
||||||
|
if instance.id in instance_ids:
|
||||||
|
result.append(instance)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
def get_instance_by_id(self, instance_id):
|
def get_instance_by_id(self, instance_id):
|
||||||
for reservation in self.all_reservations():
|
for reservation in self.all_reservations():
|
||||||
for instance in reservation.instances:
|
for instance in reservation.instances:
|
||||||
|
@ -65,6 +65,17 @@ class InstanceResponse(BaseResponse):
|
|||||||
template = Template(EC2_START_INSTANCES)
|
template = Template(EC2_START_INSTANCES)
|
||||||
return template.render(instances=instances)
|
return template.render(instances=instances)
|
||||||
|
|
||||||
|
def describe_instance_status(self):
|
||||||
|
instance_ids = instance_ids_from_querystring(self.querystring)
|
||||||
|
|
||||||
|
if instance_ids:
|
||||||
|
instances = ec2_backend.get_multi_instances_by_id(instance_ids)
|
||||||
|
else:
|
||||||
|
instances = ec2_backend.all_instances()
|
||||||
|
|
||||||
|
template = Template(EC2_INSTANCE_STATUS)
|
||||||
|
return template.render(instances=instances)
|
||||||
|
|
||||||
def describe_instance_attribute(self):
|
def describe_instance_attribute(self):
|
||||||
# TODO this and modify below should raise IncorrectInstanceState if
|
# TODO this and modify below should raise IncorrectInstanceState if
|
||||||
# instance not in stopped state
|
# instance not in stopped state
|
||||||
@ -359,3 +370,39 @@ EC2_INVALID_INSTANCE_ID = """<?xml version="1.0" encoding="UTF-8"?>
|
|||||||
<Message>The instance ID '{{ instance_id }}' does not exist</Message></Error>
|
<Message>The instance ID '{{ instance_id }}' does not exist</Message></Error>
|
||||||
</Errors>
|
</Errors>
|
||||||
<RequestID>39070fe4-6f6d-4565-aecd-7850607e4555</RequestID></Response>"""
|
<RequestID>39070fe4-6f6d-4565-aecd-7850607e4555</RequestID></Response>"""
|
||||||
|
|
||||||
|
|
||||||
|
EC2_INSTANCE_STATUS = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<DescribeInstanceStatusResponse xmlns="http://ec2.amazonaws.com/doc/2014-05-01/">
|
||||||
|
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||||
|
<instanceStatusSet>
|
||||||
|
{% for instance in instances %}
|
||||||
|
<item>
|
||||||
|
<instanceId>{{ instance.id }}</instanceId>
|
||||||
|
<availabilityZone>us-east-1d</availabilityZone>
|
||||||
|
<instanceState>
|
||||||
|
<code>16</code>
|
||||||
|
<name>running</name>
|
||||||
|
</instanceState>
|
||||||
|
<systemStatus>
|
||||||
|
<status>ok</status>
|
||||||
|
<details>
|
||||||
|
<item>
|
||||||
|
<name>reachability</name>
|
||||||
|
<status>passed</status>
|
||||||
|
</item>
|
||||||
|
</details>
|
||||||
|
</systemStatus>
|
||||||
|
<instanceStatus>
|
||||||
|
<status>ok</status>
|
||||||
|
<details>
|
||||||
|
<item>
|
||||||
|
<name>reachability</name>
|
||||||
|
<status>passed</status>
|
||||||
|
</item>
|
||||||
|
</details>
|
||||||
|
</instanceStatus>
|
||||||
|
</item>
|
||||||
|
{% endfor %}
|
||||||
|
</instanceStatusSet>
|
||||||
|
</DescribeInstanceStatusResponse>"""
|
@ -241,3 +241,37 @@ def test_run_instance_with_keypair():
|
|||||||
instance = reservation.instances[0]
|
instance = reservation.instances[0]
|
||||||
|
|
||||||
instance.key_name.should.equal("keypair_name")
|
instance.key_name.should.equal("keypair_name")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_describe_instance_status_no_instances():
|
||||||
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
|
all_status = conn.get_all_instance_status()
|
||||||
|
len(all_status).should.equal(0)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_describe_instance_status_with_instances():
|
||||||
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
|
conn.run_instances('ami-1234abcd', key_name="keypair_name")
|
||||||
|
|
||||||
|
all_status = conn.get_all_instance_status()
|
||||||
|
len(all_status).should.equal(1)
|
||||||
|
all_status[0].instance_status.status.should.equal('ok')
|
||||||
|
all_status[0].system_status.status.should.equal('ok')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_describe_instance_status_with_instance_filter():
|
||||||
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
|
|
||||||
|
# We want to filter based on this one
|
||||||
|
reservation = conn.run_instances('ami-1234abcd', key_name="keypair_name")
|
||||||
|
instance = reservation.instances[0]
|
||||||
|
|
||||||
|
# This is just to setup the test
|
||||||
|
conn.run_instances('ami-1234abcd', key_name="keypair_name")
|
||||||
|
|
||||||
|
all_status = conn.get_all_instance_status(instance_ids=[instance.id])
|
||||||
|
len(all_status).should.equal(1)
|
||||||
|
all_status[0].id.should.equal(instance.id)
|
Loading…
x
Reference in New Issue
Block a user