4 from monitor.wrapper import plc
5 from monitor import database
6 from monitor import config
8 def dsites_from_lsites(l_sites):
12 if not site['login_base'] in d_sites:
13 d_sites[site['login_base']] = site
14 id2lb[site['site_id']] = site['login_base']
16 #print "Two sites have the same login_base value %s!" % site['login_base']
19 return (d_sites, id2lb)
21 def dsn_from_dsln(d_sites, id2lb, l_nodes):
26 if id2lb[id] not in lb2hn:
30 # this won't reach sites without nodes, which I guess isn't a problem.
31 if node['site_id'] in id2lb.keys():
32 login_base = id2lb[node['site_id']]
34 print "%s has a foreign site_id %s" % (node['hostname'],
38 print i, " ", id2lb[i]
39 raise Exception, "Node has missing site id!! %s %d" %(node['hostname'], node['site_id'])
40 if not login_base in dsn:
41 lb2hn[login_base] = []
43 dsn[login_base]['plc'] = d_sites[login_base]
44 dsn[login_base]['monitor'] = {} # event log, or something
46 hostname = node['hostname']
47 lb2hn[login_base].append(node)
48 dsn[login_base][hostname] = {}
49 dsn[login_base][hostname]['plc'] = node
50 dsn[login_base][hostname]['comon'] = {}
51 dsn[login_base][hostname]['monitor'] = {}
53 hn2lb[hostname] = login_base
54 return (dsn, hn2lb, lb2hn)
56 def create_netid2ip(l_nodes, l_nodenetworks):
59 for netid in node['nodenetwork_ids']:
61 for nn in l_nodenetworks:
62 if nn['nodenetwork_id'] == netid:
64 netid2ip[netid] = nn['ip']
66 print "ERROR! %s" % node
90 api = plc.getCachedAuthAPI()
91 l_sites = api.GetSites({'peer_id':None},
92 ['login_base', 'site_id', 'abbreviated_name', 'latitude',
93 'longitude', 'max_slices', 'slice_ids', 'node_ids', 'enabled' ])
94 l_nodes = api.GetNodes({'peer_id':None},
95 ['hostname', 'node_id', 'ports', 'site_id', 'version', 'last_updated',
96 'date_created', 'last_contact', 'pcu_ids', 'nodenetwork_ids'])
97 l_pcus = api.GetPCUs()
98 l_nodenetworks = api.GetNodeNetworks()
100 (d_sites,id2lb) = dsites_from_lsites(l_sites)
101 (plcdb, hn2lb, lb2hn) = dsn_from_dsln(d_sites, id2lb, l_nodes)
102 netid2ip = create_netid2ip(l_nodes, l_nodenetworks)
106 plcdb_netid2ip = netid2ip
114 # get sites, and stats
115 l_sites = plc.getSites({'peer_id':None}, ['login_base', 'site_id', 'abbreviated_name', 'latitude', 'longitude',
116 'max_slices', 'slice_ids', 'node_ids' ])
117 if len(l_sites) == 0:
118 print "no sites! exiting..."
120 (d_sites,id2lb) = dsites_from_lsites(l_sites)
122 # get nodes at each site, and
123 l_nodes = plc.getNodes({'peer_id':None}, ['hostname', 'node_id', 'ports', 'site_id', 'version',
124 'last_updated', 'date_created', 'last_contact', 'pcu_ids', 'nodenetwork_ids'])
126 l_nodenetworks = plc.getNodeNetworks()
127 (plcdb, hn2lb, lb2hn) = dsn_from_dsln(d_sites, id2lb, l_nodes)
128 netid2ip = create_netid2ip(l_nodes, l_nodenetworks)
130 # save information for future.
135 if ('cachenodes' in dir(config) and config.cachenodes) or \
136 'cachenodes' not in dir(config):
137 database.dbDump("plcdb_hn2lb", hn2lb)
138 database.dbDump("plcdb_lb2hn", lb2hn)
139 database.dbDump("plcdb_netid2ip", netid2ip)
140 database.dbDump("l_plcnodenetworks", l_nodenetworks)
141 database.dbDump("l_plcnodes", l_nodes)
142 database.dbDump("l_plcsites", l_sites)
146 if __name__ == '__main__':
149 #print "calling plccache init()"