3 from monitor.wrapper import plc
6 from monitor import database
7 from pcucontrol import reboot
10 from monitor.common import *
12 from monitor import util
13 from monitor import parser as parsermodule
14 from monitor.model import *
17 parser = parsermodule.getParser()
18 parser.set_defaults(site=None,
23 parser.add_option("", "--site", dest="site", metavar="login_base",
24 help="The sitename to present")
25 parser.add_option("", "--findbad", dest="findbad", action="store_true",
26 help="Re-run findbad on the nodes we're going to check before acting.")
27 parser.add_option("", "--enable", dest="enable", action="store_true",
29 parser.add_option("", "--disable", dest="disable", action="store_true",
31 config = parsermodule.parse_args(parser)
33 def color_sitestatus(status):
36 elif status == "down":
42 def pf_print_siteinfo(sitename):
43 pf = PersistFlags(sitename, 1, db='site_persistflags')
44 if pf.checkattr('last_changed'):
45 print " Checked: %s" % diff_time(pf.last_checked)
46 print "\t status | nodes up / total | last_change"
47 print "\t %6s | %8s / %5s | %s" % \
48 ( color_sitestatus(pf.status), pf.nodes_up, pf.nodes_total, diff_time(pf.last_changed) )
50 print "no such site in pf"
54 def plc_print_siteinfo(plcsite):
56 print " Checked: %s" % time.ctime()
57 print "\t login_base | used / max | enabled | last_updated "
58 print "\t %13s | %4s / %3s | %7s | %12s" % \
59 (plcsite['login_base'],
60 len(plcsite['slice_ids']),
61 plcsite['max_slices'],
63 diff_time(plcsite['last_updated']))
66 nodes = api.GetNodes(plcsite['node_ids'])
67 print " Checked: %s" % time.ctime()
68 print "\t host | state | obs | created | updated | last_contact "
70 fbnode = FindbadNodeRecord.get_latest_by(hostname=plcnode['hostname']).to_dict()
71 plcnode['state'] = color_boot_state(get_current_state(fbnode))
72 print "\t %37s | %5s | %5s | %11.11s | %11.11s | %12s " % \
73 (plcnode['hostname'], color_boot_state(plcnode['boot_state']), plcnode['state'],
74 diff_time(plcnode['date_created']), diff_time(plcnode['last_updated']),
75 diff_time(plcnode['last_contact']))
78 act_all = database.dbLoad("act_all")
80 for site in config.args:
83 plc_siteinfo = api.GetSites({'login_base': config.site})[0]
84 url = "https://www.planet-lab.org/db/sites/index.php?site_pattern="
85 plc_siteinfo['url'] = url + plc_siteinfo['login_base']
88 # rerun findbad with the nodes in the given nodes.
91 nodes = api.GetNodes(plc_siteinfo['node_ids'], ['hostname'])
92 nodes = [ n['hostname'] for n in nodes ]
93 util.file.setFileFromList(file, nodes)
94 os.system("./findbad.py --cachenodes --debug=0 --dbname=findbad --increment --nodelist %s" % file)
96 print "%(login_base)s %(url)s" % plc_siteinfo
97 pf_print_siteinfo(config.site)
98 plc_print_siteinfo(plc_siteinfo)
101 api.UpdateSite(config.site, {'enabled' : True})
103 api.UpdateSite(config.site, {'enabled' : False})