X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=python%2Fvserver.py;h=c57e28197fd102a7547da383dbd9b11b2066fbdc;hb=ae26e2636c1c04c1ba154bdda5aa21e7cd8ff2e7;hp=31361ce9a16aa395e3a36691dc79db1e6a8f8c17;hpb=3693fed7541b1b95612166ce2534a07c6e43660e;p=util-vserver-pl.git diff --git a/python/vserver.py b/python/vserver.py index 31361ce..c57e281 100644 --- a/python/vserver.py +++ b/python/vserver.py @@ -20,6 +20,7 @@ import cpulimit, bwlimit from vserverimpl import DLIMIT_INF from vserverimpl import VC_LIM_KEEP +from vserverimpl import VC_LIM_INFINITY from vserverimpl import VLIMIT_NSOCK from vserverimpl import VLIMIT_OPENFD from vserverimpl import VLIMIT_ANON @@ -133,10 +134,6 @@ class VServerConfig: class VServer: - # adding the sliver name is for helping in the forensics - INITSCRIPTS = [('/etc/rc.vinit', 'start', '%(name)s'), - ('/etc/rc.d/rc', '%(runlevel)d')] - def __init__(self, name, vm_id = None, vm_running = None, logfile=None): self.name = name @@ -233,18 +230,23 @@ class VServer: def set_ipaddresses(self, addresses): vserverimpl.netremove(self.ctx, "all") - for a in addresses.split(","): - vserverimpl.netadd(self.ctx, a) + for ip in addresses: + vserverimpl.netadd(self.ctx, ip) def set_ipaddresses_config(self, addresses): - return # acb + ip_addresses = addresses.split(",") + + # add looopback interface + if not ip_addresses.__contains__("127.0.0.1"): + ip_addresses.append("127.0.0.1") + i = 0 - for a in addresses.split(","): - self.config.update("interfaces/%d/ip" % i, a) + for ip in ip_addresses: + self.config.update("interfaces/%d/ip" % i, ip) i += 1 while self.config.unset("interfaces/%d/ip" % i): i += 1 - self.set_ipaddresses(addresses) + self.set_ipaddresses(ip_addresses) def get_ipaddresses_config(self): i = 0 @@ -331,7 +333,7 @@ class VServer: def set_sched_config(self, cpu_min, cpu_share): """ Write current CPU scheduler parameters to the vserver configuration file. Currently, 'cpu_min' is not supported. """ - self.config.update('cgroup/cpu.shares', cpu_share * CPU_SHARE_MULT) + self.config.update('cgroup/cpu.shares', int(cpu_share) * CPU_SHARE_MULT) if self.is_running(): self.set_sched(cpu_min, cpu_share) @@ -339,8 +341,8 @@ class VServer: """ Update kernel CPU scheduling parameters for this context. Currently, 'cpu_min' is not supported. """ try: - cgroup = open('/dev/cgroup/%s/cpu.shares' % name, 'w') - cgroup.write('%s' % (cpu_share * CPU_SHARE_MULT)) + cgroup = open('/dev/cgroup/%s/cpu.shares' % self.name, 'w') + cgroup.write('%s' % (int(cpu_share) * CPU_SHARE_MULT)) cgroup.close() except: pass @@ -377,8 +379,10 @@ class VServer: def enter(self): subprocess.call("/usr/sbin/vserver %s enter" % self.name, shell=True) - # detach the process that triggers the initscripts - # after http://code.activestate.com/recipes/278731/ + # 2010 June 21 - Thierry + # the slice initscript now gets invoked through rc - see sliver_vs.py in nodemanager + # and, rc is triggered as part of vserver .. start + # so we don't have to worry about initscripts at all anymore here def start(self, runlevel = 3): if os.fork() != 0: # Parent should just return. @@ -391,33 +395,11 @@ class VServer: os._exit(0) # Exit parent (the first child) of the second child. # the grandson is the working one os.chdir('/') - os.umask(0) + os.umask(0022) try: # start the vserver subprocess.call(["/usr/sbin/vserver",self.name,"start"]) - # execute initscripts - for cmd_to_expand in self.INITSCRIPTS: - # enter vserver context - expand = { 'runlevel': runlevel, - 'name': self.name, } - cmd = [ x % expand for x in cmd_to_expand ] - cmd_name = os.path.basename(cmd[0]) - cmd_file = "/vservers/" + self.name + cmd[0] - if not os.path.isfile(cmd_file): - self.log("WARNING: could not find %s for %s" % (cmd_file, self.name)) - break - self.log("executing %r" % cmd) - try: - logname='/vservers/%s/var/log/%s'%(self.name,cmd_name) - log_fd=os.open(logname,os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0600) - self.log_in_file(log_fd,"Running %r into %s"%(cmd,logname)) - self.chroot_call(subprocess.call,cmd, - stdout=log_fd,stderr=subprocess.STDOUT, - close_fds=True) - except: self.log(traceback.format_exc()) - finally: os.close(log_fd) - # we get here due to an exception in the grandson process except Exception, ex: self.log(traceback.format_exc())