Пример #1
0
def check_plateform_exist(plateform=None):
    """ Check if plateform already exist.

        :param: plateform: plateform's name passed by user.
        :type: plateform: list of str
        :return: False if type doesnt exist, raise an error otherwise.
        :rtype: bool

        .. seealso:: heimdall.conf.hosts.getAllPlateformObjects()
    """
    from conf.hosts import getAllPlateformObjects
    from core.exceptions import PlateformAlreadyExist

    if not plateform:
        return False

    plateform_available = []
    [plateform_available.append(p.name) for p in getAllPlateformObjects()]
    exist = set(plateform_available).intersection(set(plateform))

    try:
        if exist:
            raise PlateformAlreadyExist("Plateform %s already exist !" % plateform, plateform)
        else:
            return False
    except PlateformAlreadyExist as pae:
        print pae
        exit(pae.code)
Пример #2
0
def check_plateform(plateform=None):
    """ Check if plateform exist by plateform name.

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

        .. seealso:: heimdall.conf.hosts.getAllPlateformObjects()
    """
    from conf.hosts import getAllPlateformObjects
    from core.exceptions import PlateformDoesNotExist

    if not plateform:
        return False

    plateform_available = []
    for p in getAllPlateformObjects():
        if plateform[0] == p.name:
            plateform_available.append(p.name)
    exist = set(plateform_available).intersection(set(plateform))

    try:
        if not exist:
            raise PlateformDoesNotExist('Plateform %s does not exists!' % plateform, plateform)
        else:
            return True
    except PlateformDoesNotExist as pde:
        print pde
        exit(pde.code)
Пример #3
0
def get_all_plateforms():
    """ Return all plateforms objects read from yaml file in heimdall/conf/hosts/plateform.yml

        :return: return all plateforms objects
        :rtype: list of plateform object

        .. seealso:: heimdall.conf.hosts.getAllPlateformObjects()
    """
    from conf.hosts import getAllPlateformObjects
    return getAllPlateformObjects()
Пример #4
0
def get_new_id():
    """ Return a new id available from all plateform.
        If heimdall/conf/host/ is empty, return 1

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

        .. seealso:: heimdall.conf.hosts.getAllPlateformObjects()
    """
    from conf.hosts import getAllPlateformObjects

    allplateform = getAllPlateformObjects()

    if not allplateform:
        return 1

    newid = []
    [newid.append(p.id) for p in allplateform]
    return max(newid) + 1
Пример #5
0
def get_plateform(plateform=None, environment=None, id=None):
    """ Take plateform information passed by user, and return list of plateforms filtered

        :param: plateform: plateform's name (same as plateform yaml file) passed by user
        :param: environment: plateform's environment passed by user
        :param: id: plateform's id passed by user
        :type: plateform: list of str
        :type: environment: list of str
        :type: id: list of int
        :return: list of plateform objects filtered
        :rtype: list of plateform objects

        .. seealso::: heimdall.conf.hosts.getPlateformObject(), heimdall.conf.hosts.getAllPlateformObjects()
    """

    plateforms_availables = []
    all_plateform = []

    from conf.hosts import getAllPlateformObjects, getPlateformObject
    if plateform:
        [all_plateform.append(getPlateformObject(p)) for p in plateform]
    else:
        all_plateform = getAllPlateformObjects()

    for p in all_plateform:
        if environment:  # if environment is set
            for env in environment:
                if id:  # if id is set, filter with environment AND id
                    [[plateforms_availables.append(p) for i in id if i == p.id] for e in p.environment if e == env]
                else:  # only filter with environment
                    [plateforms_availables.append(p) for e in p.environment if e == env]
        elif id:  # if environment is not set, but id is set filter only with id
            [plateforms_availables.append(p) for i in id if i == p.id]
        else:  # environment and id are not set, just return all plateforms
            plateforms_availables = all_plateform
    return plateforms_availables