merge from:
[monitor.git] / syncplcdb.py
index d83e8d3..73a6e57 100755 (executable)
@@ -1,11 +1,9 @@
 #!/usr/bin/python
 
-import plc
-from config import config
-import soltesz
 import sys
-
-config = config()
+from monitor.wrapper import plc
+from monitor import database
+from monitor import config
 
 def dsites_from_lsites(l_sites):
        d_sites = {}
@@ -28,6 +26,9 @@ def dsn_from_dsln(d_sites, id2lb, l_nodes):
                if node['site_id'] in id2lb.keys():
                        login_base = id2lb[node['site_id']]
                else:
+                       print "%s has a foreign site_id %s" % (node['hostname'], 
+                                                                                                       node['site_id'])
+                       continue
                        for i in id2lb:
                                print i, " ", id2lb[i]
                        raise Exception, "Node has missing site id!! %s %d" %(node['hostname'], node['site_id'])
@@ -61,6 +62,44 @@ def create_netid2ip(l_nodes, l_nodenetworks):
 
        return netid2ip
 
+l_sites = None
+l_nodes = None
+l_pcus = None
+l_nodenetworks = None
+
+plcdb_hn2lb = None
+plcdb_lb2hn = None
+plcdb_netid2ip = None
+
+def init():
+       global l_sites
+       global l_nodes
+       global l_pcus
+       global l_nodenetworks
+       global plcdb_hn2lb
+       global plcdb_lb2hn
+       global plcdb_netid2ip
+
+       api = plc.getCachedAuthAPI()
+       l_sites = api.GetSites({'peer_id':None}, 
+                                                       ['login_base', 'site_id', 'abbreviated_name', 'latitude', 
+                                                       'longitude', 'max_slices', 'slice_ids', 'node_ids' ])
+       l_nodes = api.GetNodes({'peer_id':None}, 
+                                                       ['hostname', 'node_id', 'ports', 'site_id', 'version', 'last_updated', 
+                                                        'date_created', 'last_contact', 'pcu_ids', 'nodenetwork_ids'])
+       l_pcus = api.GetPCUs()
+       l_nodenetworks = api.GetNodeNetworks()
+
+       (d_sites,id2lb) = dsites_from_lsites(l_sites)
+       (plcdb, hn2lb, lb2hn) = dsn_from_dsln(d_sites, id2lb, l_nodes)
+       netid2ip = create_netid2ip(l_nodes, l_nodenetworks)
+
+       plcdb_hn2lb = hn2lb
+       plcdb_lb2hn = lb2hn
+       plcdb_netid2ip = netid2ip
+       
+       return l_nodes
+
 def create_plcdb():
 
        # get sites, and stats
@@ -85,12 +124,12 @@ def create_plcdb():
 
        if ('cachenodes' in dir(config) and config.cachenodes) or \
                'cachenodes' not in dir(config):
-               soltesz.dbDump("plcdb_hn2lb", hn2lb)
-               soltesz.dbDump("plcdb_lb2hn", lb2hn)
-               soltesz.dbDump("plcdb_netid2ip", netid2ip)
-               soltesz.dbDump("l_plcnodenetworks", l_nodenetworks)
-               soltesz.dbDump("l_plcnodes", l_nodes)
-               soltesz.dbDump("l_plcsites", l_sites)
+               database.dbDump("plcdb_hn2lb", hn2lb)
+               database.dbDump("plcdb_lb2hn", lb2hn)
+               database.dbDump("plcdb_netid2ip", netid2ip)
+               database.dbDump("l_plcnodenetworks", l_nodenetworks)
+               database.dbDump("l_plcnodes", l_nodes)
+               database.dbDump("l_plcsites", l_sites)
        
        return l_nodes