From: Yves Vinter <yves.vinter(a)bull.net>
This patch implements the virConnectGetVersion function for the hyperv libvirt driver.
The value returned by this function must be formatted as
"<major>.<minor>.<release>"
with a maximum of 3 digits per item.
Therefore, value of Microsoft hypervisor's version has been truncated as shown below:
Hyper-V 2008 R2 SP1 (6.1.7601.17514): returned version is 6.1.760
Hyper-V 2012 (6.2.9200.16384): returned version is 6.2.920
A new WMI class has been added (CIM_DataFile).
Signed-off-by: Yves Vinter <yves.vinter(a)bull.net>
---
src/hyperv/hyperv_driver.c | 46 +++++++++++++++++++++++++++++++++++
src/hyperv/hyperv_wmi_generator.input | 37 ++++++++++++++++++++++++++++
src/hyperv/hyperv_wmi_generator.py | 4 +--
3 files changed, 85 insertions(+), 2 deletions(-)
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 5ffcb85..fba7f38 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1352,6 +1352,51 @@ hypervConnectListAllDomains(virConnectPtr conn,
#undef MATCH
+static int
+hypervConnectGetVersion(virConnectPtr conn, unsigned long *version)
+{
+ int result = -1;
+ hypervPrivate *priv = conn->privateData;
+ CIM_DataFile *datafile = NULL;
+ virBuffer query = VIR_BUFFER_INITIALIZER;
+ char *p;
+
+ virBufferAddLit(&query, "Select * from CIM_DataFile where
Name='c:\\\\windows\\\\system32\\\\vmms.exe'");
+ if (hypervGetCIMDataFileList(priv, &query, &datafile) < 0)
+ goto cleanup;
+
+ if (datafile == NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Unable to get hypervisor version"));
+ goto cleanup;
+ }
+
+ /* Delete release number and last digit of build number 1.1.111x.xxxx */
+ p = strrchr(datafile->data->Version, '.');
+ if (p == NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not parse version number from '%s'"),
+ datafile->data->Version);
+ goto cleanup;
+ }
+ p--;
+ *p = '\0';
+
+ if (virParseVersionString(datafile->data->Version,
+ version, true) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not parse version number from '%s'"),
+ datafile->data->Version);
+ goto cleanup;
+ }
+
+ result = 0;
+
+ cleanup:
+ hypervFreeObject(priv, (hypervObject *)datafile);
+
+ return result;
+}
static virHypervisorDriver hypervDriver = {
@@ -1389,6 +1434,7 @@ static virHypervisorDriver hypervDriver = {
.domainHasManagedSaveImage = hypervDomainHasManagedSaveImage, /* 0.9.5 */
.domainManagedSaveRemove = hypervDomainManagedSaveRemove, /* 0.9.5 */
.connectIsAlive = hypervConnectIsAlive, /* 0.9.8 */
+ .connectGetVersion = hypervConnectGetVersion, /* 1.2.10 */
};
diff --git a/src/hyperv/hyperv_wmi_generator.input
b/src/hyperv/hyperv_wmi_generator.input
index 97f9dff..6b969df 100644
--- a/src/hyperv/hyperv_wmi_generator.input
+++ b/src/hyperv/hyperv_wmi_generator.input
@@ -296,3 +296,40 @@ class Win32_Processor
string Version
uint32 VoltageCaps
end
+
+
+class CIM_DataFile
+ uint32 AccessMask
+ boolean Archive
+ string Caption
+ boolean Compressed
+ string CompressionMethod
+ string CreationClassName
+ datetime CreationDate
+ string CSCreationClassName
+ string CSName
+ string Description
+ string Drive
+ string EightDotThreeFileName
+ boolean Encrypted
+ string EncryptionMethod
+ string Extension
+ string FileName
+ uint64 FileSize
+ string FileType
+ string FSCreationClassName
+ string FSName
+ boolean Hidden
+ datetime InstallDate
+ uint64 InUseCount
+ datetime LastAccessed
+ datetime LastModified
+ string Manufacturer
+ string Name
+ string Path
+ boolean Readable
+ string Status
+ boolean System
+ string Version
+ boolean Writeable
+end
diff --git a/src/hyperv/hyperv_wmi_generator.py b/src/hyperv/hyperv_wmi_generator.py
index f767d54..1011719 100755
--- a/src/hyperv/hyperv_wmi_generator.py
+++ b/src/hyperv/hyperv_wmi_generator.py
@@ -68,7 +68,7 @@ class Class:
header += "\n"
header += "#define %s_RESOURCE_URI \\\n" % name_upper
- if self.name.startswith("Win32_"):
+ if self.name.startswith("Win32_") or
self.name.startswith("CIM_DataFile"):
header += "
\"http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/%s\"\n" %
self.name
else:
header += "
\"http://schemas.microsoft.com/wbem/wsman/1/wmi/root/virtualization/%s\"\n"
% self.name
@@ -113,7 +113,7 @@ class Class:
% (self.name.replace("_", ""), self.name)
source += "{\n"
- if self.name.startswith("Win32_"):
+ if self.name.startswith("Win32_") or
self.name.startswith("CIM_DataFile"):
source += " return hypervEnumAndPull(priv, query,
ROOT_CIMV2,\n"
else:
source += " return hypervEnumAndPull(priv, query,
ROOT_VIRTUALIZATION,\n"
--
1.9.1