3 from monitor.wrapper import plc
6 from monitor import database
7 from monitor.pcu import reboot
11 from nodecommon import *
13 from monitor import util
14 from monitor import parser as parsermodule
15 from unified_model import *
18 parser = parsermodule.getParser()
19 parser.set_defaults(site=None,
24 parser.add_option("", "--site", dest="site", metavar="login_base",
25 help="The sitename to present")
26 parser.add_option("", "--findbad", dest="findbad", action="store_true",
27 help="Re-run findbad on the nodes we're going to check before acting.")
28 parser.add_option("", "--enable", dest="enable", action="store_true",
30 parser.add_option("", "--disable", dest="disable", action="store_true",
32 config = parsermodule.parse_args(parser)
34 def color_sitestatus(status):
37 elif status == "down":
43 def pf_print_siteinfo(sitename):
44 pf = PersistFlags(sitename, 1, db='site_persistflags')
45 if pf.checkattr('last_changed'):
46 print " Checked: %s" % diff_time(pf.last_checked)
47 print "\t status | nodes up / total | last_change"
48 print "\t %6s | %8s / %5s | %s" % \
49 ( color_sitestatus(pf.status), pf.nodes_up, pf.nodes_total, diff_time(pf.last_changed) )
51 print "no such site in pf"
55 def plc_print_siteinfo(plcsite):
57 print " Checked: %s" % time.ctime()
58 print "\t login_base | used / max | enabled | last_updated "
59 print "\t %13s | %4s / %3s | %7s | %12s" % \
60 (plcsite['login_base'],
61 len(plcsite['slice_ids']),
62 plcsite['max_slices'],
64 diff_time(plcsite['last_updated']))
67 nodes = api.GetNodes(plcsite['node_ids'])
68 print " Checked: %s" % time.ctime()
69 print "\t host | state | obs | created | updated | last_contact "
71 fbnode = FindbadNodeRecord.get_latest_by(hostname=plcnode['hostname']).to_dict()
72 plcnode['state'] = color_boot_state(get_current_state(fbnode))
73 print "\t %37s | %5s | %5s | %11.11s | %11.11s | %12s " % \
74 (plcnode['hostname'], color_boot_state(plcnode['boot_state']), plcnode['state'],
75 diff_time(plcnode['date_created']), diff_time(plcnode['last_updated']),
76 diff_time(plcnode['last_contact']))
79 act_all = database.dbLoad("act_all")
81 for site in config.args:
84 plc_siteinfo = api.GetSites({'login_base': config.site})[0]
85 url = "https://www.planet-lab.org/db/sites/index.php?site_pattern="
86 plc_siteinfo['url'] = url + plc_siteinfo['login_base']
89 # rerun findbad with the nodes in the given nodes.
92 nodes = api.GetNodes(plc_siteinfo['node_ids'], ['hostname'])
93 nodes = [ n['hostname'] for n in nodes ]
94 util.file.setFileFromList(file, nodes)
95 os.system("./findbad.py --cachenodes --debug=0 --dbname=findbad --increment --nodelist %s" % file)
97 print "%(login_base)s %(url)s" % plc_siteinfo
98 pf_print_siteinfo(config.site)
99 plc_print_siteinfo(plc_siteinfo)
102 api.UpdateSite(config.site, {'enabled' : True})
104 api.UpdateSite(config.site, {'enabled' : False})