Ejemplo n.º 1
0
def check_drbd_status(result, resource):
    re_stand_alone = f'connection:StandAlone'
    re_string = f'{resource}\s*role:(\w+).*\s*disk:(\w+)'
    # re_peer_string = '\S+\s*role:(\w+).*\s*peer-disk:(\w+)'
    if result:
        re_stand_alone_result = utils.re_search(re_stand_alone, result, "bool")
        if re_stand_alone_result:
            return 'StandAlone'
        re_result = utils.re_search(re_string, result, "groups")
        return re_result
Ejemplo n.º 2
0
def get_crm_status_by_type(conn, result, resource, type):
    if result:
        if type in ['IPaddr2', 'iSCSITarget', 'portblock', 'iSCSILogicalUnit']:
            re_string = f'{resource}\s*\(ocf::heartbeat:{type}\):\s*(\w*)\s*(\w*)?'
            re_result = utils.re_search(conn, re_string, result, "groups")
            return re_result
        if type == 'FailedActions':
            re_string = "Failed Actions:\s*.*\*\s\w*\son\s(\S*)\s'(.*)'\s.*exitreason='(.*)',\s*.*"
            re_result = utils.re_search(conn, re_string, result, "group")
            return re_result
        if type == 'AllLUN':
            re_string = f'(\S+)\s*\(ocf::heartbeat:iSCSILogicalUnit\):\s*(\w*)\s*(\w*)?'
            re_result = utils.re_findall(conn, re_string, result)
            return re_result
Ejemplo n.º 3
0
 def get_device_name(self, resource):
     cmd = f'linstor r lv -r {resource}'
     result = utils.exec_cmd(cmd, self.conn)
     re_string = '/dev/drbd\d+'
     if result["st"]:
         re_result = utils.re_search(re_string, result["rt"], "group")
         return re_result
Ejemplo n.º 4
0
 def check_drbd_quorum(self, resource):
     cmd = f'drbdsetup show {resource}'
     result = utils.exec_cmd(cmd, self.conn)
     re_string = 'quorum\s+majority.*\s*on\s*-\s*no\s*-\s*quorum\s+io\s*-\s*error'
     if result["st"]:
         re_result = utils.re_search(re_string, result["rt"], "bool")
         return re_result
Ejemplo n.º 5
0
 def kill_dd(self, device):
     cmd_ps = 'ps -ef | grep dd'
     result = utils.exec_cmd(cmd_ps, self.conn)
     re_string = f'\w*\s*(\d+)\s*.*dd if=/dev/urandom of={device} oflag=direct status=progress'
     if result["st"]:
         re_result = utils.re_search(re_string, result["rt"], "groups")
         if re_result:
             pid = re_result[0]
             cmd_kill = f'kill -9 {pid}'
             utils.exec_cmd(cmd_kill, self.conn)
             utils.prt_log(
                 self.conn,
                 f"Kill dd on {utils.get_global_dict_value(self.conn)}.", 0)
Ejemplo n.º 6
0
def login(url, parent=None, username=None, password=None):
    if (not password) or (not username):
        return None
    qDebug("in login")
    while True:
        session = _create_session()
        # qDebug("session")
        req = _get_login_page(session, url)
        # qDebug("page")
        captcha_id = re_search(r'img.src = \'captcha\?(.*)\'', req)
        # qDebug("captcha")
        if not captcha_id:
            qDebug('Captcha not found! Retrying...')
            sleep(3)
            continue
        captcha_id += get_timestamp()
        captcha_url = 'https://jaccount.sjtu.edu.cn/jaccount/captcha?' +\
                      captcha_id
        code = _bypass_captcha(parent, session, captcha_url)
        check = Captcha(parent)
        if not check.exec_():
            session.close()
            return None
        code = check.captchaInput.text()
        qDebug(code)
        sid = re_search(r'sid" value="(.*?)"', req)
        returl = re_search(r'returl" value="(.*?)"', req)
        se = re_search(r'se" value="(.*?)"', req)
        client = re_search(r'client" value="(.*?)"', req)
        uuid = re_search(r'captcha\?uuid=(.*?)&t=', req)
        if not (sid and returl and se and uuid):
            qDebug('Params not found! Retrying...')
            sleep(3)
            continue

        res = _login(session, sid, returl, se, client,
                     username, password, code, uuid)

        if res == 2:
            parent.LogInfo.emit('[MSG]Wrong captcha! Try again!\n')
            qDebug('Wrong captcha! Try again!')
            continue
        elif res == 1:
            parent.LogInfo.emit(
                '[MSG]Wrong username or password! Try again!\n'
                )
            qDebug('Wrong username or password! Try again!')
            break
        elif res == 3:
            parent.LogInfo.emit(
                '[MSG]Opps! You are banned for 30s...Waiting...\n'
                )
            qDebug('Opps! You are banned for 30s...Waiting...')
            sleep(30)
            continue
        else:
            return session
Ejemplo n.º 7
0
 def check_vtel_result(self, result):
     re_string = f'SUCCESS|successfully created'
     re_result = utils.re_search(self.conn, re_string, result, "bool")
     return re_result
Ejemplo n.º 8
0
def get_dd_pid(conn, device, result):
    re_string = f'\w*\s*(\d+)\s*.*dd if=/dev/urandom of={device} oflag=direct status=progress'
    re_result = utils.re_search(conn, re_string, result, "groups")
    if re_result:
        return re_result[0]
Ejemplo n.º 9
0
def check_drbd_no_quorum(conn, result):
    re_string = 'quorum:no'
    if result:
        re_result = utils.re_search(conn, re_string, result)
        return re_result