Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
---
data/org.libvirt.Connect.xml | 6 ++++++
src/connect.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 1695100..ac06875 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -50,5 +50,11 @@
<arg name="domain" type="o"/>
<arg name="event" type="s"/>
</signal>
+ <method name="ListNetworks">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListAllNetworks"/>
+ <arg name="flags" type="u" direction="in"/>
+ <arg name="networks" type="ao" direction="out"/>
+ </method>
</interface>
</node>
diff --git a/src/connect.c b/src/connect.c
index 7b3f834..13fdd20 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 }
};
--
2.15.0
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Wed, Apr 04, 2018 at 02:26:10PM +0200, Katerina Koukiou wrote:
> Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
> ---
> data/org.libvirt.Connect.xml | 6 ++++++
> src/connect.c | 41 +++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 47 insertions(+)
>
> diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
> index 1695100..ac06875 100644
> --- a/data/org.libvirt.Connect.xml
> +++ b/data/org.libvirt.Connect.xml
> @@ -50,5 +50,11 @@
> <arg name="domain" type="o"/>
> <arg name="event" type="s"/>
> </signal>
> + <method name="ListNetworks">
> + <annotation name="org.gtk.GDBus.DocString"
> + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListAllNetworks"/>
> + <arg name="flags" type="u" direction="in"/>
> + <arg name="networks" type="ao" direction="out"/>
> + </method>
We should keep the methods together.
One more note, but that is for different patch series, I was thinking
about having all the properties, methods and signals sorted in
alphabetic order.
> </interface>
> </node>
> diff --git a/src/connect.c b/src/connect.c
> index 7b3f834..13fdd20 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 }
> };
Test is missing, similar to the test_list_domains test.
Pavel
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2026 Red Hat, Inc.