+def getConnection(uri):
+ # TODO: error checking
+ return connections.setdefault(uri, libvirt.open(uri))
+
+def create(name, xml, rec, conn):
+ ''' Create dirs, copy fs image, lxc_create '''
+ logger.verbose ('sliver_libvirt: %s create'%(name))
+
+ # 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. A valid hostname cannot have '_'
+ with open(os.path.join(containerDir, 'etc/hostname'), 'w') as f:
+ print >>f, name.replace('_', '-')
+
+ # Add slices group if not already present
+ command = ['/usr/sbin/groupadd', 'slices']
+ logger.log_call(command, timeout=15*60)