Merge pull request #239 from joekiller/enhance/describe_stacks_delete_stacks_stack_status
Enhance DescribeStacks. Keep track of deleted stacks. Stack status.
This commit is contained in:
commit
e67ef8f038
@ -12,6 +12,7 @@ class FakeStack(object):
|
|||||||
self.stack_id = stack_id
|
self.stack_id = stack_id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.template = template
|
self.template = template
|
||||||
|
self.status = 'CREATE_COMPLETE'
|
||||||
|
|
||||||
template_dict = json.loads(self.template)
|
template_dict = json.loads(self.template)
|
||||||
self.description = template_dict.get('Description')
|
self.description = template_dict.get('Description')
|
||||||
@ -35,6 +36,7 @@ class CloudFormationBackend(BaseBackend):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.stacks = {}
|
self.stacks = {}
|
||||||
|
self.deleted_stacks = {}
|
||||||
|
|
||||||
def create_stack(self, name, template):
|
def create_stack(self, name, template):
|
||||||
stack_id = generate_stack_id(name)
|
stack_id = generate_stack_id(name)
|
||||||
@ -42,10 +44,16 @@ class CloudFormationBackend(BaseBackend):
|
|||||||
self.stacks[stack_id] = new_stack
|
self.stacks[stack_id] = new_stack
|
||||||
return new_stack
|
return new_stack
|
||||||
|
|
||||||
def describe_stacks(self, names):
|
def describe_stacks(self, name_or_stack_id):
|
||||||
stacks = self.stacks.values()
|
stacks = self.stacks.values()
|
||||||
if names:
|
if name_or_stack_id:
|
||||||
return [stack for stack in stacks if stack.name in names]
|
for stack in stacks:
|
||||||
|
if stack.name == name_or_stack_id or stack.stack_id == name_or_stack_id:
|
||||||
|
return [stack]
|
||||||
|
deleted_stacks = self.deleted_stacks.values()
|
||||||
|
for stack in deleted_stacks:
|
||||||
|
if stack.stack_id == name_or_stack_id:
|
||||||
|
return [stack]
|
||||||
else:
|
else:
|
||||||
return stacks
|
return stacks
|
||||||
|
|
||||||
@ -68,6 +76,9 @@ class CloudFormationBackend(BaseBackend):
|
|||||||
def delete_stack(self, name_or_stack_id):
|
def delete_stack(self, name_or_stack_id):
|
||||||
if name_or_stack_id in self.stacks:
|
if name_or_stack_id in self.stacks:
|
||||||
# Delete by stack id
|
# Delete by stack id
|
||||||
|
stack = self.stacks.pop(name_or_stack_id, None)
|
||||||
|
stack.status = 'DELETE_COMPLETE'
|
||||||
|
self.deleted_stacks[stack.stack_id] = stack
|
||||||
return self.stacks.pop(name_or_stack_id, None)
|
return self.stacks.pop(name_or_stack_id, None)
|
||||||
else:
|
else:
|
||||||
# Delete by stack name
|
# Delete by stack name
|
||||||
|
@ -27,8 +27,10 @@ class CloudFormationResponse(BaseResponse):
|
|||||||
return json.dumps(stack_body)
|
return json.dumps(stack_body)
|
||||||
|
|
||||||
def describe_stacks(self):
|
def describe_stacks(self):
|
||||||
names = [value[0] for key, value in self.querystring.items() if "StackName" in key]
|
stack_name_or_id = None
|
||||||
stacks = cloudformation_backend.describe_stacks(names)
|
if self._get_param('StackName'):
|
||||||
|
stack_name_or_id = self.querystring.get('StackName')[0]
|
||||||
|
stacks = cloudformation_backend.describe_stacks(stack_name_or_id)
|
||||||
|
|
||||||
template = Template(DESCRIBE_STACKS_TEMPLATE)
|
template = Template(DESCRIBE_STACKS_TEMPLATE)
|
||||||
return template.render(stacks=stacks)
|
return template.render(stacks=stacks)
|
||||||
@ -86,7 +88,7 @@ DESCRIBE_STACKS_TEMPLATE = """<DescribeStacksResult>
|
|||||||
<StackName>{{ stack.name }}</StackName>
|
<StackName>{{ stack.name }}</StackName>
|
||||||
<StackId>{{ stack.stack_id }}</StackId>
|
<StackId>{{ stack.stack_id }}</StackId>
|
||||||
<CreationTime>2010-07-27T22:28:28Z</CreationTime>
|
<CreationTime>2010-07-27T22:28:28Z</CreationTime>
|
||||||
<StackStatus>CREATE_COMPLETE</StackStatus>
|
<StackStatus>{{ stack.status }}</StackStatus>
|
||||||
<DisableRollback>false</DisableRollback>
|
<DisableRollback>false</DisableRollback>
|
||||||
<Outputs>
|
<Outputs>
|
||||||
{% for output in stack.stack_outputs %}
|
{% for output in stack.stack_outputs %}
|
||||||
@ -108,7 +110,7 @@ LIST_STACKS_RESPONSE = """<ListStacksResponse>
|
|||||||
{% for stack in stacks %}
|
{% for stack in stacks %}
|
||||||
<member>
|
<member>
|
||||||
<StackId>{{ stack.id }}</StackId>
|
<StackId>{{ stack.id }}</StackId>
|
||||||
<StackStatus>CREATE_IN_PROGRESS</StackStatus>
|
<StackStatus>{{ stack.status }}</StackStatus>
|
||||||
<StackName>{{ stack.name }}</StackName>
|
<StackName>{{ stack.name }}</StackName>
|
||||||
<CreationTime>2011-05-23T15:47:44Z</CreationTime>
|
<CreationTime>2011-05-23T15:47:44Z</CreationTime>
|
||||||
<TemplateDescription>{{ stack.description }}</TemplateDescription>
|
<TemplateDescription>{{ stack.description }}</TemplateDescription>
|
||||||
@ -129,7 +131,7 @@ LIST_STACKS_RESOURCES_RESPONSE = """<DescribeStackResourcesResult>
|
|||||||
<PhysicalResourceId>{{ resource.physical_resource_id }}</PhysicalResourceId>
|
<PhysicalResourceId>{{ resource.physical_resource_id }}</PhysicalResourceId>
|
||||||
<ResourceType>{{ resource.type }}</ResourceType>
|
<ResourceType>{{ resource.type }}</ResourceType>
|
||||||
<Timestamp>2010-07-27T22:27:28Z</Timestamp>
|
<Timestamp>2010-07-27T22:27:28Z</Timestamp>
|
||||||
<ResourceStatus>CREATE_COMPLETE</ResourceStatus>
|
<ResourceStatus>{{ stack.status }}</ResourceStatus>
|
||||||
</member>
|
</member>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</StackResources>
|
</StackResources>
|
||||||
|
@ -47,6 +47,37 @@ def test_describe_stack_by_name():
|
|||||||
stack.stack_name.should.equal('test_stack')
|
stack.stack_name.should.equal('test_stack')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_cloudformation
|
||||||
|
def test_describe_stack_by_stack_id():
|
||||||
|
conn = boto.connect_cloudformation()
|
||||||
|
conn.create_stack(
|
||||||
|
"test_stack",
|
||||||
|
template_body=dummy_template_json,
|
||||||
|
)
|
||||||
|
|
||||||
|
stack = conn.describe_stacks("test_stack")[0]
|
||||||
|
stack_by_id = conn.describe_stacks(stack.stack_id)[0]
|
||||||
|
stack_by_id.stack_id.should.equal(stack.stack_id)
|
||||||
|
stack_by_id.stack_name.should.equal("test_stack")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_cloudformation
|
||||||
|
def test_describe_deleted_stack():
|
||||||
|
conn = boto.connect_cloudformation()
|
||||||
|
conn.create_stack(
|
||||||
|
"test_stack",
|
||||||
|
template_body=dummy_template_json,
|
||||||
|
)
|
||||||
|
|
||||||
|
stack = conn.describe_stacks("test_stack")[0]
|
||||||
|
stack_id = stack.stack_id
|
||||||
|
conn.delete_stack(stack.stack_id)
|
||||||
|
stack_by_id = conn.describe_stacks(stack_id)[0]
|
||||||
|
stack_by_id.stack_id.should.equal(stack.stack_id)
|
||||||
|
stack_by_id.stack_name.should.equal("test_stack")
|
||||||
|
stack_by_id.stack_status.should.equal("DELETE_COMPLETE")
|
||||||
|
|
||||||
|
|
||||||
@mock_cloudformation
|
@mock_cloudformation
|
||||||
def test_get_template_by_name():
|
def test_get_template_by_name():
|
||||||
conn = boto.connect_cloudformation()
|
conn = boto.connect_cloudformation()
|
||||||
|
Loading…
Reference in New Issue
Block a user