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.
11 from topology import links
14 Generate site adjacency map from list of links
16 def gen_adjacencies(links):
31 Test whether two sites are adjacent to each other in the adjacency graph.
33 def is_adjacent(adjacencies, s1, s2):
34 set1 = set(adjacencies[s1])
35 set2 = set(adjacencies[s2])
37 if s1 in set2 and s2 in set1:
39 elif not s1 in set2 and not s2 in set1:
42 raise Exception("Adjacency mismatch, sites %d and %d." % (s1, s2))
46 Check the adjacency graph for discrepancies.
48 def check_adjacencies(adjacencies):
49 for site in adjacencies:
50 for adj in adjacencies[site]:
52 test = is_adjacent(adjacencies, site, adj)
54 print "Error: ", e, " Fix adjacencies!"
60 return nodes[nodeid]['site_id']
61 raise Exception("Nodeid %s not found." % nodeid)
64 def get_ipaddr(nodeid):
66 return socket.gethostbyname(nodes[nodeid]['hostname'])
67 raise Exception("Nodeid %s not found." % nodeid)
70 def get_sitenodes(siteid):
72 return sites[siteid]['node_ids']
73 raise Exception("Siteid %s not found." % siteid)
77 Find the IP address assigned to a virtual interface in the topology
78 (for creating /etc/hosts)
80 def get_virt_ip(myid, nodeid):
82 virtip = "10.%d.%d.2" % (myid, nodeid)
84 virtip = "10.%d.%d.3" % (nodeid, myid)
89 Create a dictionary of site records keyed by site ID
93 for site in GetSites():
94 t = site['site_id'], site
100 Create a dictionary of node records keyed by node ID
104 for node in GetNodes():
105 t = node['node_id'], node
109 adjacencies = gen_adjacencies(links)
110 check_adjacencies(adjacencies)
112 """ Need global topology information """
116 for slice in GetSlices():
117 """ Create dictionary of the slice's attributes """
120 for attribute in GetSliceAttributes(slice['slice_attribute_ids']):
121 attrs[attribute['name']] = attribute['slice_attribute_id']
122 if attribute['name'] == 'topo_rspec' and attribute['node_id']:
123 topo_attr[attribute['node_id']] = attribute['slice_attribute_id']
125 if 'egre_key' in attrs:
126 #print "Virtual topology for %s:" % slice['name']
127 slicenodes = set(slice['node_ids'])
128 hosts = "127.0.0.1\t\tlocalhost\n"
130 For each node in the slice, check whether nodes at adjacent sites
131 are also in the slice's node set. If so, add a virtual link to
134 for node in slicenodes:
136 for adj in adjacencies[get_site(node)]:
137 for adj_node in get_sitenodes(adj):
138 if node != adj_node and adj_node in slicenodes:
139 link = adj_node, get_ipaddr(adj_node), "1Mbit"
141 shortname = nodes[node]['hostname'].replace('.vini-veritas.net', '')
142 hosts += "%s\t\t%s\n" % (get_virt_ip(node, adj_node),
144 topo_str = "%s" % topo
145 #print node, topo_str
146 if node in topo_attr:
147 UpdateSliceAttribute(topo_attr[node], topo_str)
150 id = slice['slice_id']
151 AddSliceAttribute(id, 'topo_rspec', topo_str, node)
155 UpdateSliceAttribute(attrs['hosts'], hosts)
157 id = slice['slice_id']
158 AddSliceAttribute(id, 'hosts', hosts)
160 #print "No EGRE key for %s" % slice['name']
162 """ Remove old topo_rspec entries """
163 for node in topo_attr:
164 DeleteSliceAttribute(topo_attr[node])