Exemplo n.º 1
0
def call_cli():
    try:
        SCREEN.display_header('CLI')

        readline.set_completer(CLI.pre_complete_cli)

        while True:
            # mac OS
            if 'libedit' in readline.__doc__:
                CLI.modify_flag = True
                CLI.save_buffer = readline.get_line_buffer()

            # select_command (handling tab event)
            cmd = CLI.input_cmd()

            if CLI.is_menu(cmd):
                SCREEN.cli_flag = False
                return
            elif CLI.is_exit(cmd):
                SCREEN.set_exit()
                return
            else:
                # send command
                CLI.process_cmd(cmd)

                while not CLI.get_cli_ret_flag():
                    time.sleep(1)
    except:
        LOG.exception_err_write()
Exemplo n.º 2
0
def select_menu():
    selected_menu_no = 1

    try:
        SCREEN.set_screen()

        SCREEN.draw_system(menu_list)
        SCREEN.draw_event(SYS.disconnect_type)
        SCREEN.draw_menu(menu_list, selected_menu_no)

        SYS.set_sys_redraw_flag(True)

        x = SCREEN.get_ch()

        # 27 = ESC
        while x != 27:
            if x == curses.KEY_DOWN:
                if selected_menu_no != len(menu_list):
                    selected_menu_no += 1

            elif x == curses.KEY_UP:
                if selected_menu_no != 1:
                    selected_menu_no -= 1

            elif x == ord("\n"):
                # stop timer
                SYS.set_sys_redraw_flag(False)

                SCREEN.refresh_screen()
                SCREEN.screen_exit()

                menu = menu_list[selected_menu_no - 1]

                if menu in ['CLI', 'Monitoring Details', 'Event History']:
                    if menu == 'CLI':
                        SCREEN.display_header(menu_list[selected_menu_no - 1])
                        SCREEN.display_sys(True)
                    elif menu == 'Monitoring Details':
                        SCREEN.display_status()
                    elif menu == 'Event History':
                        SCREEN.display_event()

                    readline.set_completer(CLI.pre_complete_cli)

                    while True:
                        # mac OS
                        if 'libedit' in readline.__doc__:
                            CLI.modify_flag = True
                            CLI.save_buffer = readline.get_line_buffer()

                        # select_command (handling tab event)
                        cmd = CLI.input_cmd()
                        cmd = cmd.strip()

                        if CLI.is_menu(cmd):
                            break
                        elif CLI.is_exit(cmd):
                            return
                        elif cmd == 'help':
                            SCREEN.display_help()
                        elif cmd == 'monitoring-details':
                            SCREEN.display_status()
                        elif cmd.startswith('event-history'):
                            if len(cmd.split(' ')) == 2:
                                try:
                                    num = int(cmd.split(' ')[1])
                                    SCREEN.display_event(num)
                                except:
                                    print 'log count param is wrong. ex) event-history 15'
                            else:
                                SCREEN.display_event()
                        elif cmd == 'flow-trace':
                            source_ip = raw_input('CLI(flow-trace)> source ip : ')
                            dest_ip = raw_input('CLI(flow-trace)> destination ip : ')
                            TRACE.process_trace_rest(source_ip, dest_ip)
                        elif cmd.startswith('traffic-test'):
                            if cmd.startswith('traffic-test -f '):
                                try:
                                    filename = cmd.split(' ')[2]
                                except:
                                    filename = ''

                                if not os.path.exists(filename):
                                    print 'file does not exist [' + filename + ']'
                                    continue

                                result_file = open(filename, 'r')

                                test_list = []
                                for line in result_file.read().splitlines():
                                    if line.startswith('#'):
                                        continue

                                    tmp = line.split(';')
                                    test_dict = dict()
                                    test_dict['node'] = tmp[0]
                                    test_dict['instance_id'] = tmp[1]
                                    test_dict['vm_user_id'] = tmp[2]
                                    test_dict['vm_user_password'] = tmp[3]
                                    test_dict['traffic_test_command'] = tmp[4]
                                    try:
                                        test_dict['next_command_interval'] = int(tmp[5])
                                    except:
                                        test_dict['next_command_interval'] = 0

                                    test_list.append(test_dict)

                                TRACE.process_traffic_test(test_list)
                            else:
                                yes_no = 'y'

                                test_list = []
                                while yes_no.upper() == 'Y':
                                    test_dict = dict()
                                    test_dict['node'] = raw_input('CLI(traffic-test)> node : ')
                                    test_dict['instance_id'] = raw_input('CLI(traffic-test)> instance id : ')
                                    test_dict['vm_user_id'] = raw_input('CLI(traffic-test)> vm user id : ')
                                    test_dict['vm_user_password'] = raw_input('CLI(traffic-test)> vm user pw : ')
                                    test_dict['traffic_test_command'] = raw_input('CLI(traffic-test)> traffic test command : ')
                                    try:
                                        test_dict['next_command_interval'] = int(raw_input('CLI(traffic-test)> next command interval : '))
                                    except:
                                        test_dict['next_command_interval']= 0

                                    yes_no = raw_input('CLI(traffic-test)> Do you want to add test conditions?(y/n) ')

                                    test_list.append(test_dict)

                                TRACE.process_traffic_test(test_list)
                        else:
                            # send command
                            CLI.process_cmd(cmd)

                            while not CLI.get_cli_ret_flag():
                                time.sleep(1)

                elif menu == 'Flow Trace':
                    from asciimatics.screen import Screen
                    from asciimatics.exceptions import ResizeScreenError

                    # clear screen
                    SCREEN.get_screen().clear()
                    SCREEN.screen_exit()

                    last_scene = None

                    while True:
                        try:
                            Screen.wrapper(SCREEN.start_screen, catch_interrupt=True, arguments=[last_scene])

                            if SCREEN.quit_flag:
                                return
                            elif SCREEN.menu_flag:
                                SCREEN.set_screen()
                                SCREEN.main_scr.timeout(-1)
                                break
                            elif SCREEN.resize_err_flag:
                                SCREEN.draw_trace_warning()
                                SCREEN.screen_exit()
                                SCREEN.menu_flag = True
                                return

                        except ResizeScreenError as e:
                            last_scene = e.scene

                elif menu == 'Quit':
                    break

            SCREEN.draw_system(menu_list)
            SCREEN.draw_event(SYS.disconnect_type)
            SCREEN.draw_menu(menu_list, selected_menu_no)
            SCREEN.refresh_screen()

            SYS.set_sys_redraw_flag(True)

            x = SCREEN.get_ch()

        SCREEN.screen_exit()
    except:
        LOG.exception_err_write()
