Skip to content
Snippets Groups Projects
xen.py 1.25 KiB
Newer Older
# -*- coding: utf-8 -*-

from libvirtwrapper import LibvirtHypervisor, MEGABYTE_DIV


class XenHypervisor(LibvirtHypervisor):
    '''
    Base class of a Xen Hypervisor
    '''
    _instance = None
    
    def __init__(self):
        '''
        '''
        super(XenHypervisor, self).__init__('xen')
    
    def __new__(cls, *args, **kwargs):
        '''
        .. note::
            We use singleton design pattern to force only a single instance
            of our libvirt hypervisor handle, it's essential since we connect
            with libvirt only on localhost so we must assure one single 
            connection to the hypervisor
        '''
        if cls._instance is None:
            cls._instance = super(XenHypervisor, cls).__new__(cls, *args,
                                                                    **kwargs)
        return cls._instance
    
    def get_mem(self):
        '''
        '''
        mem = None
        try:
            data = self._lvcon_handle.getInfo()[1]
                mem = data * MEGABYTE_DIV
        except:
            pass
        return mem
    
    def get_mem_free(self):
        '''
        '''
        return None
    
    def get_mem_used(self):
        '''
        '''
        return None