Re: [dbus PATCH 2/3] Implement GetDHCPLeases method for Network Interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 18, 2018 at 03:19:09PM +0200, Katerina Koukiou wrote:
> 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,

I think that we can convert type from int to string, there are only two
types, virIPAddrType.

> +                              lease->iaid ? lease->iaid : "None" ,
> +                              lease->ipaddr, lease->prefix,
> +                              lease->hostname ? lease->hostname : "None",
> +                              lease->clientid ? lease->clientid : "None");

If the value can be NULL we should be consistent with our APIs and
return empty string instead of "None" and to make it clear document it.

> +
> +        virNetworkDHCPLeaseFree(leases[i]);
> +    }
> +    g_free(leases);

Freeing the memory like this is OK, but since libvirt-dbus uses the
attribute cleanup convention this would require new function and
registering that function, for example like we do for list of virNetwork
virtDBusUtilVirNetworkListFree().

Pavel

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux