X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sliver_lxc.py;h=a08b0ce693dd7ab8434aa7136d3e15ab3d585746;hb=63546278c1e00ac6d1910d4d552a933bd170ed28;hp=37055986dd34ad82073f6e2542b46dd2bddbb86f;hpb=ceae8bc56f3f46d5913ca8988b701337a35135cf;p=nodemanager.git diff --git a/sliver_lxc.py b/sliver_lxc.py index 3705598..a08b0ce 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 + 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) @@ -263,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,41 +282,51 @@ unset pathmunge containerDir = Sliver_LXC.CON_BASE_DIR + '/%s'%(name) + # 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. + removeSliverFromVsys (name) + try: # 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 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", ]) - # 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) + if not os.path.exists(containerDir): + logger.log('sliver_lxc.destroy: %s cleanly destroyed.'%name) + else: + # oh no, it's still here... + logger.log("sliver_lxc.destroy: 1st warning: could not delete %s" % containerDir) + # this is for debugging but does not seem to be of much use + logger.log_call (['lsof']) + # what I can see on running nodes is that a second subvolume delete seems to do the trick here + # so let's check if that could be a workaround + logger.log("sliver_lxc.destroy: 2nd attempt at btrfs subvolume delete %s" % containerDir) + command = ['btrfs', 'subvolume', 'delete', containerDir] + logger.log_call(command, timeout=60) + if not os.path.exists(containerDir): + logger.log("sliver_lxc.destroy: WARNING: failed to delete %s after 2 attempts"%containerDir) - logger.verbose('sliver_libvirt: %s destroyed.'%name)