11 from nodecommon import *
15 import parser as parsermodule
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 from unified_model import *
35 def color_sitestatus(status):
38 elif status == "down":
44 def pf_print_siteinfo(sitename):
45 pf = PersistFlags(sitename, 1, db='site_persistflags')
46 if pf.checkattr('last_changed'):
47 print " Checked: %s" % diff_time(pf.last_checked)
48 print "\t status | nodes up / total | last_change"
49 print "\t %6s | %8s / %5s | %s" % \
50 ( color_sitestatus(pf.status), pf.nodes_up, pf.nodes_total, diff_time(pf.last_changed) )
52 print "no such site in pf"
56 def plc_print_siteinfo(plcsite):
58 print " Checked: %s" % time.ctime()
59 print "\t login_base | used / max | enabled | last_updated "
60 print "\t %13s | %4s / %3s | %7s | %12s" % \
61 (plcsite['login_base'],
62 len(plcsite['slice_ids']),
63 plcsite['max_slices'],
65 diff_time(plcsite['last_updated']))
68 nodes = api.GetNodes(plcsite['node_ids'])
69 print " Checked: %s" % time.ctime()
70 print "\t host | state | obs | created | updated | last_contact "
72 fbnode = fb['nodes'][plcnode['hostname']]['values']
73 plcnode['state'] = color_boot_state(get_current_state(fbnode))
74 print "\t %37s | %5s | %5s | %11.11s | %11.11s | %12s " % \
75 (plcnode['hostname'], color_boot_state(plcnode['boot_state']), plcnode['state'],
76 diff_time(plcnode['date_created']), diff_time(plcnode['last_updated']),
77 diff_time(plcnode['last_contact']))
80 fb = database.dbLoad("findbad")
81 act_all = database.dbLoad("act_all")
83 for site in config.args:
86 plc_siteinfo = api.GetSites({'login_base': config.site})[0]
87 url = "https://www.planet-lab.org/db/sites/index.php?site_pattern="
88 plc_siteinfo['url'] = url + plc_siteinfo['login_base']
91 # rerun findbad with the nodes in the given nodes.
94 nodes = api.GetNodes(plc_siteinfo['node_ids'], ['hostname'])
95 nodes = [ n['hostname'] for n in nodes ]
96 util.file.setFileFromList(file, nodes)
97 os.system("./findbad.py --cachenodes --debug=0 --dbname=findbad --increment --nodelist %s" % file)
99 print "%(login_base)s %(url)s" % plc_siteinfo
100 pf_print_siteinfo(config.site)
101 plc_print_siteinfo(plc_siteinfo)
104 api.UpdateSite(config.site, {'enabled' : True})
106 api.UpdateSite(config.site, {'enabled' : False})