]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
esx: split virtualswitchToNetwork helper
authorPino Toscano <ptoscano@redhat.com>
Thu, 14 Nov 2019 10:19:13 +0000 (11:19 +0100)
committerPino Toscano <ptoscano@redhat.com>
Fri, 20 Dec 2019 13:31:08 +0000 (14:31 +0100)
Move the creation of a virNetworkPtr object from the
esxVI_HostVirtualSwitch object of a virtual switch out of
esxNetworkLookupByName in an own helper. This way it can be used also
in other functions.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
src/esx/esx_network_driver.c

index b5dcfe0a8084763c0b9d6349f9153a65628214de..4f359c61e248efd24549b6e12dc78647a50029a5 100644 (file)
@@ -167,20 +167,11 @@ esxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
 
 
 static virNetworkPtr
-esxNetworkLookupByName(virConnectPtr conn, const char *name)
+virtualswitchToNetwork(virConnectPtr conn,
+                       esxVI_HostVirtualSwitch *hostVirtualSwitch)
 {
-    virNetworkPtr network = NULL;
-    esxPrivate *priv = conn->privateData;
-    esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
     unsigned char md5[VIR_CRYPTO_HASH_SIZE_MD5]; /* VIR_CRYPTO_HASH_SIZE_MD5 = VIR_UUID_BUFLEN = 16 */
 
-    if (esxVI_EnsureSession(priv->primary) < 0 ||
-        esxVI_LookupHostVirtualSwitchByName(priv->primary, name,
-                                            &hostVirtualSwitch,
-                                            esxVI_Occurrence_RequiredItem) < 0) {
-        return NULL;
-    }
-
     /*
      * HostVirtualSwitch doesn't have a UUID, but we can use the key property
      * as source for a UUID. The key is unique per host and cannot change
@@ -192,7 +183,26 @@ esxNetworkLookupByName(virConnectPtr conn, const char *name)
     if (virCryptoHashBuf(VIR_CRYPTO_HASH_MD5, hostVirtualSwitch->key, md5) < 0)
         return NULL;
 
-    network = virGetNetwork(conn, hostVirtualSwitch->name, md5);
+    return virGetNetwork(conn, hostVirtualSwitch->name, md5);
+}
+
+
+
+static virNetworkPtr
+esxNetworkLookupByName(virConnectPtr conn, const char *name)
+{
+    virNetworkPtr network = NULL;
+    esxPrivate *priv = conn->privateData;
+    esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
+
+    if (esxVI_EnsureSession(priv->primary) < 0 ||
+        esxVI_LookupHostVirtualSwitchByName(priv->primary, name,
+                                            &hostVirtualSwitch,
+                                            esxVI_Occurrence_RequiredItem) < 0) {
+        return NULL;
+    }
+
+    network = virtualswitchToNetwork(conn, hostVirtualSwitch);
 
     esxVI_HostVirtualSwitch_Free(&hostVirtualSwitch);