Skip to content
Snippets Groups Projects
kvm.py 1.07 KiB
Newer Older
Benziane Chakib's avatar
Benziane Chakib committed
'''
All KVM technology specefic functions are implemented inside this module
Two entites belong to this module: a Kvm hypervisor or a Kvm virtual machine
'''


from libvirtwrapper import *
from exceptions import *
import subprocess
Benziane Chakib's avatar
Benziane Chakib committed


class KvmHypervisor(LibvirtHypervisor):
    '''
    Base class of a Kvm Hypervisor
    This class have a attribute hv_type for tagging purposes
    '''
    _instance = None

    def __init__(self):
        super(KvmHypervisor, self).__init__('kvm')
        self.hv_type = 'KVM/QEMU'
    
    def __new__(cls, *args, **kwargs):
        '''
        .. note::
            We use singleton design pattern to force only a single instance
            of ourlibvirt 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(KvmHypervisor, cls).__new__(cls, *args,
                                                                **kwargs)
        return cls._instance