예제 #1
0
파일: parameter.py 프로젝트: piojo/aquilon
def search_path_in_personas(session, path, paramdef_holder):

    q = session.query(PersonalityParameter)
    q = q.join(Personality)
    if isinstance(paramdef_holder, ArchetypeParamDef):
        q = q.filter_by(archetype=paramdef_holder.archetype)
    else:
        q = q.join(FeatureLink)
        q = q.filter_by(feature=paramdef_holder.feature)

    holder = {}
    trypath = []
    if isinstance(paramdef_holder, ArchetypeParamDef):
        trypath.append(path)
    for param_holder in q.all():
        try:
            if not isinstance(paramdef_holder, ArchetypeParamDef):
                trypath = []
                q = session.query(FeatureLink)
                q = q.filter_by(feature=paramdef_holder.feature,
                                personality=param_holder.personality)

                for link in q.all():
                    trypath.append(Parameter.feature_path(link, path))

            for tpath in trypath:
                for param in param_holder.parameters:
                    value = param.get_path(tpath)
                    if value:
                        holder[param_holder] = {path: value}
        except NotFoundException:
            pass
    return holder
예제 #2
0
파일: parameter.py 프로젝트: ned21/aquilon
def search_path_in_personas(session, path, paramdef_holder):

    q = session.query(PersonalityParameter)
    q = q.join(Personality)
    if isinstance(paramdef_holder, ArchetypeParamDef):
        q = q.filter_by(archetype=paramdef_holder.archetype)
    else:
        q = q.join(FeatureLink)
        q = q.filter_by(feature=paramdef_holder.feature)

    holder = {}
    trypath = []
    if isinstance(paramdef_holder, ArchetypeParamDef):
        trypath.append(path)
    for param_holder in q.all():
        try:
            if not isinstance(paramdef_holder, ArchetypeParamDef):
                trypath = []
                q = session.query(FeatureLink)
                q = q.filter_by(feature=paramdef_holder.feature,
                                personality=param_holder.personality)

                for link in q.all():
                    trypath.append(Parameter.feature_path(link, path))

            for tpath in trypath:
                for param in param_holder.parameters:
                    value = param.get_path(tpath)
                    if value:
                        holder[param_holder] = {path: value}
        except NotFoundException:
            pass
    return holder
예제 #3
0
파일: parameter.py 프로젝트: piojo/aquilon
def del_all_feature_parameter(session, dblink):

    if not dblink:
        return

    paramdef_holder = None
    param_definitions = None
    if dblink:
        paramdef_holder = dblink.feature.paramdef_holder
        if paramdef_holder:
            param_definitions = paramdef_holder.param_definitions

    if not param_definitions:
        return

    dbparams = get_parameters(session, archetype=None,
                              personality=dblink.personality)

    if not dbparams:
        return

    for paramdef in param_definitions:
        for dbparam in dbparams:
            if paramdef.rebuild_required:
                validate_rebuild_required(session, paramdef.path, dbparam.holder)

            dbparam.del_path(Parameter.feature_path(dblink, paramdef.path),
                             compel=False)

    return
예제 #4
0
파일: parameter.py 프로젝트: ned21/aquilon
def del_all_feature_parameter(session, dblink):

    if not dblink:
        return

    paramdef_holder = None
    param_definitions = None
    if dblink:
        paramdef_holder = dblink.feature.paramdef_holder
        if paramdef_holder:
            param_definitions = paramdef_holder.param_definitions

    if not param_definitions:
        return

    dbparams = get_parameters(session,
                              archetype=None,
                              personality=dblink.personality)

    if not dbparams:
        return

    for paramdef in param_definitions:
        for dbparam in dbparams:
            if paramdef.rebuild_required:
                validate_rebuild_required(session, paramdef.path,
                                          dbparam.holder)

            dbparam.del_path(Parameter.feature_path(dblink, paramdef.path),
                             compel=False)

    return
