Esempio n. 1
0
def main():
    if len(sys.argv) == 1:#用户输入参数是否是本身,如果是
        print(strHelp)#打印帮助
    #OK
    elif sys.argv[1] == 'ptes':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strPTESHelp)
        elif sys.argv[2] == 'all':
            sw.print_porterror_all_formated()
        else:
            if s.is_IP(sys.argv[2]):
                sw.print_porterror_formated(sys.argv[2])
            else:
                print('Please provide correct switch ip...')
    #OK
    elif sys.argv[1] == 'ptcl':#判断执行参数是否为ptcl
        num_argv = len(sys.argv)  #获取参数的个数
        if num_argv == 2 or num_argv > 4:#如果是2个或者大于4个
            print(strPTCLHelp) #打印提示信息
        elif sys.argv[2] == 'all': #如果是3个参数是 all
            sw.clear_all() #调用清除所有交换机端口错误函数
        elif s.is_IP(sys.argv[2]):#如果第3个参数是ip的话,判断是不是ip
            if num_argv == 4:   #判断是否有第4个参数,如果有
                #if _isPort(sys.argv[3]):   错误
                if s.is_port(sys.argv[3]):   #在判断第4个参数是否是正确的端口      
                    sw.clear_one_port(sys.argv[2], sys.argv[3])#调用清除具体ip,端口错误
                else:
                    print('Please provide correct port number...') #请提供正确端口号
            else:
                print(strPTCLHelp) #打印提示
        else:
            print('Please provide correct switch ip...')#请提供正确的交换机ip
    #OK
    elif sys.argv[1] == 'sws':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strSWSHelp)
        elif sys.argv[2] == 'all':
            sw.print_switchshow_all()
        else:
            if s.is_IP(sys.argv[2]):
                sw.print_switchshow(sys.argv[2])
            else:
                print('Please provide correct switch ip...')

    #OK
    elif sys.argv[1] == 'bc':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strBCHelp)
        elif sys.argv[2] == 'all':
            haap.backup_config_all()
        else:
            if s.is_IP(sys.argv[2]):
                haap.backup_config(sys.argv[2])
            else:
                print('Please provide correct engine ip...')

    # get engines' trace files under TraceFolder based on Trace levels
    #trace、primary、seaond
    #OK git Trace   NOT have Primary
    elif sys.argv[1] == 'gt':
        num_argv = len(sys.argv)
        if num_argv > 3:
            trace_level = int(sys.argv[3])
        if num_argv == 2 or num_argv > 4:
            print(strGTHelp)
        elif sys.argv[2] == 'all':
            if num_argv > 3:
                if s.is_trace_level(trace_level):
                    haap.get_trace_all(trace_level)
                else:
                    print('Trace level must be "1" or "2" or "3"')
            else:
                haap.get_trace_all(0)
        elif s.is_IP(sys.argv[2]):
            if num_argv > 3:
                if s.is_trace_level(trace_level):
                    haap.get_trace(sys.argv[2], trace_level)
                else:
                    print('Trace level must be "1" or "2" or "3"')
            else:
                haap.get_trace(sys.argv[2], 0)
        else:
            print('Please provide correct engine ip...')

    # elif sys.argv[1] == 'at':
    #     num_argv = len(sys.argv)
    #     if num_argv > 3:
    #         trace_level = sys.argv[3]
    #     if num_argv == 2 or num_argv > 4:
    #         print(strPTCLHelp)
    #     elif sys.argv[2] == 'all':
    #         if num_argv > 3:
    #             if s.is_trace_level(trace_level):
    #                 haap.analyse_trace_all(trace_level)
    #             else:
    #                 print('Trace Level Must Be "1" or "2" or "3"')
    #         else:
    #             haap.analyse_trace_all(0)
    #     elif s.is_IP(sys.argv[2]):
    #         if num_argv > 3:
    #             if s.is_trace_level(trace_level):
    #                 haap.analyse_trace(sys.argv[2], trace_level)
    #             else:
    #                 print('Trace Level Must Be "1" or "2" or "3"')
    #         else:
    #             haap.analyse_trace(sys.argv[2], 0)
    #     else:
    #         print('Please Provide Correct Engine IP...')
    #OK python Main.py at Trace\2019-00-00
    elif sys.argv[1] == 'at':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strATHelp)
        else:
            if s.is_folder(sys.argv[2]):
                s.TraceAnalyse(sys.argv[2]).run()
            else:
                print('Please provide correct trace folder')
    #OK  python Main.py ec 10.203.1.223 cmd.txt
    elif sys.argv[1] == 'ec':
        if len(sys.argv) != 4:
            print(strECHelp)
        else:
            ip = sys.argv[2]
            command_file = sys.argv[3]
            if not s.is_IP(ip):
                print('Please provide correct engine ip...')
            if not s.is_file(command_file):
                print('File not exists. please provide correct file...')
            haap.execute_multi_commands(ip, command_file)
    #OK  python Main.py fw 10.203.1.223 FW15.9.7.7_OR.bin
    elif sys.argv[1] == 'fw':
        if len(sys.argv) != 4:
            print(strFWHelp)
        else:
            ip = sys.argv[2]
            fw_file = sys.argv[3]
            if not s.is_IP(ip):
                print('Please provide correct engine ip...')
            if not s.is_file(fw_file):
                print('File not exists. please provide correct file...')
            haap.change_firmware(ip, fw_file)
    #OK-
    elif sys.argv[1] == 'sts':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strSTSHelp)
        elif sys.argv[2] == 'all':
            haap.show_stauts_all()
        else:
            if s.is_IP(sys.argv[2]):
                haap.show_stauts(sys.argv[2])
            else:
                print('Please provide correct engine ip...')
    #OK
    elif sys.argv[1] == 'st':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strSTHelp)
        elif sys.argv[2] == 'all':
            haap.set_time_all()
        else:
            if s.is_IP(sys.argv[2]):
                haap.set_time(sys.argv[2])
            else:
                print('Please provide correct engine ip...')
    #OK    
    elif sys.argv[1] == 'stm':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 3:
            print(strSTMHelp)
        elif sys.argv[2] == 'all':
            haap.show_time_all()
        else:
            if s.is_IP(sys.argv[2]):
                haap.show_time(sys.argv[2])
            else:
                print('Please provide correct engine ip...')
    #OK
    elif sys.argv[1] == 'pc':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 4:
            print(strPCHelp)
