Esempio n. 1
0
def check_boxes(box_ids, boxes_tobe=[1] * 8):
    boxes_are_online = []
    for box_id in box_ids:
        ip = '192.168.' + box_ips[box_id][0]
        ssh = Ssh()
        try:
            ssh.login(ip)
            time.sleep(1)
            print("{}: current box: {} is online.".format(
                nowtimefmt(), box_ips[box_id][1]))
            boxes_are_online.append(1)
        except Exception as e:
            if "Unable to connect" or "连接尝试失败" in e:
                print("{}: current box: {} is offline.".format(
                    nowtimefmt(), box_ips[box_id][1]))
            else:
                print("{}: 未知错误 {}".format(nowtimefmt(), e))
            boxes_are_online.append(0)
        finally:
            try:
                ssh.ssh.close()
            except Exception:
                pass
    if len(boxes_are_online):
        return boxes_are_online == boxes_tobe
Esempio n. 2
0
def check_box_single(box_id, box_tobe):
    box_is_online = None
    ip = '192.168.' + box_ips[box_id][0]
    ssh = Ssh()
    try:
        ssh.login(ip)
        time.sleep(1)
        print("{}: current box: {} is online.".format(nowtimefmt(), box_id))
        box_is_online = 1
    except Exception as e:
        if "Unable to connect" or "连接尝试失败" in e:
            print("{}: current box: {} is offline.".format(
                nowtimefmt(), box_id))
        else:
            print("{}: {}发生未知错误 {}".format(nowtimefmt(), box_id, e))
        box_is_online = 0
    finally:
        try:
            ssh.ssh.close()
        except Exception:
            pass
    return box_is_online == box_tobe