def render(self, session, feature, type, path, **kwargs): dbfeature = Feature.get_unique(session, name=feature, feature_type=type, compel=True) if not dbfeature.paramdef_holder: raise ArgumentError( "No parameter definitions found for {0:l}.".format(dbfeature)) db_paramdef = ParamDefinition.get_unique( session, path=path, holder=dbfeature.paramdef_holder, compel=True) ## validate if this path is being used holder = search_path_in_personas(session, path, dbfeature.paramdef_holder) if holder: raise ArgumentError( "Parameter with path {0} used by following and cannot be deleted : " .format(path) + ", ".join([ "{0.holder_object:l}".format(h) for h in holder.iterkeys() ])) session.delete(db_paramdef) session.flush() return
def render(self, session, feature, type, path, value_type, required, rebuild_required, default, description, **kwargs): dbfeature = Feature.get_unique(session, name=feature, feature_type=type, compel=True) if not dbfeature.paramdef_holder: dbfeature.paramdef_holder = FeatureParamDef() ## strip slash from path start and end if path.startswith("/"): path = path[1:] if path.endswith("/"): path = path[:-1] validate_param_definition(path, value_type, default) ParamDefinition.get_unique(session, path=path, holder=dbfeature.paramdef_holder, preclude=True) db_paramdef = ParamDefinition(path=path, holder=dbfeature.paramdef_holder, value_type=value_type, default=default, required=required, rebuild_required=rebuild_required, description=description) session.add(db_paramdef) session.flush() return
def render(self, session, feature, type, path, required, rebuild_required, default, description, **kwargs): dbfeature = Feature.get_unique(session, name=feature, feature_type=type, compel=True) if not dbfeature.paramdef_holder: dbfeature.paramdef_holder = FeatureParamDef() db_paramdef = ParamDefinition.get_unique( session, path=path, holder=dbfeature.paramdef_holder, compel=True) if default: validate_param_definition(db_paramdef.path, db_paramdef.value_type, default) db_paramdef.default = default if required is not None: db_paramdef.required = required if rebuild_required is not None: db_paramdef.rebuild_required = rebuild_required if description: db_paramdef.description = description session.flush() return
def render(self, session, feature, type, path, required, rebuild_required, default, description, **kwargs): dbfeature = Feature.get_unique(session, name=feature, feature_type=type, compel=True) if not dbfeature.paramdef_holder: dbfeature.paramdef_holder = FeatureParamDef() db_paramdef = ParamDefinition.get_unique(session, path=path, holder=dbfeature.paramdef_holder, compel=True) if default: validate_param_definition(db_paramdef.path, db_paramdef.value_type, default) db_paramdef.default = default if required is not None: db_paramdef.required = required if rebuild_required is not None: db_paramdef.rebuild_required = rebuild_required if description: db_paramdef.description = description session.flush() return
def render(self, session, feature, type, **arguments): dbfeature = Feature.get_unique(session, name=feature, feature_type=type, compel=True) if dbfeature.paramdef_holder and \ dbfeature.paramdef_holder.param_definitions: return dbfeature.paramdef_holder.param_definitions raise NotFoundException("No parameter definitions found for " "{0:l}.".format(dbfeature))
def render(self, session, feature, type, **arguments): cls = Feature.polymorphic_subclass(type, "Unknown feature type") dbfeature = cls.get_unique(session, name=feature, compel=True) if dbfeature.links: raise ArgumentError("{0} is still in use and cannot be deleted." .format(dbfeature)) session.delete(dbfeature) session.flush() return
def render(self, session, feature, type, **arguments): cls = Feature.polymorphic_subclass(type, "Unknown feature type") dbfeature = cls.get_unique(session, name=feature, compel=True) if dbfeature.links: raise ArgumentError( "{0} is still in use and cannot be deleted.".format(dbfeature)) session.delete(dbfeature) session.flush() return
def render(self, session, feature, type, archetype, personality, **arguments): if not (personality or archetype): raise ArgumentError("Archetype or Personality must be specified") dbfeature = Feature.get_unique(session, name=feature, feature_type=type, compel=True) parameters = get_parameters(session, archetype=archetype, personality=personality, feature=dbfeature) if parameters: return parameters raise NotFoundException("No parameters found for feature %s." % feature)
def get_feature_link(session, feature, model, interface_name, personality): dblink = None dbmodel = None feature_type = 'host' if interface_name: feature_type = 'interface' if model: feature_type = 'hardware' dbmodel = Model.get_unique(session, name=model, compel=True) dbfeature = Feature.get_unique(session, name=feature, feature_type=feature_type, compel=True) dblink = FeatureLink.get_unique(session, feature=dbfeature, interface_name=interface_name, model=dbmodel, personality=personality, compel=True) return dblink
def render(self, session, feature, type, archetype, personality, **arguments): if not (personality or archetype): raise ArgumentError("Archetype or Personality must be specified") dbfeature = Feature.get_unique(session, name=feature, feature_type=type, compel=True) parameters = get_parameters(session, archetype=archetype, personality=personality, feature=dbfeature) if parameters: return parameters raise NotFoundException("No parameters found for feature %s." % feature)
def render(self, session, feature, type, post_personality, comments, **arguments): cls = Feature.polymorphic_subclass(type, "Unknown feature type") if _name_re.search(feature): raise ArgumentError("Path components in the feature name must not " "start with a dot.") if post_personality and not cls.post_personality_allowed: raise UnimplementedError("The post_personality attribute is " "implemented only for host features.") cls.get_unique(session, name=feature, preclude=True) dbfeature = cls(name=feature, post_personality=post_personality, comments=comments) session.add(dbfeature) session.flush() return
def render(self, session, feature, type, path, **kwargs): dbfeature = Feature.get_unique(session, name=feature, feature_type=type, compel=True) if not dbfeature.paramdef_holder: raise ArgumentError("No parameter definitions found for {0:l}." .format(dbfeature)) db_paramdef = ParamDefinition.get_unique(session, path=path, holder=dbfeature.paramdef_holder, compel=True) ## validate if this path is being used holder = search_path_in_personas(session, path, dbfeature.paramdef_holder) if holder: raise ArgumentError("Parameter with path {0} used by following and cannot be deleted : ".format(path) + ", ".join(["{0.holder_object:l}".format(h) for h in holder.iterkeys()])) session.delete(db_paramdef) session.flush() return
def get_feature_link(session, feature, model, interface_name, personality): dblink = None dbmodel = None feature_type = 'host' if interface_name: feature_type = 'interface' if model: feature_type = 'hardware' dbmodel = Model.get_unique(session, name=model, compel=True) dbfeature = Feature.get_unique(session, name=feature, feature_type=feature_type, compel=True) dblink = FeatureLink.get_unique(session, feature=dbfeature, interface_name=interface_name, model=dbmodel, personality=personality, compel=True) return dblink
def render(self, session, feature, type, post_personality, comments, **arguments): cls = Feature.polymorphic_subclass(type, "Unknown feature type") if _name_re.search(feature): raise ArgumentError("Path components in the feature name must not " "start with a dot.") if post_personality and not cls.post_personality_allowed: raise UnimplementedError("The post_personality attribute is " "implemented only for host features.") cls.get_unique(session, name=feature, preclude=True) dbfeature = cls(name=feature, post_personality=post_personality, comments=comments) session.add(dbfeature) session.flush() return
def render(self, session, logger, feature, archetype, personality, model, vendor, interface, justification, user, **arguments): # Binding a feature to a named interface makes sense in the scope of a # personality, but not for a whole archetype. if interface and not personality: raise ArgumentError("Binding to a named interface needs " "a personality.") q = session.query(Personality) dbarchetype = None feature_type = "host" justification_required = True # Warning: order matters here! params = {} if personality: justification_required = False dbpersonality = Personality.get_unique(session, name=personality, archetype=archetype, compel=True) params["personality"] = dbpersonality if interface: params["interface_name"] = interface feature_type = "interface" dbarchetype = dbpersonality.archetype q = q.filter_by(archetype=dbarchetype) q = q.filter_by(name=personality) elif archetype: dbarchetype = Archetype.get_unique(session, archetype, compel=True) params["archetype"] = dbarchetype q = q.filter_by(archetype=dbarchetype) else: # It's highly unlikely that a feature template would work for # _any_ archetype, so disallow this case for now. As I can't # rule out that such a case will not have some uses in the # future, the restriction is here and not in the model. raise ArgumentError("Please specify either an archetype or " "a personality when binding a feature.") if model: dbmodel = Model.get_unique(session, name=model, vendor=vendor, compel=True) if dbmodel.model_type.isNic(): feature_type = "interface" else: feature_type = "hardware" params["model"] = dbmodel if dbarchetype and not dbarchetype.is_compileable: raise UnimplementedError("Binding features to non-compilable " "archetypes is not implemented.") if not feature_type: # pragma: no cover raise InternalError("Feature type is not known.") dbfeature = Feature.get_unique(session, name=feature, feature_type=feature_type, compel=True) cnt = q.count() # TODO: should the limit be configurable? if justification_required and cnt > 0: if not justification: raise AuthorizationException("Changing feature bindings for " "more than just a personality " "requires --justification.") validate_justification(user, justification) self.do_link(session, logger, dbfeature, params) session.flush() plenaries = PlenaryCollection(logger=logger) for dbpersonality in q: plenaries.append(Plenary.get_plenary(dbpersonality)) written = plenaries.write() logger.client_info("Flushed %d/%d templates." % (written, len(plenaries.plenaries))) return
def render(self, session, feature, type, **arguments): cls = Feature.polymorphic_subclass(type, "Unknown feature type") return cls.get_unique(session, name=feature, compel=True)
def render(self, session, logger, feature, archetype, personality, model, vendor, interface, justification, user, **arguments): # Binding a feature to a named interface makes sense in the scope of a # personality, but not for a whole archetype. if interface and not personality: raise ArgumentError("Binding to a named interface needs " "a personality.") q = session.query(Personality) dbarchetype = None feature_type = "host" justification_required = True # Warning: order matters here! params = {} if personality: justification_required = False dbpersonality = Personality.get_unique(session, name=personality, archetype=archetype, compel=True) params["personality"] = dbpersonality if interface: params["interface_name"] = interface feature_type = "interface" dbarchetype = dbpersonality.archetype q = q.filter_by(archetype=dbarchetype) q = q.filter_by(name=personality) elif archetype: dbarchetype = Archetype.get_unique(session, archetype, compel=True) params["archetype"] = dbarchetype q = q.filter_by(archetype=dbarchetype) else: # It's highly unlikely that a feature template would work for # _any_ archetype, so disallow this case for now. As I can't # rule out that such a case will not have some uses in the # future, the restriction is here and not in the model. raise ArgumentError("Please specify either an archetype or " "a personality when binding a feature.") if model: dbmodel = Model.get_unique(session, name=model, vendor=vendor, compel=True) if dbmodel.machine_type == "nic": feature_type = "interface" else: feature_type = "hardware" params["model"] = dbmodel if dbarchetype and not dbarchetype.is_compileable: raise UnimplementedError("Binding features to non-compilable " "archetypes is not implemented.") if not feature_type: # pragma: no cover raise InternalError("Feature type is not known.") dbfeature = Feature.get_unique(session, name=feature, feature_type=feature_type, compel=True) cnt = q.count() # TODO: should the limit be configurable? if justification_required and cnt > 0: if not justification: raise AuthorizationException( "Changing feature bindings for more " "than just a personality requires --justification.") validate_justification(user, justification) self.do_link(session, logger, dbfeature, params) session.flush() idx = 0 written = 0 successful = [] failed = [] with CompileKey(logger=logger): personalities = q.all() for personality in personalities: idx += 1 if idx % 1000 == 0: # pragma: no cover logger.client_info("Processing personality %d of %d..." % (idx, cnt)) if not personality.archetype.is_compileable: # pragma: no cover continue try: plenary_personality = PlenaryPersonality(personality) written += plenary_personality.write(locked=True) successful.append(plenary_personality) except IncompleteError: pass except Exception, err: # pragma: no cover failed.append("{0} failed: {1}".format(personality, err)) if failed: # pragma: no cover for plenary in successful: plenary.restore_stash() raise PartialError([], failed)
def render(self, session, logger, feature, archetype, personality, model, vendor, interface, justification, user, **arguments): # Binding a feature to a named interface makes sense in the scope of a # personality, but not for a whole archetype. if interface and not personality: raise ArgumentError("Binding to a named interface needs " "a personality.") q = session.query(Personality) dbarchetype = None feature_type = "host" justification_required = True # Warning: order matters here! params = {} if personality: justification_required = False dbpersonality = Personality.get_unique(session, name=personality, archetype=archetype, compel=True) params["personality"] = dbpersonality if interface: params["interface_name"] = interface feature_type = "interface" dbarchetype = dbpersonality.archetype q = q.filter_by(archetype=dbarchetype) q = q.filter_by(name=personality) elif archetype: dbarchetype = Archetype.get_unique(session, archetype, compel=True) params["archetype"] = dbarchetype q = q.filter_by(archetype=dbarchetype) else: # It's highly unlikely that a feature template would work for # _any_ archetype, so disallow this case for now. As I can't # rule out that such a case will not have some uses in the # future, the restriction is here and not in the model. raise ArgumentError("Please specify either an archetype or " "a personality when binding a feature.") if model: dbmodel = Model.get_unique(session, name=model, vendor=vendor, compel=True) if dbmodel.machine_type == "nic": feature_type = "interface" else: feature_type = "hardware" params["model"] = dbmodel if dbarchetype and not dbarchetype.is_compileable: raise UnimplementedError("Binding features to non-compilable " "archetypes is not implemented.") if not feature_type: # pragma: no cover raise InternalError("Feature type is not known.") dbfeature = Feature.get_unique(session, name=feature, feature_type=feature_type, compel=True) cnt = q.count() # TODO: should the limit be configurable? if justification_required and cnt > 0: if not justification: raise AuthorizationException( "Changing feature bindings for more " "than just a personality requires --justification.") validate_justification(user, justification) self.do_link(session, logger, dbfeature, params) session.flush() idx = 0 written = 0 successful = [] failed = [] with CompileKey(logger=logger): personalities = q.all() for personality in personalities: idx += 1 if idx % 1000 == 0: # pragma: no cover logger.client_info("Processing personality %d of %d..." % (idx, cnt)) if not personality.archetype.is_compileable: # pragma: no cover continue try: plenary_personality = PlenaryPersonality(personality) written += plenary_personality.write(locked=True) successful.append(plenary_personality) except IncompleteError: pass except Exception, err: # pragma: no cover failed.append("{0} failed: {1}".format(personality, err)) if failed: # pragma: no cover for plenary in successful: plenary.restore_stash() raise PartialError([], failed)