#             print(strPTCLHelp) 原
        elif num_argv > 2:
            if sys.argv[2] == 'all':
                haap.periodically_check_all()
                sw.periodically_check_all()
            elif sys.argv[2] == 'haap':
                if num_argv == 3:
                    haap.periodically_check_all()
                elif num_argv > 3:
                    if s.is_IP(sys.argv[3]):
                        haap.periodically_check(sys.argv[3])
                    else:
                        print('Please provide correct engine ip...')
            elif sys.argv[2] == 'sw':
                if num_argv == 3:
                    sw.periodically_check_all()
                elif num_argv > 3:
                    if s.is_IP(sys.argv[3]):
                        sw.periodically_check(sys.argv[3])
                    else:
                        print('Please provide correct SAN switch ip...')
            else:
                print(strPCHelp)
    #OK
    elif sys.argv[1] == 'mnt':
        num_argv = len(sys.argv)
        if num_argv == 2 or num_argv > 4:
            print(strMNTHelp)
        elif sys.argv[2] == 'rt':
            m.monitor_rt_1_thread()
        elif sys.argv[2] == 'db':
            m.monitor_db_4_thread()
        else:
            print('rt(realtime) or db(datarase)')
            
    elif sys.argv[1] == 'v':
        print("VersaTEL G1",Version)
    else:
        print(strHelp)
Esempio n. 2
0
def test_is_trace_level():
    assert sun.is_trace_level(0) == None
    assert sun.is_trace_level(1) == True