review timeouts
[nodemanager.git] / sliver_lxc.py
index d78446e..0f26464 100644 (file)
@@ -11,9 +11,9 @@ from string import Template
 
 import logger
 import bwlimit
-import sliver_libvirt
+from sliver_libvirt import Sliver_Libvirt
 
-class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
+class Sliver_LXC(Sliver_Libvirt):
     """This class wraps LXC commands"""
 
     SHELL = '/bin/sshsh'
@@ -28,7 +28,7 @@ class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
     def create(name, rec=None):
         ''' Create dirs, copy fs image, lxc_create '''
         logger.verbose ('sliver_lxc: %s create'%(name))
-        conn = sliver_libvirt.getConnection(Sliver_LXC.TYPE)
+        conn = Sliver_Libvirt.getConnection(Sliver_LXC.TYPE)
 
         # Get the type of image from vref myplc tags specified as:
         # pldistro = lxc
@@ -45,13 +45,15 @@ class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
         # check the template exists -- there's probably a better way..
         if not os.path.isdir(refImgDir):
             logger.log('sliver_lxc: %s: ERROR Could not create sliver - reference image %s not found' % (name,vref))
-            logger.log('sliver_lxc: %s: ERROR ctd expected reference image in %s'%(name,refImgDir))
+            logger.log('sliver_lxc: %s: ERROR Expected reference image in %s'%(name,refImgDir))
             return
 
         # Snapshot the reference image fs (assume the reference image is in its own
         # subvolume)
         command = ['btrfs', 'subvolume', 'snapshot', refImgDir, containerDir]
-        logger.log_call(command, timeout=15*60)
+        if not logger.log_call(command, timeout=15*60):
+            logger.log('sliver_lxc: ERROR Could not create BTRFS snapshot at', containDir)
+            return
         command = ['chmod', '755', containerDir]
         logger.log_call(command, timeout=15*60)
 
@@ -83,16 +85,16 @@ class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
         # password... maybe remove the need for authentication inside the
         # guest?
         command = ['su', '-s', '/bin/bash', '-c', 'ssh-keygen -t rsa -N "" -f /home/%s/.ssh/id_rsa'%(name)]
-        logger.log_call(command, timeout=15*60)
+        logger.log_call(command, timeout=60)
 
         command = ['chown', '-R', '%s.slices'%name, '/home/%s/.ssh'%name]
-        logger.log_call(command, timeout=15*60)
+        logger.log_call(command, timeout=30)
 
         command = ['mkdir', '%s/root/.ssh'%containerDir]
-        logger.log_call(command, timeout=15*60)
+        logger.log_call(command, timeout=10)
 
         command = ['cp', '/home/%s/.ssh/id_rsa.pub'%name, '%s/root/.ssh/authorized_keys'%containerDir]
-        logger.log_call(command, timeout=15*60)
+        logger.log_call(command, timeout=30)
 
         # 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
@@ -120,13 +122,13 @@ class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
             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.debuginfo(dom)))
 
 
     @staticmethod
     def destroy(name):
         logger.verbose ('sliver_lxc: %s destroy'%(name))
-        conn = sliver_libvirt.getConnection(Sliver_LXC.TYPE)
+        conn = Sliver_Libvirt.getConnection(Sliver_LXC.TYPE)
 
         containerDir = Sliver_LXC.CON_BASE_DIR + '/%s'%(name)
 
@@ -134,15 +136,17 @@ class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
             # Destroy libvirt domain
             dom = conn.lookupByName(name)
         except:
-            logger.verbose('sliver_lxc: Domain %s does not exist! UNEXPECTED'%name)
-            return
+            logger.verbose('sliver_lxc: Domain %s does not exist!' % name)
 
         try:
             dom.destroy()
         except:
-            logger.verbose('sliver_lxc: Domain %s not running... continuing.'%name)
+            logger.verbose('sliver_lxc: Domain %s not running... continuing.' % name)
 
-        dom.undefine()
+        try:
+            dom.undefine()
+        except:
+            logger.verbose('sliver_lxc: Domain %s is not defined... continuing.' % name)
 
         # Remove user after destroy domain to force logout
         command = ['/usr/sbin/userdel', '-f', '-r', name]
@@ -150,7 +154,7 @@ class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
 
         # Remove rootfs of destroyed domain
         command = ['btrfs', 'subvolume', 'delete', containerDir]
-        logger.log_call(command, timeout=15*60)
+        logger.log_call(command, timeout=60)
 
         logger.verbose('sliver_libvirt: %s destroyed.'%name)