コード例 #1
0
def check_profile(profile=None):
    """ Check if profile exist by profile name.

        :param: profile: profile's name passed by user.
        :type: profile: list of str
        :return: True if profile exist, False otherwise.
        :rtype: bool

        .. seealso:: heimdall.conf.profiles.getAllProfilesObjects
    """
    from conf.profiles import getAllProfilesObjects
    from core.exceptions import ProfileDoesNotExist

    if not profile:
        return False

    profile_available = []
    [profile_available.append(p.name) for p in getAllProfilesObjects()]
    try:
        for p in profile:
            if p not in profile_available:  # Check profile exist
                raise ProfileDoesNotExist("Profile %s doesnt exist !" %
                                          profile)
        else:
            return True
    except ProfileDoesNotExist as pne:
        print pne
        exit(pne.code)
コード例 #2
0
def get_all_profiles():
    """ Return all Profile Objects read from yaml file in heimdall/conf/profiles/profile.yml

        :return: return all Profile Objects
        :rtype: list of Profile Objects

        .. seealso:: heimdall.conf.profiles.getAllProfilesObjects()
    """
    from conf.profiles import getAllProfilesObjects
    return getAllProfilesObjects()
コード例 #3
0
def get_profile(profiles=None, type=None, id=None):
    """ Take profile information passed by user, and return list of Profile Objects filtered.

        :param: profiles: list of profiles's name (same as type yaml file) passed by user
        :param: type: list of type's name (same as type yaml file) passed by user
        :param: id: list of rule's id (same as type yaml file) passed by user
        :type: profiles: list of str
        :type: type: list of str
        :type: id: list of int
        :return: list of Profile Objects filtered
        :rtype: list of Profile Objects

        ..seealso:: heimdall.conf.profiles.getProfileObject()
    """
    from conf.profiles import getAllProfilesObjects, getProfileObject

    profiles_availables = []
    all_profile = []
    if profiles:
        [all_profile.append(getProfileObject(p)) for p in profiles]
    else:
        all_profile = getAllProfilesObjects()

    for p in all_profile:
        rtype = []
        rulesid = []
        if type:
            [rtype.append(t) for t in p.type if t.name in type]
            if rtype:
                if id:
                    [rulesid.append(r.id) for rt in rtype for r in rt.rules]
                    if set(rulesid).intersection(id):
                        profiles_availables.append(p)
                else:
                    profiles_availables.append(p)
        elif id:
            [rtype.append(t) for t in p.type]
            [rulesid.append(r.id) for rt in rtype for r in rt.rules]
            if set(rulesid).intersection(id):
                profiles_availables.append(p)
        else:
            profiles_availables = all_profile

    return profiles_availables
コード例 #4
0
def clean_profiles(type=None, id=None):
    """ update profile file when one or more rules are deleted.

        :param: type: type's name passed by user.
        :param: id: rule's id passed by user.
        :type: type: list of str
        :type: id: list of int
        :return: True
        :rtype: bool

        .. seealso:: heimdall.conf.profiles.getAllProfilesObjects(), heimdall.utils.rule.unlink_rule()
    """
    from conf.profiles import getAllProfilesObjects
    from utils.rule import unlink_rule

    if not id:
        id = -1
    unlink_rule(getAllProfilesObjects(), type, id)
    return True
コード例 #5
0
def get_new_id():
    """ Return a new id available from all profile.
        If heimdall/conf/profile/ is empty, return 1

        :return: new id if one plateform exist, 1 otherwise
        :rtype: int

        .. seealso:: heimdall.conf.profiles.getAllProfilesObjects
    """
    from conf.profiles import getAllProfilesObjects

    allprofiles = getAllProfilesObjects()

    if not allprofiles:
        return 1

    newid = []
    [newid.append(t.id) for t in allprofiles]
    return max(newid) + 1