X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sliver_lxc.py;h=e68a0b44c19a5883fc8709404dc90670c10891ed;hb=ae9ce869dc1f25965dfd8107c88bfc7bcddcf3e2;hp=a93a21573061122b0f04036c8c1c64af12070fba;hpb=d7a9ab6470e79e705ff2fbfc8494c31abd460253;p=nodemanager.git diff --git a/sliver_lxc.py b/sliver_lxc.py index a93a215..e68a0b4 100644 --- a/sliver_lxc.py +++ b/sliver_lxc.py @@ -3,33 +3,77 @@ """LXC slivers""" import accounts +import logger +import subprocess +import os +import libvirt +import sys +from string import Template +import sliver_libvirt as lv + +URI = 'lxc://' class Sliver_LXC(accounts.Account): """This class wraps LXC commands""" - - SHELL = '/bin/bash' + + SHELL = '/bin/sshsh' + TYPE = 'sliver.LXC' # Need to add a tag at myplc to actually use this account # type = 'sliver.LXC' - def __init__(self, rec): - print "TODO __init__" - + @staticmethod - def create(name, rec = None): - print "TODO create" + def create(name, rec=None): + conn = lv.getConnection(URI) + + # 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 + lv.create(name, config, rec, conn) + @staticmethod def destroy(name): - print "TODO destroy" + conn = lv.getConnection(URI) + lv.destroy(name, conn) + + def __init__(self, rec): + self.name = rec['name'] + logger.verbose ('sliver_lxc: %s init'%(self.name)) + + self.dir = '/vservers/%s'%(self.name) + + # Assume the directory with the image and config files + # are in place + + self.keys = '' + self.rspec = {} + self.slice_id = rec['slice_id'] + self.disk_usage_initialized = False + self.initscript = '' + self.enabled = True + self.conn = lv.getConnection(URI) + try: + self.container = self.conn.lookupByName(self.name) + except: + logger.verbose('sliver_libvirt: Unexpected error on %s: %s'%(self.name, sys.exc_info()[0])) def start(self, delay=0): - print "TODO start" - + lv.start(self.container) + def stop(self): - print "TODO stop" - + lv.stop(self.container) + def is_running(self): - print "TODO is_running" + lv.is_running(self.container) - + def configure(self, rec): + ''' Allocate resources and fancy configuration stuff ''' + logger.verbose('sliver_libvirt: %s configure'%(self.name)) + accounts.Account.configure(self, rec)