add instance rebooting
This commit is contained in:
parent
4fa9cac7d6
commit
1d42cc3f53
@ -52,6 +52,16 @@ class EC2Backend(BaseBackend):
|
|||||||
|
|
||||||
return terminated_instances
|
return terminated_instances
|
||||||
|
|
||||||
|
def reboot_instances(self, instance_ids):
|
||||||
|
rebooted_instances = []
|
||||||
|
for instance in self.all_instances():
|
||||||
|
if instance.id in instance_ids:
|
||||||
|
# TODO double check instances go to pending when reboot
|
||||||
|
instance._state = InstanceState(0, 'pending')
|
||||||
|
rebooted_instances.append(instance)
|
||||||
|
|
||||||
|
return rebooted_instances
|
||||||
|
|
||||||
def all_instances(self):
|
def all_instances(self):
|
||||||
instances = []
|
instances = []
|
||||||
for reservation in self.all_reservations():
|
for reservation in self.all_reservations():
|
||||||
|
@ -9,7 +9,11 @@ from .utils import instance_ids_from_querystring, camelcase_to_underscores
|
|||||||
|
|
||||||
|
|
||||||
def instances(uri, body, headers):
|
def instances(uri, body, headers):
|
||||||
querystring = parse_qs(body)
|
if body:
|
||||||
|
querystring = parse_qs(body)
|
||||||
|
else:
|
||||||
|
querystring = parse_qs(headers)
|
||||||
|
|
||||||
action = querystring['Action'][0]
|
action = querystring['Action'][0]
|
||||||
instance_ids = instance_ids_from_querystring(querystring)
|
instance_ids = instance_ids_from_querystring(querystring)
|
||||||
|
|
||||||
@ -25,6 +29,10 @@ def instances(uri, body, headers):
|
|||||||
instances = ec2_backend.terminate_instances(instance_ids)
|
instances = ec2_backend.terminate_instances(instance_ids)
|
||||||
template = Template(EC2_TERMINATE_INSTANCES)
|
template = Template(EC2_TERMINATE_INSTANCES)
|
||||||
return template.render(instances=instances)
|
return template.render(instances=instances)
|
||||||
|
elif action == 'RebootInstances':
|
||||||
|
instances = ec2_backend.reboot_instances(instance_ids)
|
||||||
|
template = Template(EC2_REBOOT_INSTANCES)
|
||||||
|
return template.render(instances=instances)
|
||||||
elif action == 'StopInstances':
|
elif action == 'StopInstances':
|
||||||
instances = ec2_backend.stop_instances(instance_ids)
|
instances = ec2_backend.stop_instances(instance_ids)
|
||||||
template = Template(EC2_STOP_INSTANCES)
|
template = Template(EC2_STOP_INSTANCES)
|
||||||
@ -55,6 +63,7 @@ def instances(uri, body, headers):
|
|||||||
return EC2_MODIFY_INSTANCE_ATTRIBUTE
|
return EC2_MODIFY_INSTANCE_ATTRIBUTE
|
||||||
else:
|
else:
|
||||||
import pdb;pdb.set_trace()
|
import pdb;pdb.set_trace()
|
||||||
|
return EC2_REBOOT_INSTANCE
|
||||||
|
|
||||||
|
|
||||||
EC2_RUN_INSTANCES = """<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
EC2_RUN_INSTANCES = """<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||||
@ -295,6 +304,10 @@ EC2_START_INSTANCES = """
|
|||||||
</instancesSet>
|
</instancesSet>
|
||||||
</StartInstancesResponse>"""
|
</StartInstancesResponse>"""
|
||||||
|
|
||||||
|
EC2_REBOOT_INSTANCES = """<RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||||
|
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||||
|
<return>true</return>
|
||||||
|
</RebootInstancesResponse>"""
|
||||||
|
|
||||||
EC2_DESCRIBE_INSTANCE_ATTRIBUTE = """<DescribeInstanceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
EC2_DESCRIBE_INSTANCE_ATTRIBUTE = """<DescribeInstanceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||||
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||||
|
@ -45,6 +45,15 @@ def test_instance_start_and_stop():
|
|||||||
started_instances[0].state.should.equal('pending')
|
started_instances[0].state.should.equal('pending')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_instance_reboot():
|
||||||
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
|
reservation = conn.run_instances('<ami-image-id>')
|
||||||
|
instance = reservation.instances[0]
|
||||||
|
instance.reboot()
|
||||||
|
instance.state.should.equal('pending')
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
def test_instance_attribute_instance_type():
|
def test_instance_attribute_instance_type():
|
||||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
|
Loading…
Reference in New Issue
Block a user