Include an OS::stack_id output when generating a template

When generating a template to act as a facade for an existing resource
type, include an OS::stack_id output so that doing get_resource on the
facade resource will return the physical ID of the inner resource.

Change-Id: I257e9cc2eefd2cb8153e94cd05b21fed4b03c6c7
This commit is contained in:
Zane Bitter 2017-01-10 14:31:57 -05:00
parent 5553a6f29c
commit e1124b2605
3 changed files with 26 additions and 1 deletions

View File

@ -122,6 +122,17 @@ class Attribute(object):
}
def _stack_id_output(resource_name, template_type='cfn'):
if template_type == 'hot':
return {
"value": {"get_resource": resource_name},
}
else:
return {
"Value": {"Ref": resource_name},
}
@repr_wrapper
class Attributes(collections.Mapping):
"""Models a collection of Resource Attributes."""
@ -156,8 +167,10 @@ class Attributes(collections.Mapping):
attr_schema.update(resource_class.base_attributes_schema)
attribs = Attributes._make_attributes(attr_schema).items()
return dict((n, att.as_output(resource_name,
outp = dict((n, att.as_output(resource_name,
template_type)) for n, att in attribs)
outp['OS::stack_id'] = _stack_id_output(resource_name, template_type)
return outp
@staticmethod
def schema_from_outputs(json_snippet):

View File

@ -172,6 +172,9 @@ class AttributesTest(common.HeatTestCase):
"test3": {
"Value": {"Fn::GetAtt": ["test_resource", "test3"]},
"Description": "Test attrib 3"
},
"OS::stack_id": {
"Value": {"Ref": "test_resource"},
}
}
MyTestResourceClass = mock.MagicMock()
@ -202,6 +205,9 @@ class AttributesTest(common.HeatTestCase):
"test3": {
"value": {"get_attr": ["test_resource", "test3"]},
"description": "Test attrib 3"
},
"OS::stack_id": {
"value": {"get_resource": "test_resource"},
}
}
MyTestResourceClass = mock.MagicMock()

View File

@ -1442,6 +1442,9 @@ class ResourceTest(common.HeatTestCase):
'show': {
'Description': u'Detailed information about resource.',
'Value': {"Fn::GetAtt": ["TestResource", "show"]}
},
'OS::stack_id': {
'Value': {"Ref": "TestResource"}
}
}
}
@ -1526,6 +1529,9 @@ class ResourceTest(common.HeatTestCase):
'show': {
'description': u'Detailed information about resource.',
'value': {"get_attr": ["TestResource", "show"]}
},
'OS::stack_id': {
'value': {"get_resource": "TestResource"}
}
}
}