def get_attribute(self, key, *path): if key.startswith("resource."): return grouputils.get_nested_attrs(self, key, False, *path) names = self._resource_names() 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.REMOVED_RSRC_LIST: return self._current_blacklist() if key == self.ATTR_ATTRIBUTES: if not path: raise exception.InvalidTemplateAttribute(resource=self.name, key=key) return dict( (n, grouputils.get_rsrc_attr(self, key, False, n, *path)) for n in names) path = [key] + list(path) return [ grouputils.get_rsrc_attr(self, key, False, n, *path) for n in names ]
def get_attribute(self, key, *path): if key == self.REMOVED_RSRC_LIST: return self._current_blacklist() if key == self.ATTR_ATTRIBUTES and not path: raise exception.InvalidTemplateAttribute(resource=self.name, key=key) is_resource_ref = (key.startswith("resource.") and not path and (len(key.split('.', 2)) == 2)) if is_resource_ref: output_name = self.REFS_MAP else: output_name = self._attribute_output_name(key, *path) if self.resource_id is not None: try: output = self.get_output(output_name) except (exception.NotFound, exception.TemplateOutputError) as op_err: LOG.debug('Falling back to grouputils due to %s', op_err) else: if is_resource_ref: try: target = key.split('.', 2)[1] return output[target] except KeyError: raise exception.NotFound( _("Member '%(mem)s' not " "found in group resource " "'%(grp)s'.") % { 'mem': target, 'grp': self.name }) if key == self.REFS: return attributes.select_from_attribute(output, path) return output if key.startswith("resource."): return grouputils.get_nested_attrs(self, key, False, *path) names = self._resource_names() 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: return dict( (n, grouputils.get_rsrc_attr(self, key, False, n, *path)) for n in names) path = [key] + list(path) return [ grouputils.get_rsrc_attr(self, key, False, n, *path) for n in names ]
def get_attribute(self, key, *path): if self.resource_id is None: return None # first look for explicit resource.x.y if key.startswith('resource.'): return grouputils.get_nested_attrs(self, key, False, *path) # then look for normal outputs return attributes.select_from_attribute(self.get_output(key), path)
def get_attribute(self, key, *path): if key == self.REMOVED_RSRC_LIST: return self._current_blacklist() if key == self.ATTR_ATTRIBUTES and not path: raise exception.InvalidTemplateAttribute(resource=self.name, key=key) is_resource_ref = (key.startswith("resource.") and not path and (len(key.split('.', 2)) == 2)) if is_resource_ref: output_name = self.REFS_MAP else: output_name = self._attribute_output_name(key, *path) if self.resource_id is not None: try: output = self.get_output(output_name) except (exception.NotFound, exception.TemplateOutputError) as op_err: LOG.debug('Falling back to grouputils due to %s', op_err) else: if is_resource_ref: try: target = key.split('.', 2)[1] return output[target] except KeyError: raise exception.NotFound(_("Member '%(mem)s' not " "found in group resource " "'%(grp)s'.") % {'mem': target, 'grp': self.name}) if key == self.REFS: return attributes.select_from_attribute(output, path) return output if key.startswith("resource."): return grouputils.get_nested_attrs(self, key, False, *path) names = self._resource_names() 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: return dict((n, grouputils.get_rsrc_attr( self, key, False, n, *path)) for n in names) path = [key] + list(path) return [grouputils.get_rsrc_attr(self, key, False, n, *path) for n in names]
def get_attribute(self, key, *path): if self.resource_id is None: return None # first look for explicit resource.x.y if key.startswith('resource.'): return grouputils.get_nested_attrs(self, key, False, *path) # then look for normal outputs try: return attributes.select_from_attribute(self.get_output(key), path) except exception.NotFound: raise exception.InvalidTemplateAttribute(resource=self.name, key=key)
def get_attribute(self, key, *path): stack = self.nested() if stack is None: return None # first look for explicit resource.x.y if key.startswith('resource.'): return grouputils.get_nested_attrs(self, key, False, *path) # then look for normal outputs if key in stack.outputs: return attributes.select_from_attribute(self.get_output(key), path) # otherwise the key must be wrong. raise exception.InvalidTemplateAttribute(resource=self.name, key=key)
def get_attribute(self, key, *path): if key == self.CURRENT_SIZE: return grouputils.get_size(self) if path: members = grouputils.get_members(self) attrs = ((rsrc.name, rsrc.FnGetAtt(*path)) for rsrc in members) if key == self.OUTPUTS: return dict(attrs) if key == self.OUTPUTS_LIST: return [value for name, value in attrs] if key.startswith("resource."): return grouputils.get_nested_attrs(self, key, True, *path) raise exception.InvalidTemplateAttribute(resource=self.name, key=key)
def FnGetAtt(self, key, *path): if key.startswith("resource."): return grouputils.get_nested_attrs(self, key, False, *path) names = self._resource_names() 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.ATTR_ATTRIBUTES: if not path: raise exception.InvalidTemplateAttribute(resource=self.name, key=key) return dict((n, grouputils.get_rsrc_attr(self, key, False, n, *path)) for n in names) path = [key] + list(path) return [grouputils.get_rsrc_attr(self, key, False, n, *path) for n in names]
def FnGetAtt(self, key, *path): if key.startswith("resource."): return grouputils.get_nested_attrs(self, key, False, *path) names = self._resource_names() if key == self.REFS: return [grouputils.get_rsrc_id(self, key, False, n) for n in names] if key == self.ATTR_ATTRIBUTES: if not path: raise exception.InvalidTemplateAttribute( resource=self.name, key=key) return dict((n, grouputils.get_rsrc_attr( self, key, False, n, *path)) for n in names) path = [key] + list(path) return [grouputils.get_rsrc_attr(self, key, False, n, *path) for n in names]
def get_attribute(self, key, *path): if key.startswith('resource.'): return grouputils.get_nested_attrs(self, key, False, *path) resource_types = self.properties[self.RESOURCES] names = self._resource_names(resource_types) 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.ATTR_ATTRIBUTES: if not path: raise exception.InvalidTemplateAttribute( resource=self.name, key=key) return dict((n, grouputils.get_rsrc_attr( self, key, False, n, *path)) for n in names) path = [key] + list(path) return [grouputils.get_rsrc_attr(self, key, False, n, *path) for n in names]
def get_attribute(self, key, *path): if key == self.ATTR_ATTRIBUTES and not path: raise exception.InvalidTemplateAttribute(resource=self.name, key=key) try: output = self.get_output(self._attribute_output_name(key, *path)) except (exception.NotFound, exception.TemplateOutputError) as op_err: resource_types = self.properties[self.RESOURCES] names = self._resource_names(resource_types) if key.startswith('resource.'): target = key.split('.', 2)[1] if target not in names: raise exception.NotFound( _("Member '%(mem)s' not " "found in group resource " "'%(grp)s'.") % { 'mem': target, 'grp': self.name }) LOG.debug('Falling back to grouputils due to %s', op_err) else: if key == self.REFS: return attributes.select_from_attribute(output, path) return output if key.startswith('resource.'): return grouputils.get_nested_attrs(self, key, False, *path) 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.ATTR_ATTRIBUTES: return dict( (n, grouputils.get_rsrc_attr(self, key, False, n, *path)) for n in names) path = [key] + list(path) return [ grouputils.get_rsrc_attr(self, key, False, n, *path) for n in names ]
def get_attribute(self, key, *path): if key == self.ATTR_ATTRIBUTES and not path: raise exception.InvalidTemplateAttribute(resource=self.name, key=key) try: output = self.get_output(self._attribute_output_name(key, *path)) except (exception.NotFound, exception.TemplateOutputError) as op_err: resource_types = self.properties[self.RESOURCES] names = self._resource_names(resource_types) if key.startswith('resource.'): target = key.split('.', 2)[1] if target not in names: raise exception.NotFound(_("Member '%(mem)s' not " "found in group resource " "'%(grp)s'.") % {'mem': target, 'grp': self.name}) LOG.debug('Falling back to grouputils due to %s', op_err) else: if key == self.REFS: return attributes.select_from_attribute(output, path) return output if key.startswith('resource.'): return grouputils.get_nested_attrs(self, key, False, *path) 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.ATTR_ATTRIBUTES: return dict((n, grouputils.get_rsrc_attr( self, key, False, n, *path)) for n in names) path = [key] + list(path) return [grouputils.get_rsrc_attr(self, key, False, n, *path) for n in names]
def get_attribute(self, key, *path): if key.startswith("resource."): return grouputils.get_nested_attrs(self, key, False, *path) names = self._resource_names() 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.REMOVED_RSRC_LIST: return self._current_blacklist() if key == self.ATTR_ATTRIBUTES: if not path: raise exception.InvalidTemplateAttribute( resource=self.name, key=key) return dict((n, grouputils.get_rsrc_attr( self, key, False, n, *path)) for n in names) path = [key] + list(path) return [grouputils.get_rsrc_attr(self, key, False, n, *path) for n in names]
def get_attribute(self, key, *path): # noqa: C901 if key == self.CURRENT_SIZE: return grouputils.get_size(self) op_key = key op_path = path keycomponents = None if key == self.OUTPUTS_LIST: op_key = self.OUTPUTS elif key == self.REFS: op_key = self.REFS_MAP elif key.startswith("resource."): keycomponents = key.split('.', 2) if len(keycomponents) > 2: op_path = (keycomponents[2], ) + path op_key = self.OUTPUTS if op_path else self.REFS_MAP try: output = self.get_output( self._attribute_output_name(op_key, *op_path)) except (exception.NotFound, exception.TemplateOutputError) as op_err: LOG.debug('Falling back to grouputils due to %s', op_err) if key == self.REFS: return grouputils.get_member_refids(self) if key == self.REFS_MAP: members = grouputils.get_members(self) return {m.name: m.resource_id for m in members} if path and key in {self.OUTPUTS, self.OUTPUTS_LIST}: members = grouputils.get_members(self) attrs = ((rsrc.name, rsrc.FnGetAtt(*path)) for rsrc in members) if key == self.OUTPUTS: return dict(attrs) if key == self.OUTPUTS_LIST: return [value for name, value in attrs] if keycomponents is not None: return grouputils.get_nested_attrs(self, key, True, *path) else: if key in {self.REFS, self.REFS_MAP}: names = self._group_data().member_names(False) if key == self.REFS: return [output[n] for n in names if n in output] else: return {n: output[n] for n in names if n in output} if path and key in {self.OUTPUTS_LIST, self.OUTPUTS}: names = self._group_data().member_names(False) if key == self.OUTPUTS_LIST: return [output[n] for n in names if n in output] else: return {n: output[n] for n in names if n in output} if keycomponents is not None: names = list(self._group_data().member_names(False)) index = keycomponents[1] try: resource_name = names[int(index)] return output[resource_name] except (IndexError, KeyError): raise exception.NotFound( _("Member '%(mem)s' not found " "in group resource '%(grp)s'.") % { 'mem': index, 'grp': self.name }) raise exception.InvalidTemplateAttribute(resource=self.name, key=key)
def get_attribute(self, key, *path): if key == self.CURRENT_SIZE: return grouputils.get_size(self) op_key = key op_path = path keycomponents = None if key == self.OUTPUTS_LIST: op_key = self.OUTPUTS elif key == self.REFS: op_key = self.REFS_MAP elif key.startswith("resource."): keycomponents = key.split('.', 2) if len(keycomponents) > 2: op_path = (keycomponents[2],) + path op_key = self.OUTPUTS if op_path else self.REFS_MAP try: output = self.get_output(self._attribute_output_name(op_key, *op_path)) except (exception.NotFound, exception.TemplateOutputError) as op_err: LOG.debug('Falling back to grouputils due to %s', op_err) if key == self.REFS: return grouputils.get_member_refids(self) if key == self.REFS_MAP: members = grouputils.get_members(self) return {m.name: m.resource_id for m in members} if path and key in {self.OUTPUTS, self.OUTPUTS_LIST}: members = grouputils.get_members(self) attrs = ((rsrc.name, rsrc.FnGetAtt(*path)) for rsrc in members) if key == self.OUTPUTS: return dict(attrs) if key == self.OUTPUTS_LIST: return [value for name, value in attrs] if keycomponents is not None: return grouputils.get_nested_attrs(self, key, True, *path) else: if key in {self.REFS, self.REFS_MAP}: names = self._group_data().member_names(False) if key == self.REFS: return [output[n] for n in names if n in output] else: return {n: output[n] for n in names if n in output} if path and key in {self.OUTPUTS_LIST, self.OUTPUTS}: names = self._group_data().member_names(False) if key == self.OUTPUTS_LIST: return [output[n] for n in names if n in output] else: return {n: output[n] for n in names if n in output} if keycomponents is not None: names = list(self._group_data().member_names(False)) index = keycomponents[1] try: resource_name = names[int(index)] return output[resource_name] except (IndexError, KeyError): raise exception.NotFound(_("Member '%(mem)s' not found " "in group resource '%(grp)s'.") % {'mem': index, 'grp': self.name}) raise exception.InvalidTemplateAttribute(resource=self.name, key=key)