"""LibVirt slivers"""
-import account
-import logger
+import sys
+import os, os.path
import subprocess
-import os
-import os.path
+import pprint
+
import libvirt
-import sys
-import shutil
+
+from account import Account
+import logger
import bwlimit
import cgroups
-import pprint
-
-from string import Template
STATES = {
libvirt.VIR_DOMAIN_NOSTATE: 'no state',
connections = dict()
-# Helper methods
+# Common Libvirt code
-def getConnection(sliver_type):
- # TODO: error checking
- # vtype is of the form sliver.[LXC/QEMU] we need to lower case to lxc/qemu
- vtype = sliver_type.split('.')[1].lower()
- uri = vtype + '://'
- return connections.setdefault(uri, libvirt.open(uri))
+class Sliver_Libvirt(Account):
-def debuginfo(dom):
- ''' Helper method to get a "nice" output of the info struct for debug'''
- [state, maxmem, mem, ncpu, cputime] = dom.info()
- return '%s is %s, maxmem = %s, mem = %s, ncpu = %s, cputime = %s' % (dom.name(), STATES.get(state, state), maxmem, mem, ncpu, cputime)
+ # Helper methods
-# Common Libvirt code
+ @staticmethod
+ def getConnection(sliver_type):
+ # TODO: error checking
+ # vtype is of the form sliver.[LXC/QEMU] we need to lower case to lxc/qemu
+ vtype = sliver_type.split('.')[1].lower()
+ uri = vtype + '://'
+ return connections.setdefault(uri, libvirt.open(uri))
-class Sliver_Libvirt(account.Account):
+ @staticmethod
+ def debuginfo(dom):
+ ''' Helper method to get a "nice" output of the info struct for debug'''
+ [state, maxmem, mem, ncpu, cputime] = dom.info()
+ return '%s is %s, maxmem = %s, mem = %s, ncpu = %s, cputime = %s' % (dom.name(), STATES.get(state, state), maxmem, mem, ncpu, cputime)
def __init__(self, rec):
self.name = rec['name']
cgroups.write(self.name, 'cpu.shares', cpu_share)
# Call the upper configure method (ssh keys...)
- account.Account.configure(self, rec)
+ Account.configure(self, rec)
import logger
import bwlimit
-import sliver_libvirt
+from sliver_libvirt import Sliver_Libvirt
-class Sliver_LXC(sliver_libvirt.Sliver_Libvirt):
+class Sliver_LXC(Sliver_Libvirt):
"""This class wraps LXC commands"""
SHELL = '/bin/sshsh'
def create(name, rec=None):
''' Create dirs, copy fs image, lxc_create '''
logger.verbose ('sliver_lxc: %s create'%(name))
- conn = sliver_libvirt.getConnection(Sliver_LXC.TYPE)
+ conn = Sliver_Libvirt.getConnection(Sliver_LXC.TYPE)
# Get the type of image from vref myplc tags specified as:
# pldistro = lxc
dom = conn.lookupByName(name)
except:
dom = conn.defineXML(xml)
- logger.verbose('lxc_create: %s -> %s'%(name, sliver_libvirt.debuginfo(dom)))
+ logger.verbose('lxc_create: %s -> %s'%(name, Sliver_Libvirt.debuginfo(dom)))
@staticmethod
def destroy(name):
logger.verbose ('sliver_lxc: %s destroy'%(name))
- conn = sliver_libvirt.getConnection(Sliver_LXC.TYPE)
+ conn = Sliver_Libvirt.getConnection(Sliver_LXC.TYPE)
containerDir = Sliver_LXC.CON_BASE_DIR + '/%s'%(name)