Skip to content
Snippets Groups Projects
Commit 867b1cbe authored by Anael Beutot's avatar Anael Beutot
Browse files

Updated hypervisor tags.

parent 9e017ea9
No related branches found
No related tags found
No related merge requests found
import logging import logging
import weakref
import libvirt import libvirt
...@@ -17,10 +18,11 @@ class Handler(HostHandler): ...@@ -17,10 +18,11 @@ class Handler(HostHandler):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
""" """
:param proxy: sjRpc proxy :param proxy: sjRpc proxy
:param hypervisor_name: hypervisor name
""" """
HostHandler.__init__(self, *args, **kwargs) HostHandler.__init__(self, *args, **kwargs)
for t in tag_inspector(tags): for t in tag_inspector(tags, self):
self.tags[t.name] = t self.tags[t.name] = t
# set tag hv # set tag hv
...@@ -29,7 +31,9 @@ class Handler(HostHandler): ...@@ -29,7 +31,9 @@ class Handler(HostHandler):
# initialize hypervisor instance # initialize hypervisor instance
global hypervisor global hypervisor
if hypervisor is None: if hypervisor is None:
hypervisor = Hypervisor() hypervisor = Hypervisor(kwargs.pop('hypervisor_name', None))
self.hypervisor = weakref.proxy(hypervisor)
# register domains # register domains
proxy = kwargs.pop('proxy') proxy = kwargs.pop('proxy')
...@@ -74,7 +78,11 @@ class Handler(HostHandler): ...@@ -74,7 +78,11 @@ class Handler(HostHandler):
class Hypervisor(object): class Hypervisor(object):
"""Container for all hypervisor related state.""" """Container for all hypervisor related state."""
def __init__(self): def __init__(self, name=None):
#: hv attributes
self.name = name
self.type = u'kvm'
self.event_loop = EventLoop() self.event_loop = EventLoop()
# This tells libvirt what event loop implementation it # This tells libvirt what event loop implementation it
# should use # should use
...@@ -135,17 +143,17 @@ class Hypervisor(object): ...@@ -135,17 +143,17 @@ class Hypervisor(object):
@property @property
def vm_started(self): def vm_started(self):
"""Number of VMs started.""" """Number of VMs started."""
return self._count_domain(lambda d: d.status == 'started') return self._count_domain(lambda d: d.state == 'running')
@property @property
def vm_stopped(self): def vm_stopped(self):
"""Number of VMs stopped.""" """Number of VMs stopped."""
return self._count_domain(lambda d: d.status == 'stopped') return self._count_domain(lambda d: d.state == 'stopped')
@property @property
def vm_paused(self): def vm_paused(self):
"""Number of VMs paused.""" """Number of VMs paused."""
return self._count_domain(lambda d: d.status == 'paused') return self._count_domain(lambda d: d.state == 'paused')
@property @property
def vm_total(self): def vm_total(self):
......
from ccnode.hypervisor import lib as libvirt_
from ccnode.utils import and_ from ccnode.utils import and_
...@@ -8,10 +9,11 @@ def htype(): ...@@ -8,10 +9,11 @@ def htype():
return u'kvm' return u'kvm'
def hv(): def hv(handl):
"""Hypervisor name.""" """Hypervisor name."""
# What is the point of this tag ? if the information not already in a and id # What is the point of this tag ? if the information not already in a and id
# ? # ?
return handl.hypervisor.name
def hvm(): def hvm():
...@@ -39,10 +41,12 @@ def hvm(): ...@@ -39,10 +41,12 @@ def hvm():
def hvver(): def hvver():
"""Hypervisor version.""" """Hypervisor version."""
return libvirt_.connection.getVersion()
def libvirtver(): def libvirtver():
"""Version of running libvirt.""" """Version of running libvirt."""
return libvirt_.connection.getLibVersion()
# jobs # jobs
...@@ -58,17 +62,21 @@ def sto(): ...@@ -58,17 +62,21 @@ def sto():
# dynamic sto # dynamic sto
# Vm related tags # Vm related tags
def nvm(): def nvm(handl):
"""Number of VMS in the current hypervisor.""" """Number of VMS in the current hypervisor."""
return handl.hypervisor.vm_total
def vmpaused(): def vmpaused(handl):
"""Count of VMs paused.""" """Count of VMs paused."""
return handl.hypervisor.vm_paused
def vmstarted(): def vmstarted(handl):
"""Count of VMs started.""" """Count of VMs started."""
return handl.hypervisor.vm_started
def vmstopped(): def vmstopped(handl):
"""Count of VMs Stopped.""" """Count of VMs Stopped."""
return handl.hypervisor.vm_stopped
...@@ -105,7 +105,8 @@ class Node(Thread): ...@@ -105,7 +105,8 @@ class Node(Thread):
elif role == u'hv': elif role == u'hv':
logger.debug(u'Role hypervisor affected.') logger.debug(u'Role hypervisor affected.')
from ccnode.hypervisor import Handler as HypervisorHandler from ccnode.hypervisor import Handler as HypervisorHandler
self.connection.rpc.set_handler(HypervisorHandler(proxy=self.proxy)) self.connection.rpc.set_handler(HypervisorHandler(
proxy=self.proxy, hypervisor_name=self.user_name))
self.role = u'hv' self.role = u'hv'
else: else:
logger.debug(u'Wrong role returned: %s', role) logger.debug(u'Wrong role returned: %s', role)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment