- @staticmethod
- def create(name, rec = None):
- ''' Create dirs, copy fs image, lxc_create '''
- logger.verbose ('sliver_libvirt: %s create'%(name))
- dir = '/vservers/%s'%(name)
-
- # Template for libvirt sliver configuration
- template = Template(open('/vservers/.lvref/config_template.xml').read())
- config = template.substitute(name=name)
-
- lxc_log = '%s/log'%(dir)
-
- # 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"
-
- # check the template exists -- there's probably a better way..
- if not os.path.isdir ("/vservers/.lvref/%s"%vref):
- 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', '/vservers/.lvref/%s'%vref, '/vservers/%s'%name]
- logger.log_call(command, timeout=15*60)
-
- # Set hostname
- file('/vservers/%s/etc/hostname' % name, 'w').write(name)
-
- # Add slices group if not already present
- command = ['/usr/sbin/groupadd slices']
- logger.log_call(command, timeout=15*60)
- # Add unix account
- command = ['/usr/sbin/useradd', '-g', 'slices', '-s', '/bin/sh', name, '-p', '*']
- 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)))