X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=create-topo-attributes.py;h=78d965eba36ef77ebae2245c2b88aed7bd3e1b91;hb=refs%2Fheads%2Fmaster;hp=925b7217818469927f192b5688c61695f53cec2c;hpb=e7f5d461dc4c2546d7d6aea0c9458d49b77e1de9;p=nodemanager-topo.git diff --git a/create-topo-attributes.py b/create-topo-attributes.py index 925b721..78d965e 100755 --- a/create-topo-attributes.py +++ b/create-topo-attributes.py @@ -8,7 +8,7 @@ slices that have an EGRE key. This script to be run from a cron job. import string import socket -from topology import links +from topology import links, bwlimits class Node: def __init__(self, node): @@ -61,11 +61,11 @@ class Node: def init_rspecs(self): self.rspecs = [] - def add_rspec(self, remote): + def add_rspec(self, remote, bw): my_ip = self.get_virt_ip(remote) remote_ip = remote.get_virt_ip(self) net = self.get_virt_net(remote) - rspec = remote.id, remote.ipaddr, "1Mbit", my_ip, remote_ip, net + rspec = remote.id, remote.ipaddr, bw, my_ip, remote_ip, net self.rspecs.append(rspec) @@ -116,9 +116,11 @@ class Slice: record = {'slice_tag_id':None, 'slice_id':self.id, 'tagname':tagname, 'value':value} if node: record['node_id'] = node.id + else: + record['node_id'] = None tag = Slicetag(record) - slicetags[id] = tag - self.slice_tag_ids.append(id) + slicetags[tag.id] = tag + self.slice_tag_ids.append(tag.id) tag.changed = True tag.updated = True return tag @@ -165,7 +167,7 @@ class Slice: if cap == "CAP_NET_ADMIN": return else: - newcaps = "CAP_NET_ADMIN," + caps + newcaps = "CAP_NET_ADMIN," + tag.value self.update_tag('capabilities', newcaps, slicetags) else: self.add_tag('capabilities', 'CAP_NET_ADMIN', slicetags) @@ -232,9 +234,15 @@ class Slicetag: else: AddSliceTag(self.slice_id, self.tagname, self.value, self.node_id) elif self.deleted and int(self.id) > 0: - DeleteSliceTag(self.id) + try: + DeleteSliceTag(self.id) + except: + print "[%s] %s: could not delete" % (self.id, self.tagname) else: - slice = slices[self.slice_id].name + try: + slice = slices[self.slice_id].name + except: + return if self.node_id: node = nodes[tag.node_id].hostname if self.updated: @@ -295,8 +303,8 @@ def get_slice_tags(): Find a free EGRE key """ def free_egre_key(slicetags): + used = set() for i in slicetags: - used = set() tag = slicetags[i] if tag.tagname == 'egre_key': used.add(int(tag.value)) @@ -331,7 +339,14 @@ for i in slices: else: topo_type = None - if topo_type == 'vsys' or topo_type == 'iias': + """ + Valid values of topo_type: + 'vsys': Use vsys topology scripts to set up virtual links + 'iias': Automatically create a virtual topology mirroring the physical one + 'manual': Don't modify the topo_rspec tags if present + None: No virtual topology + """ + if topo_type in ['vsys', 'iias', 'manual']: slice.assign_egre_key(slicetags) slice.turn_on_netns(slicetags) slice.add_cap_net_admin(slicetags) @@ -348,6 +363,11 @@ for i in slices: if dryrun: print "Building virtual topology for %s" % slice.name + if slice.name in bwlimits: + bw = bwlimits[slice.name] + else: + bw = "1Mbit" + hosts = "127.0.0.1\t\tlocalhost\n" """ For each node in the slice, check whether the slice is running on any @@ -357,7 +377,7 @@ for i in slices: node.init_rspecs() adj_nodes = node.adjacent_nodes(sites, nodes, slice.node_ids) for adj in adj_nodes: - node.add_rspec(adj) + node.add_rspec(adj, bw) hosts += "%s\t\t%s\n" % (node.get_virt_ip(adj), node.shortname) if node.rspecs: topo_str = "%s" % node.rspecs @@ -368,6 +388,12 @@ for i in slices: if dryrun: print "Slice %s not using IIAS" % slice.name + if topo_type == 'manual' and slice.get_tag('egre_key', slicetags): + for node in slice.get_nodes(nodes): + topo_tag = slice.get_tag('topo_rspec', slicetags, node) + if topo_tag: + topo_tag.updated = True + # Update the tag values in the database for i in slicetags: tag = slicetags[i]