import time
import traceback
import subprocess
+import commands
import resource
import vserverimpl
class NoSuchVServer(Exception): pass
-
class VServerConfig:
def __init__(self, name, directory):
self.name = name
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
vserverimpl.setrlimit(self.ctx, resource_type, hard, soft, min)
except OSError, e:
self.log("Error: setrlimit(%d, %s, %d, %d, %d): %s"
- % (self.ctx, type.lower(), hard, soft, min))
+ % (self.ctx, type.lower(), hard, soft, min, e))
return update
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)
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)
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)
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)
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)
(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
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)
+ pass
def getname(self):
'''Get vcVHI_CONTEXT field in kernel'''