Merge "Refactor ResourceGroup's FnGetAtt()"

This commit is contained in:
Jenkins 2014-07-24 13:56:10 +00:00 committed by Gerrit Code Review
commit 9b146809d6

View File

@ -126,28 +126,26 @@ class ResourceGroup(stack_resource.StackResource):
return self.delete_nested() return self.delete_nested()
def FnGetAtt(self, key): def FnGetAtt(self, key):
if key.startswith("resource."): nested_stack = self.nested()
parts = key.split(".", 2)
attr_name = parts[-1] if len(parts) > 2 else None def get_rsrc_attr(resource_name, attr_name=None):
try: try:
res = self.nested()[parts[1]] resource = nested_stack[resource_name]
except KeyError: except KeyError:
raise exception.InvalidTemplateAttribute(resource=self.name, raise exception.InvalidTemplateAttribute(resource=self.name,
key=key) key=key)
if attr_name is None:
return resource.FnGetRefId()
else: else:
return (res.FnGetRefId() if attr_name is None return resource.FnGetAtt(attr_name)
else res.FnGetAtt(attr_name))
if key.startswith("resource."):
parts = key.split(".", 2)
return get_rsrc_attr(*parts[1:])
else: else:
count = self.properties[self.COUNT]
def get_aggregated_attr(func, *args): attr = None if key == self.REFS else key
for n in range(self.properties[self.COUNT]): return [get_rsrc_attr(str(n), attr) for n in range(count)]
resource_method = getattr(self.nested()[str(n)], func)
yield resource_method(*args)
method_name, method_call = (("FnGetRefId", []) if self.REFS == key
else ("FnGetAtt", [key]))
return [val for val in get_aggregated_attr(method_name,
*method_call)]
def _assemble_nested(self, count, include_all=False): def _assemble_nested(self, count, include_all=False):
child_template = copy.deepcopy(template_template) child_template = copy.deepcopy(template_template)