]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Extend the ESX URL to habdle ports and GSX
authorMatthias Bolte <matthias.bolte@googlemail.com>
Wed, 5 Aug 2009 08:23:59 +0000 (10:23 +0200)
committerDaniel Veillard <veillard@redhat.com>
Wed, 5 Aug 2009 08:23:59 +0000 (10:23 +0200)
* src/esx/esx_driver.c src/esx/esx_vi.[ch] src/esx/esx_vmx.[ch]:
  adds version checking for GSX 2.0, allows to pass a specific port
  for the connection and also add a new specific gsx scheme for
  easier connections to GSX hosts

src/esx/esx_driver.c
src/esx/esx_vi.c
src/esx/esx_vi.h
src/esx/esx_vmx.c
src/esx/esx_vmx.h

index e6ac00598f33952313581dfebf3563790ce1ee5c..dba6305a986d95300017bf4ebe3904b11521eb0c 100644 (file)
@@ -67,16 +67,23 @@ typedef struct _esxPrivate {
 
 
 /*
- * URI format: esx://[<user>@]<server>[?transport={http|https}][&vcenter=<vcenter>][&no_verify={0|1}]
+ * URI format: {esx|gsx}://[<user>@]<server>[:<port>][?transport={http|https}][&vcenter=<vcenter>][&no_verify={0|1}]
  *             esx:///phantom
  *
+ * If no port is specified the default port is set dependent on the scheme and
+ * transport parameter:
+ * - esx+http  80
+ * - esx+https 433
+ * - gsx+http  8222
+ * - gsx+https 8333
+ *
  * If no transport parameter is specified https is used.
  *
  * The vcenter parameter is only necessary for migration, because the vCenter
  * server is in charge to initiate a migration between two ESX hosts.
  *
  * If the no_verify parameter is set to 1, this disables libcurl client checks
- * of the server's certificate.
+ * of the server's certificate. The default value it 0.
  *
  * The esx:///phantom URI may be used for tasks that don't require an actual
  * connection to the hypervisor like domxml-{from,to}-native:
@@ -95,9 +102,10 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
     char *password = NULL;
     int phantom = 0; // boolean
 
-    /* Decline if the URI is NULL or the scheme is not 'esx' */
+    /* Decline if the URI is NULL or the scheme is neither 'esx' nor 'gsx' */
     if (conn->uri == NULL || conn->uri->scheme == NULL ||
-        STRNEQ(conn->uri->scheme, "esx")) {
+        (STRCASENEQ(conn->uri->scheme, "esx") &&
+         STRCASENEQ(conn->uri->scheme, "gsx"))) {
         return VIR_DRV_OPEN_DECLINED;
     }
 
@@ -147,8 +155,30 @@ 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(conn->uri->scheme, "esx")) {
+                if (STRCASEEQ(priv->transport, "https")) {
+                    conn->uri->port = 443;
+                } else {
+                    conn->uri->port = 80;
+                }
+            } else { /* GSX */
+                if (STRCASEEQ(priv->transport, "https")) {
+                    conn->uri->port = 8333;
+                } else {
+                    conn->uri->port = 8222;
+                }
+            }
+        }
+
+        if (virAsprintf(&url, "%s://%s:%d/sdk", priv->transport,
+                        conn->uri->server, conn->uri->port) < 0) {
             virReportOOMError(conn);
             goto failure;
         }
@@ -185,6 +215,22 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
             goto failure;
         }
 
+        if (STRCASEEQ(conn->uri->scheme, "esx")) {
+            if (priv->host->productVersion != esxVI_ProductVersion_ESX35 &&
+                priv->host->productVersion != esxVI_ProductVersion_ESX40) {
+                ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+                          "%s is neither an ESX 3.5 host nor an ESX 4.0 host",
+                          conn->uri->server);
+                goto failure;
+            }
+        } else { /* GSX */
+            if (priv->host->productVersion != esxVI_ProductVersion_GSX20) {
+                ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+                          "%s isn't a GSX 2.0 host", conn->uri->server);
+                goto failure;
+            }
+        }
+
         VIR_FREE(url);
         VIR_FREE(password);
         VIR_FREE(username);
@@ -221,6 +267,15 @@ esxOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUSED)
                 goto failure;
             }
 
+            if (priv->vcenter->productVersion != esxVI_ProductVersion_VPX25 &&
+                priv->vcenter->productVersion != esxVI_ProductVersion_VPX40) {
+                ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+                          "%s is neither a vCenter 2.5 server nor a vCenter "
+                          "4.0 server",
+                          conn->uri->server);
+                goto failure;
+            }
+
             VIR_FREE(url);
             VIR_FREE(password);
             VIR_FREE(username);
@@ -1996,10 +2051,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;
     }
@@ -2008,7 +2063,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);
@@ -2039,7 +2094,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;
 
@@ -2050,10 +2105,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);
@@ -2581,8 +2636,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;
         }
index 7a429761d927e0b890595b6cb936c403a5cdb612..f3b318456a2dc621ac22d90db41e480ed876211e 100644 (file)
@@ -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 {
index 8f4d790cc4ea7a67f7568c5c0c9efcdf476735a5..e85dd6bb7d225859e08acf4d1712463f8feb528a 100644 (file)
@@ -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;
index 3d5e783031c03559bafda9f082aae2f17b9ae408..af5234e9bdf5e099571de5e2918298c4e15866eb 100644 (file)
@@ -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,
index 8d524a4df17db680122865a89a3f0fffb9047c82..8288003d910bbd31ebe601e10cd0f8c50b23fc2a 100644 (file)
 
 #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);