Re: [libvirt] VMware support and Server 2.0.1

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

 



2009/7/29 Timo Makinen <tmakinen@xxxxxxxxxx>:
> On Wed, Jul 29, 2009 at 06:12:59PM +0200, Matthias Bolte wrote:
>> 2009/7/27 Timo Makinen <tmakinen@xxxxxxxxxx>:
[...]
> The dumpxml seems to be failing with this config option:
>
> ethernet0.connectionType = "custom"
>
> without this it works correctly.

Ah, I found the cause. ethernet0.connectionType = "custom" was a good
hint. I missed to initialize one variable correctly that is only used
in the ethernet0.connectionType = "custom" case.

>> Could you do some basic testing beside listing and dumpxml, as I have
>> currently no VMware GSX installation at hand? Just test if the
>> following commands work as expected in virsh:
>>
>> - start
>> - shutdown
>> - reboot
>> - suspend
>> - resume
>> - nodeinfo
>> - dominfo
>>
>> Regards,
>>   Matthias
>
> All these worked out of the box.

Nice!

Could you test the attached patch? It adds handling for the port in
the URI, extends the version checking for GSX 2.0 and fixes the bug in
VMX parsing.

Matthias
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index e3d60a5..eb3e09e 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -70,7 +70,7 @@ typedef struct _esxPrivate {
 
 
 /*
- * URI format: esx://[<user>@]<server>[?transport={http|https}][&vcenter=<vcenter>][&no_verify={0|1}]
+ * URI format: esx://[<user>@]<server>[:<port>][?transport={http|https}][&vcenter=<vcenter>][&no_verify={0|1}]
  *             esx:///phantom
  *
  * If no transport parameter is specified https is used.
@@ -150,8 +150,22 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
             goto failure;
         }
 
-        if (virAsprintf(&url, "%s://%s/sdk", priv->transport,
-                        conn->uri->server) < 0) {
+        /*
+         * Set the port dependent on the transport protocol if no port is
+         * specified. This allows us to rely on the port parameter being
+         * correctly set when building URIs later on, without the need to
+         * distinguish between the situations port == 0 and port != 0
+         */
+        if (conn->uri->port == 0) {
+            if (STRCASEEQ(priv->transport, "https")) {
+                conn->uri->port = 443;
+            } else {
+                conn->uri->port = 80;
+            }
+        }
+
+        if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport,
+                        conn->uri->server, conn->uri->port) < 0) {
             virReportOOMError(conn);
             goto failure;
         }
@@ -1999,10 +2013,10 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
         goto failure;
     }
 
-    if (virAsprintf(&url, "%s://%s/folder/%s?dcPath=%s&dsName=%s",
+    if (virAsprintf(&url, "%s://%s:%d/folder/%s?dcPath=%s&dsName=%s",
                     priv->transport, domain->conn->uri->server,
-                    vmxPath, priv->host->datacenter->value,
-                    datastoreName) < 0) {
+                    domain->conn->uri->port, vmxPath,
+                    priv->host->datacenter->value, datastoreName) < 0) {
         virReportOOMError(domain->conn);
         goto failure;
     }
@@ -2011,7 +2025,7 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
         goto failure;
     }
 
-    def = esxVMX_ParseConfig(domain->conn, vmx, priv->host->serverVersion);
+    def = esxVMX_ParseConfig(domain->conn, vmx, priv->host->apiVersion);
 
     if (def != NULL) {
         xml = virDomainDefFormat(domain->conn, def, flags);
@@ -2042,7 +2056,7 @@ esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
                        unsigned int flags ATTRIBUTE_UNUSED)
 {
     esxPrivate *priv = (esxPrivate *)conn->privateData;
-    int serverVersion = -1;
+    esxVI_APIVersion apiVersion = esxVI_APIVersion_Unknown;
     virDomainDefPtr def = NULL;
     char *xml = NULL;
 
@@ -2053,10 +2067,10 @@ esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
     }
 
     if (! priv->phantom) {
-        serverVersion = priv->host->serverVersion;
+        apiVersion = priv->host->apiVersion;
     }
 