예제 #5
0
파일: parameter.py 프로젝트: piojo/aquilon
def del_parameter(session, path, param_holder, feature=None, model=None, interface_name=None):
    dbparameter = Parameter.get_unique(session, holder=param_holder,
                                       compel=True)

    dblink = None
    if feature:
        dblink = get_feature_link(session, feature, model, interface_name,
                                  param_holder.personality)

    match = get_paramdef_for_parameter(session, path, param_holder, dblink)

    if match and match.rebuild_required:
        validate_rebuild_required(session, path, param_holder)

    if dblink:
        path = Parameter.feature_path(dblink, path)
    dbparameter.del_path(path)
    return dbparameter
예제 #6
0
파일: personality.py 프로젝트: jrha/aquilon
def get_path_under_top(path, value, ret):
    """ input variable of type xx/yy would be printed as yy only in the
        particular structure template
        if path is just xx and points to a dict
            i.e action = {startup: {a: b}}
            then print as action/startup = pancized({a: b}
        if path is just xx and points to non dict
            ie xx = yy
            then print xx = yy
    """
    pparts = Parameter.path_parts(path)
    if not pparts:
        return
    top = pparts.pop(0)
    if pparts:
        ret[Parameter.topath(pparts)] = value
    elif isinstance(value, dict):
        for k in value:
            ret[k] = value[k]
    else:
        ret[top] = value
예제 #7
0
def get_path_under_top(path, value, ret):
    """ input variable of type xx/yy would be printed as yy only in the
        particular structure template
        if path is just xx and points to a dict
            i.e action = {startup: {a: b}}
            then print as action/startup = pancized({a: b}
        if path is just xx and points to non dict
            ie xx = yy
            then print xx = yy
    """
    pparts = Parameter.path_parts(path)
    if not pparts:
        return
    top = pparts.pop(0)
    if pparts:
        ret[Parameter.topath(pparts)] = value
    elif isinstance(value, dict):
        for k in value:
            ret[k] = value[k]
    else:
        ret[top] = value
예제 #8
0
파일: parameter.py 프로젝트: piojo/aquilon
def set_parameter(session, param_holder, feature, model, interface_name,
                  path, value, compel=False, preclude=False):
    """
        Handles add parameter as well as update parameter. Parmeters for features
        will be stored as part of personality as features/<feature_name>/<path>
    """

    dbparameter = Parameter.get_unique(session, holder=param_holder,
                                       compel=compel)
    ## create dbparameter if doesnt exist
    if not dbparameter:
        if compel:
            raise NotFoundException("No parameter of path=%s defined." % path)

        dbparameter = Parameter(holder=param_holder, value={})

    dblink = None
    if feature:
        dblink = get_feature_link(session, feature, model, interface_name,
                                  param_holder.personality)

    retval, param_def = validate_parameter(session, path, value, param_holder, dblink)

    if feature:
        path = Parameter.feature_path(dblink, path)
    dbparameter.set_path(path, retval, compel, preclude)
    dbparameter.param_def = param_def
    return dbparameter
예제 #9
0
파일: parameter.py 프로젝트: ned21/aquilon
def del_parameter(session,
                  path,
                  param_holder,
                  feature=None,
                  model=None,
                  interface_name=None):
    dbparameter = Parameter.get_unique(session,
                                       holder=param_holder,
                                       compel=True)

    dblink = None
    if feature:
        dblink = get_feature_link(session, feature, model, interface_name,
                                  param_holder.personality)

    match = get_paramdef_for_parameter(session, path, param_holder, dblink)

    if match and match.rebuild_required:
        validate_rebuild_required(session, path, param_holder)

    if dblink:
        path = Parameter.feature_path(dblink, path)
    dbparameter.del_path(path)
    return dbparameter
