5 Scan the VINI Central database and create topology "rspec" attributes for
6 slices that have an EGRE key. This script to be run from a cron job.
13 Map sites to adjacent sites in topology. Generated manually :-(
14 A site is adjacent to itself.
17 1: [1], 2: [2,12], 3: [3], 4: [4,5,6,7,9,10], 5: [4,5,6,8],
18 6: [4,5,6,10], 7: [4,7,8], 8: [5,7,8], 9: [4,9,10], 10: [4,6,9,10],
19 11: [11,13,15,16,17], 12: [2,12,13], 13: [11,12,13,15], 14: [14],
20 15: [11,13,15,19], 16: [11,16], 17: [11,17,19,22], 18: [18],
21 19: [15,17,19,20], 20: [19,20,21,22], 21: [20,21,22], 22: [17,20,21,22]
25 Test whether two sites are adjacent to each other in the adjacency graph.
27 def is_adjacent(s1, s2):
28 set1 = set(adjacencies[s1])
29 set2 = set(adjacencies[s2])
31 if s1 in set2 and s2 in set1:
33 elif not s1 in set2 and not s2 in set1:
36 raise Exception("Adjacency mismatch, sites %d and %d." % (s1, s2))
40 Check the adjacency graph for discrepancies.
42 def check_adjacencies():
43 for site in adjacencies:
44 for adj in adjacencies[site]:
46 test = is_adjacent(site, adj)
48 print "Error: ", e, " Fix adjacencies!"
54 return nodes[nodeid]['site_id']
55 raise Exception("Nodeid %s not found." % nodeid)
58 def get_ipaddr(nodeid):
60 return socket.gethostbyname(nodes[nodeid]['hostname'])
61 raise Exception("Nodeid %s not found." % nodeid)
64 def get_sitenodes(siteid):
66 return sites[siteid]['node_ids']
67 raise Exception("Siteid %s not found." % siteid)
71 Create a dictionary of site records keyed by site ID
75 for site in GetSites():
76 t = site['site_id'], site
82 Create a dictionary of node records keyed by node ID
86 for node in GetNodes():
87 t = node['node_id'], node
94 """ Need global topology information """
98 for slice in GetSlices():
99 """ Create dictionary of the slice's attributes """
102 for attribute in GetSliceAttributes(slice['slice_attribute_ids']):
103 attrs.append(attribute['name'])
104 if attribute['name'] == 'topo_rspec' and attribute['node_id']:
105 topo_attr[attribute['node_id']] = attribute['slice_attribute_id']
107 if 'egre_key' in attrs:
108 print "Virtual topology for %s:" % slice['name']
109 slicenodes = set(slice['node_ids'])
111 For each node in the slice, check whether nodes at adjacent sites
112 are also in the slice's node set. If so, add a virtual link to
115 for node in slicenodes:
117 for adj in adjacencies[get_site(node)]:
118 for adj_node in get_sitenodes(adj):
119 if node != adj_node and adj_node in slicenodes:
120 link = adj_node, get_ipaddr(adj_node), "1Mbit"
122 topo_str = "%s" % topo
124 if node in topo_attr:
125 UpdateSliceAttribute(topo_attr[node], topo_str)
128 id = slice['slice_id']
129 AddSliceAttribute(id, 'topo_rspec', topo_str, node)
131 """ Remove old topo_rspec entries """
132 for node in topo_attr:
133 DeleteSliceAttribute(topo_attr[node])
136 print "No EGRE key for %s" % slice['name']