예제 #1
0
    def required_resource_names(self):
        """Return a set of names of all resources on which this depends.

        Note that this is done entirely in isolation from the rest of the
        template, so the resource names returned may refer to resources that
        don't actually exist, or would have strict_dependency=False. Use the
        dependencies() method to get validated dependencies.
        """
        if self._dep_names is None:
            explicit_depends = [] if self._depends is None else self._depends

            def path(section):
                return '.'.join([self.name, section])

            prop_deps = function.dependencies(self._properties,
                                              path(PROPERTIES))
            metadata_deps = function.dependencies(self._metadata,
                                                  path(METADATA))
            implicit_depends = six.moves.map(lambda rp: rp.name,
                                             itertools.chain(prop_deps,
                                                             metadata_deps))

            # (ricolin) External resource should not depend on any other
            # resources. This operation is not allowed for now.
            if self.external_id():
                if explicit_depends:
                    raise exception.InvalidExternalResourceDependency(
                        external_id=self.external_id(),
                        resource_type=self.resource_type
                    )
                self._dep_names = set()
            else:
                self._dep_names = set(itertools.chain(explicit_depends,
                                                      implicit_depends))
        return self._dep_names
예제 #2
0
파일: properties.py 프로젝트: blitzbs/heat
    def _get_property_value(self, key, validate=False):
        if key not in self:
            raise KeyError(_('%(prefix)sInvalid Property %(key)s') %
                           {'prefix': self.error_prefix, 'key': key})

        prop = self.props[key]

        if key in self.data:
            try:
                unresolved_value = self.data[key]
                if validate:
                    deps = function.dependencies(unresolved_value)
                    if any(res.action == res.INIT for res in deps):
                        validate = False

                value = self.resolve(unresolved_value)
                return prop.get_value(value, validate)
            # the resolver function could raise any number of exceptions,
            # so handle this generically
            except Exception as e:
                raise ValueError('%s%s %s' % (self.error_prefix, key,
                                              six.text_type(e)))
        elif prop.has_default():
            return prop.get_value(None, validate)
        elif prop.required():
            raise ValueError(_('%(prefix)sProperty %(key)s not assigned') %
                             {'prefix': self.error_prefix, 'key': key})
예제 #3
0
파일: properties.py 프로젝트: dfsis/heat
    def _get_property_value(self, key, validate=False):
        if key not in self:
            raise KeyError(_('Invalid Property %s') % key)

        prop = self.props[key]

        if key in self.data:
            try:
                unresolved_value = self.data[key]
                if validate:
                    deps = function.dependencies(unresolved_value)
                    if any(res.action == res.INIT for res in deps):
                        validate = False

                value = self.resolve(unresolved_value)
                return prop.get_value(value, validate)
            # Children can raise StackValidationFailed with unique path which
            # is necessary for further use in StackValidationFailed exception.
            # So we need to handle this exception in this method.
            except exception.StackValidationFailed as e:
                raise exception.StackValidationFailed(path=e.path,
                                                      message=e.error_message)
            # the resolver function could raise any number of exceptions,
            # so handle this generically
            except Exception as e:
                raise ValueError(six.text_type(e))
        elif prop.has_default():
            return prop.get_value(None, validate)
        elif prop.required():
            raise ValueError(_('Property %s not assigned') % key)
예제 #4
0
    def _get_property_value(self, key, validate=False):
        if key not in self:
            raise KeyError(
                _('%(prefix)sInvalid Property %(key)s') % {
                    'prefix': self.error_prefix,
                    'key': key
                })

        prop = self.props[key]

        if key in self.data:
            try:
                unresolved_value = self.data[key]
                if validate:
                    deps = function.dependencies(unresolved_value)
                    if any(res.action == res.INIT for res in deps):
                        validate = False

                value = self.resolve(unresolved_value)
                return prop.get_value(value, validate)
            # the resolver function could raise any number of exceptions,
            # so handle this generically
            except Exception as e:
                raise ValueError('%s%s %s' %
                                 (self.error_prefix, key, six.text_type(e)))
        elif prop.has_default():
            return prop.get_value(None, validate)
        elif prop.required():
            raise ValueError(
                _('%(prefix)sProperty %(key)s not assigned') % {
                    'prefix': self.error_prefix,
                    'key': key
                })
