Re: [libvirt] [PATCH v2 06/12] esx: implement connectListAllNetworks

2019-12-17 Thread Cole Robinson
On 11/15/19 7:40 AM, Pino Toscano wrote:
> Implement the .connectListAllNetworks networks API in the esx network
> driver.
> 
> Signed-off-by: Pino Toscano 
> ---
>  src/esx/esx_network_driver.c | 66 
>  1 file changed, 66 insertions(+)

Needs the same treatment Jano pointed out in patch #4, size_t
adjustment, and versions changes to 6.0.0. With that:

Reviewed-by: Cole Robinson 

- Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



[libvirt] [PATCH v2 06/12] esx: implement connectListAllNetworks

2019-11-15 Thread Pino Toscano
Implement the .connectListAllNetworks networks API in the esx network
driver.

Signed-off-by: Pino Toscano 
---
 src/esx/esx_network_driver.c | 66 
 1 file changed, 66 insertions(+)

diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c
index 4f359c61e2..79a7ecae5f 100644
--- a/src/esx/esx_network_driver.c
+++ b/src/esx/esx_network_driver.c
@@ -863,6 +863,71 @@ esxNetworkIsPersistent(virNetworkPtr network G_GNUC_UNUSED)
 
 
 
+#define MATCH(FLAG) (flags & (FLAG))
+static int
+esxConnectListAllNetworks(virConnectPtr conn,
+  virNetworkPtr **nets,
+  unsigned int flags)
+{
+bool success = false;
+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,
+  ) < 0) {
+return -1;
+}
+
+for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch;
+ hostVirtualSwitch = hostVirtualSwitch->_next) {
+virNetworkPtr net = virtualswitchToNetwork(conn, hostVirtualSwitch);
+
+if (VIR_APPEND_ELEMENT(*nets, count, net) < 0)
+goto cleanup;
+}
+
+success = true;
+
+ cleanup:
+if (! success) {
+if (*nets) {
+for (i = 0; i < count; ++i)
+VIR_FREE((*nets)[i]);
+VIR_FREE(*nets);
+}
+
+count = -1;
+}
+
+esxVI_HostVirtualSwitch_Free();
+
+return count;
+}
+#undef MATCH
+
+
+
 virNetworkDriver esxNetworkDriver = {
 .connectNumOfNetworks = esxConnectNumOfNetworks, /* 0.10.0 */
 .connectListNetworks = esxConnectListNetworks, /* 0.10.0 */
@@ -877,4 +942,5 @@ virNetworkDriver esxNetworkDriver = {
 .networkSetAutostart = esxNetworkSetAutostart, /* 0.10.0 */
 .networkIsActive = esxNetworkIsActive, /* 0.10.0 */
 .networkIsPersistent = esxNetworkIsPersistent, /* 0.10.0 */
+.connectListAllNetworks = esxConnectListAllNetworks, /* 5.10.0 */
 };
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list