예제 #10
0
파일: show_diff.py 프로젝트: ned21/aquilon
    def populate_data(self, session, dbpersona, dtype, ret):
        """ pouplate data we are interesetd in seeing as part of diff """

        ## parameters
        params = {}

        dbpersona_parameters = get_parameters(session, personality=dbpersona)

        for param in dbpersona_parameters:
            params.update(Parameter.flatten(param.value))
        ret["Parameters"][dtype] = params

        ## process features
        features = dict((fl.feature.name, True) for fl in dbpersona.features)
        ret["Features"][dtype] = features

        ## process required_services
        services = dict((srv.name, True) for srv in dbpersona.services)
        ret["Required Services"][dtype] = services

        ## service maps
        q = session.query(PersonalityServiceMap).filter_by(personality=dbpersona)

        smaps = dict(("{0} {1}".format(sm.service_instance, sm.location), True) for sm in q.all())

        ret["ServiceMap"][dtype] = smaps

        ## grns
        grns = dict((grn, True) for grn in dbpersona.grns)
        ret["Grns"][dtype] = grns

        ## options
        enabled = defaultdict()
        if dbpersona.config_override:
            enabled["ConfigOverride"] = True
        if dbpersona.cluster_required:
            enabled["Cluster Required"] = True

        enabled["Environment"] = dbpersona.host_environment.name
        ret["Options"][dtype] = enabled
예제 #11
0
    def format_proto(self, param, skeleton=None):
        container = skeleton
        if not container:
            container = self.loaded_protocols[self.protocol].ParameterList()

        param_definitions = None
        paramdef_holder = None
        dbpersonality = param.holder.personality
        paramdef_holder = dbpersonality.archetype.paramdef_holder

        if paramdef_holder:
            param_definitions = paramdef_holder.param_definitions
            for param_def in param_definitions:
                value = param.get_path(param_def.path, compel=False)
                if value:
                    skeleton = container.parameters.add()
                    skeleton.path = str(param_def.path)
                    if param_def.value_type == 'json':
                        skeleton.value = json.dumps(value)
                    else:
                        skeleton.value = str(value)
        for link in dbpersonality.features:
            if not link.feature.paramdef_holder:
                continue
            param_definitions = link.feature.paramdef_holder.param_definitions
            for param_def in param_definitions:
                value = param.get_feature_path(link,
                                               param_def.path,
                                               compel=False)
                if value:
                    skeleton = container.parameters.add()
                    skeleton.path = str(
                        Parameter.feature_path(link, param_def.path))
                    if param_def.value_type == 'json':
                        skeleton.value = json.dumps(value)
                    else:
                        skeleton.value = str(value)

        return container
예제 #12
0
파일: parameter.py 프로젝트: jrha/aquilon
    def format_proto(self, param, skeleton=None):
        container = skeleton
        if not container:
            container = self.loaded_protocols[self.protocol].ParameterList()

        param_definitions = None
        paramdef_holder = None
        dbpersonality = param.holder.personality
        paramdef_holder = dbpersonality.archetype.paramdef_holder

        if paramdef_holder:
            param_definitions = paramdef_holder.param_definitions
            for param_def in param_definitions:
                value = param.get_path(param_def.path, compel=False)
                if value:
                    skeleton = container.parameters.add()
                    skeleton.path = str(param_def.path)
                    if param_def.value_type == 'json':
                        skeleton.value = json.dumps(value)
                    else:
                        skeleton.value = str(value)
        for link in dbpersonality.features:
            if not link.feature.paramdef_holder:
                continue
            param_definitions = link.feature.paramdef_holder.param_definitions
            for param_def in param_definitions:
                value = param.get_feature_path(link, param_def.path,
                                               compel=False)
                if value:
                    skeleton = container.parameters.add()
                    skeleton.path = str(Parameter.feature_path(link, param_def.path))
                    if param_def.value_type == 'json':
                        skeleton.value = json.dumps(value)
                    else:
                        skeleton.value = str(value)

        return container
