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(a)redhat.com>
---
src/esx/esx_network_driver.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c
index b5dcfe0a80..4f359c61e2 100644
--- a/src/esx/esx_network_driver.c
+++ b/src/esx/esx_network_driver.c
@@ -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);
--
2.21.0