-class Sliver_LV(accounts.Account):
- """This class wraps LibVirt commands"""
-
- SHELL = '/bin/sh'
-
- # Need to add a tag at myplc to actually use this account
- # type = 'sliver.LIBVIRT'
- TYPE = 'sliver.LIBVIRT'
-
-
- @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 sliver configuration
- template = Template(open('/vservers/config_template.xml').read())
- config = template.substitute(name=name)
-
- lxc_log = '%s/log'%(dir)
-
- # TODO: copy the sliver FS to the correct path if sliver does not
- # exist.
- if not (os.path.isdir(dir) and
- os.access(dir, os.R_OK | os.W_OK | os.X_OK)):
- logger.verbose('lxc_create: directory %s does not exist or wrong perms'%(dir))
- return
-
- # Set hostname
- file('/vservers/%s/rootfs/etc/hostname' % name, 'w').write(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)))