mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
esx: implement connectListAllNetworks
Implement the .connectListAllNetworks networks API in the esx network driver. Signed-off-by: Pino Toscano <ptoscano@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
9e7aa1c012
commit
2e65f0ad4a
@ -863,6 +863,74 @@ esxNetworkIsPersistent(virNetworkPtr network G_GNUC_UNUSED)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define MATCH(FLAG) (flags & (FLAG))
|
||||||
|
static int
|
||||||
|
esxConnectListAllNetworks(virConnectPtr conn,
|
||||||
|
virNetworkPtr **nets,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
esxPrivate *priv = conn->privateData;
|
||||||
|
esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
|
||||||
|
esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
|
||||||
|
size_t count = 0;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
virCheckFlags(VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL, -1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ESX networks are always active, persistent, and
|
||||||
|
* autostarted, so return zero elements in case we are asked
|
||||||
|
* for networks different than that.
|
||||||
|
*/
|
||||||
|
if (MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) &&
|
||||||
|
!(MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE)))
|
||||||
|
return 0;
|
||||||
|
if (MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_PERSISTENT) &&
|
||||||
|
!(MATCH(VIR_CONNECT_LIST_NETWORKS_PERSISTENT)))
|
||||||
|
return 0;
|
||||||
|
if (MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_AUTOSTART) &&
|
||||||
|
!(MATCH(VIR_CONNECT_LIST_NETWORKS_AUTOSTART)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (esxVI_EnsureSession(priv->primary) < 0 ||
|
||||||
|
esxVI_LookupHostVirtualSwitchList(priv->primary,
|
||||||
|
&hostVirtualSwitchList) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch;
|
||||||
|
hostVirtualSwitch = hostVirtualSwitch->_next) {
|
||||||
|
if (nets) {
|
||||||
|
virNetworkPtr net = virtualswitchToNetwork(conn, hostVirtualSwitch);
|
||||||
|
if (!net)
|
||||||
|
goto cleanup;
|
||||||
|
if (VIR_APPEND_ELEMENT(*nets, count, net) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = count;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (ret < 0) {
|
||||||
|
if (nets && *nets) {
|
||||||
|
for (i = 0; i < count; ++i)
|
||||||
|
VIR_FREE((*nets)[i]);
|
||||||
|
VIR_FREE(*nets);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#undef MATCH
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virNetworkDriver esxNetworkDriver = {
|
virNetworkDriver esxNetworkDriver = {
|
||||||
.connectNumOfNetworks = esxConnectNumOfNetworks, /* 0.10.0 */
|
.connectNumOfNetworks = esxConnectNumOfNetworks, /* 0.10.0 */
|
||||||
.connectListNetworks = esxConnectListNetworks, /* 0.10.0 */
|
.connectListNetworks = esxConnectListNetworks, /* 0.10.0 */
|
||||||
@ -877,4 +945,5 @@ virNetworkDriver esxNetworkDriver = {
|
|||||||
.networkSetAutostart = esxNetworkSetAutostart, /* 0.10.0 */
|
.networkSetAutostart = esxNetworkSetAutostart, /* 0.10.0 */
|
||||||
.networkIsActive = esxNetworkIsActive, /* 0.10.0 */
|
.networkIsActive = esxNetworkIsActive, /* 0.10.0 */
|
||||||
.networkIsPersistent = esxNetworkIsPersistent, /* 0.10.0 */
|
.networkIsPersistent = esxNetworkIsPersistent, /* 0.10.0 */
|
||||||
|
.connectListAllNetworks = esxConnectListAllNetworks, /* 6.8.0 */
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user