long awaited vsys callback. Still in progress.
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Wed, 6 Feb 2008 22:05:32 +0000 (22:05 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Wed, 6 Feb 2008 22:05:32 +0000 (22:05 +0000)
vsys.py [new file with mode: 0644]

diff --git a/vsys.py b/vsys.py
new file mode 100644 (file)
index 0000000..6f6d14f
--- /dev/null
+++ b/vsys.py
@@ -0,0 +1,50 @@
+# $Id$
+# $URL$
+
+"""vsys configurator.  Maintains ACLs and script pipes inside vservers based on slice attributes."""
+
+import logger
+import os
+
+
+def start(options, config):
+    pass
+
+def GetSlivers(data):
+    """For each sliver with the vsys attribute, set the script ACL, create the vsys directory in the slice, and restart vsys."""
+    confedSlivers = parseConf("/etc/vsys.conf")
+    newSlivers = []
+    for sliver in data['slivers']:
+        for attribute in sliver['attributes']:
+            if attribute['name'] == 'vsys':
+                # As the name implies, when we find an attribute, we
+                createVsysDir(sliver)
+                if sliver['name'] not in confedSlivers: newSlivers.append(sliver['name'])
+
+    writeConf(confedSlivers + newSlivers, "/etc/vsys.conf")
+
+def secureScripts():
+
+def createVsysDir(sliver):
+    '''Create /vsys directory in slice.  Update vsys conf file.'''
+    try: os.makedirs("/vservers/%s/vsys" % sliver['name'])
+    except OSError: pass
+
+
+def parseConf(file):
+    '''Parse the vserver conf.  Return [slices] in conf.'''
+    slices = []
+    f = open(file)
+    for line in f.readlines():
+        (slice, path) = line.split()
+        slices.append(slice)
+    f.close()
+    return slices
+
+
+def writeConf(slivers, file):
+    f = open(file,"w")
+    for sliver in slivers:
+        f.write("/vservers/%(name)s/vsys %(name)s\n" % {"name": sliver})
+    f.truncate()
+    f.close()