more fixes
[util-vserver.git] / python / vserver.py
index 1ec678a..b2fe876 100644 (file)
@@ -46,6 +46,8 @@ FLAGS_NAMESPACE = 128
 # default values for new vserver scheduler
 SCHED_TOKENS_MIN = 50
 SCHED_TOKENS_MAX = 100
+SCHED_TOKENS = 100
+SCHED_INTERVAL = 1000
 
               
 class VServer:
@@ -83,10 +85,10 @@ class VServer:
 
     def __do_chroot(self):
 
-        return os.chroot("%s/%s" % (VROOTDIR, self.name))
+        return os.chroot("%s/%s" % (DEFAULT_VSERVERDIR, self.name))
 
     def set_disklimit(self, blocktotal):
-        path = "%s/%s" % (VROOTDIR, self.name)
+        path = "%s/%s" % (DEFAULT_VSERVERDIR, self.name)
         inodes, blockcount, size = vduimpl.vdu(path)
         blockcount = blockcount >> 1
 
@@ -98,7 +100,7 @@ class VServer:
             print "block limit (%d) ignored for vserver %s" %(blocktotal,self.name)
 
     def get_disklimit(self):
-        path = "%s/%s" % (VROOTDIR, self.name)
+        path = "%s/%s" % (DEFAULT_VSERVERDIR, self.name)
         try:
             blocksused, blocktotal, inodesused, inodestotal, reserved = \
                         vserverimpl.getdlimit(path,self.ctx)
@@ -110,7 +112,7 @@ class VServer:
 
         return blocktotal
 
-    def set_sched(self, shares, besteffort = True):
+    def set_sched(self, shares = 32, besteffort = True):
         # for the old CKRM scheduler
         if cpulimit.checkckrm() is True:
             cpulimit.cpuinit()
@@ -124,20 +126,20 @@ class VServer:
 
         # for the new vserver scheduler
         else:
-            global SCHED_TOKENS_MIN, SCHED_TOKENS_MAX
+            global SCHED_TOKENS_MIN, SCHED_TOKENS_MAX, SCHED_TOKENS, SCHED_INTERVAL
             tokensmin = SCHED_TOKENS_MIN
             tokensmax = SCHED_TOKENS_MAX
+            tokens    = SCHED_TOKENS
+            interval  = SCHED_INTERVAL
+            fillrate = shares
 
             if besteffort is True:
-                # magic "interval" value for Andy's scheduler to denote besteffort
-                interval = 1000
-                fillrate = shares
+                cpuguaranteed = 0
             else:
-                interval = 1001
-                fillrate = shares
+                cpuguaranteed = 1
 
             try:
-                vserverimpl.setsched(self.ctx,fillrate,interval,tokensmin,tokensmax)
+                vserverimpl.setsched(self.ctx,fillrate,interval,tokens,tokensmin,tokensmax,cpuguaranteed)
             except OSError, ex:
                 if ex.errno == 22:
                     print "kernel does not support vserver scheduler"
@@ -237,7 +239,11 @@ class VServer:
 
     def __do_chcontext(self, state_file = None):
 
-        vserverimpl.chcontext(self.ctx, self.remove_caps)
+        vserverimpl.create(self.ctx)
+        vserverimpl.flags(self.ctx)
+        self.set_sched()
+        vserverimpl.enter(self.ctx)
+
         if not state_file:
             return
         print >>state_file, "S_CONTEXT=%d" % self.ctx