X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=python%2Fvserver.py;h=8fdb50577957671b9a0795c2a64f848cc247f932;hb=88d249dcc24798a4e8a149b59a2b353038e8e631;hp=315edbbdf96db0336c6f36bf51930d3ed437bc0e;hpb=0420b6b2adea04ecab404c4889b9dbf95e0a745c;p=util-vserver-pl.git diff --git a/python/vserver.py b/python/vserver.py index 315edbb..8fdb505 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 @@ -229,18 +230,25 @@ 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) + # create emtpy nodev files to silent "No device specified for" warnings + self.config.update("interfaces/%d/nodev" % i, "") i += 1 - while self.config.unset("interfaces/%d/ip" % i): + while self.config.unset("interfaces/%d/ip" % i) and self.config.update("interfaces/%d/nodev" % i): i += 1 - self.set_ipaddresses(addresses) + self.set_ipaddresses(ip_addresses) def get_ipaddresses_config(self): i = 0 @@ -327,7 +335,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) @@ -335,8 +343,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 @@ -389,7 +397,7 @@ 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"])