This is to list the network objects, supported filtering flags
are: active|inactive, persistent|transient, autostart|no-autostart.
include/libvirt/libvirt.h.in: Declare enum virConnectListAllNetworkFlags
and virConnectListAllNetworks.
python/generator.py: Skip auto-generating
src/driver.h: (virDrvConnectListAllNetworks)
src/libvirt.c: Implement the public API
src/libvirt_public.syms: Export the symbol to public
---
include/libvirt/libvirt.h.in | 20 ++++++++++++
python/generator.py | 1 +
src/driver.h | 5 +++
src/libvirt.c | 68 ++++++++++++++++++++++++++++++++++++++++++
src/libvirt_public.syms | 1 +
5 files changed, 95 insertions(+), 0 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index c5b16bf..15a9a1b 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2196,6 +2196,26 @@ int virConnectNumOfDefinedNetworks
(virConnectPtr conn);
int virConnectListDefinedNetworks (virConnectPtr conn,
char **const names,
int maxnames);
+/*
+ * virConnectListAllNetworks:
+ *
+ * Flags used to filter the returned networks. Flags in each group
+ * are exclusive attributes of a network.
+ */
+typedef enum {
+ VIR_CONNECT_LIST_NETWORKS_INACTIVE = 1 << 0,
+ VIR_CONNECT_LIST_NETWORKS_ACTIVE = 1 << 1,
+
+ VIR_CONNECT_LIST_NETWORKS_PERSISTENT = 1 << 2,
+ VIR_CONNECT_LIST_NETWORKS_TRANSIENT = 1 << 3,
+
+ VIR_CONNECT_LIST_NETWORKS_AUTOSTART = 1 << 4,
+ VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART = 1 << 5,
+} virConnectListAllNetworksFlags;
+
+int virConnectListAllNetworks (virConnectPtr conn,
+ virNetworkPtr **nets,
+ unsigned int flags);
/*
* Lookup network by name or uuid
diff --git a/python/generator.py b/python/generator.py
index 4b3f7e6..44b56c2 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -458,6 +458,7 @@ skip_function = (
'virDomainSnapshotListAllChildren', # overridden in virDomainSnapshot.py
'virConnectListAllStoragePools', # overridden in virConnect.py
'virStoragePoolListAllVolumes', # overridden in virStoragePool.py
+ 'virConnectListAllNetworks', # overridden in virConnect.py
'virStreamRecvAll', # Pure python libvirt-override-virStream.py
'virStreamSendAll', # Pure python libvirt-override-virStream.py
diff --git a/src/driver.h b/src/driver.h
index ee1341f..68a1f04 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1055,6 +1055,10 @@ typedef int
(*virDrvListDefinedNetworks) (virConnectPtr conn,
char **const names,
int maxnames);
+typedef int
+ (*virDrvListAllNetworks) (virConnectPtr conn,
+ virNetworkPtr **nets,
+ unsigned int flags);
typedef virNetworkPtr
(*virDrvNetworkLookupByUUID) (virConnectPtr conn,
const unsigned char *uuid);
@@ -1113,6 +1117,7 @@ struct _virNetworkDriver {
virDrvListNetworks listNetworks;
virDrvNumOfDefinedNetworks numOfDefinedNetworks;
virDrvListDefinedNetworks listDefinedNetworks;
+ virDrvListAllNetworks listAllNetworks;
virDrvNetworkLookupByUUID networkLookupByUUID;
virDrvNetworkLookupByName networkLookupByName;
virDrvNetworkCreateXML networkCreateXML;
diff --git a/src/libvirt.c b/src/libvirt.c
index 7780534..622a590 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -9588,6 +9588,74 @@ virNetworkGetConnect (virNetworkPtr net)
}
/**
+ * virConnectListAllNetworks:
+ * @conn: Pointer to the hypervisor connection.
+ * @nets: Pointer to a variable to store the array containing the network
+ * objects or NULL if the list is not required (just returns number
+ * of networks).
+ * @flags: bitwise-OR of virConnectListAllNetworksFlags.
+ *
+ * Collect the list of networks, and allocate an array to store those
+ * objects. This API solves the race inherent between virConnectListNetworks
+ * and virConnectListDefinedNetworks.
+ *
+ * By default, this API covers all networks; it is also possible to return
+ * the filtered objects with flags. Filters are provided in groups, where each
+ * group contains bits that describe mutually exclusive attributes of a network.
+ *
+ * The first group of @flags is VIR_CONNECT_LIST_NETWORKS_INACTIVE and
+ * VIR_CONNECT_LIST_NETWORKS_INACTIVE to fitler the networks by state.
+ *
+ * The second group of @flags is VIR_CONNECT_LIST_NETWORKS_PERSITENT
+ * and VIR_CONNECT_LIST_NETWORKS_TRANSICIENT, to filter the networks by
+ * whether they have persistent config or not.
+ *
+ * The third group of @flags is VIR_CONNECT_LIST_NETWORKS_AUTOSTART
+ * and VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART, to filter the networks by
+ * whether they are marked as autostart or not.
+ *
+ * Returns the number of networks found or -1 and sets @nets to NULL in case
+ * of error. On success, the array stored into @nets is guaranteed to have an
+ * extra allocated element set to NULL but not included in the return count,
+ * to make iteration easier. The caller is responsible for calling
+ * virStorageNetworkFree() on each array element, then calling free() on @nets.
+ */
+int
+virConnectListAllNetworks(virConnectPtr conn,
+ virNetworkPtr **nets,
+ unsigned int flags)
+{
+ VIR_DEBUG("conn=%p, nets=%p, flags=%x", conn, nets, flags);
+
+ virResetLastError();
+
+ if (nets)
+ *nets = NULL;
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+ virDispatchError(NULL);
+ return -1;
+ }
+
+ if (conn->networkDriver &&
+ conn->networkDriver->listAllNetworks) {
+ int ret;
+ ret = conn->networkDriver->listAllNetworks(conn, nets, flags);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ virDispatchError(conn);
+ return -1;
+}
+
+
+/**
* virConnectNumOfNetworks:
* @conn: pointer to the hypervisor connection
*
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index ea052ed..0ce120a 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -548,6 +548,7 @@ LIBVIRT_0.9.14 {
global:
virConnectListAllStoragePools;
virStoragePoolListAllVolumes;
+ virConnectListAllNetworks;
} LIBVIRT_0.9.13;
# .... define new API here using predicted next version number ....
--
1.7.7.3