- @staticmethod
- def create(name, rec = None):
- ''' Create dirs, copy fs image, lxc_create '''
- logger.verbose ('sliver_libvirt: %s create'%(name))
-
- # Template for libvirt sliver configuration
- try:
- with open('/vservers/.lvref/config_template.xml') as f:
- template = Template(f.read())
- config = template.substitute(name=name)
- except IOError:
- logger.log('Cannot find XML template file')
- return
-
- # Get the type of image from vref myplc tags specified as:
- # pldistro = lxc
- # fcdistro = squeeze
- # arch x86_64
- vref = rec['vref']
- if vref is None:
- logger.log('sliver_libvirt: %s: WARNING - no vref attached defaults to lxc-debian' % (name))
- vref = "lxc-squeeze-x86_64"
-
- refImgDir = os.path.join(REF_IMG_BASE_DIR, vref)
- containerDir = os.path.join(CON_BASE_DIR, name)
-
- # check the template exists -- there's probably a better way..
- if not os.path.isdir(refImgDir):
- logger.log('sliver_libvirt: %s: ERROR Could not create sliver - reference image %s not found' % (name,vref))
- return
-
- # Copy the reference image fs
- # shutil.copytree("/vservers/.lvref/%s"%vref, "/vservers/%s"%name, symlinks=True)
- command = ['cp', '-r', refImgDir, containerDir]
- logger.log_call(command, timeout=15*60)
-
- # Set hostname
- with open(os.path.join(containerDir, 'etc/hostname'), 'w') as f:
- print >>f, name
-
- # Add unix account
- command = ['/usr/sbin/useradd', '-s', '/bin/sh', name]
- logger.log_call(command, timeout=15*60)
-
- # Get a connection and lookup for the sliver before actually
- # defining it, just in case it was already defined.
- conn = Sliver_LV.getConnection()
- try:
- dom = conn.lookupByName(name)
- except:
- dom = conn.defineXML(config)
- logger.verbose('lxc_create: %s -> %s'%(name, Sliver_LV.info(dom)))