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
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})
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)
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 })
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
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
def strict_func_deps(data, datapath): return six.moves.filter( lambda r: getattr(r, 'strict_dependency', True), function.dependencies(data, datapath))
def test_dependencies(self): deps = list(function.dependencies(self.snippet)) self.assertIn('foo', deps) self.assertIn('bar', deps) self.assertEqual(2, len(deps))
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
def strict_func_deps(data, datapath): return itertools.ifilter( lambda r: getattr(r, 'strict_dependency', True), function.dependencies(data, datapath))
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)))
def strict_func_deps(data, datapath): return itertools.ifilter(lambda r: getattr(r, 'strict_dependency', True), function.dependencies(data, datapath))