add exception for KeyboardInterrupt to allow for manual stop without
[monitor.git] / monitor / scanapi.py
index 3e95ef2..e1a09e8 100644 (file)
@@ -11,8 +11,7 @@ import threading
 import socket
 from pcucontrol import reboot
 
-from monitor import util
-from monitor.util import command
+from pcucontrol.util import command
 from monitor import config
 
 from monitor.database.info.model import *
@@ -20,9 +19,8 @@ from monitor.database.info.model import *
 from monitor.sources import comon
 from monitor.wrapper import plc, plccache
 
-from nodequery import verify,query_to_dict,node_select
 import traceback
-from nodecommon import nmap_port_status
+from monitor.common import nmap_port_status
 
 COMON_COTOPURL= "http://summer.cs.princeton.edu/status/tabulator.cgi?" + \
                        "table=table_nodeview&" + \
@@ -168,7 +166,7 @@ class ScanNodeInternal(ScanInterface):
        def collectNMAP(self, nodename, cohash):
                #### RUN NMAP ###############################
                values = {}
-               nmap = util.command.CMD()
+               nmap = command.CMD()
                print "nmap -oG - -P0 -p22,80,806 %s | grep Host:" % nodename
                (oval,eval) = nmap.run_noexcept("nmap -oG - -P0 -p22,80,806 %s | grep Host:" % nodename)
                # NOTE: an empty / error value for oval, will still work.
@@ -210,7 +208,7 @@ class ScanNodeInternal(ScanInterface):
                                                echo '  "princeton_comon_running":"'`ls -d /proc/virtual/$ID`'",'
                                                echo '  "princeton_comon_procs":"'`vps ax | grep $ID | grep -v grep | wc -l`'",'
                                                echo "}"
-       EOF                             """)
+EOF                            """)
                                        
                                        values['ssh_error'] = errval
                                        if len(oval) > 0:
@@ -342,7 +340,7 @@ class ScanNodeInternal(ScanInterface):
                        values['plc_node_stats'] = d_node
 
                        ##### NMAP  ###################
-                       (n, v) = collectNMAP(nodename, None)
+                       (n, v) = self.collectNMAP(nodename, None)
                        values.update(v)
 
                        ### GET PLC PCU ######################
@@ -376,7 +374,6 @@ class ScanNodeInternal(ScanInterface):
 
                return (nodename, values)
 
-
 def internalprobe(hostname):
        fbsync = FindbadNodeRecordSync.findby_or_create(hostname="global", 
                                                                                                        if_new_set={'round' : 1})
@@ -434,7 +431,7 @@ class ScanPCU(ScanInterface):
 
                        #### RUN NMAP ###############################
                        if continue_probe:
-                               nmap = util.command.CMD()
+                               nmap = command.CMD()
                                print "nmap -oG - -P0 -p22,23,80,443,5869,9100,16992 %s | grep Host:" % reboot.pcu_name(values['plc_pcu_stats'])
                                (oval,eval) = nmap.run_noexcept("nmap -oG - -P0 -p22,23,80,443,5869,9100,16992 %s | grep Host:" % reboot.pcu_name(values['plc_pcu_stats']))
                                # NOTE: an empty / error value for oval, will still work.
@@ -496,7 +493,7 @@ class ScanPCU(ScanInterface):
 
 
                        ######  DRY RUN  ############################
-                       if 'node_ids' in values['plc_pcu_stats'] and \
+                       if continue_probe and 'node_ids' in values['plc_pcu_stats'] and \
                                len(values['plc_pcu_stats']['node_ids']) > 0:
                                rb_ret = reboot.reboot_test_new(values['plc_pcu_stats']['nodenames'][0], 
                                                                                                values, 1, True)
@@ -512,7 +509,8 @@ class ScanPCU(ScanInterface):
                        print "____________________________________"
                        errors['traceback'] = traceback.format_exc()
                        print errors['traceback']
-                       values['reboot_trial_status'] = errors['traceback']
+                       values['reboot_trial_status'] = str(errors['traceback'])
+                       print values
 
                values['entry_complete']=" ".join(values['entry_complete'])