command line program to both get and set a vservers disklimits
Marc Fiuczynski [Thu, 10 May 2007 15:20:50 +0000 (15:20 +0000)]
python/disklimit [new file with mode: 0755]

diff --git a/python/disklimit b/python/disklimit
new file mode 100755 (executable)
index 0000000..f8c9787
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/env python
+
+import vserver, sys, os, re, getopt
+
+def usage():
+    print """
+Usage:
+
+%s [OPTION]... [COMMAND] [ARGUMENT]...
+
+Options:
+
+
+Commands:
+        set slice space
+               Set max disk limit for a slice
+
+        get slice
+                Get current disk limit for slice
+""" % (sys.argv[0])
+
+    sys.exit(1)
+    
+def get(argv):
+    slicename = argv[0]
+    vs = vserver.VServer(slicename)
+    limit = vs.get_disklimit()
+    return "%s %d limit" % (slicename,limit)
+
+def set(argv):
+    slicename = argv[0]
+    vs = vserver.VServer(slicename)
+    oldlimit = vs.get_disklimit()
+    newlimit = int(argv[1])
+    if newlimit >= oldlimit:
+        vs.set_disklimit(newlimit)
+    return None
+
+def main():
+    functions = {"get":get, "set":set}
+    argv = sys.argv[1:]
+    if len(argv):
+            func = functions.get(argv[0],usage)
+            result = func(argv[1:])
+            if result <> None:
+                print result
+           sys.exit(0)
+
+    # no command given
+    usage()
+
+
+if __name__ == '__main__':
+    main()