Skip to content

Commit

Permalink
Added cpu_info report to HyperV Compute driver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Luis Fernandez Alvarez committed Nov 23, 2012
1 parent 2e1ff2e commit 70619d4
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 4 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions nova/tests/test_hypervapi.py
Expand Up @@ -76,7 +76,7 @@ def _setup_stubs(self):
fake_image.stub_out_image_service(self.stubs)
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs)

def fake_dumps(msg):
def fake_dumps(msg, default=None, **kwargs):
return '""'
self.stubs.Set(json, 'dumps', fake_dumps)

Expand Down Expand Up @@ -108,7 +108,8 @@ def update(self_fake, context, image_id, image_metadata, f):
'multiprocessing',
'_winreg',
'nova.virt.configdrive',
'nova.utils'
'nova.utils',
'ctypes'
]

# Modules in which the mocks are going to be injected
Expand Down
24 changes: 24 additions & 0 deletions nova/virt/hyperv/constants.py
Expand Up @@ -44,6 +44,30 @@
'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
Expand Down
35 changes: 33 additions & 2 deletions nova/virt/hyperv/hostops.py
Expand Up @@ -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__)
Expand All @@ -35,6 +38,35 @@ def __init__(self):
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.
Expand Down Expand Up @@ -114,7 +146,6 @@ def get_available_resource(self):
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,
Expand All @@ -124,7 +155,7 @@ def get_available_resource(self):
'hypervisor_type': "hyperv",
'hypervisor_version': self._get_hypervisor_version(),
'hypervisor_hostname': platform.node(),
'cpu_info': 'unknown'}
'cpu_info': self._get_cpu_info()}

return dic

Expand Down

0 comments on commit 70619d4

Please sign in to comment.