add instance stop/start
This commit is contained in:
parent
4283cca63c
commit
3a9c757e46
4 changed files with 85 additions and 9 deletions
|
|
@ -20,6 +20,24 @@ class EC2Backend(BaseBackend):
|
|||
self.reservations[new_reservation.id] = new_reservation
|
||||
return new_reservation
|
||||
|
||||
def start_instances(self, instance_ids):
|
||||
started_instances = []
|
||||
for instance in self.all_instances():
|
||||
if instance.id in instance_ids:
|
||||
instance._state = InstanceState(0, 'pending')
|
||||
started_instances.append(instance)
|
||||
|
||||
return started_instances
|
||||
|
||||
def stop_instances(self, instance_ids):
|
||||
stopped_instances = []
|
||||
for instance in self.all_instances():
|
||||
if instance.id in instance_ids:
|
||||
instance._state = InstanceState(64, 'stopping')
|
||||
stopped_instances.append(instance)
|
||||
|
||||
return stopped_instances
|
||||
|
||||
def terminate_instances(self, instance_ids):
|
||||
terminated_instances = []
|
||||
for instance in self.all_instances():
|
||||
|
|
|
|||
|
|
@ -21,8 +21,18 @@ def instances(uri, body, headers):
|
|||
instances = ec2_backend.terminate_instances(instance_ids)
|
||||
template = Template(EC2_TERMINATE_INSTANCES)
|
||||
return template.render(instances=instances)
|
||||
elif action == 'StopInstances':
|
||||
instance_ids = querystring.get('InstanceId.1')[0]
|
||||
instances = ec2_backend.stop_instances(instance_ids)
|
||||
template = Template(EC2_STOP_INSTANCES)
|
||||
return template.render(instances=instances)
|
||||
elif action == 'StartInstances':
|
||||
instance_ids = querystring.get('InstanceId.1')[0]
|
||||
instances = ec2_backend.start_instances(instance_ids)
|
||||
template = Template(EC2_START_INSTANCES)
|
||||
return template.render(instances=instances)
|
||||
else:
|
||||
raise ValueError("Not implemented", action)
|
||||
import pdb;pdb.set_trace()
|
||||
|
||||
|
||||
EC2_RUN_INSTANCES = """<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||
|
|
@ -221,4 +231,44 @@ EC2_TERMINATE_INSTANCES = """
|
|||
</item>
|
||||
{% endfor %}
|
||||
</instancesSet>
|
||||
</TerminateInstancesResponse>"""
|
||||
</TerminateInstancesResponse>"""
|
||||
|
||||
EC2_STOP_INSTANCES = """
|
||||
<StopInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||
<instancesSet>
|
||||
{% for instance in instances %}
|
||||
<item>
|
||||
<instanceId>{{ instance.id }}</instanceId>
|
||||
<currentState>
|
||||
<code>32</code>
|
||||
<name>{{ instance.state }}</name>
|
||||
</currentState>
|
||||
<previousState>
|
||||
<code>16</code>
|
||||
<name>running</name>
|
||||
</previousState>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</instancesSet>
|
||||
</StopInstancesResponse>"""
|
||||
|
||||
EC2_START_INSTANCES = """
|
||||
<StartInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
||||
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
||||
<instancesSet>
|
||||
{% for instance in instances %}
|
||||
<item>
|
||||
<instanceId>{{ instance.id }}</instanceId>
|
||||
<currentState>
|
||||
<code>32</code>
|
||||
<name>{{ instance.state }}</name>
|
||||
</currentState>
|
||||
<previousState>
|
||||
<code>16</code>
|
||||
<name>running</name>
|
||||
</previousState>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</instancesSet>
|
||||
</StartInstancesResponse>"""
|
||||
|
|
|
|||
|
|
@ -15,13 +15,6 @@ def bucket_response(uri, body, headers):
|
|||
hostname = uri.hostname
|
||||
method = uri.method
|
||||
|
||||
# s3_base_url = "s3.amazonaws.com"
|
||||
# if hostname == s3_base_url:
|
||||
# # No bucket specified. Listing all buckets
|
||||
# all_buckets = s3_backend.get_all_buckets()
|
||||
# template = Template(S3_ALL_BUCKETS)
|
||||
# return template.render(buckets=all_buckets)
|
||||
|
||||
bucket_name = bucket_name_from_hostname(hostname)
|
||||
|
||||
if method == 'GET':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue