diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/automation/trex_control_plane/client/trex_stateless_client.py | 44 | ||||
-rwxr-xr-x | scripts/automation/trex_control_plane/console/trex_console.py | 40 |
2 files changed, 56 insertions, 28 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py index 6907c9c2..a2b1f6d9 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -289,7 +289,9 @@ class CTRexStatelessClient(object): ############ boot up section ################ # connection sequence - def connect(self, force = False): + + # mode can be RW - read / write, RWF - read write with force , RO - read only + def connect(self, mode = "RW"): if self.is_connected(): self.disconnect() @@ -342,17 +344,34 @@ class CTRexStatelessClient(object): return rc # acquire all ports - rc = self.acquire(force = force) - if rc.bad(): - # release all the succeeded ports and set as read only - self.release(self.get_acquired_ports()) - self.read_only = True - else: + if mode == "RW": + rc = self.acquire(force = False) + + # fallback to read only if failed + if rc.bad(): + rc.annotate(show_status = False) + print format_text("Switching to read only mode - only few commands will be available", 'bold') + + self.release(self.get_acquired_ports()) + self.read_only = True + else: + self.read_only = False + + elif mode == "RWF": + rc = self.acquire(force = True) + if rc.bad(): + return rc self.read_only = False + elif mode == "RO": + # no acquire on read only + rc = RC_OK() + self.read_only = True + + self.connected = True - return rc + return RC_OK() def is_read_only (self): @@ -653,8 +672,8 @@ class CTRexStatelessClient(object): rc.annotate("Pinging the server on '{0}' port '{1}': ".format(self.get_connection_ip(), self.get_connection_port())) return rc - def cmd_connect(self, force): - rc = self.connect(force) + def cmd_connect(self, mode = "RW"): + rc = self.connect(mode) rc.annotate() return rc @@ -846,7 +865,10 @@ class CTRexStatelessClient(object): if opts is None: return RC_ERR("bad command line parameters") - return self.cmd_connect(opts.force) + if opts.force: + rc = self.cmd_connect(mode = "RWF") + else: + rc = self.cmd_connect(mode = "RW") @timing def cmd_start_line (self, line): diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index e8f90186..0ecfce9c 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -114,14 +114,13 @@ class TRexGeneralCmd(cmd.Cmd): class TRexConsole(TRexGeneralCmd): """Trex Console""" - def __init__(self, stateless_client, acquire_all_ports=True, verbose=False): + def __init__(self, stateless_client, verbose=False): self.stateless_client = stateless_client TRexGeneralCmd.__init__(self) self.tui = trex_tui.TrexTUI(stateless_client) self.verbose = verbose - self.acquire_all_ports = acquire_all_ports self.intro = "\n-=TRex Console v{ver}=-\n".format(ver=__version__) self.intro += "\nType 'help' or '?' for supported actions\n" @@ -321,17 +320,13 @@ class TRexConsole(TRexGeneralCmd): def do_connect (self, line): '''Connects to the server\n''' - rc = self.stateless_client.cmd_connect_line(line) - if rc.bad(): - return + self.stateless_client.cmd_connect_line(line) def do_disconnect (self, line): '''Disconnect from the server\n''' - rc = self.stateless_client.cmd_disconnect() - if rc.bad(): - return + self.stateless_client.cmd_disconnect() ############### start @@ -556,6 +551,10 @@ def setParserOptions(): help = "Run the console in a batch mode with file", default = None) + parser.add_argument("-t", "--tui", dest="tui", + action="store_true", help="Starts with TUI mode", + default = False) + return parser @@ -567,17 +566,20 @@ def main(): stateless_client = CTRexStatelessClient(options.user, options.server, options.port, options.pub) print "\nlogged as {0}".format(format_text(options.user, 'bold')) - rc = stateless_client.connect() - # error can be either no able to connect or a read only + # TUI or no acquire will give us READ ONLY mode + if options.tui or not options.acquire: + rc = stateless_client.connect("RO") + else: + rc = stateless_client.connect("RW") + + # unable to connect - bye if rc.bad(): - if not stateless_client.is_connected(): - rc.annotate() - else: - rc.annotate(show_status = False) - print format_text("Switching to read only mode - only few commands will be available", 'bold') + rc.annotate() + return + # a script mode if options.batch: cont = stateless_client.run_script_file(options.batch[0]) if not cont: @@ -585,8 +587,12 @@ def main(): # console try: - console = TRexConsole(stateless_client, options.acquire, options.verbose) - console.cmdloop() + console = TRexConsole(stateless_client, options.verbose) + if options.tui: + console.do_tui("") + else: + console.cmdloop() + except KeyboardInterrupt as e: print "\n\n*** Caught Ctrl + C... Exiting...\n\n" |