From b50c17f7ef41fc3c8f7574c14dd621de2175d1dd Mon Sep 17 00:00:00 2001 From: Andy Bavier Date: Wed, 25 Feb 2009 16:55:30 +0000 Subject: [PATCH] Generate 'hosts' attribute for the slice --- create-topo-attributes.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/create-topo-attributes.py b/create-topo-attributes.py index 6d64d99..8f26ff8 100755 --- a/create-topo-attributes.py +++ b/create-topo-attributes.py @@ -67,6 +67,18 @@ def get_sitenodes(siteid): 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 """ @@ -97,16 +109,17 @@ nodes = get_nodes() 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 @@ -119,8 +132,11 @@ for slice in GetSlices(): 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] @@ -128,10 +144,17 @@ for slice in GetSlices(): 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]) + -- 2.43.0