Commit 53696d3c authored by Antoine Millet's avatar Antoine Millet
Browse files

Added memremaining tag

parent 012be518
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ class Handler(HostHandler):

        # we must refresh those tags only when domains tags are registered to
        # have the calculated values
        for tag in ('cpualloc', 'cpurunning', 'memalloc', 'memrunning'):
        for tag in ('cpualloc', 'cpurunning', 'memalloc', 'memrunning', 'memremaining'):
            self.tag_db['__main__'][tag].update_value()

        # register libvirt handlers
+9 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ from functools import wraps
import libvirt

from cloudcontrol.node.utils import and_
from cloudcontrol.common.client.tags import ttl, refresh


logger = logging.getLogger(__name__)
@@ -175,3 +176,11 @@ def memalloc(handl):
    """Memory used by all VMs on the hypervisor."""
    return sum(int(vm.tag_db['__main__']['mem'].value) for vm in
               handl.hypervisor.domains.itervalues() if vm.tag_db['__main__']['mem'].value)


@_check_virt_connected
def memremaining(handl):
    """Allocatable memory remaining on the hypervisor."""
    mem = int(handl.tag_db['__main__']['mem'].value)
    memalloc = int(handl.tag_db['__main__']['memalloc'].value)
    return mem - memalloc
 No newline at end of file