- Timestamp:
- Apr 12, 2012, 7:34:31 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/check-batch-cmd
r10433 r10434 51 51 pass 52 52 53 class ConnectError(Exception): 54 pass 55 53 56 54 57 55 58 def host_ssh_cmd(hostname, cmd): 56 ssh = paramiko.SSHClient() 57 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 58 ssh.connect(hostname, username='root', password=SSHPASS,timeout=3) 59 stdin, stdout, stderr = ssh.exec_command(cmd) 60 stdout = stdout.readlines() 61 stderr = stderr.readlines() 62 ssh.close() 63 if stderr: 64 raise CmdError((stderr, stdout)) 65 return stdout 59 try: 60 ssh = paramiko.SSHClient() 61 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 62 ssh.connect(hostname, username='root', password=SSHPASS,timeout=3) 63 stdin, stdout, stderr = ssh.exec_command(cmd) 64 stdout = stdout.readlines() 65 stderr = stderr.readlines() 66 ssh.close() 67 if stderr: 68 raise CmdError((stderr, stdout)) 69 return stdout 70 except socket.error, e: 71 raise ConnectError(e) 66 72 67 73 def parse_ini(lines): … … 168 174 parser = argparse.ArgumentParser(prog='Various WL management tools') 169 175 parser.add_argument('--ask-pass', dest="ask_pass", action='store_true', help='Ask password if SSHPASS is not found') 176 parser.add_argument('--filter', dest="use_filter", action='store_true', help='Thread the host definition as an filter') 170 177 subparsers = parser.add_subparsers(help='sub-command help') 171 178 … … 189 196 SSHPASS = getpass.getpass("WL root password: ") 190 197 191 # XXX: We need this loop when using filters 192 #for host in gformat.get_hostlist(): 193 # if filters and not any([f.lower() in host.lower() for f in filters]): 194 # continue 195 196 197 if args.func == 'bridge': 198 if args.action == 'keys': 199 ubnt_keys(args.host) 200 elif args.action == 'snmp': 201 ubnt_snmp(args.host) 202 elif args.action == 'probe': 203 ubnt_probe(args.host) 204 elif args.func == 'node': 205 if args.action == 'check': 206 node_check(args.host) 198 199 if args.use_filter: 200 hosts = [] 201 for host in gformat.get_hostlist(): 202 if args.host in host: 203 hosts.append(host) 204 else: 205 hosts = [args.host] 206 207 208 for host in hosts: 209 try: 210 if args.func == 'bridge': 211 if args.action == 'keys': 212 ubnt_keys(host) 213 elif args.action == 'snmp': 214 ubnt_snmp(host) 215 elif args.action == 'probe': 216 ubnt_probe(host) 217 elif args.func == 'node': 218 if args.action == 'check': 219 node_check(host) 220 except ConnectError: 221 print "#ERR: Connection failed to host %s" % host
Note:
See TracChangeset
for help on using the changeset viewer.