Exemplo n.º 3
0
def select_menu():
    selected_menu_no = 1

    try:
        SCREEN.set_screen()

        SCREEN.draw_system(menu_list)
        SCREEN.draw_event(SYS.disconnect_flag)
        SCREEN.draw_menu(menu_list, selected_menu_no)

        SYS.set_sys_redraw_flag(True)

        x = SCREEN.get_ch()

        # 27 = ESC
        while x != 27:
            if x == curses.KEY_DOWN:
                if selected_menu_no != len(menu_list):
                    selected_menu_no += 1

            elif x == curses.KEY_UP:
                if selected_menu_no != 1:
                    selected_menu_no -= 1

            elif x == ord("\n"):
                # stop timer
                SYS.set_sys_redraw_flag(False)

                # ?? is it necessary?
                SCREEN.refresh_screen()
                SCREEN.screen_exit()

                menu = menu_list[selected_menu_no - 1]

                if menu == 'CLI' or menu == 'Event List':
                    if menu == 'CLI':
                        SCREEN.display_header(menu_list[selected_menu_no - 1])
                        SCREEN.display_sys(True)
                    elif menu == 'Event List':
                        SCREEN.display_event()

                    readline.set_completer(CLI.pre_complete_cli)

                    while True:
                        # mac OS
                        if 'libedit' in readline.__doc__:
                            CLI.modify_flag = True
                            CLI.save_buffer = readline.get_line_buffer()

                        # select_command (handling tab event)
                        cmd = CLI.input_cmd()
                        cmd = cmd.strip()

                        if CLI.is_menu(cmd):
                            break
                        elif CLI.is_exit(cmd):
                            return
                        elif cmd == 'dis-system':
                            SCREEN.display_sys()
                        elif cmd == 'help':
                            SCREEN.display_help()
                        else:
                            # send command
                            CLI.process_cmd(cmd)

                            while not CLI.get_cli_ret_flag():
                                time.sleep(1)

                elif menu == 'Flow Trace':
                    from asciimatics.screen import Screen
                    from asciimatics.exceptions import ResizeScreenError

                    # clear screen
                    SCREEN.get_screen().clear()
                    SCREEN.screen_exit()

                    last_scene = None

                    while True:
                        try:
                            Screen.wrapper(SCREEN.start_screen,
                                           catch_interrupt=True,
                                           arguments=[last_scene])

                            if SCREEN.quit_flag:
                                return
                            elif SCREEN.menu_flag:
                                return
                            elif SCREEN.resize_err_flag:
                                SCREEN.draw_trace_warning()
                                SCREEN.screen_exit()
                                SCREEN.menu_flag = True
                                return

                        except ResizeScreenError as e:
                            last_scene = e.scene

            SCREEN.draw_system(menu_list)
            SCREEN.draw_event(SYS.disconnect_flag)
            SCREEN.draw_menu(menu_list, selected_menu_no)
            SCREEN.refresh_screen()

            SYS.set_sys_redraw_flag(True)

            x = SCREEN.get_ch()

        SCREEN.screen_exit()
    except:
        LOG.exception_err_write()