Esempio n. 1
0
    def get_output(self, op):
        """Return the specified Output value from the nested stack.

        If the output key does not exist, raise an InvalidTemplateAttribute
        exception.
        """
        stack = self.nested()
        if stack is None:
            return None
        if op not in stack.outputs:
            raise exception.InvalidTemplateAttribute(resource=self.name,
                                                     key=op)
        result = stack.output(op)
        if result is None and stack.outputs[op].get('error_msg') is not None:
            raise exception.InvalidTemplateAttribute(resource=self.name,
                                                     key=op)
        return result
Esempio n. 2
0
def get_resource(stack, resource_name, use_indices, key):
    nested_stack = stack.nested()
    if not nested_stack:
        return None
    try:
        if use_indices:
            return get_members(stack)[int(resource_name)]
        else:
            return nested_stack[resource_name]
    except (IndexError, KeyError):
        raise exception.InvalidTemplateAttribute(resource=stack.name,
                                                 key=key)
Esempio n. 3
0
    def handle_create(self):
        profile = self.properties[self.LOGIN_PROFILE]
        if profile and self.LOGIN_PROFILE_PASSWORD in profile:
            self.password = profile[self.LOGIN_PROFILE_PASSWORD]

        if self.properties[self.POLICIES]:
            if not self._validate_policies(self.properties[self.POLICIES]):
                raise exception.InvalidTemplateAttribute(resource=self.name,
                                                         key=self.POLICIES)

        super(User, self).handle_create()
        self.resource_id_set(self._get_user_id())
Esempio n. 4
0
    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)
Esempio n. 5
0
    def validate(self):
        super(GetAtt, self).validate()
        res = self._resource()

        if self._allow_without_attribute_name():
            # if allow without attribute_name, then don't check
            # when attribute_name is None
            if self._attribute is None:
                return

        attr = function.resolve(self._attribute)
        from conveyor.conveyorheat.engine import resource
        if (type(res).get_attribute == resource.Resource.get_attribute
                and attr not in six.iterkeys(res.attributes_schema)):
            raise exception.InvalidTemplateAttribute(
                resource=self._resource_name, key=attr)
Esempio n. 6
0
    def get_attribute(self, key, *path):
        """Resource attributes map to deployment outputs values."""
        sd = self.rpc_client().show_software_deployment(
            self.context, self.resource_id)
        ov = sd[rpc_api.SOFTWARE_DEPLOYMENT_OUTPUT_VALUES] or {}
        if key in ov:
            attribute = ov.get(key)
            return attributes.select_from_attribute(attribute, path)

        # Since there is no value for this key yet, check the output schemas
        # to find out if the key is valid
        sc = self.rpc_client().show_software_config(
            self.context, self.properties[self.CONFIG])
        outputs = sc[rpc_api.SOFTWARE_CONFIG_OUTPUTS] or []
        output_keys = [output['name'] for output in outputs]
        if key not in output_keys and key not in self.ATTRIBUTES:
            raise exception.InvalidTemplateAttribute(resource=self.name,
                                                     key=key)
        return None
Esempio n. 7
0
    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.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
        ]
Esempio n. 8
0
 def get_attribute(self, key, *path):
     if key and not key.startswith('Outputs.'):
         raise exception.InvalidTemplateAttribute(resource=self.name,
                                                  key=key)
     attribute = self.get_output(key.partition('.')[-1])
     return attributes.select_from_attribute(attribute, path)