Ejemplo n.º 1
0
def add_link(session, logger, dbfeature, params):
    FeatureLink.get_unique(session, feature=dbfeature, preclude=True, **params)

    # Binding a feature both at the personality and at the archetype level
    # is not an error, as the templete generation will skip duplicates.
    # Still it is worth to emit a warning so the user is aware of this case.
    q = session.query(FeatureLink)
    q = q.filter_by(feature=dbfeature, model=params.get("model", None))
    if "personality" in params and "interface_name" not in params:
        q = q.filter_by(archetype=params["personality"].archetype, personality=None)
        if q.first():
            logger.client_info(
                "Warning: {0:l} is already bound to {1:l}; "
                "binding it to {2:l} is redundant.".format(
                    dbfeature, params["personality"].archetype, params["personality"]
                )
            )
    elif "archetype" in params:
        q = q.filter_by(interface_name=None)
        q = q.join(Personality)
        q = q.filter_by(archetype=params["archetype"])
        for link in q.all():
            logger.client_info(
                "Warning: {0:l} is bound to {1:l} which "
                "is now redundant; consider removing it.".format(dbfeature, link.personality)
            )

    dbfeature.links.append(FeatureLink(**params))
Ejemplo n.º 2
0
    def do_link(self, session, logger, dbfeature, params):
        dblink = FeatureLink.get_unique(session, feature=dbfeature, compel=True,
                                        **params)

        ## check any params defined for feature in personality and delete them
        del_all_feature_parameter(session, dblink)

        dbfeature.links.remove(dblink)
Ejemplo n.º 3
0
    def do_link(self, session, logger, dbfeature, params):
        dblink = FeatureLink.get_unique(session,
                                        feature=dbfeature,
                                        compel=True,
                                        **params)

        ## check any params defined for feature in personality and delete them
        del_all_feature_parameter(session, dblink)

        dbfeature.links.remove(dblink)
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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