X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=python%2Fvserver.py;h=b2ad6a8d20581ead3367c33e99076b57749bcc2d;hb=b3e6c1ed03bc50f25d03ca8f13aa5bca7419206f;hp=96ebcdda1f4cb5e1bde2bebb91e701a65163bcdf;hpb=9dfaea8dd87b2cadfd5472e184a766e1a0a75d52;p=util-vserver-pl.git diff --git a/python/vserver.py b/python/vserver.py index 96ebcdd..b2ad6a8 100644 --- a/python/vserver.py +++ b/python/vserver.py @@ -16,7 +16,8 @@ import commands import resource import vserverimpl -import cpulimit, bwlimit +import cpulimit +import plnode.bwlimit as bwlimit from vserverimpl import DLIMIT_INF from vserverimpl import VC_LIM_KEEP @@ -193,7 +194,7 @@ class VServer: def get_prefix_from_capabilities(self, capabilities, prefix): split_caps = capabilities.split(',') - return ",".join(["%s" % (c) for c in split_caps if c.startswith(prefix.upper()) or c.startswith(prefix.lower())]) + return ",".join(["%s" % (c[len(prefix):]) for c in split_caps if c.startswith(prefix.upper()) or c.startswith(prefix.lower())]) def get_bcaps_from_capabilities(self, capabilities): return self.get_prefix_from_capabilities(capabilities, "cap_") @@ -230,18 +231,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, add_loopback=True): + ip_addresses = addresses.split(",") + + # add looopback interface + if not ip_addresses.__contains__("127.0.0.1") and add_loopback: + ip_addresses.append("127.0.0.1") - def set_ipaddresses_config(self, addresses): - return # acb 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 @@ -390,7 +398,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"]) @@ -461,12 +469,3 @@ def create(vm_name, static = False, ctor = VServer): vm_id = pwd.getpwnam(vm_name)[2] return ctor(vm_name, vm_id) - - -def close_nonstandard_fds(): - """Close all open file descriptors other than 0, 1, and 2.""" - _SC_OPEN_MAX = 4 - for fd in range(3, os.sysconf(_SC_OPEN_MAX)): - try: os.close(fd) - except OSError: pass # most likely an fd that isn't open -