An accessor following pattern laid out by virDomainObjList* APIs.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/network_conf.c | 26 ++++++++++++++++++++++++++
src/conf/network_conf.h | 5 +++++
src/libvirt_private.syms | 1 +
3 files changed, 32 insertions(+)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index fdf5907..dea180a 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -4355,3 +4355,29 @@ virNetworkObjListGetNames(virNetworkObjListPtr nets,
VIR_FREE(names[i]);
return -1;
}
+
+int
+virNetworkObjListNumOfNetworks(virNetworkObjListPtr nets,
+ bool active,
+ virNetworkObjListFilter filter,
+ virConnectPtr conn)
+{
+ int count = 0;
+ size_t i;
+
+ for (i = 0; i < nets->count; i++) {
+ virNetworkObjPtr obj = nets->objs[i];
+ virNetworkObjLock(obj);
+ if (filter && !filter(conn, obj->def)) {
+ virNetworkObjUnlock(obj);
+ continue;
+ }
+
+ if ((active && virNetworkObjIsActive(obj)) ||
+ (!active && !virNetworkObjIsActive(obj)))
+ count++;
+ virNetworkObjUnlock(obj);
+ }
+
+ return count;
+}
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 598ddc2..bd9e3b4 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -459,6 +459,11 @@ int virNetworkObjListGetNames(virNetworkObjListPtr nets,
virNetworkObjListFilter filter,
virConnectPtr conn);
+int virNetworkObjListNumOfNetworks(virNetworkObjListPtr nets,
+ bool active,
+ virNetworkObjListFilter filter,
+ virConnectPtr conn);
+
/* for testing */
int
virNetworkDefUpdateSection(virNetworkDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f572592..57c1a8c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -572,6 +572,7 @@ virNetworkObjListExport;
virNetworkObjListForEach;
virNetworkObjListFree;
virNetworkObjListGetNames;
+virNetworkObjListNumOfNetworks;
virNetworkObjLock;
virNetworkObjReplacePersistentDef;
virNetworkObjSetDefTransient;
--
2.0.5