--- /dev/null
+# $Id$
+# $URL$
+
+"""Trellis configurator. Toggles network namespace based on slice attribute"""
+
+import logger
+import os
+from sets import Set
+
+def start(options, config):
+ pass
+
+def GetSlivers(data):
+ """For each sliver with the netns attribute, write the value to /etc/vservers/<slice>/spaces/net"""
+ # Parse attributes and update dict of scripts
+ for sliver in data['slivers']:
+ for attribute in sliver['attributes']:
+ if attribute['name'] == 'netns':
+ writeConf(sliver['name'], attribute['value'])
+
+def writeConf(slicename, value):
+ SLICEDIR="/etc/vservers/%s/" % slicename
+ SPACESDIR="%s/spaces/" % SLICEDIR
+ if os.path.exists(SLICEDIR):
+ if not os.path.exists(SPACESDIR):
+ try:
+ os.mkdir(SPACESDIR)
+ except os.error:
+ logger.log("trellis: could not create %s\n" % SPACESDIR)
+ return
+ f = open("%s/net" % SPACESDIR, "w")
+ f.write("%s\n" % value)
+ f.close()
+
+