+ return block_limit
+
+ def set_sched_config(self, cpu_share, sched_flags):
+
+ """ Write current CPU scheduler parameters to the vserver
+ configuration file. This method does not modify the kernel CPU
+ scheduling parameters for this context. """
+
+ if cpu_share == int(self.config.get("CPULIMIT", -1)):
+ return
+ cpu_guaranteed = sched_flags & SCHED_CPU_GUARANTEED
+ cpu_config = { "CPULIMIT": cpu_share, "CPUGUARANTEED": cpu_guaranteed }
+ self.update_resources(cpu_config)
+ if self.vm_running:
+ self.set_sched(cpu_share, sched_flags)
+
+ def set_sched(self, cpu_share, sched_flags = 0):
+
+ """ Update kernel CPU scheduling parameters for this context. """
+
+ vserverimpl.setsched(self.ctx, cpu_share, sched_flags)
+
+ 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 set_bwlimit(self, maxrate, minrate = 1, share = None, dev = "eth0"):
+
+ if maxrate != 0:
+ bwlimit.on(self.ctx, dev, share, minrate, maxrate)
+ else:
+ bwlimit.off(self.ctx, dev)
+
+ def get_bwlimit(self, dev = "eth0"):
+
+ # result of bwlimit.get is (ctx, share, minrate, maxrate)
+ return bwlimit.get(self.ctx)[1:]
+
+ def open(self, filename, mode = "r", bufsize = -1):
+
+ return self.chroot_call(open, filename, mode, bufsize)
+
+ def __do_chcontext(self, state_file):
+
+ if state_file:
+ print >>state_file, "S_CONTEXT=%u" % self.ctx
+ print >>state_file, "S_PROFILE="
+ state_file.close()
+
+ if vserverimpl.chcontext(self.ctx):
+ self.set_resources()
+ vserverimpl.setup_done(self.ctx)
+
+ def __prep(self, runlevel, log):
+
+ """ Perform all the crap that the vserver script does before
+ actually executing the startup scripts. """
+
+ # remove /var/run and /var/lock/subsys files
+ # but don't remove utmp from the top-level /var/run
+ RUNDIR = "/var/run"
+ LOCKDIR = "/var/lock/subsys"
+ filter_fn = lambda fs: filter(lambda f: f != 'utmp', fs)
+ garbage = reduce((lambda (out, ff), (dir, subdirs, files):
+ (out + map((dir + "/").__add__, ff(files)),
+ lambda fs: fs)),
+ list(os.walk(RUNDIR)),
+ ([], filter_fn))[0]
+ garbage += filter(os.path.isfile, map((LOCKDIR + "/").__add__,
+ os.listdir(LOCKDIR)))
+ for f in garbage:
+ os.unlink(f)
+
+ # set the initial runlevel
+ f = open(RUNDIR + "/utmp", "w")
+ utmp.set_runlevel(f, runlevel)
+ f.close()
+
+ # mount /proc and /dev/pts
+ self.__do_mount("none", "/proc", "proc")
+ # XXX - magic mount options
+ self.__do_mount("none", "/dev/pts", "devpts", 0, "gid=5,mode=0620")
+
+ def __do_mount(self, *mount_args):