Added refs_map attribute to resource groups

This attribute produces a map of resource name to ID, suitable for
passing into a SoftwareDeploymentGroup servers input.

Change-Id: I9c9a2cd8f3f4c1fd50837c74bd49fc4dd4d06bcf
Partial-Bug: #1582837
This commit is contained in:
Jay Dobies 2016-05-18 15:45:25 -04:00
parent 69251cdcbd
commit 05ea885e73
2 changed files with 18 additions and 2 deletions

View File

@ -109,9 +109,9 @@ class ResourceGroup(stack_resource.StackResource):
)
ATTRIBUTES = (
REFS, ATTR_ATTRIBUTES,
REFS, REFS_MAP, ATTR_ATTRIBUTES,
) = (
'refs', 'attributes',
'refs', 'refs_map', 'attributes',
)
properties_schema = {
@ -200,6 +200,12 @@ class ResourceGroup(stack_resource.StackResource):
_("A list of resource IDs for the resources in the group."),
type=attributes.Schema.LIST
),
REFS_MAP: attributes.Schema(
_("A map of resource names to IDs for the resources in "
"the group."),
type=attributes.Schema.MAP,
support_status=support.SupportStatus(version='7.0.0'),
),
ATTR_ATTRIBUTES: attributes.Schema(
_("A map of resource names to the specified attribute of each "
"individual resource. "
@ -418,6 +424,10 @@ class ResourceGroup(stack_resource.StackResource):
if key == self.REFS:
vals = [grouputils.get_rsrc_id(self, key, False, n) for n in names]
return attributes.select_from_attribute(vals, path)
if key == self.REFS_MAP:
refs_map = {n: grouputils.get_rsrc_id(self, key, False, n)
for n in names}
return refs_map
if key == self.ATTR_ATTRIBUTES:
if not path:
raise exception.InvalidTemplateAttribute(

View File

@ -786,6 +786,12 @@ class ResourceGroupAttrTest(common.HeatTestCase):
self.assertEqual(expected[1], resg.FnGetAtt("refs", 1))
self.assertIsNone(resg.FnGetAtt("refs", 2))
def test_aggregate_refs_map(self):
resg = self._create_dummy_stack()
found = resg.FnGetAtt("refs_map")
expected = {'0': 'ID-0', '1': 'ID-1'}
self.assertEqual(expected, found)
def test_aggregate_outputs(self):
"""Test outputs aggregation."""
expected = {'0': ['foo', 'bar'], '1': ['foo', 'bar']}