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'
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
# 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)
# 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
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)
# 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]
# 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)