move command.py from monitor module into pcucontrol module. pcucontrol should
[monitor.git] / findbadpcu.py
index 9feb62d..d00d7f7 100755 (executable)
@@ -13,14 +13,13 @@ import threadpool
 import threading
 
 import monitor
-from pcucontrol  import reboot
 from monitor import config
 from monitor.database.info.model import FindbadPCURecordSync, FindbadPCURecord, session
 from monitor import database
 from monitor import util 
 from monitor.wrapper import plc, plccache
 from nodequery import pcu_select
-from nodecommon import nmap_port_status
+from monitor.common import nmap_port_status
 from monitor.scanapi import *
 
 plc_lock = threading.Lock()
@@ -91,9 +90,9 @@ def main():
                                                                                        if_new_set={'round' : global_round})
 
        global_round = fbsync.round
+       api = plc.getAuthAPI()
 
        if config.site is not None:
-               api = plc.getAuthAPI()
                site = api.GetSites(config.site)
                l_nodes = api.GetNodes(site[0]['node_ids'], ['pcu_ids'])
                pcus = []
@@ -101,6 +100,21 @@ def main():
                        pcus += node['pcu_ids']
                # clear out dups.
                l_pcus = [pcu for pcu in sets.Set(pcus)]
+       elif config.sitelist:
+               site_list = config.sitelist.split(',')
+
+               sites = api.GetSites(site_list)
+               node_ids = []
+               for s in sites:
+                       node_ids += s['node_ids']
+
+               l_nodes = api.GetNodes(node_ids, ['pcu_ids'])
+               pcus = []
+               for node in l_nodes:
+                       pcus += node['pcu_ids']
+               # clear out dups.
+               l_pcus = [pcu for pcu in sets.Set(pcus)]
+
        elif config.pcuselect is not None:
                n, pcus = pcu_select(config.pcuselect)
                print pcus
@@ -149,6 +163,7 @@ if __name__ == '__main__':
                                                pcuid=None,
                                                pcuselect=None,
                                                site=None,
+                                               sitelist=None,
                                                dbname="findbadpcus", 
                                                cachenodes=False,
                                                cachecalls=True,
@@ -158,6 +173,8 @@ if __name__ == '__main__':
                                                help="Provide the input file for the node list")
        parser.add_option("", "--site", dest="site", metavar="FILE", 
                                                help="Get all pcus associated with the given site's nodes")
+       parser.add_option("", "--sitelist", dest="sitelist", metavar="FILE", 
+                                               help="Get all pcus associated with the given site's nodes")
        parser.add_option("", "--pcuselect", dest="pcuselect", metavar="FILE", 
                                                help="Query string to apply to the findbad pcus")
        parser.add_option("", "--pcuid", dest="pcuid", metavar="id", 
@@ -188,6 +205,8 @@ if __name__ == '__main__':
                time.sleep(1)
        except Exception, err:
                traceback.print_exc()
+               from monitor.common import email_exception
+               email_exception()
                print "Exception: %s" % err
                print "Saving data... exitting."
                sys.exit(0)