add areSlicesEnabled and isSiteEnabled convenience checks
[monitor.git] / commands / pcuinfo.py
1 #!/usr/bin/python
2
3 import database
4 import plc
5 import parser as parsermodule
6 import sys
7 from reboot import pcu_name, get_pcu_values
8
9 import sys
10
11 def print_dict(dict):
12         for key in dict.keys():
13                 print "%30s : %s" % (key, dict[key])
14
15 parser = parsermodule.getParser()
16 parser.set_defaults(withpcu=False,
17                                         refresh=False)
18 parser.add_option("-f", "--nodelist",dest="filename",default="", metavar="FILE",
19                                   help="Provide the input file for the downnode list")
20 parser.add_option("", "--refresh", action="store_true", dest="refresh",
21                                         help="Refresh the cached values")
22
23 config = parsermodule.parse_args(parser)
24
25 if not config.run:
26         k = config.__dict__.keys()
27         k.sort()
28         for o in k:
29                 print o, "=", config.__dict__[o]
30         print "Add --run to actually perform the command"
31         sys.exit(1)
32
33 pculist = plccache.l_pcus # database.if_cached_else_refresh(1, 
34                                                   #     config.refresh, 
35                                                   #     "pculist", 
36                                                   #     lambda : plc.GetPCUs())
37 for pcu in pculist:
38         #print pcu
39         #sys.exit(1)
40         if pcu['model'] == None:
41                 continue
42
43         if True: # pcu['model'].find("APC AP79xx/Masterswitch") >= 0:
44                 host = pcu_name(pcu)
45                 values = get_pcu_values(pcu['pcu_id'])
46                 if 'portstatus' not in values:
47                         portstatus = ""
48                 else:
49                         if values['reboot'] == 0 or (not isinstance(values['reboot'],int) and values['reboot'].find("error") >= 0):
50                                 portstatus = "22:%(22)s 23:%(23)s" % values['portstatus']
51                 if values['reboot'] == 0:
52                         print "%6d %20s %50s %s" % (pcu['pcu_id'], pcu['password'], "%s@%s" % (pcu['username'], host), portstatus)
53
54 #database.dbDump("pculist", pculist, 'php')