示例#1
0
def single(install_list):
    """ 单台机器安装.

    """
    idc = install_list["idc"]
    sn = install_list["sn"]
    _type = install_list["type"]
    version = install_list["version"]
    usage = install_list["usage"]
    device = install_list["device"]
    product = install_list["product"]
    cabinet = install_list["cabinet"]
    user_data = install_list["user_data"]

    message = "start to install %s." % sn
    logger.info(message)

    # 查询控制卡 ip.
    ip = ilo_info.ip(idc, sn)
    if not ip or not utils.is_valid_ip(ip):
        result = "failed"
        message = "get ilo ip failed"
        install_list["result"] = result
        install_list["message"] = message
        return install_list
    message = "get %s ilo ip: %s" % (sn, ip)
    logger.info(message)

    # 拿到密码.
    passwd = ilo_info.passwd(idc, ip, sn)
    if not passwd:
        result = "failed"
        message = "get ilo passwd failed"
        install_list["result"] = result
        install_list["message"] = message
        return install_list
    passwd = passwd.strip()
    message = "get %s ilo passwd: %s" % (sn, passwd)
    logger.info(message)

    # 获取 ilo 对象.
    oj = ilo_oper.generate(idc, ip, passwd)
    message = "get %s ilo object" % (sn)
    logger.info(message)

    # 检查 SN 是否一致.
    curr_sn = oj.get_sn()
    if sn != curr_sn:
        result = "failed"
        message = "check sn failed"
        install_list["result"] = result
        install_list["message"] = message
        return install_list
    message = "check %s sn consistency success" % (sn)
    logger.info(message)

    # 查询网卡名称.
    nic = oj.get_nic_name(device)
    if not nic:
        logger.error("cann't get nic name")
        result = "failed"
        message = "cann't get nic name"
        install_list["result"] = result
        install_list["message"] = message
        return install_list
    message = "get %s nic name: %s" % (sn, nic)
    logger.info(message)

    # 设置网卡支持 PXE 启动.
    if not oj.get_nic_pxeboot(nic):
        if not oj.setup_nic_pxeboot(nic):
            result = "failed"
            message = "setup network device to support pxe boot failed"
            install_list["result"] = result
            install_list["message"] = message
            return install_list
    message = "set %s nic pxe boot success" % sn
    logger.info(message)

    # 设置启动顺序.
    nic_seq = oj.get_boot_order(nic)
    if not oj.check_boot_order(nic_seq):
        if not oj.setup_boot_order(nic_seq):
            result = "failed"
            message = "can't setup right bootseq - %s" % nic_seq
            install_list["result"] = result
            install_list["message"] = message
            return install_list
    message = "set %s nic support pxe boot success" % sn
    logger.info(message)

    # 设置机器从 PXE 启动一次.
    if not oj.setup_pxeboot_once():
        result = "failed"
        message = "setup pxe once boot failed"
        install_list["result"] = result
        install_list["message"] = message
        return install_list
    message = "set %s nic pxe boot once success" % sn
    logger.info(message)

    # 拷贝 pxelinux 配置文件.
    mac = oj.get_mac(nic)
    if not oj.constract_tftp(_type, version, mac):
        result = "failed"
        message = "copy pxelinux cfg failed"
        install_list["result"] = result
        install_list["message"] = message
        return install_list
    message = "copy %s pxelinux cfg success" % sn
    logger.info(message)

    # 重启.
    if not oj.reboot():
        result = "failed"
        message = "restart server failed"
        install_list["result"] = result
        install_list["message"] = message
        return install_list
    message = "reboot %s success" % sn
    logger.info(message)

    # 安装信息进 redis.
    client.hset(sn, "idc", idc)
    client.hset(sn, "usage", usage)

    client.hset(sn, "hostname", "")
    client.hset(sn, "ip", "")

    message = "set %s's idc, usage, hostname, ip to redis success" % sn
    logger.info(message)

    # 设置 user_data, 装机之后机器会获取并执行 user_data 中的内容.
    if user_data is None:
        client_user_data.exists(sn) and client_user_data.delete(sn)
    else:
        client_user_data.set(sn, user_data)

    # 循环等待安装完成.
    timeout = 2700
    interval = 30
    timetotal = 0

    installed = False
    inasset = False

    while timetotal < timeout:
        if not installed:
            hostname = client.hget(sn, "hostname")
            ip = client.hget(sn, "ip")

            if "" in [hostname, ip]:
                time.sleep(interval)
                timetotal += interval
            else:
                installed = True
        elif installed and not inasset:
            try:
                ret = server.get("sn", sn)
                if not isinstance(ret, dict):
                    time.sleep(interval)
                    timetotal += interval
                elif "hostname" not in ret:
                    time.sleep(interval)
                    timetotal += interval
                elif ret["hostname"] != hostname:
                    time.sleep(interval)
                    timetotal += interval
                else:
                    inasset = True
            except Exception, e:
                message = traceback.format_exc()
                logger.error(message)
                time.sleep(interval)
                timetotal += interval
        else:
            break
示例#2
0
def single(check_list):
    """ 检查是否能够正常安装.

    """

    idc = check_list["idc"]
    sn = check_list["sn"]
    device = check_list["device"]

    # 查询控制卡 ip.    
    ip = ilo_info.ip(idc, sn)
    if ip == False or utils.is_valid_ip(ip) == False:
        result = "failed"
        message = "get ilo ip failed"
        check_list["result"] = result
        check_list["message"] = message
        return check_list

    # 拿到密码.
    passwd = ilo_info.passwd(idc, ip, sn)
    if passwd == False:
        result = "failed"
        message = "get ilo passwd failed"
        check_list["result"] = result
        check_list["message"] = message
        return check_list

    passwd = passwd.strip()

    # 获取 ilo 对象.
    oj = ilo_oper.generate(idc, ip, passwd)

    # 检查 SN 是否一致.
    curr_sn = oj.get_sn()
    if sn != curr_sn:
        result = "failed"
        message = "check sn failed"
        check_list["result"] = result
        check_list["message"] = message
        return check_list

    # 查询网卡名称.
    nic = oj.get_nic_name(device)
    if not nic:
        logger.error("cann't get nic name")
        result = "failed"
        message = "cann't get nic name"
        check_list["result"] = result
        check_list["message"] = message
        return check_list

    # 设置网卡支持 PXE 启动.
    if not oj.get_nic_pxeboot(nic):
        if not oj.setup_nic_pxeboot(nic):
            result = "failed"
            message = "setup network device to support pxe boot failed"
            check_list["result"] = result
            check_list["message"] = message
            return check_list

    # 设置启动顺序.
    nic_seq = oj.get_boot_order(nic)
    if not oj.check_boot_order(nic_seq):
        if not oj.setup_boot_order(nic_seq):
            result = "failed"
            message = "can't setup right bootseq - %s" % nic_seq
            check_list["result"] = result
            check_list["message"] = message
            return check_list

    logger.info("%s(%s) check install success ", sn, ip)

    result = "success"
    message = "check success"
    check_list["result"] = result
    check_list["message"] = message
    return check_list