Clean up ec2 instance state

This commit is contained in:
Steve Pulec 2013-07-08 20:29:13 -04:00
parent dda5b2f145
commit 76ea9172da
2 changed files with 25 additions and 20 deletions

View File

@ -16,30 +16,35 @@ from .utils import (
)
class InstanceState(object):
def __init__(self, name='pending', code=0):
self.name = name
self.code = code
class Instance(BotoInstance):
def __init__(self, image_id, user_data):
super(Instance, self).__init__()
self.id = random_instance_id()
self.image_id = image_id
self._state_name = "pending"
self._state_code = 0
self._state = InstanceState()
self.user_data = user_data
def start(self):
self._state_name = "pending"
self._state_code = 0
self._state.name = "pending"
self._state.code = 0
def stop(self):
self._state_name = "stopping"
self._state_code = 64
self._state.name = "stopping"
self._state.code = 64
def terminate(self):
self._state_name = "shutting-down"
self._state_code = 32
self._state.name = "shutting-down"
self._state.code = 32
def reboot(self):
self._state_name = "pending"
self._state_code = 0
self._state.name = "pending"
self._state.code = 0
class InstanceBackend(object):

View File

@ -86,8 +86,8 @@ EC2_RUN_INSTANCES = """<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc
<instanceId>{{ instance.id }}</instanceId>
<imageId>{{ instance.image_id }}</imageId>
<instanceState>
<code>{{ instance._state_code }}</code>
<name>{{ instance._state_name }}</name>
<code>{{ instance._state.code }}</code>
<name>{{ instance._state.name }}</name>
</instanceState>
<privateDnsName/>
<dnsName/>
@ -138,8 +138,8 @@ EC2_DESCRIBE_INSTANCES = """<DescribeInstancesResponse xmlns='http://ec2.amazona
<instanceId>{{ instance.id }}</instanceId>
<imageId>{{ instance.image_id }}</imageId>
<instanceState>
<code>{{ instance._state_code }}</code>
<name>{{ instance._state_name }}</name>
<code>{{ instance._state.code }}</code>
<name>{{ instance._state.name }}</name>
</instanceState>
<privateDnsName/>
<dnsName/>
@ -198,8 +198,8 @@ EC2_TERMINATE_INSTANCES = """
<name>running</name>
</previousState>
<currentState>
<code>{{ instance._state_code }}</code>
<name>{{ instance._state_name }}</name>
<code>{{ instance._state.code }}</code>
<name>{{ instance._state.name }}</name>
</currentState>
</item>
{% endfor %}
@ -218,8 +218,8 @@ EC2_STOP_INSTANCES = """
<name>running</name>
</previousState>
<currentState>
<code>{{ instance._state_code }}</code>
<name>{{ instance._state_name }}</name>
<code>{{ instance._state.code }}</code>
<name>{{ instance._state.name }}</name>
</currentState>
</item>
{% endfor %}
@ -238,8 +238,8 @@ EC2_START_INSTANCES = """
<name>running</name>
</previousState>
<currentState>
<code>{{ instance._state_code }}</code>
<name>{{ instance._state_name }}</name>
<code>{{ instance._state.code }}</code>
<name>{{ instance._state.name }}</name>
</currentState>
</item>
{% endfor %}