Update CPU token buckets of running vserver
[util-vserver-pl.git] / python / vserver.py
index f6d6505..39275de 100644 (file)
@@ -17,7 +17,6 @@ import resource
 import vserverimpl
 import cpulimit, bwlimit
 
 import vserverimpl
 import cpulimit, bwlimit
 
-from vserverimpl import VS_SCHED_CPU_GUARANTEED as SCHED_CPU_GUARANTEED
 from vserverimpl import DLIMIT_INF
 from vserverimpl import VC_LIM_KEEP
 from vserverimpl import VLIMIT_NSOCK
 from vserverimpl import DLIMIT_INF
 from vserverimpl import VC_LIM_KEEP
 from vserverimpl import VLIMIT_NSOCK
@@ -157,12 +156,12 @@ class VServer:
     def log(self,msg):
         if self.logfile:
             try:
     def log(self,msg):
         if self.logfile:
             try:
-                fd = os.open(self.logfile,"a", 0600)
+                fd = os.open(self.logfile,os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0600)
                 if not msg.endswith('\n'): msg += '\n'
                 os.write(fd, '%s: %s' % (time.asctime(time.gmtime()), msg))
                 os.close(fd)
             except:
                 if not msg.endswith('\n'): msg += '\n'
                 os.write(fd, '%s: %s' % (time.asctime(time.gmtime()), msg))
                 os.close(fd)
             except:
-                print msg
+                print '%s: (%s failed to open) %s'%(time.asctime(time.gmtime()),self.logfile,msg)
 
     def have_limits_changed(self):
         return self.rlimits_changed
 
     def have_limits_changed(self):
         return self.rlimits_changed
@@ -325,25 +324,23 @@ class VServer:
 
         return block_limit
 
 
         return block_limit
 
-    def set_sched_config(self, cpu_share, sched_flags):
+    def set_sched_config(self, cpu_min, cpu_share):
 
         """ Write current CPU scheduler parameters to the vserver
         configuration file. This method does not modify the kernel CPU
         scheduling parameters for this context. """
 
 
         """ Write current CPU scheduler parameters to the vserver
         configuration file. This method does not modify the kernel CPU
         scheduling parameters for this context. """
 
-        if sched_flags & SCHED_CPU_GUARANTEED:
-            cpu_guaranteed = cpu_share
-        else:
-            cpu_guaranteed = 0
+        self.config.update('sched/fill-rate', cpu_min)
         self.config.update('sched/fill-rate2', cpu_share)
         self.config.update('sched/fill-rate2', cpu_share)
-        self.config.update('sched/fill-rate', cpu_guaranteed)
-
-        if self.vm_running:
-            self.set_sched(cpu_share, sched_flags)
+        if cpu_share == 0:
+            self.config.unset('sched/idle-time')
+        
+        if self.is_running():
+            self.set_sched(cpu_min, cpu_share)
 
 
-    def set_sched(self, cpu_share, sched_flags = 0):
+    def set_sched(self, cpu_min, cpu_share):
         """ Update kernel CPU scheduling parameters for this context. """
         """ Update kernel CPU scheduling parameters for this context. """
-        vserverimpl.setsched(self.ctx, cpu_share, sched_flags)
+        vserverimpl.setsched(self.ctx, cpu_min, cpu_share)
 
     def get_sched(self):
         # have no way of querying scheduler right now on a per vserver basis
 
     def get_sched(self):
         # have no way of querying scheduler right now on a per vserver basis
@@ -381,7 +378,7 @@ class VServer:
             self.set_resources()
             vserverimpl.setup_done(self.ctx)
 
             self.set_resources()
             vserverimpl.setup_done(self.ctx)
 
-    def __prep(self, runlevel, log):
+    def __prep(self, runlevel):
 
         """ Perform all the crap that the vserver script does before
         actually executing the startup scripts. """
 
         """ Perform all the crap that the vserver script does before
         actually executing the startup scripts. """
@@ -444,6 +441,10 @@ class VServer:
                 if fd != 0:
                     os.dup2(fd, 0)
                     os.close(fd)
                 if fd != 0:
                     os.dup2(fd, 0)
                     os.close(fd)
+                # perform pre-init cleanup
+                self.__prep(runlevel)
+
                 self.config.cache_it()
                 self.__do_chroot()
                 log = open("/var/log/boot.log", "a", 0)
                 self.config.cache_it()
                 self.__do_chroot()
                 log = open("/var/log/boot.log", "a", 0)
@@ -453,10 +454,6 @@ class VServer:
 
                 print >>log, ("%s: starting the virtual server %s" %
                               (time.asctime(time.gmtime()), self.name))
 
                 print >>log, ("%s: starting the virtual server %s" %
                               (time.asctime(time.gmtime()), self.name))
-
-                # perform pre-init cleanup
-                self.__prep(runlevel, log)
-
                 # execute each init script in turn
                 # XXX - we don't support all scripts that vserver script does
                 self.__do_chcontext(state_file)
                 # execute each init script in turn
                 # XXX - we don't support all scripts that vserver script does
                 self.__do_chcontext(state_file)