esx: split virtualswitchToNetwork helper

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>
This commit is contained in:
Pino Toscano 2019-11-14 11:19:13 +01:00
parent 1652ce6680
commit 1331e29115
1 changed files with 22 additions and 12 deletions

View 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);