-    def = esxVMX_ParseConfig(conn, nativeConfig, serverVersion);
+    def = esxVMX_ParseConfig(conn, nativeConfig, apiVersion);
 
     if (def != NULL) {
         xml = virDomainDefFormat(conn, def, VIR_DOMAIN_XML_INACTIVE);
@@ -2584,8 +2598,8 @@ esxDomainMigratePrepare(virConnectPtr dconn,
             return -1;
         }
 
-        if (virAsprintf(uri_out, "%s://%s/sdk", transport,
-                        dconn->uri->server) < 0) {
+        if (virAsprintf(uri_out, "%s://%s:%d/sdk", transport,
+                        dconn->uri->server, dconn->uri->port) < 0) {
             virReportOOMError(dconn);
             goto failure;
         }
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 7a42976..f3b3184 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -270,9 +270,9 @@ esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx, const char *url,
     if (STREQ(ctx->service->about->apiType, "HostAgent") ||
         STREQ(ctx->service->about->apiType, "VirtualCenter")) {
         if (STRPREFIX(ctx->service->about->apiVersion, "2.5")) {
-            ctx->apiVersion = 25;
+            ctx->apiVersion = esxVI_APIVersion_25;
         } else if (STRPREFIX(ctx->service->about->apiVersion, "4.0")) {
-            ctx->apiVersion = 40;
+            ctx->apiVersion = esxVI_APIVersion_40;
         } else {
             ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
                          "Expecting VI API major/minor version '2.5' or '4.0' "
@@ -280,14 +280,44 @@ esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx, const char *url,
             goto failure;
         }
 
-        if (STRPREFIX(ctx->service->about->version, "3.5")) {
-            ctx->serverVersion = 35;
-        } else if (STRPREFIX(ctx->service->about->version, "4.0")) {
-            ctx->serverVersion = 40;
+        if (STREQ(ctx->service->about->productLineId, "gsx")) {
+            if (STRPREFIX(ctx->service->about->version, "2.0")) {
+                ctx->productVersion = esxVI_ProductVersion_GSX20;
+            } else {
+                ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+                             "Expecting GSX major/minor version '2.0' but "
+                             "found '%s'", ctx->service->about->version);
+                goto failure;
+            }
+        } else if (STREQ(ctx->service->about->productLineId, "esx") ||
+                   STREQ(ctx->service->about->productLineId, "embeddedEsx")) {
+            if (STRPREFIX(ctx->service->about->version, "3.5")) {
+                ctx->productVersion = esxVI_ProductVersion_ESX35;
+            } else if (STRPREFIX(ctx->service->about->version, "4.0")) {
+                ctx->productVersion = esxVI_ProductVersion_ESX40;
+            } else {
+                ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+                             "Expecting ESX major/minor version '3.5' or "
+                             "'4.0' but found '%s'",
+                             ctx->service->about->version);
+                goto failure;
+            }
+        } else if (STREQ(ctx->service->about->productLineId, "vpx")) {
+            if (STRPREFIX(ctx->service->about->version, "2.5")) {
+                ctx->productVersion = esxVI_ProductVersion_VPX25;
+            } else if (STRPREFIX(ctx->service->about->version, "4.0")) {
+                ctx->productVersion = esxVI_ProductVersion_VPX40;
+            } else {
+                ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+                             "Expecting VPX major/minor version '2.5' or '4.0' "
+                             "but found '%s'", ctx->service->about->version);
+                goto failure;
+            }
         } else {
             ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
-                         "Expecting server major/minor version '3.5' or '4.0' "
-                         "but found '%s'", ctx->service->about->version);
+                         "Expecting product 'gsx' or 'esx' or 'embeddedEsx' "
+                         "or 'vpx' but found '%s'",
+                         ctx->service->about->productLineId);
             goto failure;
         }
     } else {
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index 8f4d790..e85dd6b 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -31,6 +31,8 @@
 #include "datatypes.h"
 #include "esx_vi_types.h"
 
+typedef enum _esxVI_APIVersion esxVI_APIVersion;
+typedef enum _esxVI_ProductVersion esxVI_ProductVersion;
 typedef struct _esxVI_Context esxVI_Context;
 typedef struct _esxVI_RemoteResponse esxVI_RemoteResponse;
 typedef struct _esxVI_RemoteRequest esxVI_RemoteRequest;
@@ -40,6 +42,24 @@ typedef struct _esxVI_List esxVI_List;
 
 
 
+enum _esxVI_APIVersion {
+    esxVI_APIVersion_Undefined = 0,
+    esxVI_APIVersion_Unknown,
+    esxVI_APIVersion_25,
+    esxVI_APIVersion_40
+};
+
+enum _esxVI_ProductVersion {
+    esxVI_ProductVersion_Undefined = 0,
+    esxVI_ProductVersion_GSX20,
+    esxVI_ProductVersion_ESX35,
+    esxVI_ProductVersion_ESX40,
+    esxVI_ProductVersion_VPX25,
+    esxVI_ProductVersion_VPX40
+};
+
+
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  * Context
  */
@@ -52,8 +72,8 @@ struct _esxVI_Context {
     char *username;
     char *password;
     esxVI_ServiceContent *service;
-    int apiVersion;
-    int serverVersion;
+    esxVI_APIVersion apiVersion;
+    esxVI_ProductVersion productVersion;
     esxVI_UserSession *session;
     esxVI_ManagedObjectReference *datacenter;
     esxVI_ManagedObjectReference *vmFolder;
diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c
index 3d5e783..af5234e 100644
--- a/src/esx/esx_vmx.c
+++ b/src/esx/esx_vmx.c
@@ -406,7 +406,8 @@ def->parallels[0]...
 
 
 virDomainDefPtr
-esxVMX_ParseConfig(virConnectPtr conn, const char *vmx, int serverVersion)
+esxVMX_ParseConfig(virConnectPtr conn, const char *vmx,
+                   esxVI_APIVersion apiVersion)
 {
     virConfPtr conf = NULL;
     virDomainDefPtr def = NULL;
@@ -453,28 +454,28 @@ esxVMX_ParseConfig(virConnectPtr conn, const char *vmx, int serverVersion)
         goto failure;
     }
 
-    switch (serverVersion) {
-      case 35:
+    switch (apiVersion) {
+      case esxVI_APIVersion_25:
         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);
+                      "VI API version 2.5 but found %lld", virtualHW_version);
             goto failure;
         }
 
         break;
 
-      case 40:
+      case esxVI_APIVersion_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);
+                      "VI API version 4.0 but found %lld", virtualHW_version);
             goto failure;
         }
 
         break;
 
