5 VINI/Trellis NodeManager plugin.
6 Create virtual links from the topo_rspec slice attribute.
17 setup_link_cmd="/usr/share/vini/setup-egre-link"
18 teardown_link_cmd="/usr/share/vini/teardown-egre-link"
27 return subprocess.call(cmd, shell=True);
31 Check for existence of interface d<key>x<nodeid>
33 def virtual_link(key, nodeid):
34 name = "d%sx%s" % (key, nodeid)
42 Create a "virtual link" for slice between here and nodeid.
43 The key is used to create the EGRE tunnel.
45 def setup_virtual_link(slice, key, rate, myid, nodeid, ipaddr):
46 logger.log("%s: Set up virtual link to node %d" % (slice, nodeid))
48 virtip = "10.%d.%d.2" % (myid, nodeid)
50 virtip = "10.%d.%d.3" % (nodeid, myid)
52 run(setup_link_cmd + " %s %s %s %s %s %s" % (slice, nodeid, ipaddr,
58 Tear down the "virtual link" for slice between here and nodeid.
60 def teardown_virtual_link(key, nodeid):
61 logger.log("topo: Tear down virtual link %sx%s" % (key, nodeid))
62 run(teardown_link_cmd + " %s %s" % (nodeid, key))
67 Called for all active virtual link interfaces, so they won't be cleaned up.
69 def refresh_virtual_link(nodeid, key):
71 name = "d%sx%s" % (key, nodeid)
78 Clean up old virtual links (e.g., to nodes that have been deleted
81 def clean_up_old_virtual_links():
82 pattern = "d(.*)x(.*)"
83 for iface in old_ifaces:
84 m = re.match(pattern, iface)
87 node = int(m.group(2))
88 teardown_virtual_link(key, node)
92 Not the safest thing to do, probably should use pickle() or something.
94 def convert_topospec_to_list(rspec):
99 Update virtual links for the slice
101 def update(slice, myid, topospec, key, netns):
102 topolist = convert_topospec_to_list(topospec)
103 for (nodeid,ipaddr,rate) in topolist:
104 if not virtual_link(key, nodeid):
106 setup_virtual_link(slice, key, rate, myid, nodeid, ipaddr)
108 logger.log("%s: virtual link to node %s exists" % (slice, nodeid))
109 refresh_virtual_link(nodeid, key)
112 Write /etc/vservers/<slicename>/spaces/net
114 def writeConf(slicename, value):
115 SLICEDIR="/etc/vservers/%s/" % slicename
116 SPACESDIR="%s/spaces/" % SLICEDIR
117 if os.path.exists(SLICEDIR):
118 if not os.path.exists(SPACESDIR):
122 logger.log("netns: could not create %s\n" % SPACESDIR)
124 f = open("%s/net" % SPACESDIR, "w")
125 f.write("%s\n" % value)
130 logger.log("%s: network namespace %s\n" % (slicename, STATUS))
133 def start(options, config):
138 Update the virtual links for a sliver if it has a 'netns' attribute,
139 an 'egre_key' attribute, and a 'topo_rspec' attribute.
141 Creating the virtual link depends on the contents of
142 /etc/vservers/<slice>/spaces/net. Update this first.
144 def GetSlivers(data):
145 global ifaces, old_ifaces
146 ifaces = old_ifaces = sioc.gifconf()
148 for sliver in data['slivers']:
150 for attribute in sliver['attributes']:
151 attrs[attribute['name']] = attribute['value']
153 netns = int(attrs['netns'])
154 writeConf(sliver['name'], netns)
159 if vserver.VServer(sliver['name']).is_running():
160 if 'egre_key' in attrs and 'topo_rspec' in attrs:
161 logger.log("topo: Update topology for slice %s" % \
163 update(sliver['name'], data['node_id'],
164 attrs['topo_rspec'], attrs['egre_key'], netns)
166 logger.log("topo: sliver %s not running yet. Deferring." % \
169 clean_up_old_virtual_links()