This file implements the core functionality of the resman bwlimit script
[util-vserver.git] / python / vserver.py
index 4a7728d..e5d9d2f 100644 (file)
@@ -13,6 +13,7 @@ import linuxcaps
 import passfdimpl
 import utmp
 import vserverimpl, vduimpl
+import cpulimit
 
 from util_vserver_vars import *
 
@@ -110,25 +111,58 @@ class VServer:
         return blocktotal
 
     def set_sched(self, shares, besteffort = True):
-        global SCHED_TOKENS_MIN, SCHED_TOKENS_MAX
-        tokensmin = SCHED_TOKENS_MIN
-        tokensmax = SCHED_TOKENS_MAX
-
-        if besteffort is True:
-            # magic "interval" value for Andy's scheduler to denote besteffort
-            interval = 1000
-            fillrate = shares
-        else:
-            interval = 1001
-            fillrate = shares
+        # for the old CKRM scheduler
+        if cpulimit.checkckrm() is True:
+            cpulimit.cpuinit()
+            cpulimit.vs2ckrm_on(self.name)
+            try:
+                cpulimit.cpulimit(self.name,shares)
+            except OSError, ex:
+                if ex.errno == 22:
+                    print "invalid shares argument"
+                    # should re-raise exception?!
 
-        try:
-            vserverimpl.setsched(self.ctx,fillrate,interval,tokensmin,tokensmax)
-        except OSError, ex:
-            if ex.errno == 22:
-                print "kernel does not support vserver scheduler"
+        # for the new vserver scheduler
+        else:
+            global SCHED_TOKENS_MIN, SCHED_TOKENS_MAX
+            tokensmin = SCHED_TOKENS_MIN
+            tokensmax = SCHED_TOKENS_MAX
+
+            if besteffort is True:
+                # magic "interval" value for Andy's scheduler to denote besteffort
+                interval = 1000
+                fillrate = shares
             else:
-                raise ex
+                interval = 1001
+                fillrate = shares
+
+            try:
+                vserverimpl.setsched(self.ctx,fillrate,interval,tokensmin,tokensmax)
+            except OSError, ex:
+                if ex.errno == 22:
+                    print "kernel does not support vserver scheduler"
+                else:
+                    raise ex
+
+    def get_sched(self):
+        # have no way of querying scheduler right now on a per vserver basis
+        return -1, False
+
+    def set_memlimit(self, limit):
+        ret = vserverimpl.setrlimit(self.ctx,5,limit)
+        return ret
+
+    def get_memlimit(self):
+        ret = vserverimpl.getrlimit(self.ctx,5)
+        return ret
+    
+    def set_tasklimit(self, limit):
+        ret = vserverimpl.setrlimit(self.ctx,6,limit)
+        return ret
+
+    def get_tasklimit(self):
+        ret = vserverimpl.getrlimit(self.ctx,6)
+        return ret
 
     def open(self, filename, mode = "r", bufsize = -1):