X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sliver_lxc.py;h=c3b098ec274a148b9b65084cd3a8008ada690c69;hb=1cb176d4c1d89f39b6683cb53c8e1e5e4917a902;hp=a4f65f00b9aecd7def5c83190327c0d0284d4896;hpb=edf678989b7eeacd1120e6849ed9bc5befe4c3be;p=nodemanager.git diff --git a/sliver_lxc.py b/sliver_lxc.py index a4f65f0..c3b098e 100644 --- a/sliver_lxc.py +++ b/sliver_lxc.py @@ -10,6 +10,13 @@ import grp from pwd import getpwnam from string import Template +# vsys probably should not be a plugin +# the thing is, the right way to handle stuff would be that +# if slivers get created by doing a,b,c +# then they sohuld be delted by doing c,b,a +# the current ordering model for vsys plugins completely fails to capture that +from plugins.vsys import removeSliverFromVsys, startService as vsysStartService + import libvirt import logger @@ -83,7 +90,7 @@ class Sliver_LXC(Sliver_Libvirt, Initscript): vref = rec['vref'] if vref is None: - vref = "lxc-f14-x86_64" + vref = "lxc-f18-x86_64" logger.log("sliver_libvirt: %s: WARNING - no vref attached, using hard-wired default %s" % (name,vref)) refImgDir = os.path.join(Sliver_LXC.REF_IMG_BASE_DIR, vref) @@ -229,6 +236,10 @@ unset pathmunge if not found: with open(from_root,"a") as user_profile: user_profile.write(enforced_line) + # in case we create the slice's .profile when writing + if from_root.find("/home")>=0: + command=['chown','%s:slices'%name,from_root] + logger.log_call(command,timeout=5) # Lookup for xid and create template after the user is created so we # can get the correct xid based on the name of the slice @@ -259,7 +270,7 @@ unset pathmunge dom = conn.lookupByName(name) except: dom = conn.defineXML(xml) - logger.verbose('lxc_create: %s -> %s'%(name, Sliver_Libvirt.debuginfo(dom))) + logger.verbose('lxc_create: %s -> %s'%(name, Sliver_Libvirt.dom_details(dom))) @staticmethod @@ -275,37 +286,58 @@ unset pathmunge # Destroy libvirt domain dom = conn.lookupByName(name) except: - logger.verbose('sliver_lxc: Domain %s does not exist!' % name) + logger.verbose('sliver_lxc.destroy: Domain %s does not exist!' % name) + return + + # Slivers with vsys running will fail the subvolume delete + # removeSliverFromVsys return True if it stops vsys, telling us to start it again later + vsys_stopped = removeSliverFromVsys (name) try: + logger.log("sliver_lxc.destroy: destroying domain %s"%name) dom.destroy() except: - logger.verbose('sliver_lxc: Domain %s not running... continuing.' % name) + logger.verbose('sliver_lxc.destroy: Domain %s not running... continuing.' % name) try: + logger.log("sliver_lxc.destroy: undefining domain %s"%name) dom.undefine() except: - logger.verbose('sliver_lxc: Domain %s is not defined... continuing.' % name) + logger.verbose('sliver_lxc.destroy: Domain %s is not defined... continuing.' % name) # Remove user after destroy domain to force logout command = ['/usr/sbin/userdel', '-f', '-r', name] logger.log_call(command, timeout=15*60) - if os.path.exists(os.path.join(containerDir,"vsys")): - # Slivers with vsys running will fail the subvolume delete. - # A more permanent solution may be to ensure that the vsys module - # is called before the sliver is destroyed. - logger.log("destroying vsys directory and restarting vsys") - logger.log_call(["rm", "-fR", os.path.join(containerDir, "vsys")]) - logger.log_call(["/etc/init.d/vsys", "restart", ]) - + # clean up rootfs as userdel will only take care of /home/ + command = ['rm','-rf', containerDir] + logger.log_call(command, timeout=60) + # at this point we sometimes see one subvolume left in /vservers//vrefname + command = ['btrfs', 'subvolume', 'delete', "%s/*"%containerDir ] + logger.log_call(command, timeout=10) # Remove rootfs of destroyed domain command = ['btrfs', 'subvolume', 'delete', containerDir] - logger.log_call(command, timeout=60) - - if os.path.exists(containerDir): - # oh no, it's still here... - logger.log("WARNING: failed to destroy container %s" % containerDir) - - logger.verbose('sliver_libvirt: %s destroyed.'%name) + logger.log_call(command, timeout=10) + if not os.path.exists(containerDir): + logger.log('sliver_lxc.destroy: %s cleanly destroyed.'%name) + else: + # oh no, it's still here... + # this is more of a way to try and understand what is going on here + # than a real solution to anything + pass_no=1 + max_passes=2 + while pass_no <= max_passes: + command = ['rm', '-rf', containerDir] + logger.log("sliver_lxc.destroy: cleanup pass %d - command %s"%(pass_no,command)) + logger.log_call(command, timeout=5) + command = ['btrfs', 'subvolume', 'delete', containerDir] + logger.log("sliver_lxc.destroy: cleanup pass %d - command %s"%(pass_no,command)) + logger.log_call(command, timeout=5) + import time + time.sleep(1) + pass_no += 1 + if os.path.exists(containerDir): + logger.log('sliver_lxc.destroy: could not cleanly destroy %s - giving up'%name) + + if vsys_stopped: vsysStartService()