-      case -1:
+      case esxVI_APIVersion_Unknown:
         if (virtualHW_version != 4 && virtualHW_version != 7) {
             ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
                       "Expecting VMX entry 'virtualHW.version' to be 4 or 7 "
@@ -486,8 +487,7 @@ esxVMX_ParseConfig(virConnectPtr conn, const char *vmx, int serverVersion)
 
       default:
         ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
-                  "Expecting server version 3.5 or 4.0 but got %d",
-                  serverVersion);
+                  "Expecting VI API version 2.5 or 4.0");
         goto failure;
     }
 
@@ -1343,6 +1343,7 @@ esxVMX_ParseEthernet(virConnectPtr conn, virConfPtr conf, int controller,
     ESX_BUILD_VMX_NAME(generatedAddress);
     ESX_BUILD_VMX_NAME(address);
     ESX_BUILD_VMX_NAME(virtualDev);
+    ESX_BUILD_VMX_NAME(vnet);
 
     /* vmx:present */
     if (esxUtil_GetConfigBoolean(conn, conf, present_name,
diff --git a/src/esx/esx_vmx.h b/src/esx/esx_vmx.h
index 8d524a4..8288003 100644
--- a/src/esx/esx_vmx.h
+++ b/src/esx/esx_vmx.h
@@ -25,13 +25,15 @@
 
 #include "internal.h"
 #include "domain_conf.h"
+#include "esx_vi.h"
 
 virDomainDefPtr
-esxVMX_ParseConfig(virConnectPtr conn, const char *vmx, int serverVersion);
+esxVMX_ParseConfig(virConnectPtr conn, const char *vmx,
+                   esxVI_APIVersion apiVersion);
 
 int
 esxVMX_ParseSCSIController(virConnectPtr conn, virConfPtr conf,
-                          int controller, int *present, char **virtualDev);
+                           int controller, int *present, char **virtualDev);
 
 char *
 esxVMX_IndexToDiskName(virConnectPtr conn, int idx, const char *prefix);
--
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]