Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.Connect.xml | 6 ++++++
src/connect.c | 41 +++++++++++++++++++++++++++++++++++++++++
test/test_connect.py | 12 ++++++++++++
3 files changed, 59 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 1695100..94704ff 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -44,6 +44,12 @@
<arg name="uuid" type="s" direction="in"/>
<arg name="domain" type="o" direction="out"/>
</method>
+ <method name="ListNetworks">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListAllNe...
+ <arg name="flags" type="u" direction="in"/>
+ <arg name="networks" type="ao"
direction="out"/>
+ </method>
<signal name="DomainEvent">
<annotation name="org.gtk.GDBus.DocString"
value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEven...
diff --git a/src/connect.c b/src/connect.c
index 2fdd248..f9cd96c 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -280,6 +280,46 @@ virtDBusDomainLookupByUUID(GVariant *inArgs,
*outArgs = g_variant_new("(o)", path);
}
+static void
+virtDBusConnectListNetworks(GVariant *inArgs,
+ GUnixFDList *inFDs G_GNUC_UNUSED,
+ const gchar *objectPath G_GNUC_UNUSED,
+ gpointer userData,
+ GVariant **outArgs,
+ GUnixFDList **outFDs G_GNUC_UNUSED,
+ GError **error)
+{
+ virtDBusConnect *connect = userData;
+ g_autoptr(virNetworkPtr) networks = NULL;
+ guint flags;
+ GVariantBuilder builder;
+ GVariant *gnetworks;
+
+ g_variant_get(inArgs, "(u)", &flags);
+
+ if (!virtDBusConnectOpen(connect, error))
+ return;
+
+ if (virConnectListAllNetworks(connect->connection, &networks, flags) < 0)
+ return virtDBusUtilSetLastVirtError(error);
+
+ if (!*networks)
+ return;
+
+ g_variant_builder_init(&builder, G_VARIANT_TYPE("ao"));
+
+ for (gint i = 0; networks[i]; i++) {
+ g_autofree gchar *path = NULL;
+ path = virtDBusUtilBusPathForVirNetwork(networks[i],
+ connect->networkPath);
+
+ g_variant_builder_add(&builder, "o", path);
+ }
+
+ gnetworks = g_variant_builder_end(&builder);
+ *outArgs = g_variant_new_tuple(&gnetworks, 1);
+}
+
static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
{ "Version", virtDBusConnectGetVersion, NULL },
{ 0 }
@@ -292,6 +332,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
{ "DomainLookupByID", virtDBusDomainLookupByID },
{ "DomainLookupByName", virtDBusDomainLookupByName },
{ "DomainLookupByUUID", virtDBusDomainLookupByUUID },
+ { "ListNetworks", virtDBusConnectListNetworks },
{ 0 }
};
diff --git a/test/test_connect.py b/test/test_connect.py
index 5df7a5b..03f353f 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -74,6 +74,18 @@ class TestConnect(libvirttest.BaseTestClass):
props = obj.GetAll('org.libvirt.Connect',
dbus_interface=dbus.PROPERTIES_IFACE)
assert isinstance(props[property_name], expected_type)
+ def test_list_networks(self):
+ networks = self.connect.ListNetworks(0)
+ assert isinstance(networks, dbus.Array)
+ assert len(networks) == 1
+
+ for path in networks:
+ assert isinstance(path, dbus.ObjectPath)
+ network = self.bus.get_object('org.libvirt', path)
+
+ # ensure the path exists by calling Introspect on it
+ network.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE)
+
if __name__ == '__main__':
libvirttest.run()
--
2.15.0