raise Exception("Siteid %s not found." % siteid)
+"""
+Find the IP address assigned to a virtual interface in the topology
+(for creating /etc/hosts)
+"""
+def get_virt_ip(myid, nodeid):
+ if myid < nodeid:
+ virtip = "10.%d.%d.2" % (myid, nodeid)
+ else:
+ virtip = "10.%d.%d.3" % (nodeid, myid)
+ return virtip
+
+
"""
Create a dictionary of site records keyed by site ID
"""
for slice in GetSlices():
""" Create dictionary of the slice's attributes """
- attrs = []
+ attrs ={}
topo_attr = {}
for attribute in GetSliceAttributes(slice['slice_attribute_ids']):
- attrs.append(attribute['name'])
+ attrs[attribute['name']] = attribute['slice_attribute_id']
if attribute['name'] == 'topo_rspec' and attribute['node_id']:
topo_attr[attribute['node_id']] = attribute['slice_attribute_id']
if 'egre_key' in attrs:
- print "Virtual topology for %s:" % slice['name']
+ #print "Virtual topology for %s:" % slice['name']
slicenodes = set(slice['node_ids'])
+ hosts = "127.0.0.1\t\tlocalhost\n"
"""
For each node in the slice, check whether nodes at adjacent sites
are also in the slice's node set. If so, add a virtual link to
if node != adj_node and adj_node in slicenodes:
link = adj_node, get_ipaddr(adj_node), "1Mbit"
topo.append(link)
+ shortname = nodes[node]['hostname'].replace('.vini-veritas.net', '')
+ hosts += "%s\t\t%s\n" % (get_virt_ip(node, adj_node),
+ shortname)
topo_str = "%s" % topo
- print node, topo_str
+ #print node, topo_str
if node in topo_attr:
UpdateSliceAttribute(topo_attr[node], topo_str)
del topo_attr[node]
id = slice['slice_id']
AddSliceAttribute(id, 'topo_rspec', topo_str, node)
- else:
- print "No EGRE key for %s" % slice['name']
+ #print hosts
+ if 'hosts' in attrs:
+ UpdateSliceAttribute(attrs['hosts'], hosts)
+ else:
+ id = slice['slice_id']
+ AddSliceAttribute(id, 'hosts', hosts)
+ #else:
+ #print "No EGRE key for %s" % slice['name']
""" Remove old topo_rspec entries """
for node in topo_attr:
DeleteSliceAttribute(topo_attr[node])
+