From 70619d45cc540ae4f46927fc22972060fba43750 Mon Sep 17 00:00:00 2001 From: Luis Fernandez Alvarez Date: Fri, 23 Nov 2012 09:46:52 +0100 Subject: Added cpu_info report to HyperV Compute driver It fixes bug 1082275 The current version of the HyperV Compute driver wasn't returning CPU information when it reported its resources. In order to solve it, this patch extracts the cpu properties from WMI and Win32 calls. Change-Id: I5c2a89b5e432f4e958354a15582258d4cff83658 --- nova/virt/hyperv/constants.py | 24 ++++++++++++++++++++++++ nova/virt/hyperv/hostops.py | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/hyperv/constants.py b/nova/virt/hyperv/constants.py index 29a98d345..4be569e88 100644 --- a/nova/virt/hyperv/constants.py +++ b/nova/virt/hyperv/constants.py @@ -44,6 +44,30 @@ REQ_POWER_STATE = { 'Suspended': HYPERV_VM_STATE_SUSPENDED, } +WMI_WIN32_PROCESSOR_ARCHITECTURE = { + 0: 'x86', + 1: 'MIPS', + 2: 'Alpha', + 3: 'PowerPC', + 5: 'ARM', + 6: 'Itanium-based systems', + 9: 'x64', +} + +PROCESSOR_FEATURE = { + 7: '3dnow', + 3: 'mmx', + 12: 'nx', + 9: 'pae', + 8: 'rdtsc', + 20: 'slat', + 13: 'sse3', + 21: 'vmx', + 6: 'sse', + 10: 'sse2', + 17: 'xsave', +} + WMI_JOB_STATUS_STARTED = 4096 WMI_JOB_STATE_RUNNING = 4 WMI_JOB_STATE_COMPLETED = 7 diff --git a/nova/virt/hyperv/hostops.py b/nova/virt/hyperv/hostops.py index c07388c35..8c501ab30 100644 --- a/nova/virt/hyperv/hostops.py +++ b/nova/virt/hyperv/hostops.py @@ -18,13 +18,16 @@ """ Management class for host operations. """ +import ctypes import multiprocessing import os import platform from nova.openstack.common import cfg +from nova.openstack.common import jsonutils from nova.openstack.common import log as logging from nova.virt.hyperv import baseops +from nova.virt.hyperv import constants CONF = cfg.CONF LOG = logging.getLogger(__name__) @@ -35,6 +38,35 @@ class HostOps(baseops.BaseOps): super(HostOps, self).__init__() self._stats = None + def _get_cpu_info(self): + """ Get the CPU information. + :returns: A dictionary containing the main properties + of the central processor in the hypervisor. + """ + cpu_info = dict() + processor = self._conn_cimv2.query( + "SELECT * FROM Win32_Processor WHERE ProcessorType = 3") + + cpu_info['arch'] = constants.WMI_WIN32_PROCESSOR_ARCHITECTURE\ + .get(processor[0].Architecture, 'Unknown') + cpu_info['model'] = processor[0].Name + cpu_info['vendor'] = processor[0].Manufacturer + + topology = dict() + topology['sockets'] = len(processor) + topology['cores'] = processor[0].NumberOfCores + topology['threads'] = processor[0].NumberOfLogicalProcessors\ + / processor[0].NumberOfCores + cpu_info['topology'] = topology + + features = list() + for fkey, fname in constants.PROCESSOR_FEATURE.items(): + if ctypes.windll.kernel32.IsProcessorFeaturePresent(fkey): + features.append(fname) + cpu_info['features'] = features + + return jsonutils.dumps(cpu_info) + def _get_vcpu_total(self): """Get vcpu number of physical computer. :returns: the number of cpu core. @@ -114,7 +146,6 @@ class HostOps(baseops.BaseOps): LOG.info(_('get_available_resource called')) local_gb, used_gb = self._get_local_hdd_info_gb() - # TODO(alexpilotti) implemented cpu_info dic = {'vcpus': self._get_vcpu_total(), 'memory_mb': self._get_memory_mb_total(), 'local_gb': local_gb, @@ -124,7 +155,7 @@ class HostOps(baseops.BaseOps): 'hypervisor_type': "hyperv", 'hypervisor_version': self._get_hypervisor_version(), 'hypervisor_hostname': platform.node(), - 'cpu_info': 'unknown'} + 'cpu_info': self._get_cpu_info()} return dic -- cgit