예제 #13
0
파일: parameter.py 프로젝트: ned21/aquilon
def set_parameter(session,
                  param_holder,
                  feature,
                  model,
                  interface_name,
                  path,
                  value,
                  compel=False,
                  preclude=False):
    """
        Handles add parameter as well as update parameter. Parmeters for features
        will be stored as part of personality as features/<feature_name>/<path>
    """

    dbparameter = Parameter.get_unique(session,
                                       holder=param_holder,
                                       compel=compel)
    ## create dbparameter if doesnt exist
    if not dbparameter:
        if compel:
            raise NotFoundException("No parameter of path=%s defined." % path)

        dbparameter = Parameter(holder=param_holder, value={})

    dblink = None
    if feature:
        dblink = get_feature_link(session, feature, model, interface_name,
                                  param_holder.personality)

    retval, param_def = validate_parameter(session, path, value, param_holder,
                                           dblink)

    if feature:
        path = Parameter.feature_path(dblink, path)
    dbparameter.set_path(path, retval, compel, preclude)
    dbparameter.param_def = param_def
    return dbparameter
예제 #14
0
    def render(self, session, logger, personality, archetype,
               grn, eon_id, host_environment, comments,
               cluster_required, copy_from, config_override, **arguments):
        if not VALID_PERSONALITY_RE.match(personality):
            raise ArgumentError("Personality name '%s' is not valid." %
                                personality)
        if not (grn or eon_id):
            raise ArgumentError("GRN or EON ID is required for adding a "
                                "personality.")

        dbarchetype = Archetype.get_unique(session, archetype, compel=True)

        if not host_environment:
            try:
                host_environment = self.config.get("archetype_" + archetype,
                                                   "default_environment")
            except (NoSectionError, NoOptionError):
                raise ArgumentError("Default environment is not configured "
                                    "for {0:l}, please specify "
                                    "--host_environment.".format(dbarchetype))

        HostEnvironment.polymorphic_subclass(host_environment,
                                             "Unknown environment name")
        Personality.validate_env_in_name(personality, host_environment)
        host_env = HostEnvironment.get_unique(session, host_environment, compel=True)

        Personality.get_unique(session, archetype=dbarchetype, name=personality,
                               preclude=True)

        dbgrn = lookup_grn(session, grn, eon_id, logger=logger,
                           config=self.config)

        dbpersona = Personality(name=personality, archetype=dbarchetype,
                                cluster_required=bool(cluster_required),
                                host_environment=host_env, owner_grn=dbgrn,
                                comments=comments,
                                config_override=config_override)
        session.add(dbpersona)

        if self.config.has_option("archetype_" + archetype, "default_grn_target"):
            dbpersona.grns.append((dbpersona, dbgrn,
                                   self.config.get("archetype_" + archetype,
                                                   "default_grn_target")))

        if copy_from:
            ## copy config data
            dbfrom_persona = Personality.get_unique(session,
                                                    archetype=dbarchetype,
                                                    name=copy_from,
                                                    compel=True)

            src_parameters = get_parameters(session,
                                            personality=dbfrom_persona)
            db_param_holder = PersonalityParameter(personality=dbpersona)

            for param in src_parameters:
                dbparameter = Parameter(value=param.value,
                                        comments=param.comments,
                                        holder=db_param_holder)
                session.add(dbparameter)

            for link in dbfrom_persona.features:
                params = {}
                params["personality"] = dbpersona
                if link.model:
                    params["model"] = link.model
                if link.interface_name:
                    params["interface_name"] = link.interface_name

                add_link(session, logger, link.feature, params)

            ## service maps
            q = session.query(PersonalityServiceMap).filter_by(personality=dbfrom_persona)

            for sm in q.all() :
                dbmap = PersonalityServiceMap(service_instance=sm.service_instance,
                                              location=sm.location,
                                              network=sm.network,
                                              personality=dbpersona)
                session.add(dbmap)

            ## required services
            dbpersona.services.extend(dbfrom_persona.services)

        session.flush()

        plenary = PlenaryPersonality(dbpersona, logger=logger)
        plenary.write()
        return