summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis Fernandez Alvarez <luis.fernandez.alvarez@cern.ch>2012-11-12 14:35:12 +0100
committerLuis Fernandez Alvarez <luis.fernandez.alvarez@cern.ch>2012-11-12 17:35:49 +0100
commit3d09a28ceca8bf0e594fc103f977e844071e3ea8 (patch)
treea066cae7997f52a3c223cbb4776545a5c7c319cc
parent24e86f40f7230544666ef99650353da76a1b9297 (diff)
Fixed HyperV to get disk stats of instances drive
It fixes bug 1077922 The current version of the HyperV Compute driver was returning the disk stats about the C: drive always. This patch makes HyperV driver extract the current drive from the flag 'instances_path'. In order to optimize the procedure, the disk stats extraction is also unified in one method. Change-Id: I4920cf2cc07d0f514c0358144b7bceb15d439a63
-rw-r--r--nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_multiprocessing.p.gzbin270 -> 270 bytes
-rw-r--r--nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_os.p.gzbin0 -> 423 bytes
-rw-r--r--nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_shutil.p.gzbin298 -> 298 bytes
-rw-r--r--nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_wmi.p.gzbin1013 -> 978 bytes
-rw-r--r--nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_os.p.gzbin0 -> 415 bytes
-rw-r--r--nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_shutil.p.gzbin290 -> 290 bytes
-rw-r--r--nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_wmi.p.gzbin888 -> 842 bytes
-rw-r--r--nova/virt/hyperv/hostops.py50
8 files changed, 20 insertions, 30 deletions
diff --git a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_multiprocessing.p.gz b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_multiprocessing.p.gz
index 3f50a76e0..42665b9f1 100644
--- a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_multiprocessing.p.gz
+++ b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_multiprocessing.p.gz
Binary files differ
diff --git a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_os.p.gz b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_os.p.gz
new file mode 100644
index 000000000..56a2cc958
--- /dev/null
+++ b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_os.p.gz
Binary files differ
diff --git a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_shutil.p.gz b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_shutil.p.gz
index 35126ad4b..e38b94d44 100644
--- a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_shutil.p.gz
+++ b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_shutil.p.gz
Binary files differ
diff --git a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_wmi.p.gz b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_wmi.p.gz
index 1a34569d1..fd4fd77af 100644
--- a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_wmi.p.gz
+++ b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_available_resource_wmi.p.gz
Binary files differ
diff --git a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_os.p.gz b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_os.p.gz
new file mode 100644
index 000000000..56bc137ed
--- /dev/null
+++ b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_os.p.gz
Binary files differ
diff --git a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_shutil.p.gz b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_shutil.p.gz
index 805931bbb..aaa2cdc1c 100644
--- a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_shutil.p.gz
+++ b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_shutil.p.gz
Binary files differ
diff --git a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_wmi.p.gz b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_wmi.p.gz
index e9852d038..c60521c1d 100644
--- a/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_wmi.p.gz
+++ b/nova/tests/hyperv/stubs/test_hypervapi.HyperVAPITestCase.test_get_host_stats_wmi.p.gz
Binary files differ
diff --git a/nova/virt/hyperv/hostops.py b/nova/virt/hyperv/hostops.py
index a2f9d5904..627cf72bc 100644
--- a/nova/virt/hyperv/hostops.py
+++ b/nova/virt/hyperv/hostops.py
@@ -19,11 +19,14 @@
Management class for host operations.
"""
import multiprocessing
+import os
import platform
+from nova import config
from nova.openstack.common import log as logging
from nova.virt.hyperv import baseops
+CONF = config.CONF
LOG = logging.getLogger(__name__)
@@ -55,19 +58,21 @@ class HostOps(baseops.BaseOps):
total_mb = long(total_kb) / 1024
return total_mb
- def _get_local_gb_total(self):
- """Get the total hdd size(GB) of physical computer.
+ def _get_local_hdd_info_gb(self):
+ """Get the total and used size of the volume containing
+ CONF.instances_path expressed in GB.
:returns:
- The total amount of HDD(GB).
- Note that this value shows a partition where
- NOVA-INST-DIR/instances mounts.
+ A tuple with the total and used space in GB.
"""
- #TODO(jordanrinke): This binds to C only right now,
- #need to bind to instance dir
- total_kb = self._conn_cimv2.query(
- "SELECT Size FROM win32_logicaldisk WHERE DriveType=3")[0].Size
- total_gb = long(total_kb) / (1024 ** 3)
- return total_gb
+ normalized_path = os.path.normpath(CONF.instances_path)
+ drive, path = os.path.splitdrive(normalized_path)
+ hdd_info = self._conn_cimv2.query(
+ ("SELECT FreeSpace,Size FROM win32_logicaldisk WHERE DeviceID='%s'"
+ ) % drive)[0]
+ total_gb = long(hdd_info.Size) / (1024 ** 3)
+ free_gb = long(hdd_info.FreeSpace) / (1024 ** 3)
+ used_gb = total_gb - free_gb
+ return total_gb, used_gb
def _get_vcpu_used(self):
""" Get vcpu usage number of physical computer.
@@ -88,21 +93,6 @@ class HostOps(baseops.BaseOps):
return total_mb
- def _get_local_gb_used(self):
- """Get the free hdd size(GB) of physical computer.
- :returns:
- The total usage of HDD(GB).
- Note that this value shows a partition where
- NOVA-INST-DIR/instances mounts.
- """
- #TODO(jordanrinke): This binds to C only right now,
- #need to bind to instance dir
- total_kb = self._conn_cimv2.query(
- "SELECT FreeSpace FROM win32_logicaldisk WHERE DriveType=3")[0]\
- .FreeSpace
- total_gb = long(total_kb) / (1024 ** 3)
- return total_gb
-
def _get_hypervisor_version(self):
"""Get hypervisor version.
:returns: hypervisor version (ex. 12003)
@@ -123,13 +113,14 @@ 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': self._get_local_gb_total(),
+ 'local_gb': local_gb,
'vcpus_used': self._get_vcpu_used(),
'memory_mb_used': self._get_memory_mb_used(),
- 'local_gb_used': self._get_local_gb_used(),
+ 'local_gb_used': used_gb,
'hypervisor_type': "hyperv",
'hypervisor_version': self._get_hypervisor_version(),
'hypervisor_hostname': platform.node(),
@@ -141,8 +132,7 @@ class HostOps(baseops.BaseOps):
LOG.debug(_("Updating host stats"))
data = {}
- data["disk_total"] = self._get_local_gb_total()
- data["disk_used"] = self._get_local_gb_used()
+ data["disk_total"], data["disk_used"] = self._get_local_hdd_info_gb()
data["disk_available"] = data["disk_total"] - data["disk_used"]
data["host_memory_total"] = self._get_memory_mb_total()
data["host_memory_overhead"] = self._get_memory_mb_used()