make work with new libraries
[monitor.git] / getnodes.py
1 #!/usr/bin/python
2
3 import database
4 import plc
5 import sys
6 from reboot import pcu_name, get_pcu_values
7
8 import sys
9 import parser as parsermodule
10
11 parser = parsermodule.getParser()
12 parser.set_defaults(withpcu=False,
13                                         refresh=False)
14 parser.add_option("", "--refresh", action="store_true", dest="refresh",
15                                         help="Refresh the cached values")
16 config = parsermodule.parse_args(parser)
17
18 if not config.run:
19         k = config.__dict__.keys()
20         k.sort()
21         for o in k:
22                 print o, "=", config.__dict__[o]
23         print "Add --run to actually perform the command"
24         sys.exit(1)
25
26 nodelist = database.if_cached_else_refresh(1, 
27                                                         config.refresh, 
28                                                         "l_plcnodes", 
29                                                         lambda : plc.getNodes({'peer_id':None}, ['hostname']))
30 nodes = [n['hostname'] for n in nodelist]
31
32 for nodename in nodes:
33         print nodename