Add cloudformation tags.
This commit is contained in:
parent
2a9085dfc6
commit
1dcfcbca57
@ -10,7 +10,7 @@ from .exceptions import ValidationError
|
||||
|
||||
|
||||
class FakeStack(object):
|
||||
def __init__(self, stack_id, name, template, parameters, region_name, notification_arns=None):
|
||||
def __init__(self, stack_id, name, template, parameters, region_name, notification_arns=None, tags=None):
|
||||
self.stack_id = stack_id
|
||||
self.name = name
|
||||
self.template = template
|
||||
@ -18,6 +18,7 @@ class FakeStack(object):
|
||||
self.parameters = parameters
|
||||
self.region_name = region_name
|
||||
self.notification_arns = notification_arns if notification_arns else []
|
||||
self.tags = tags if tags else {}
|
||||
self.status = 'CREATE_COMPLETE'
|
||||
|
||||
self.description = self.template_dict.get('Description')
|
||||
@ -58,7 +59,7 @@ class CloudFormationBackend(BaseBackend):
|
||||
self.stacks = {}
|
||||
self.deleted_stacks = {}
|
||||
|
||||
def create_stack(self, name, template, parameters, region_name, notification_arns=None):
|
||||
def create_stack(self, name, template, parameters, region_name, notification_arns=None, tags=None):
|
||||
stack_id = generate_stack_id(name)
|
||||
new_stack = FakeStack(
|
||||
stack_id=stack_id,
|
||||
@ -67,6 +68,7 @@ class CloudFormationBackend(BaseBackend):
|
||||
parameters=parameters,
|
||||
region_name=region_name,
|
||||
notification_arns=notification_arns,
|
||||
tags=tags,
|
||||
)
|
||||
self.stacks[stack_id] = new_stack
|
||||
return new_stack
|
||||
|
@ -27,6 +27,7 @@ class CloudFormationResponse(BaseResponse):
|
||||
stack_body = self._get_param('TemplateBody')
|
||||
template_url = self._get_param('TemplateURL')
|
||||
parameters_list = self._get_list_prefix("Parameters.member")
|
||||
tags = dict((item['key'], item['value']) for item in self._get_list_prefix("Tags.member"))
|
||||
|
||||
# Hack dict-comprehension
|
||||
parameters = dict([
|
||||
@ -43,7 +44,8 @@ class CloudFormationResponse(BaseResponse):
|
||||
template=stack_body,
|
||||
parameters=parameters,
|
||||
region_name=self.region,
|
||||
notification_arns=stack_notification_arns
|
||||
notification_arns=stack_notification_arns,
|
||||
tags=tags,
|
||||
)
|
||||
stack_body = {
|
||||
'CreateStackResponse': {
|
||||
@ -150,6 +152,14 @@ DESCRIBE_STACKS_TEMPLATE = """<DescribeStacksResult>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</Parameters>
|
||||
<Tags>
|
||||
{% for tag_key, tag_value in stack.tags.items() %}
|
||||
<member>
|
||||
<Key>{{ tag_key }}</Key>
|
||||
<Value>{{ tag_value }}</Value>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</Tags>
|
||||
</member>
|
||||
{% endfor %}
|
||||
</Stacks>
|
||||
|
@ -219,6 +219,19 @@ def test_cloudformation_params():
|
||||
param.value.should.equal('testing123')
|
||||
|
||||
|
||||
@mock_cloudformation
|
||||
def test_stack_tags():
|
||||
conn = boto.connect_cloudformation()
|
||||
conn.create_stack(
|
||||
"test_stack",
|
||||
template_body=dummy_template_json,
|
||||
tags={"foo": "bar", "baz": "bleh"},
|
||||
)
|
||||
|
||||
stack = conn.describe_stacks()[0]
|
||||
dict(stack.tags).should.equal({"foo": "bar", "baz": "bleh"})
|
||||
|
||||
|
||||
# @mock_cloudformation
|
||||
# def test_update_stack():
|
||||
# conn = boto.connect_cloudformation()
|
||||
|
Loading…
Reference in New Issue
Block a user