[libvirt] Re: VMware ESX: Accept VI API version 4.0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/7/27 Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx>:
> Hi,
>
> This patch extends the VI API version checks to accept version 4.0 too.
>
> Regards,
>  Matthias
>

This second version of the patch takes care of the virtualHW.version
change from 4 to 7.

Regards,
  Matthias
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index b8aa5cb..a4812b0 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -2011,7 +2011,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
         goto failure;
     }
 
-    def = esxVMX_ParseConfig(domain->conn, vmx);
+    def = esxVMX_ParseConfig(domain->conn, vmx, priv->host->serverVersion);
 
     if (def != NULL) {
         xml = virDomainDefFormat(domain->conn, def, flags);
@@ -2041,6 +2041,8 @@ esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
                        const char *nativeConfig,
                        unsigned int flags ATTRIBUTE_UNUSED)
 {
+    esxPrivate *priv = (esxPrivate *)conn->privateData;
+    int serverVersion = -1;
     virDomainDefPtr def = NULL;
     char *xml = NULL;
 
@@ -2050,7 +2052,11 @@ esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
         return NULL;
     }
 
-    def = esxVMX_ParseConfig(conn, nativeConfig);
+    if (! priv->phantom) {
+        serverVersion = priv->host->serverVersion;
+    }
+
+    def = esxVMX_ParseConfig(conn, nativeConfig, serverVersion);
 
     if (def != NULL) {
         xml = virDomainDefFormat(conn, def, VIR_DOMAIN_XML_INACTIVE);
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 18e11e7..1087926 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -266,19 +266,27 @@ esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx, const char *url,
         goto failure;
     }
 
-    if (STREQ(ctx->service->about->apiType, "HostAgent")) {
-        if (STRNEQ(ctx->service->about->apiVersion, "2.5.0") &&
-            STRNEQ(ctx->service->about->apiVersion, "2.5u2")) {
+    if (STREQ(ctx->service->about->apiType, "HostAgent") ||
+        STREQ(ctx->service->about->apiType, "VirtualCenter")) {
+        if (STRPREFIX(ctx->service->about->apiVersion, "2.5")) {
+            ctx->apiVersion = 25;
+        } else if (STRPREFIX(ctx->service->about->apiVersion, "4.0")) {
+            ctx->apiVersion = 40;
+        } else {
             ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
-                         "Expecting VI API version '2.5.0' or '2.5u2' but "
-                         "found '%s'", ctx->service->about->apiVersion);
+                         "Expecting VI API major/minor version '2.5' or '4.0' "
+                         "but found '%s'", ctx->service->about->apiVersion);
             goto failure;
         }
-    } else if (STREQ(ctx->service->about->apiType, "VirtualCenter")) {
-        if (STRNEQ(ctx->service->about->apiVersion, "2.5u2")) {
+
+        if (STRPREFIX(ctx->service->about->version, "3.5")) {
+            ctx->serverVersion = 35;
+        } else if (STRPREFIX(ctx->service->about->version, "4.0")) {
+            ctx->serverVersion = 40;
+        } else {
             ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
-                         "Expecting VI API version '2.5u2' but found '%s'",
-                         ctx->service->about->apiVersion);
+                         "Expecting server major/minor version '3.5' or '4.0' "
+                         "but found '%s'", ctx->service->about->version);
             goto failure;
         }
     } else {
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index efef101..8f4d790 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -52,6 +52,8 @@ struct _esxVI_Context {
     char *username;
     char *password;
     esxVI_ServiceContent *service;
+    int apiVersion;
+    int serverVersion;
     esxVI_UserSession *session;
     esxVI_ManagedObjectReference *datacenter;
     esxVI_ManagedObjectReference *vmFolder;
diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c
index 635a483..3d5e783 100644
--- a/src/esx/esx_vmx.c
+++ b/src/esx/esx_vmx.c
@@ -37,7 +37,8 @@ domain-xml                        <=>   vmx
 
 
                                         config.version = "8"                    # essential
-                                        virtualHW.version = "4"                 # essential
+                                        virtualHW.version = "4"                 # essential for ESX 3.5
+                                        virtualHW.version = "7"                 # essential for ESX 4.0
 
 
 ???                               <=>   guestOS = "<value>"                     # essential, FIXME: not representable
@@ -405,7 +406,7 @@ def->parallels[0]...
 
 
 virDomainDefPtr
-esxVMX_ParseConfig(virConnectPtr conn, const char *vmx)
+esxVMX_ParseConfig(virConnectPtr conn, const char *vmx, int serverVersion)
 {
     virConfPtr conf = NULL;
     virDomainDefPtr def = NULL;
@@ -442,8 +443,8 @@ esxVMX_ParseConfig(virConnectPtr conn, const char *vmx)
 
     if (config_version != 8) {
         ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
-                  "Expecting VMX entry 'config.version' to be \"8\" but "
-                  "found \"%lld\"", config_version);
+                  "Expecting VMX entry 'config.version' to be 8 but found "
+                  "%lld", config_version);
         goto failure;
     }
 
@@ -452,10 +453,41 @@ esxVMX_ParseConfig(virConnectPtr conn, const char *vmx)
         goto failure;
     }
 
-    if (virtualHW_version != 4) {
+    switch (serverVersion) {
+      case 35:
+        if (virtualHW_version != 4) {
+            ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+                      "Expecting VMX entry 'virtualHW.version' to be 4 for "
+                      "server version 3.5 but found %lld", virtualHW_version);
+            goto failure;
+        }
+
+        break;
+
+      case 40:
+        if (virtualHW_version != 7) {
+            ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+                      "Expecting VMX entry 'virtualHW.version' to be 7 for "
+                      "server version 4.0 but found %lld", virtualHW_version);
+            goto failure;
+        }
+
+        break;
+
+      case -1:
+        if (virtualHW_version != 4 && virtualHW_version != 7) {
+            ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+                      "Expecting VMX entry 'virtualHW.version' to be 4 or 7 "
+                      "but found %lld", virtualHW_version);
+            goto failure;
+        }
+
+        break;
+
+      default:
         ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
-                  "Expecting VMX entry 'virtualHW.version' to be \"4\" but "
-                  "found \"%lld\"", virtualHW_version);
+                  "Expecting server version 3.5 or 4.0 but got %d",
+                  serverVersion);
         goto failure;
     }
 
diff --git a/src/esx/esx_vmx.h b/src/esx/esx_vmx.h
index f32a50a..8d524a4 100644
--- a/src/esx/esx_vmx.h
+++ b/src/esx/esx_vmx.h
@@ -27,7 +27,7 @@
 #include "domain_conf.h"
 
 virDomainDefPtr
-esxVMX_ParseConfig(virConnectPtr conn, const char *vmx);
+esxVMX_ParseConfig(virConnectPtr conn, const char *vmx, int serverVersion);
 
 int
 esxVMX_ParseSCSIController(virConnectPtr conn, virConfPtr conf,
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]