Skip to content
tags.py 1.88 KiB
Newer Older
from ccnode.utils import and_
from ccnode.hypervisor.lib import vir_tag


# hypervisor related tags
def htype():
    """Hypervisor type."""
    # FIXME for other support
    return u'kvm'


Anael Beutot's avatar
Anael Beutot committed
def hv(handl):
    """Hypervisor name."""
    # What is the point of this tag ? if the information not already in a and id
    # ?
Anael Beutot's avatar
Anael Beutot committed
    return handl.hypervisor.name


def hvm():
    """Hardware virtualization enable."""
    # see
    # http://www.linux-kvm.org/page/FAQ#How_can_I_tell_if_I_have_Intel_VT_or_AMD-V.3F
    # or
    # http://www.cyberciti.biz/faq/linux-xen-vmware-kvm-intel-vt-amd-v-support/
    # if we are in a xen hypervisor we won't see vt in /proc/cpuinfo
    result = {True: u'yes', False: u'no'}

    if htype() == u'kvm':
        # findout in /proc/cpuinfo if all CPUs have virtualisation enabled
        return result[and_(
            set(
                'vmx',  # Intel VT
                'svm',  # AMD 
            ) & set(
                l.split(': ')[-1].split()
            ) for l in open('/proc/cpuinfo').readline() if l.startswith('Tags')
        )]

    return None


def hvver(handl):
    """Hypervisor version."""
    return handl.hypervisor.vir_con.getVersion()
def libvirtver(handl):
    """Version of running libvirt."""
    return handl.hypervisor.vir_con.getLibVersion()


# jobs
def rjobs():
    """Number of currently running jobs."""


# storage pools
Anael Beutot's avatar
Anael Beutot committed
def sto(handl):
    """Storage pool names."""
Anael Beutot's avatar
Anael Beutot committed
    return u' '.join(handl.hypervisor.storage.storages.iterkeys())
Anael Beutot's avatar
Anael Beutot committed
def nvm(handl):
    """Number of VMS in the current hypervisor."""
Anael Beutot's avatar
Anael Beutot committed
    return handl.hypervisor.vm_total
Anael Beutot's avatar
Anael Beutot committed
def vmpaused(handl):
    """Count of VMs paused."""
Anael Beutot's avatar
Anael Beutot committed
    return handl.hypervisor.vm_paused
Anael Beutot's avatar
Anael Beutot committed
def vmstarted(handl):
    """Count of VMs started."""
Anael Beutot's avatar
Anael Beutot committed
    return handl.hypervisor.vm_started
Anael Beutot's avatar
Anael Beutot committed
def vmstopped(handl):
    """Count of VMs Stopped."""
Anael Beutot's avatar
Anael Beutot committed
    return handl.hypervisor.vm_stopped