class ImportedBlueprints(Element): """ Internal DSL element used for maintaining a list of imported blueprints, this is for enabling protection against their deletion when used. """ schema = List(type=Imported)
class PolicyInstanceTargets(Element): required = True schema = List(type=PolicyInstanceTarget) def parse(self, **kwargs): """ This is a patch due to a problem in the infrastructure, the internal targets values do not get a namespace while they should. So in order to allow namespacing, this patch enforces namespace assignment. """ if self.namespace: for i in xrange(len(self._initial_value)): self._initial_value[i] = utils.generate_namespaced_value( self.namespace, self.initial_value[i]) return self.initial_value def validate(self): if len(self.children()) < 1: raise exceptions.DSLParsingLogicException( exceptions.ERROR_NO_TARGETS, "Policy '{0}' has no targets groups defined for it. " "At least one target group is required.".format( self.ancestor(Policy).name))
class PolicyInstanceTargets(Element): required = True schema = List(type=PolicyInstanceTarget) def validate(self): if len(self.children()) < 1: raise exceptions.DSLParsingLogicException( exceptions.ERROR_NO_TARGETS, "Policy '{0}' has no targets groups defined for it. " "At least one target group is required." .format(self.ancestor(Policy).name))
class GroupMembers(Element): required = True schema = List(type=GroupMember) def validate(self): if len(self.children()) < 1: raise exceptions.DSLParsingFormatException( 1, "At least one member should be specified") def parse(self): # ensure uniqueness return list(set([c.value for c in self.children()]))
class ImportsLoader(Element): schema = List(type=ImportLoader) provides = ['resource_base'] requires = { 'inputs': ['main_blueprint_holder', 'resources_base_path', 'blueprint_location', 'version', 'resolver', 'validate_version'] } resource_base = None def validate(self, **kwargs): imports = [i.value for i in self.children()] imports_set = set() for _import in imports: if _import in imports_set: raise exceptions.DSLParsingFormatException( 2, 'Duplicate imports') imports_set.add(_import) def parse(self, main_blueprint_holder, resources_base_path, blueprint_location, version, resolver, validate_version): if blueprint_location: blueprint_location = _dsl_location_to_url( dsl_location=blueprint_location, resources_base_path=resources_base_path) slash_index = blueprint_location.rfind('/') self.resource_base = blueprint_location[:slash_index] parsed_blueprint = _combine_imports( parsed_dsl_holder=main_blueprint_holder, dsl_location=blueprint_location, resources_base_path=resources_base_path, version=version, resolver=resolver, validate_version=validate_version) return parsed_blueprint def calculate_provided(self, **kwargs): return { 'resource_base': self.resource_base }
class NodeTemplateRelationships(Element): schema = List(type=NodeTemplateRelationship) provides = ['contained_in'] def validate(self): contained_in_relationships = [] contained_in_targets = [] for relationship in self.children(): relationship_target = relationship.child( NodeTemplateRelationshipTarget).value relationship_type = relationship.child( NodeTemplateRelationshipType).value type_hierarchy = relationship.value[constants.TYPE_HIERARCHY] if constants.CONTAINED_IN_REL_TYPE in type_hierarchy: contained_in_relationships.append(relationship_type) contained_in_targets.append(relationship_target) if len(contained_in_relationships) > 1: ex = exceptions.DSLParsingLogicException( 112, "Node '{0}' has more than one relationship that is " "derived from '{1}' relationship. Found: {2} for targets:" " {3}".format( self.ancestor(NodeTemplate).name, constants.CONTAINED_IN_REL_TYPE, contained_in_relationships, contained_in_targets)) ex.relationship_types = contained_in_relationships raise ex def parse(self): return [ c.value for c in sorted(self.children(), key=lambda child: child.index) ] def calculate_provided(self): contained_in_list = [ r.child(NodeTemplateRelationshipTarget).value for r in self.children() if constants.CONTAINED_IN_REL_TYPE in r.value[constants.TYPE_HIERARCHY] ] contained_in = contained_in_list[0] if contained_in_list else None return {'contained_in': contained_in}
class Imports(Element): schema = List(type=Import)
class Constraints(Element): schema = List(type=Constraint)
class ScheduleWeekdays(Element): schema = List(type=Weekday)