Simple module for toggling network namespaces based on slice attributes trellis trellis
authorAndy Bavier <acb@cs.princeton.edu>
Wed, 3 Dec 2008 19:46:52 +0000 (19:46 +0000)
committerAndy Bavier <acb@cs.princeton.edu>
Wed, 3 Dec 2008 19:46:52 +0000 (19:46 +0000)
trellis.py [new file with mode: 0644]

diff --git a/trellis.py b/trellis.py
new file mode 100644 (file)
index 0000000..a70d0f6
--- /dev/null
@@ -0,0 +1,35 @@
+# $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()
+
+