- qemuDomainSetThrottleGroup: Enforce non-zero 'groupname' string length (RHEL-141820) - qemuDomainSetBlockIoTuneField: Move setting of 'group_name' out of the loop (RHEL-141820) - qemuDomainSetThrottleGroup: Always honour thottle group name passed as argument (RHEL-141820) - qemuDomainSetThrottleGroup: Don't put group name into the 'tunable' event twice (RHEL-141820) - qemuSnapshotDiskHasBackingDisk: Avoid call of virStorageSourceIsSameLocation with NULL argument (RHEL-144089) - qemuSnapshotUpdateBackingStore: Remove stale comment (RHEL-144089) - qemuSnapshotDiskHasBackingDisk: Use proper 'max_depth' when calling 'virStorageSourceGetMetadata' (RHEL-144089) - virDomainSnapshotDefAssignExternalNames: Improve error message (RHEL-144089) - qemuSnapshotUpdateBackingStore: Retry as curent user if qemu-img fails (RHEL-144089) - esx: Debug URL just before opening with curl (RHEL-138300) - esx: Abstract all URL-creation code into one function (RHEL-138300) - esx: Switch to creating URLs using virURIFormat (RHEL-138300) - esx_util: Introduce esxUtil_EscapeInventoryObject() (RHEL-140196) - esx: URI encode inventory objects twice (RHEL-140196) Resolves: RHEL-138300, RHEL-140196, RHEL-141820, RHEL-144089
120 lines
4.5 KiB
Diff
120 lines
4.5 KiB
Diff
From 95ff5dcad20269f8e26eda628c85168dd4702285 Mon Sep 17 00:00:00 2001
|
|
Message-ID: <95ff5dcad20269f8e26eda628c85168dd4702285.1769699749.git.jdenemar@redhat.com>
|
|
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
Date: Mon, 26 Jan 2026 10:47:01 +0000
|
|
Subject: [PATCH] esx: Abstract all URL-creation code into one function
|
|
|
|
Abstract the places where we create URLs into one place. This is just
|
|
refactoring and should not change the behaviour.
|
|
|
|
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
|
|
(cherry picked from commit e013d5b5cae732ddeae479098165b9331b8ea441)
|
|
Resolves: https://issues.redhat.com/browse/RHEL-138300
|
|
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
---
|
|
src/esx/esx_driver.c | 53 +++++++++++++++++++++++++++++++++++---------
|
|
1 file changed, 43 insertions(+), 10 deletions(-)
|
|
|
|
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
|
|
index 9f965811b1..29735e359f 100644
|
|
--- a/src/esx/esx_driver.c
|
|
+++ b/src/esx/esx_driver.c
|
|
@@ -582,7 +582,37 @@ esxCapsInit(esxPrivate *priv)
|
|
return NULL;
|
|
}
|
|
|
|
+static char *
|
|
+esxCreateURL(const char *transport,
|
|
+ const char *server,
|
|
+ int port,
|
|
+ const char *path)
|
|
+{
|
|
+ char *url;
|
|
|
|
+ url = g_strdup_printf("%s://%s:%d%s",
|
|
+ transport,
|
|
+ server,
|
|
+ port,
|
|
+ path);
|
|
+ return url;
|
|
+}
|
|
+
|
|
+/*
|
|
+ * Same as above, but add it to a buffer because the calling code will
|
|
+ * append query strings etc.
|
|
+ */
|
|
+static void
|
|
+esxCreateURLBuffer(virBuffer *buffer,
|
|
+ const char *transport,
|
|
+ const char *server,
|
|
+ int port,
|
|
+ const char *path)
|
|
+{
|
|
+ g_autofree char *url = esxCreateURL(transport, server, port, path);
|
|
+
|
|
+ virBufferAdd(buffer, url, -1);
|
|
+}
|
|
|
|
static int
|
|
esxConnectToHost(esxPrivate *priv,
|
|
@@ -619,8 +649,8 @@ esxConnectToHost(esxPrivate *priv,
|
|
conn->uri->server)))
|
|
goto cleanup;
|
|
|
|
- url = g_strdup_printf("%s://%s:%d/sdk", priv->parsedUri->transport,
|
|
- conn->uri->server, conn->uri->port);
|
|
+ url = esxCreateURL(priv->parsedUri->transport,
|
|
+ conn->uri->server, conn->uri->port, "/sdk");
|
|
|
|
if (esxVI_Context_Alloc(&priv->host) < 0 ||
|
|
esxVI_Context_Connect(priv->host, url, ipAddress, username, password,
|
|
@@ -706,8 +736,8 @@ esxConnectToVCenter(esxPrivate *priv,
|
|
if (!(password = virAuthGetPassword(conn, auth, "esx", username, hostname)))
|
|
return -1;
|
|
|
|
- url = g_strdup_printf("%s://%s:%d/sdk", priv->parsedUri->transport, hostname,
|
|
- conn->uri->port);
|
|
+ url = esxCreateURL(priv->parsedUri->transport, hostname,
|
|
+ conn->uri->port, "/sdk");
|
|
|
|
if (esxVI_Context_Alloc(&priv->vCenter) < 0 ||
|
|
esxVI_Context_Connect(priv->vCenter, url, ipAddress, username,
|
|
@@ -2357,8 +2387,9 @@ esxDomainScreenshot(virDomainPtr domain, virStreamPtr stream,
|
|
}
|
|
|
|
/* Build URL */
|
|
- virBufferAsprintf(&buffer, "%s://%s:%d/screen?id=", priv->parsedUri->transport,
|
|
- domain->conn->uri->server, domain->conn->uri->port);
|
|
+ esxCreateURLBuffer(&buffer, priv->parsedUri->transport,
|
|
+ domain->conn->uri->server, domain->conn->uri->port,
|
|
+ "/screen?id=");
|
|
virBufferURIEncodeString(&buffer, virtualMachine->obj->value);
|
|
|
|
url = virBufferContentAndReset(&buffer);
|
|
@@ -2563,8 +2594,9 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
|
|
goto cleanup;
|
|
}
|
|
|
|
- virBufferAsprintf(&buffer, "%s://%s:%d/folder/", priv->parsedUri->transport,
|
|
- domain->conn->uri->server, domain->conn->uri->port);
|
|
+ esxCreateURLBuffer(&buffer, priv->parsedUri->transport,
|
|
+ domain->conn->uri->server, domain->conn->uri->port,
|
|
+ "/folder/");
|
|
virBufferURIEncodeString(&buffer, directoryAndFileName);
|
|
virBufferAddLit(&buffer, "?dcPath=");
|
|
virBufferURIEncodeString(&buffer, priv->primary->datacenterPath);
|
|
@@ -2987,8 +3019,9 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
|
|
goto cleanup;
|
|
}
|
|
|
|
- virBufferAsprintf(&buffer, "%s://%s:%d/folder/", priv->parsedUri->transport,
|
|
- conn->uri->server, conn->uri->port);
|
|
+ esxCreateURLBuffer(&buffer, priv->parsedUri->transport,
|
|
+ conn->uri->server, conn->uri->port,
|
|
+ "/folder/");
|
|
|
|
if (directoryName) {
|
|
virBufferURIEncodeString(&buffer, directoryName);
|
|
--
|
|
2.52.0
|