From 2001167f89a1d9d2e9ef2c2fe93e7df26173b9ee Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Tue, 13 May 2008 18:09:47 +0000 Subject: [PATCH] Improvements for older records. Consolidated code related to ending a record. --- nodegroups.py | 58 ++++++++++++++++++---------- nodeinfo.py | 102 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 107 insertions(+), 53 deletions(-) diff --git a/nodegroups.py b/nodegroups.py index 7ec1dde..90ca183 100755 --- a/nodegroups.py +++ b/nodegroups.py @@ -19,26 +19,26 @@ api = plc.PLC(auth.auth, auth.plc) from config import config from optparse import OptionParser +from sets import Set +from nodecommon import * import soltesz fb = soltesz.dbLoad("findbad") -def get_current_state(fbnode): - state = fbnode['state'] - l = state.lower() - if l == "debug": return 'dbg' - return l - parser = OptionParser() parser.set_defaults(nodegroup="Alpha", node=None, nodelist=None, list=False, add=False, + notng=False, delete=False, ) +parser.add_option("", "--not", dest="notng", action="store_true", + help="All nodes NOT in nodegroup.") parser.add_option("", "--nodegroup", dest="nodegroup", metavar="NodegroupName", help="Specify a nodegroup to perform actions on") + parser.add_option("", "--list", dest="list", action="store_true", help="List all nodes in the given nodegroup") parser.add_option("", "--add", dest="add", action="store_true", @@ -53,25 +53,45 @@ config = config(parser) config.parse_args() # COLLECT nodegroups, nodes and node lists -ng = api.GetNodeGroups({'name' : config.nodegroup}) -nodelist = api.GetNodes(ng[0]['node_ids']) -hostnames = [ n['hostname'] for n in nodelist ] - if config.node or config.nodelist: - if config.node: hostnames = [ config.node ] - else: hostnames = config.getListFromFile(config.nodelist) + if config.node: + hostlist = [ config.node ] + else: + hostlist = config.getListFromFile(config.nodelist) + nodelist = api.GetNodes(hostlist) + + group_str = "Given" + +else: + ng = api.GetNodeGroups({'name' : config.nodegroup}) + nodelist = api.GetNodes(ng[0]['node_ids']) + + group_str = config.nodegroup + +if config.notng: + # Get nodegroup nodes + ng_nodes = nodelist + + # Get all nodes + all_nodes = api.GetNodes({'peer_id': None}) + + # remove ngnodes from all node list + ng_list = [ x['hostname'] for x in ng_nodes ] + all_list = [ x['hostname'] for x in all_nodes ] + not_ng_nodes = Set(all_list) - Set(ng_list) + + # keep each node that *is* in the not_ng_nodes set + nodelist = filter(lambda x : x['hostname'] in not_ng_nodes, all_nodes) + +hostnames = [ n['hostname'] for n in nodelist ] # commands: if config.list: - print " ---- Nodes in the %s Node Group ----" % config.nodegroup - i = 0 + print " ---- Nodes in the %s Node Group ----" % group_str + i = 1 for node in nodelist: print "%-2d" % i, - if node['hostname'] in fb['nodes']: - node['current'] = get_current_state(fb['nodes'][node['hostname']]['values']) - else: - node['current'] = 'none' - print "%(hostname)-38s %(boot_state)5s %(current)5s %(key)s" % node + print nodegroup_display(node, fb) i += 1 elif config.add: diff --git a/nodeinfo.py b/nodeinfo.py index 5c6f422..be2b93c 100755 --- a/nodeinfo.py +++ b/nodeinfo.py @@ -12,6 +12,7 @@ import reboot import time from model import * +from nodecommon import * from config import config from optparse import OptionParser @@ -22,11 +23,15 @@ parser.add_option("", "--node", dest="node", metavar="nodename.edu", help="A single node name to add to the nodegroup") parser.add_option("", "--endrecord", dest="endrecord", action="store_true", help="Force an end to the action record; to prompt Montior to start messaging again.") +parser.add_option("", "--bootcd", dest="bootcd", action="store_true", + help="A stock help message for fetching a new BootCD from the PLC GUI.") config = config(parser) config.parse_args() def diff_time(timestamp): now = time.time() + if timestamp == None: + return "unknown" diff = now - timestamp # return the number of seconds as a difference from current time. t_str = "" @@ -57,11 +62,11 @@ def plc_print_nodeinfo(plcnode): print "%(hostname)s %(url)s" % plcnode print " Checked: %s" % time.ctime() - print "\t boot_state | created | updated | last_contact" - print "\t %10.10s | %11.11s | %11.11s | %12s" % \ - (plcnode['boot_state'], diff_time(plcnode['date_created']), + print "\t boot_state | created | updated | last_contact | key" + print "\t %5s | %11.11s | %11.11s | %12s | %s" % \ + (color_boot_state(plcnode['boot_state']), diff_time(plcnode['date_created']), diff_time(plcnode['last_updated']), - diff_time(plcnode['last_contact'])) + diff_time(plcnode['last_contact']), plcnode['key']) def fb_print_nodeinfo(fbnode): print " Checked: ", @@ -74,17 +79,22 @@ def fb_print_nodeinfo(fbnode): fbnode['bootcd'] = fbnode['bootcd'].split()[-1] else: fbnode['bootcd'] = "unknown" + if 'state' in fbnode: + fbnode['state'] = color_boot_state(get_current_state(fbnode)) + else: + fbnode['state'] = "none" fbnode['kernel'] = fbnode['kernel'].split()[2] - print "\t %(state)10.10s | %(ssh)5.5s | %(pcu)5.5s | %(bootcd)6.6s | %(category)8.8s | %(kernel)s" % fbnode + print "\t %(state)5s | %(ssh)5.5s | %(pcu)5.5s | %(bootcd)6.6s | %(category)8.8s | %(kernel)s" % fbnode def act_print_nodeinfo(actnode, header): if header[0]: - print " Created: %11.11s" % diff_time(actnode['date_created']) + if 'date_created' in actnode: + print " Created: %11.11s" % diff_time(actnode['date_created']) print " LastTime %11.11s" % diff_time(actnode['time']) print "\t RT | category | action | msg" header[0] = False - if 'rt' in actnode: + if 'rt' in actnode and 'Status' in actnode['rt']: print "\t %5.5s %5.5s | %8.8s | %15.15s | %s" % \ (actnode['rt']['Status'], actnode['rt']['id'][7:], actnode['category'], actnode['action'][0], @@ -99,10 +109,15 @@ def act_print_nodeinfo(actnode, header): else: category = "none" - print "\t %5.5s | %8.8s | %15.15s | %s" % \ + if 'msg_format' in actnode: + print "\t %5.5s | %8.8s | %15.15s | %s" % \ (actnode['ticket_id'], category, action, actnode['msg_format'][:-1]) + else: + print "\t %5.5s | %8.8s | %15.15s" % \ + (actnode['ticket_id'], + category, action) def pcu_print_info(pcuinfo, hostname): print " Checked: ", @@ -111,22 +126,23 @@ def pcu_print_info(pcuinfo, hostname): else: print "Unknown" - print "\t user | password | port | hostname " - print "\t %17s | %17s | %4s | %30s | %s" % \ + print "\t user | password | port | pcu_id | hostname " + print "\t %17s | %17s | %4s | %6s | %30s | %s" % \ (pcuinfo['username'], pcuinfo['password'], - pcuinfo[hostname], reboot.pcu_name(pcuinfo), pcuinfo['model']) - - if pcuinfo['portstatus']['22'] == "open": - print "\t ssh -o PasswordAuthentication=yes -o PubkeyAuthentication=no %s@%s" % (pcuinfo['username'], reboot.pcu_name(pcuinfo)) - if pcuinfo['portstatus']['23'] == "open": - print "\t telnet %s" % (reboot.pcu_name(pcuinfo)) - if pcuinfo['portstatus']['80'] == "open" or \ - pcuinfo['portstatus']['443'] == "open": - print "\t http://%s" % (reboot.pcu_name(pcuinfo)) - if pcuinfo['portstatus']['443'] == "open": - print "\t racadm.py -r %s -u %s -p '%s'" % (pcuinfo['ip'], pcuinfo['username'], pcuinfo['password']) - print "\t cmdhttps/locfg.pl -s %s -f iloxml/Reset_Server.xml -u %s -p %s | grep MESSAGE" % \ - (reboot.pcu_name(pcuinfo), pcuinfo['username'], pcuinfo['password']) + pcuinfo[hostname], pcuinfo['pcu_id'], reboot.pcu_name(pcuinfo), pcuinfo['model']) + + if 'portstatus' in pcuinfo and pcuinfo['portstatus'] != {} and pcuinfo['portstatus'] != None: + if pcuinfo['portstatus']['22'] == "open": + print "\t ssh -o PasswordAuthentication=yes -o PubkeyAuthentication=no %s@%s" % (pcuinfo['username'], reboot.pcu_name(pcuinfo)) + if pcuinfo['portstatus']['23'] == "open": + print "\t telnet %s" % (reboot.pcu_name(pcuinfo)) + if pcuinfo['portstatus']['80'] == "open" or \ + pcuinfo['portstatus']['443'] == "open": + print "\t http://%s" % (reboot.pcu_name(pcuinfo)) + if pcuinfo['portstatus']['443'] == "open": + print "\t racadm.py -r %s -u %s -p '%s'" % (pcuinfo['ip'], pcuinfo['username'], pcuinfo['password']) + print "\t cmdhttps/locfg.pl -s %s -f iloxml/Reset_Server.xml -u %s -p '%s' | grep MESSAGE" % \ + (reboot.pcu_name(pcuinfo), pcuinfo['username'], pcuinfo['password']) for node in config.args: config.node = node @@ -145,19 +161,37 @@ for node in config.args: header = [True] if config.endrecord: - a = Action(config.node, act_all[config.node][0]) - a.delField('rt') - a.delField('second-mail-at-oneweek') - a.delField('second-mail-at-twoweeks') - a.delField('first-found') - rec = a.get() - rec['action'] = ["close_rt"] - rec['category'] = "UNKNOWN" - rec['stage'] = "monitor-end-record" - rec['time'] = time.time() - 7*60*60*24 - act_all[config.node].insert(0,rec) + node_end_record(config.node) + #a = Action(config.node, act_all[config.node][0]) + #a.delField('rt') + #a.delField('found_rt_ticket') + #a.delField('second-mail-at-oneweek') + #a.delField('second-mail-at-twoweeks') + #a.delField('first-found') + #rec = a.get() + #rec['action'] = ["close_rt"] + #rec['category'] = "UNKNOWN" + #rec['stage'] = "monitor-end-record" + #rec['time'] = time.time() - 7*60*60*24 + #act_all[config.node].insert(0,rec) + #soltesz.dbDump("act_all", act_all) for act_nodeinfo in act_all[config.node]: act_print_nodeinfo(act_nodeinfo, header) else: act_nodeinfo = None + print "" + + if config.bootcd: + print """ +If you need a new bootcd, the steps are very simple: + +Visit: + * https://www.planet-lab.org/db/nodes/index.php?nodepattern=%s + * Select Download -> Download ISO image for %s + * Save the ISO, and burn it to a writable CD-ROM. + * Replace the old CD and reboot the machine. + +Please let me know if you have any additional questions. +""" % (config.node, config.node) + -- 2.43.0