Skip to content
Snippets Groups Projects
Commit 51820950 authored by Thibault VINCENT's avatar Thibault VINCENT
Browse files

cleanup

parent 1e3a7beb
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
import libvirt
import re
import psutil
import xml.dom.minidom
from logging import debug, info
from logging import error, warning, info, debug
from time import sleep
from common import Hypervisor, VM, Storage, StoragePool, StorageVolume
from utils import RWLock
from exceptions import HypervisorError, VMError, StoragePoolError
KVM_LIBVIRT_SESSION = 'qemu:///system'
......@@ -29,10 +29,10 @@ class LibvirtHypervisor(Hypervisor):
'''
try:
if hv_type == 'kvm':
debug("LibvirtHypervisor: initialized as KVM")
warning("LibvirtHypervisor: initialized as KVM")
self._lvcon_handle = libvirt.open(KVM_LIBVIRT_SESSION)
elif hv_type == 'xen':
debug("LibvirtHypervisor: initialized as Xen")
warning("LibvirtHypervisor: initialized as Xen")
self._lvcon_handle = libvirt.open(XEN_LIBVIRT_SESSION)
else:
raise NotImplemented('Unknown hypervisor type')
......@@ -55,24 +55,22 @@ class LibvirtHypervisor(Hypervisor):
running = {}
defined = {}
#debug("_vm_cache_rebuild: listing running domains")
for dom_id in self._lvcon_handle.listDomainsID():
#debug("domid=%i" % dom_id)
try:
vm = LibvirtVm(self, self._lvcon_handle.lookupByID(dom_id))
running[vm.get_name()] = vm
except Exception as err:
debug("%s: %s" % (err,err))
debug("_cache_vm_rebuild: listDomainsID: `%s` -> `%s`",
repr(err), err)
#debug("_vm_cache_rebuild: listing defined domains")
for dom_name in self._lvcon_handle.listDefinedDomains():
#debug("domid=%s" % dom_name)
try:
vm = LibvirtVm(self,
self._lvcon_handle.lookupByName(dom_name))
defined[vm.get_name()] = vm
except Exception as err:
debug("%s: %s" % (err,err))
debug("_cache_vm_rebuild: listDefinedDomains: `%s` -> `%s`",
repr(err), err)
with self._vm_cache_lock.write:
self._vm_cache_running = running
......@@ -92,8 +90,7 @@ class LibvirtHypervisor(Hypervisor):
try:
data = self._lvcon_handle.getVersion()
if data:
version = data
version = data
except:
pass
return version
......@@ -537,7 +534,7 @@ class LibvirtVm(VM):
if xarch in self.ARCH:
arch = self.ARCH[xarch]
except:
pass
pass
return arch
def get_cpu_core(self):
......
......@@ -6,6 +6,8 @@ class RWLock(object):
'''
'''
def __init__(self):
'''
'''
self._mutex = Lock()
self._writemutex = Lock()
self._readers = 0
......@@ -17,17 +19,23 @@ class RWLock(object):
'''
'''
def __init__(self, rwlock):
'''
'''
self._parent = rwlock
class _WLock(_Lock):
'''
'''
def __enter__(self):
'''
'''
with self._parent._mutex:
self._parent._writers += 1
self._parent._writemutex.acquire()
def __exit__(self, exc_type, exc_value, traceback):
'''
'''
with self._parent._mutex:
self._parent._writers -= 1
self._parent._writemutex.release()
......@@ -36,6 +44,8 @@ class RWLock(object):
'''
'''
def __enter__(self):
'''
'''
self._parent._mutex.acquire()
if self._parent._writers > 0 or self._parent._readers == 0:
self._parent._mutex.release()
......@@ -45,6 +55,8 @@ class RWLock(object):
self._parent._mutex.release()
def __exit__(self, exc_type, exc_value, traceback):
'''
'''
self._parent._mutex.acquire()
self._parent._readers -= 1
if self._parent._readers == 0:
......
[node]
# address and port of the CloudControl server
address =
address = 10.15.255.42
#port = 1984
# account created for this node on the server
login =
password =
login = $$LOGIN$$
password = $$PASSWORD$$
# logging verbosity level 0-3
verbosity =
#verbosity = 0
# hypervisor detection and connection, set to 'no' on regular hosts or when
# the node should not attempt to use local hypervisors
detect_hypervisor = yes
#detect_hypervisor = yes
# allow remote command execution (or host shutdown/reboot)
#command_execution = yes
# TO BE REMOVED IN LATER RELEASES
# force usage of Xen
force_xen = no
# allow remote command execution (or host shutdown/reboot)
command_execution = yes
#force_xen = no
\ No newline at end of file
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