From: Stephen Soltesz Date: Tue, 25 May 2010 21:15:27 +0000 (+0000) Subject: add generic routines for manipulating lists from PLCAPI X-Git-Tag: monitor-3.1-1~42 X-Git-Url: http://git.onelab.eu/?p=monitor.git;a=commitdiff_plain;h=1b7c976ee5db56ce00ee045768283db1a07f3571 add generic routines for manipulating lists from PLCAPI --- diff --git a/monitor/wrapper/plccache.py b/monitor/wrapper/plccache.py index dbfb7e0..524b045 100755 --- a/monitor/wrapper/plccache.py +++ b/monitor/wrapper/plccache.py @@ -5,7 +5,29 @@ from monitor.wrapper import plc from monitor.database.info.model import * import profile +def d_from_l(l, key): + d = {} + for obj in l: + if not str(obj[key]) in d: + d[str(obj[key])] = obj + else: + print "Two objects have the same %s key %s!" % (key, obj[key]) + continue + return d + +def dpcus_from_lpcus(l_pcus): + d_pcus = d_from_l(l_pcus, 'pcu_id') + return d_pcus + +def dnodes_from_lnodes(l_nodes): + d_nodes = d_from_l(l_nodes, 'hostname') + return d_nodes + def dsites_from_lsites(l_sites): + d_sites = d_from_l(l_sites, 'login_base') + return d_sites + +def dsites_from_lsites_id(l_sites): d_sites = {} id2lb = {} for site in l_sites: @@ -93,7 +115,7 @@ def init(): l_pcus.append(pcu) print >>sys.stderr, "building id2lb" - (d_sites,id2lb) = dsites_from_lsites(l_sites) + (d_sites,id2lb) = dsites_from_lsites_id(l_sites) print >>sys.stderr, "building lb2hn" (plcdb, hn2lb, lb2hn) = dsn_from_dsln(d_sites, id2lb, l_nodes) @@ -115,6 +137,7 @@ def GetNodesBySite(loginbase): return GetNodesByIds(site.plc_site_stats['node_ids']) def GetNodeByName(hostname): + print "GetNodeByName %s" % hostname node = PlcNode.get_by(hostname=hostname) return node.plc_node_stats