3 from monitor.wrapper import plc
6 from monitor import database
9 from monitor.common import *
11 from monitor import util
12 from monitor import parser as parsermodule
13 from monitor.model import *
16 parser = parsermodule.getParser()
17 parser.set_defaults(site=None,
22 parser.add_option("", "--site", dest="site", metavar="login_base",
23 help="The sitename to present")
24 parser.add_option("", "--findbad", dest="findbad", action="store_true",
25 help="Re-run findbad on the nodes we're going to check before acting.")
26 parser.add_option("", "--enable", dest="enable", action="store_true",
28 parser.add_option("", "--disable", dest="disable", action="store_true",
30 config = parsermodule.parse_args(parser)
32 def color_sitestatus(status):
35 elif status == "down":
41 def pf_print_siteinfo(sitename):
42 pf = PersistFlags(sitename, 1, db='site_persistflags')
43 if pf.checkattr('last_changed'):
44 print " Checked: %s" % diff_time(pf.last_checked)
45 print "\t status | nodes up / total | last_change"
46 print "\t %6s | %8s / %5s | %s" % \
47 ( color_sitestatus(pf.status), pf.nodes_up, pf.nodes_total, diff_time(pf.last_changed) )
49 print "no such site in pf"
53 def plc_print_siteinfo(plcsite):
55 print " Checked: %s" % time.ctime()
56 print "\t login_base | used / max | enabled | last_updated "
57 print "\t %13s | %4s / %3s | %7s | %12s" % \
58 (plcsite['login_base'],
59 len(plcsite['slice_ids']),
60 plcsite['max_slices'],
62 diff_time(plcsite['last_updated']))
65 nodes = plccache.GetNodesByIds(plcsite['node_ids'])
66 print " Checked: %s" % time.ctime()
67 print "\t host | state | obs | created | updated | last_contact "
69 fbnode = FindbadNodeRecord.get_latest_by(hostname=plcnode['hostname']).to_dict()
70 plcnode['state'] = color_boot_state(get_current_state(fbnode))
71 print "\t %37s | %5s | %5s | %11.11s | %11.11s | %12s " % \
72 (plcnode['hostname'], color_boot_state(plcnode['boot_state']), plcnode['state'],
73 diff_time(plcnode['date_created']), diff_time(plcnode['last_updated']),
74 diff_time(plcnode['last_contact']))
77 act_all = database.dbLoad("act_all")
79 for site in config.args:
82 plc_siteinfo = plccache.GetSitesByName([config.site])
83 url = "https://www.planet-lab.org/db/sites/index.php?site_pattern="
84 plc_siteinfo['url'] = url + plc_siteinfo['login_base']
87 # rerun findbad with the nodes in the given nodes.
90 nodes = plccache.GetNodesByIds(plc_siteinfo['node_ids'])
91 nodes = [ n['hostname'] for n in nodes ]
92 util.file.setFileFromList(file, nodes)
93 os.system("./findbad.py --cachenodes --debug=0 --dbname=findbad --increment --nodelist %s" % file)
95 print "%(login_base)s %(url)s" % plc_siteinfo
96 pf_print_siteinfo(config.site)
97 plc_print_siteinfo(plc_siteinfo)
100 api.UpdateSite(config.site, {'enabled' : True})
102 api.UpdateSite(config.site, {'enabled' : False})