Changeset 10434 in genesis for tools


Ignore:
Timestamp:
Apr 12, 2012, 7:34:31 AM (13 years ago)
Author:
rick
Message:

Lets start storing the board type in gformat, to give a better look of the hardware in production (and check interface naming for example).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/check-batch-cmd

    r10433 r10434  
    5151  pass
    5252
     53class ConnectError(Exception):
     54  pass
     55
    5356
    5457
    5558def 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)
    6672
    6773def parse_ini(lines):
     
    168174  parser = argparse.ArgumentParser(prog='Various WL management tools')
    169175  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')
    170177  subparsers = parser.add_subparsers(help='sub-command help')
    171178 
     
    189196      SSHPASS = getpass.getpass("WL root password: ")
    190197
    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.