예제 #5
0
    def _get_property_value(self, key, validate=False):
        if key not in self:
            raise KeyError(_('Invalid Property %s') % key)

        prop = self.props[key]

        if key in self.data:
            try:
                unresolved_value = self.data[key]
                if validate:
                    deps = function.dependencies(unresolved_value)
                    if any(res.action == res.INIT for res in deps):
                        validate = False

                value = self.resolve(unresolved_value)
                return prop.get_value(value, validate)
            # Children can raise StackValidationFailed with unique path which
            # is necessary for further use in StackValidationFailed exception.
            # So we need to handle this exception in this method.
            except exception.StackValidationFailed as e:
                raise exception.StackValidationFailed(path=e.path,
                                                      message=e.error_message)
            # the resolver function could raise any number of exceptions,
            # so handle this generically
            except Exception as e:
                raise ValueError(six.text_type(e))
        elif prop.has_default():
            return prop.get_value(None, validate)
        elif prop.required():
            raise ValueError(_('Property %s not assigned') % key)
예제 #6
0
 def required_resource_names(self):
     if self._deps is None:
         try:
             required_resources = function.dependencies(self._value)
             self._deps = set(map(lambda rp: rp.name, required_resources))
         except (exception.InvalidTemplateAttribute,
                 exception.InvalidTemplateReference):
             # This output ain't gonna work anyway
             self._deps = set()
     return self._deps
예제 #7
0
파일: output.py 프로젝트: sdake/heat
 def required_resource_names(self):
     if self._deps is None:
         try:
             required_resources = function.dependencies(self._value)
             self._deps = set(six.moves.map(lambda rp: rp.name,
                                            required_resources))
         except (exception.InvalidTemplateAttribute,
                 exception.InvalidTemplateReference):
             # This output ain't gonna work anyway
             self._deps = set()
     return self._deps
예제 #8
0
 def strict_func_deps(data, datapath):
     return six.moves.filter(
         lambda r: getattr(r, 'strict_dependency', True),
         function.dependencies(data, datapath))
예제 #9
0
 def test_dependencies(self):
     deps = list(function.dependencies(self.snippet))
     self.assertIn('foo', deps)
     self.assertIn('bar', deps)
     self.assertEqual(2, len(deps))
예제 #10
0
 def _find_deps_any_in_init(self, unresolved_value):
     deps = function.dependencies(unresolved_value)
     if any(res.action == res.INIT for res in deps):
         return True
예제 #11
0
파일: rsrc_defn.py 프로젝트: whiteear/heat
 def strict_func_deps(data, datapath):
     return itertools.ifilter(
         lambda r: getattr(r, 'strict_dependency', True),
         function.dependencies(data, datapath))
예제 #12
0
 def strict_func_deps(data, datapath):
     return six.moves.filter(
         lambda r: getattr(r, 'strict_dependency', True),
         six.moves.map(lambda rp: stack[rp.name],
                       function.dependencies(data, datapath)))
예제 #13
0
파일: properties.py 프로젝트: aaratn/heat
 def _find_deps_any_in_init(self, unresolved_value):
     deps = function.dependencies(unresolved_value)
     if any(res.action == res.INIT for res in deps):
         return True
예제 #14
0
 def test_dependencies(self):
     deps = list(function.dependencies(self.snippet))
     self.assertIn('foo', deps)
     self.assertIn('bar', deps)
     self.assertEqual(2, len(deps))
예제 #15
0
 def strict_func_deps(data, datapath):
     return itertools.ifilter(lambda r: getattr(r, 'strict_dependency',
                                                True),
                              function.dependencies(data, datapath))