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 Find the IP address assigned to a virtual interface in the topology
72 (for creating /etc/hosts)
74 def get_virt_ip(myid, nodeid):
76 virtip = "10.%d.%d.2" % (myid, nodeid)
78 virtip = "10.%d.%d.3" % (nodeid, myid)
83 Create a dictionary of site records keyed by site ID
87 for site in GetSites():
88 t = site['site_id'], site
94 Create a dictionary of node records keyed by node ID
98 for node in GetNodes():
99 t = node['node_id'], node
106 """ Need global topology information """
110 for slice in GetSlices():
111 """ Create dictionary of the slice's attributes """
114 for attribute in GetSliceAttributes(slice['slice_attribute_ids']):
115 attrs[attribute['name']] = attribute['slice_attribute_id']
116 if attribute['name'] == 'topo_rspec' and attribute['node_id']:
117 topo_attr[attribute['node_id']] = attribute['slice_attribute_id']
119 if 'egre_key' in attrs:
120 #print "Virtual topology for %s:" % slice['name']
121 slicenodes = set(slice['node_ids'])
122 hosts = "127.0.0.1\t\tlocalhost\n"
124 For each node in the slice, check whether nodes at adjacent sites
125 are also in the slice's node set. If so, add a virtual link to
128 for node in slicenodes:
130 for adj in adjacencies[get_site(node)]:
131 for adj_node in get_sitenodes(adj):
132 if node != adj_node and adj_node in slicenodes:
133 link = adj_node, get_ipaddr(adj_node), "1Mbit"
135 shortname = nodes[node]['hostname'].replace('.vini-veritas.net', '')
136 hosts += "%s\t\t%s\n" % (get_virt_ip(node, adj_node),
138 topo_str = "%s" % topo
139 #print node, topo_str
140 if node in topo_attr:
141 UpdateSliceAttribute(topo_attr[node], topo_str)
144 id = slice['slice_id']
145 AddSliceAttribute(id, 'topo_rspec', topo_str, node)
149 UpdateSliceAttribute(attrs['hosts'], hosts)
151 id = slice['slice_id']
152 AddSliceAttribute(id, 'hosts', hosts)
154 #print "No EGRE key for %s" % slice['name']
156 """ Remove old topo_rspec entries """
157 for node in topo_attr:
158 DeleteSliceAttribute(topo_attr[node])