Revert create-topo-attributes.py
[nodemanager-topo.git] / create-topo-attributes.py
index 8f26ff8..05b5aba 100755 (executable)
@@ -8,23 +8,29 @@ slices that have an EGRE key.  This script to be run from a cron job.
 
 import string
 import socket
+from topology import links
 
 """
-Map sites to adjacent sites in topology.  Generated manually :-(
-A site is adjacent to itself.
+Generate site adjacency map from list of links
 """
-adjacencies = {
-    1: [1], 2: [2,12], 3: [3], 4: [4,5,6,7,9,10], 5: [4,5,6,8], 
-    6: [4,5,6,10], 7: [4,7,8], 8: [5,7,8], 9: [4,9,10], 10: [4,6,9,10], 
-    11: [11,13,15,16,17], 12: [2,12,13], 13: [11,12,13,15], 14: [14], 
-    15: [11,13,15,19], 16: [11,16], 17: [11,17,19,22], 18: [18], 
-    19: [15,17,19,20], 20: [19,20,21,22], 21: [20,21,22], 22: [17,20,21,22]
-    }
+def gen_adjacencies(links):
+    adj = {}
+    for (a, b) in links:
+        if a in adj:
+            adj[a].append(b)
+        else:
+            adj[a] = [a, b]
+        if b in adj:
+            adj[b].append(a)
+        else:
+            adj[b] = [b, a]
+    return adj
+
 
 """
 Test whether two sites are adjacent to each other in the adjacency graph.
 """
-def is_adjacent(s1, s2):
+def is_adjacent(adjacencies, s1, s2):
     set1 = set(adjacencies[s1])
     set2 = set(adjacencies[s2])
 
@@ -39,11 +45,11 @@ def is_adjacent(s1, s2):
 """
 Check the adjacency graph for discrepancies.
 """
-def check_adjacencies():
+def check_adjacencies(adjacencies):
     for site in adjacencies:
         for adj in adjacencies[site]:
             try:
-                test = is_adjacent(site, adj)
+                test = is_adjacent(adjacencies, site, adj)
             except Exception, e:
                 print "Error: ", e, " Fix adjacencies!"
     return
@@ -100,8 +106,8 @@ def get_nodes():
         tmp.append(t)
     return dict(tmp)
 
-    
-check_adjacencies()
+adjacencies = gen_adjacencies(links)    
+check_adjacencies(adjacencies)
 
 """ Need global topology information """
 sites = get_sites()