X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sliver_libvirt.py;h=56ab8ac6cada6d6d9122ee1297475b5ff23b4b27;hb=41bbd0186435d3a61b0fa889f87c40b92cea0177;hp=a3578eb7860b8762d51b7485fa8e6bf1e2440359;hpb=6ec82e6a49df218bcbf4337d85d8d87dc8273824;p=nodemanager.git diff --git a/sliver_libvirt.py b/sliver_libvirt.py index a3578eb..56ab8ac 100644 --- a/sliver_libvirt.py +++ b/sliver_libvirt.py @@ -1,18 +1,16 @@ """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', @@ -26,23 +24,25 @@ STATES = { 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'] @@ -161,5 +161,5 @@ class Sliver_Libvirt(account.Account): cgroups.write(self.name, 'cpu.shares', cpu_share) # Call the upper configure method (ssh keys...) - account.Account.configure(self, rec) + Account.configure(self, rec)