Add cloudformation list_stack_resources.
This commit is contained in:
parent
8b41af84a8
commit
7f73d7e26d
@ -91,6 +91,10 @@ class CloudFormationBackend(BaseBackend):
|
|||||||
# stack.template = template
|
# stack.template = template
|
||||||
# return stack
|
# return stack
|
||||||
|
|
||||||
|
def list_stack_resources(self, stack_name_or_id):
|
||||||
|
stack = self.get_stack(stack_name_or_id)
|
||||||
|
return stack.stack_resources
|
||||||
|
|
||||||
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
|
||||||
|
@ -67,7 +67,7 @@ class CloudFormationResponse(BaseResponse):
|
|||||||
stack_name = self._get_param('StackName')
|
stack_name = self._get_param('StackName')
|
||||||
stack = self.cloudformation_backend.get_stack(stack_name)
|
stack = self.cloudformation_backend.get_stack(stack_name)
|
||||||
|
|
||||||
template = self.response_template(LIST_STACKS_RESOURCES_RESPONSE)
|
template = self.response_template(DESCRIBE_STACKS_RESOURCES_RESPONSE)
|
||||||
return template.render(stack=stack)
|
return template.render(stack=stack)
|
||||||
|
|
||||||
def list_stacks(self):
|
def list_stacks(self):
|
||||||
@ -75,6 +75,13 @@ class CloudFormationResponse(BaseResponse):
|
|||||||
template = self.response_template(LIST_STACKS_RESPONSE)
|
template = self.response_template(LIST_STACKS_RESPONSE)
|
||||||
return template.render(stacks=stacks)
|
return template.render(stacks=stacks)
|
||||||
|
|
||||||
|
def list_stack_resources(self):
|
||||||
|
stack_name_or_id = self._get_param('StackName')
|
||||||
|
resources = self.cloudformation_backend.list_stack_resources(stack_name_or_id)
|
||||||
|
|
||||||
|
template = self.response_template(LIST_STACKS_RESOURCES_RESPONSE)
|
||||||
|
return template.render(resources=resources)
|
||||||
|
|
||||||
def get_template(self):
|
def get_template(self):
|
||||||
name_or_stack_id = self.querystring.get('StackName')[0]
|
name_or_stack_id = self.querystring.get('StackName')[0]
|
||||||
|
|
||||||
@ -166,7 +173,7 @@ LIST_STACKS_RESPONSE = """<ListStacksResponse>
|
|||||||
</ListStacksResponse>"""
|
</ListStacksResponse>"""
|
||||||
|
|
||||||
|
|
||||||
LIST_STACKS_RESOURCES_RESPONSE = """<DescribeStackResourcesResult>
|
DESCRIBE_STACKS_RESOURCES_RESPONSE = """<DescribeStackResourcesResult>
|
||||||
<StackResources>
|
<StackResources>
|
||||||
{% for resource in stack.stack_resources %}
|
{% for resource in stack.stack_resources %}
|
||||||
<member>
|
<member>
|
||||||
@ -181,3 +188,23 @@ LIST_STACKS_RESOURCES_RESPONSE = """<DescribeStackResourcesResult>
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</StackResources>
|
</StackResources>
|
||||||
</DescribeStackResourcesResult>"""
|
</DescribeStackResourcesResult>"""
|
||||||
|
|
||||||
|
|
||||||
|
LIST_STACKS_RESOURCES_RESPONSE = """<ListStackResourcesResponse>
|
||||||
|
<ListStackResourcesResult>
|
||||||
|
<StackResourceSummaries>
|
||||||
|
{% for resource in resources %}
|
||||||
|
<member>
|
||||||
|
<ResourceStatus>CREATE_COMPLETE</ResourceStatus>
|
||||||
|
<LogicalResourceId>{{ resource.logical_resource_id }}</LogicalResourceId>
|
||||||
|
<LastUpdatedTimestamp>2011-06-21T20:15:58Z</LastUpdatedTimestamp>
|
||||||
|
<PhysicalResourceId>{{ resource.physical_resource_id }}</PhysicalResourceId>
|
||||||
|
<ResourceType>{{ resource.type }}</ResourceType>
|
||||||
|
</member>
|
||||||
|
{% endfor %}
|
||||||
|
</StackResourceSummaries>
|
||||||
|
</ListStackResourcesResult>
|
||||||
|
<ResponseMetadata>
|
||||||
|
<RequestId>2d06e36c-ac1d-11e0-a958-f9382b6eb86b</RequestId>
|
||||||
|
</ResponseMetadata>
|
||||||
|
</ListStackResourcesResponse>"""
|
||||||
|
@ -68,6 +68,37 @@ def test_stack_sqs_integration():
|
|||||||
queue.physical_resource_id.should.equal("my-queue")
|
queue.physical_resource_id.should.equal("my-queue")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_cloudformation()
|
||||||
|
def test_stack_list_resources():
|
||||||
|
sqs_template = {
|
||||||
|
"AWSTemplateFormatVersion": "2010-09-09",
|
||||||
|
"Resources": {
|
||||||
|
"QueueGroup": {
|
||||||
|
|
||||||
|
"Type": "AWS::SQS::Queue",
|
||||||
|
"Properties": {
|
||||||
|
"QueueName": "my-queue",
|
||||||
|
"VisibilityTimeout": 60,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
sqs_template_json = json.dumps(sqs_template)
|
||||||
|
|
||||||
|
conn = boto.cloudformation.connect_to_region("us-west-1")
|
||||||
|
conn.create_stack(
|
||||||
|
"test_stack",
|
||||||
|
template_body=sqs_template_json,
|
||||||
|
)
|
||||||
|
|
||||||
|
resources = conn.list_stack_resources("test_stack")
|
||||||
|
assert len(resources) == 1
|
||||||
|
queue = resources[0]
|
||||||
|
queue.resource_type.should.equal('AWS::SQS::Queue')
|
||||||
|
queue.logical_resource_id.should.equal("QueueGroup")
|
||||||
|
queue.physical_resource_id.should.equal("my-queue")
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2()
|
@mock_ec2()
|
||||||
@mock_cloudformation()
|
@mock_cloudformation()
|
||||||
def test_stack_ec2_integration():
|
def test_stack_ec2_integration():
|
||||||
@ -1198,14 +1229,14 @@ def test_subnets_should_be_created_with_availability_zone():
|
|||||||
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
||||||
|
|
||||||
subnet_template = {
|
subnet_template = {
|
||||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
"AWSTemplateFormatVersion": "2010-09-09",
|
||||||
"Resources" : {
|
"Resources": {
|
||||||
"testSubnet" : {
|
"testSubnet": {
|
||||||
"Type" : "AWS::EC2::Subnet",
|
"Type": "AWS::EC2::Subnet",
|
||||||
"Properties" : {
|
"Properties": {
|
||||||
"VpcId" : vpc.id,
|
"VpcId": vpc.id,
|
||||||
"CidrBlock" : "10.0.0.0/24",
|
"CidrBlock": "10.0.0.0/24",
|
||||||
"AvailabilityZone" : "us-west-1b",
|
"AvailabilityZone": "us-west-1b",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user