1- import argparse
21import pexpect
32import subprocess
4- import sys
53from pexpect import pxssh
64
75from log import logger
86from remote_commands import cmd_list
97
10- parser = argparse .ArgumentParser (description = "Noninteractive and Interactive \
11- command execution. Must provide all the details in cmd_list \
12- in remote_commands.py for interactive commands." )
8+ import arguments
139
14- parser .add_argument ("command" , help = "provide command. If interactive, \
15- should be one of commands in remote_commands.py or all which would \
16- execute every command in remote_commands.py one after another. e.g.\n \
17- python shell.py testshell1 127.0.0.1 root password \n \
18- python shell.py all 127.0.0.1 root password" )
19-
20- parser .add_argument ("host" , help = "provide host name" , nargs = "?" ,
21- default = "localhost" )
22- parser .add_argument ("username" , help = "provide user name" , nargs = "?" ,
23- default = "root" )
24- parser .add_argument ("password" , help = "provide password" , nargs = "?" ,
25- default = "netsim" )
26- #parser.add_argument("cmd_type", nargs='?',
27- # help="provide i for interactive, n for non-interactive", default="n")
28-
29- if len (sys .argv ) < 2 :
30- parser .print_help ()
31- sys .exit (1 )
32-
33- args = parser .parse_args ()
10+ args = arguments .args
3411
12+ # Setting command type to interactive if given command is found in cmd_list
3513interactive = False
3614icmd = None
3715for i in cmd_list :
@@ -56,7 +34,7 @@ def remote(self):
5634 password = self .password
5735 s .login (hostname , username , password )
5836 if not interactive and args .command != "all" :
59- self .exec_remote_normal (s = s )
37+ self .exec_remote_noninteractive (s = s )
6038 elif args .command != "all" :
6139 self .exec_remote (s = s )
6240 else :
@@ -95,7 +73,7 @@ def exec_remote_all(self, s):
9573 logger .info (s .before )
9674 logger .info (s .after )
9775
98- def exec_remote_normal (self ,s ):
76+ def exec_remote_noninteractive (self ,s ):
9977 logger .info ("remote non-interactive" )
10078 cur_cmd = self .command
10179 logger .info ("Executing COMMAND {0}" .format (cur_cmd ) +
0 commit comments