From 753906c40722555e77e91a0021b81ef12ffd9793 Mon Sep 17 00:00:00 2001 From: Andy Bavier Date: Mon, 26 Oct 2009 16:01:03 +0000 Subject: [PATCH] Clean up. Start network namespace per slice by default. --- python/vserver.py | 82 ++++++-------------------------------------- scripts/vuseradd | 3 ++ util-vserver-pl.spec | 2 +- 3 files changed, 15 insertions(+), 72 deletions(-) diff --git a/python/vserver.py b/python/vserver.py index fa58beb..59141aa 100644 --- a/python/vserver.py +++ b/python/vserver.py @@ -12,6 +12,7 @@ import sys import time import traceback import subprocess +import commands import resource import vserverimpl @@ -54,7 +55,6 @@ for entry in resource.__dict__.keys(): class NoSuchVServer(Exception): pass - class VServerConfig: def __init__(self, name, directory): self.name = name @@ -144,7 +144,7 @@ class VServer: os.access(self.dir, os.R_OK | os.W_OK | os.X_OK)): raise NoSuchVServer, "no such vserver: " + name self.config = VServerConfig(name, "/etc/vservers/%s" % name) - self.remove_caps = ~vserverimpl.CAP_SAFE; + #self.remove_caps = ~vserverimpl.CAP_SAFE; if vm_id == None: vm_id = int(self.config.get('context')) self.ctx = vm_id @@ -232,7 +232,7 @@ class VServer: vserverimpl.netadd(self.ctx, a) def set_ipaddresses_config(self, addresses): - return + return # acb i = 0 for a in addresses.split(","): self.config.update("interfaces/%d/ip" % i, a) @@ -254,21 +254,14 @@ class VServer: def get_ipaddresses(self): # No clean way to do this right now. + self.log("Calling Vserver.get_ipaddresses for slice %s" % self.name) return None - def get_unshare_netns_config(self): - try: - unshare_netns = int(self.config.get('spaces/net')) - except: - unshare_netns = 0; - return unshare_netns; - def __do_chroot(self): os.chroot(self.dir) os.chdir("/") def chroot_call(self, fn, *args): - cwd_fd = os.open(".", os.O_RDONLY) try: root_fd = os.open("/", os.O_RDONLY) @@ -312,14 +305,13 @@ class VServer: except OSError, e: self.log("Unexpected error with setdlimit for context %d" % self.ctx) - self.config.update('dlimits/0/space_total', block_limit) def is_running(self): - return vserverimpl.isrunning(self.ctx) + status = subprocess.call(["/usr/sbin/vserver", self.name, "running"], shell=False) + return not status def get_disklimit(self): - try: (self.disk_blocks, block_limit, self.disk_inodes, inode_limit, reserved) = vserverimpl.getdlimit(self.dir, self.ctx) @@ -332,7 +324,6 @@ class VServer: return block_limit 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) @@ -378,55 +369,6 @@ class VServer: return self.chroot_call(open, filename, mode, bufsize) - def __do_chcontext(self, state_file): - - if state_file: - print >>state_file, "%u" % self.ctx - state_file.close() - - if vserverimpl.chcontext(self.ctx, vserverimpl.text2bcaps(self.get_capabilities_config()), self.get_unshare_netns_config()): - self.set_resources() - vserverimpl.setup_done(self.ctx) - - def __prep(self, runlevel): - - """ 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))) - if False: - for f in garbage: - os.unlink(f) - - # set the initial runlevel - vserverimpl.setrunlevel(RUNDIR + "/utmp", runlevel) - - # mount /proc and /dev/pts - self.__do_mount("none", self.dir, "/proc", "proc") - # XXX - magic mount options - self.__do_mount("none", self.dir, "/dev/pts", "devpts", 0, "gid=5,mode=0620") - - def __do_mount(self, *mount_args): - - try: - vserverimpl.mount(*mount_args) - except OSError, ex: - if ex.errno == errno.EBUSY: - # assume already mounted - return - raise ex - def enter(self): subprocess.call("/usr/sbin/vserver %s enter" % self.name, shell=True) @@ -438,8 +380,12 @@ class VServer: else: # child process try: + f = "/etc/vservers/%s/spaces/net" % self.name + # Always start vserver with a network namespace. + subprocess.call(["/bin/touch", f], shell=False) subprocess.call("/usr/sbin/vserver %s start" % self.name, shell=True) + #subprocess.call(["/bin/rm", f], shell=False) # we get here due to an exception in the top-level child process except Exception, ex: self.log(traceback.format_exc()) @@ -475,7 +421,6 @@ class VServer: (space, inodes) = line.split() self.disk_inodes = int(inodes) self.disk_blocks = int(space) - #(self.disk_inodes, self.disk_blocks) = vduimpl.vdu(self.dir) return self.disk_blocks * 1024 @@ -484,12 +429,7 @@ class VServer: subprocess.call("/usr/sbin/vserver %s stop" % self.name, shell=True) def setname(self, slice_id): - '''Set vcVHI_CONTEXT field in kernel to slice_id''' - vserverimpl.setname(self.ctx, slice_id) - - def getname(self): - '''Get vcVHI_CONTEXT field in kernel''' - return vserverimpl.getname(self.ctx) + pass def create(vm_name, static = False, ctor = VServer): diff --git a/scripts/vuseradd b/scripts/vuseradd index ef57534..b54aec9 100755 --- a/scripts/vuseradd +++ b/scripts/vuseradd @@ -117,6 +117,9 @@ if [ ! -d $__CONFDIR/$NAME ] ; then # Disable mount namespaces touch $DIR/nonamespace + # Add spaces directory + mkdir -p $DIR/spaces + # Remove the basically empty guest directory rm -rf $__DEFAULT_VSERVERDIR/$NAME # Move the guest back diff --git a/util-vserver-pl.spec b/util-vserver-pl.spec index a936e4a..915c77b 100644 --- a/util-vserver-pl.spec +++ b/util-vserver-pl.spec @@ -5,7 +5,7 @@ %define name util-vserver-pl %define version 0.4 -%define taglevel 3 +%define taglevel 4 %define release %{taglevel}%{?pldistro:.%{pldistro}}%{?date:.%{date}} -- 2.43.0