Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- data/org.libvirt.Network.xml | 8 +++++++ src/network.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml index 48e3324..385eb82 100644 --- a/data/org.libvirt.Network.xml +++ b/data/org.libvirt.Network.xml @@ -36,6 +36,14 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkDestroy"/> </method> + <method name="GetDHCPLeases"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetDHCPLeases + Empty string can be used to pass a NULL as @mac argument."/> + <arg name="mac" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="leases" type="a(stisssuss)" direction="out"/> + </method> <method name="GetXMLDesc"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetXMLDesc"/> diff --git a/src/network.c b/src/network.c index 1448777..492f0bd 100644 --- a/src/network.c +++ b/src/network.c @@ -209,6 +209,56 @@ virtDBusNetworkDestroy(GVariant *inArgs G_GNUC_UNUSED, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusNetworkGetDHCPLeases(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virNetwork) network = NULL; + const gchar *mac; + guint flags; + virNetworkDHCPLeasePtr *leases = NULL; + gint nleases; + GVariantBuilder builder; + GVariant *res; + + g_variant_get(inArgs, "(&su)", &mac, &flags); + if (g_str_equal(mac, "")) + mac = NULL; + + network = virtDBusNetworkGetVirNetwork(connect, objectPath, error); + if (!network) + return; + + nleases = virNetworkGetDHCPLeases(network, mac, &leases, flags); + if (nleases < 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(stisssuss)")); + for (gint i = 0; i < nleases; i++) { + virNetworkDHCPLeasePtr lease = leases[i]; + + g_variant_builder_add(&builder, "(stisssuss)", + lease->iface, lease->expirytime, + lease->type, lease->mac, + lease->iaid ? lease->iaid : "None" , + lease->ipaddr, lease->prefix, + lease->hostname ? lease->hostname : "None", + lease->clientid ? lease->clientid : "None"); + + virNetworkDHCPLeaseFree(leases[i]); + } + g_free(leases); + res = g_variant_builder_end(&builder); + + *outArgs = g_variant_new_tuple(&res, 1); +} + static void virtDBusNetworkGetXMLDesc(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -269,6 +319,7 @@ static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = { static virtDBusGDBusMethodTable virtDBusNetworkMethodTable[] = { { "Create", virtDBusNetworkCreate }, { "Destroy", virtDBusNetworkDestroy }, + { "GetDHCPLeases", virtDBusNetworkGetDHCPLeases }, { "GetXMLDesc", virtDBusNetworkGetXMLDesc }, { "Undefine", virtDBusNetworkUndefine }, { 0 } -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list