Ejemplo n.º 1
0
def delete_profile(id):
    profile = Profile.objects.get(pk=id)

    # decrement ref count of configlets used in this profile
    for cfg in profile.construct_list:
        configlet.update_ref_count(cfg[CONFIGLET_ID], -1)
        for param_detail in cfg[PARAM_LIST]:
            if param_detail[PARAM_TYPE] == POOL:
                update_pool_ref_count(int(param_detail[PARAM_VALUE]), -1)
    try:
        profile.delete()
    except ProtectedError:
        raise IgniteException(ERR_PROF_IN_USE)
Ejemplo n.º 2
0
def delete_profile_index(prindex_id):
    pr_index = ProfileIndex.objects.get(pk=prindex_id)
    profiles = Profile.objects.filter(profileindex_id=prindex_id)

    # decrement ref count of configlets used in this profile
    for pr in profiles:
        for cfg in pr.construct_list:
            configlet.update_ref_count(cfg[CONFIGLETINDEX_ID], cfg[VERSION], -1)
            for param_detail in cfg[PARAM_LIST]:
                if param_detail[PARAM_TYPE] == POOL:
                    update_pool_ref_count(int(param_detail[PARAM_VALUE]), -1)
        try:
            pr.delete()
        except ProtectedError:
            raise IgniteException(ERR_PROF_IN_USE)
    pr_index.delete()
Ejemplo n.º 3
0
def delete_profile(prindex_id, pr_id):
    pr = get_profile_by_index(prindex_id, pr_id)
    current_version = get_profile_current_version(prindex_id)
    obj = Profile.objects.get(profileindex=prindex_id, version=current_version)
    if int(current_version) == 1:
        err = "This is the Basic version(1), can't be deleted from here"
        logger.error(err)
        raise IgniteException(err)
    if obj.id != pr_id:
        err = "Update/Newversion can only be done with latest version of config profile"
        logger.error(err)
        raise IgniteException(err)

    for cfg in pr.construct_list:
        configlet.update_ref_count(cfg[CONFIGLETINDEX_ID], cfg[VERSION], -1)
        for param_detail in cfg[PARAM_LIST]:
            if param_detail[PARAM_TYPE] == POOL:
                update_pool_ref_count(int(param_detail[PARAM_VALUE]), -1)
    try:
        pr.delete()
    except ProtectedError:
        raise IgniteException(ERR_PROF_IN_USE)
Ejemplo n.º 4
0
def _add_profile(data, user, id=0):
    logger.debug("profile name = %s", data[NAME])

    if id:
        # get existing profile
        profile = Profile.objects.get(pk=id)

        for cfg in profile.construct_list:
            configlet.update_ref_count(cfg[CONFIGLET_ID], -1)
            for param_detail in cfg[PARAM_LIST]:
                if param_detail[PARAM_TYPE] == POOL:
                    update_pool_ref_count(int(param_detail[PARAM_VALUE]), -1)

    else:
        # create new profile
        profile = Profile()

    profile.name = data[NAME]
    profile.submit = data[SUBMIT]

    if not data[CONSTRUCT_LIST]:
        raise IgniteException(ERR_PROF_IS_EMPTY)
    else:
        profile.construct_list = data[CONSTRUCT_LIST]

    profile.updated_by = user
    profile.save()

    # increment ref count of configlets and pool used in this profile
    for cfg in profile.construct_list:
        configlet.update_ref_count(cfg[CONFIGLET_ID], 1)
        for param_detail in cfg[PARAM_LIST]:
            if param_detail[PARAM_TYPE] == POOL:
                update_pool_ref_count(int(param_detail[PARAM_VALUE]), 1)

    return profile
Ejemplo n.º 5
0
def _add_profile_index(data, user, prindex_id=0, pr_id=0):
    logger.debug("profile name = %s", data[NAME])
    import hashlib

    pr_index = None
    profile = None
    temp1 = json.dumps(data[CONSTRUCT_LIST])

    if pr_id and prindex_id:
        # get existing profile
        pr_index = ProfileIndex.objects.get(pk=prindex_id)
        profile = Profile.objects.get(pk=pr_id, profileindex_id=prindex_id)
        current_version = get_profile_current_version(prindex_id)
        new = hashlib.md5(str(json.loads(temp1))).hexdigest()
        old = hashlib.md5(str(profile.construct_list)).hexdigest()

        if not data[CONSTRUCT_LIST]:
            raise IgniteException(ERR_PROF_IS_EMPTY)

        if old == new:
            if not profile.submit:
                profile.submit = data[SUBMIT]
                profile.save()
            return profile

        obj = Profile.objects.get(profileindex=prindex_id, version=current_version)
        if obj.id != pr_id:
            err = "Update/Newversion can only be done with latest version of config profile"
            logger.error(err)
            raise IgniteException(err)

        for cfg in profile.construct_list:
            configlet.update_ref_count(cfg[CONFIGLETINDEX_ID], cfg[VERSION], -1)
            for param_detail in cfg[PARAM_LIST]:
                if param_detail[PARAM_TYPE] == POOL:
                    update_pool_ref_count(int(param_detail[PARAM_VALUE]), -1)

        if data[NEW_VERSION]:
            if not profile.submit:
                err = "Please submit current version, then create new version"
                logger.error(err)
                raise IgniteException(err)

            profile = Profile()
            profile.version = current_version + 1
        else:
            profile = Profile.objects.get(pk=pr_id)
    else:
        # create new profile
        if not data[CONSTRUCT_LIST]:
            raise IgniteException(ERR_PROF_IS_EMPTY)
        pr_index = ProfileIndex()
        pr_index.name = data[NAME]
        pr_index.updated_by = user
        pr_index.save()

        profile = Profile()
        profile.version = 1

    profile.name = data[NAME]
    profile.construct_list = data[CONSTRUCT_LIST]
    profile.submit = data[SUBMIT]
    profile.updated_by = user
    profile.profileindex = pr_index
    profile.save()

    # increment ref count of configlets and pool used in this profile
    for cfg in profile.construct_list:
        configlet.update_ref_count(cfg[CONFIGLETINDEX_ID], cfg[VERSION],  1)
        for param_detail in cfg[PARAM_LIST]:
            if param_detail[PARAM_TYPE] == POOL:
                update_pool_ref_count(int(param_detail[PARAM_VALUE]), 1)

    return profile