Francesco Romani has uploaded a new change for review. Change subject: vdsm interface: implement CachingInterface ......................................................................
vdsm interface: implement CachingInterface reimplement vdsm interface in terms of CachingInterface to increase the efficiency Change-Id: I325d6ece32bc947495fb4e862ca86788e1e7054b Signed-off-by: Francesco Romani <[email protected]> --- M mom/HypervisorInterfaces/vdsmInterface.py 1 file changed, 26 insertions(+), 34 deletions(-) git pull ssh://gerrit.ovirt.org:29418/mom refs/changes/25/41225/1 diff --git a/mom/HypervisorInterfaces/vdsmInterface.py b/mom/HypervisorInterfaces/vdsmInterface.py index 8111d3d..02a73e2 100644 --- a/mom/HypervisorInterfaces/vdsmInterface.py +++ b/mom/HypervisorInterfaces/vdsmInterface.py @@ -20,11 +20,13 @@ import supervdsm import logging import traceback + +from mom.HypervisorInterfaces.CachingInterface import CachingInterface from mom.HypervisorInterfaces.HypervisorInterface import HypervisorInterface, \ HypervisorInterfaceError -class vdsmInterface(HypervisorInterface): +class vdsmInterface(CachingInterface): """ vdsmInterface provides a wrapper for the VDSM API so that VDSM- related error handling can be consolidated in one place. An instance of @@ -32,7 +34,8 @@ threads. """ - def __init__(self): + def __init__(self, config): + super(vdsmInterface, self).__init__(config) self.logger = logging.getLogger('mom.vdsmInterface') try: self.vdsm_api = API.Global() @@ -86,14 +89,7 @@ def getVmMemoryStats(self, uuid): try: - vm = API.VM(uuid) - response = vm.getStats() - self._check_status(response) - stats = response['statsList'][0] - err_msg = _check_vm_memory_stats(stats) - if err_msg: - raise HypervisorInterfaceError(err_msg) - ret = _memory_info_from_vm_stats(stats) + ret = _memory_info_from_vm_stats(self._getVmStats(uuid)) self.logger.debug('Memory stats: %s', ret) return ret except vdsmException, e: @@ -107,15 +103,6 @@ except vdsmException, e: e.handle_exception() - def getVmInfo(self, id): - data = {} - data['uuid'] = id - data['pid'] = self.getVmPid(id) - data['name'] = self.getVmName(id) - if None in data.values(): - return None - return data - def getStatsFields(self=None): return set(['mem_available', 'mem_unused', 'mem_free', 'major_fault', 'minor_fault', 'swap_in', 'swap_out', @@ -123,25 +110,17 @@ def getVmBalloonInfo(self, uuid): try: - vm = API.VM(uuid) - response = vm.getStats() - self._check_status(response) - ret = _balloon_info_from_vm_stats(response['statsList'][0]) - if ret: - return ret - return None + ret = _balloon_info_from_vm_stats(self._getVmStats(uuid)) + self.logger.debug('Balloon info stats: %s', ret) + return ret except vdsmException, e: e.handle_exception() def getVmCpuTuneInfo(self, uuid): try: - vm = API.VM(uuid) - response = vm.getStats() - self._check_status(response) - ret = _cpu_tune_info_from_vm_stats(response['statsList'][0]) - if ret: - return ret - return None + ret = _cpu_tune_info_from_vm_stats(self._getVmStats(uuid)) + self.logger.debug('Cpu Tune stats: %s', ret) + return ret except vdsmException, e: e.handle_exception() @@ -163,6 +142,19 @@ # So we need resort to supervdsm to set the KSM parameters. superVdsm = supervdsm.getProxy() superVdsm.ksmTune(tuningParams) + + def _refreshVmStats(self): + return self._getAllVmStats() + + def _getAllVmStats(self): + try: + response = self.vdsm_api.getAllVmStats() + self._check_status(response) + return dict((stat['vmId'], stat) + for stat in response['statsList']) + except vdsmException, e: + e.handle_exception() + return None def _check_vm_memory_stats(vm_stats): @@ -260,4 +252,4 @@ def instance(config): - return vdsmInterface() + return vdsmInterface(config) -- To view, visit https://gerrit.ovirt.org/41225 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I325d6ece32bc947495fb4e862ca86788e1e7054b Gerrit-PatchSet: 1 Gerrit-Project: mom Gerrit-Branch: master Gerrit-Owner: Francesco Romani <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
