On Mon, Jun 29, 2015 at 03:08:55PM +0100, Zeeshan Ali (Khattak) wrote:
---
libvirt-gobject/libvirt-gobject-network.c | 53
+++
libvirt-gobject/libvirt-gobject-network.h | 4 +++
libvirt-gobject/libvirt-gobject.sym | 3 ++
3 files changed, 60 insertions(+)
diff --git a/libvirt-gobject/libvirt-gobject-network.c
b/libvirt-gobject/libvirt-gobject-network.c
index b1b38a0..650a164 100644
--- a/libvirt-gobject/libvirt-gobject-network.c
+++ b/libvirt-gobject/libvirt-gobject-network.c
@@ -29,6 +29,7 @@
#include libvirt-glib/libvirt-glib.h
#include libvirt-gobject/libvirt-gobject.h
#include libvirt-gobject-compat.h
+#include libvirt-gobject/libvirt-gobject-network-dhcp-lease-private.h
#define GVIR_NETWORK_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK,
GVirNetworkPrivate))
@@ -224,3 +225,55 @@ GVirConfigNetwork *gvir_network_get_config(GVirNetwork
*network,
free(xml);
return conf;
}
+
+/**
+ * gvir_network_get_dhcp_leases:
+ * @network: the network
+ * @mac: (allow-none): The optional ASCII formatted MAC address of an
interface
+ * @flags: the flags
This should be documented as not being used, and needing to be 0
together with a runtime precondition in the method impl.
+ * @err: Place-holder for possible errors
+ *
+ * This function fetches leases info of guests in the specified network. If
the
+ * optional parameter @mac is specified, the returned list will contain only
+ * lease info about a specific guest interface with @mac. There can be
multiple
+ * leases for a single @mac because this API supports DHCPv6 too.
+ *
+ * Returns: (element-type LibvirtGObject.NetworkDHCPLease) (transfer full):
the
+ * list of network leases. Each object in the returned list should be
unreffed
+ * with g_object_unref() and the list itself using g_list_free, when no
longer
+ * needed.
+ */
+GList *gvir_network_get_dhcp_leases(GVirNetwork *network,
+const char* mac,
+guint flags,
+GError **err)
+{
+virNetworkDHCPLeasePtr *leases;
+GList *ret = NULL;
+int num_leases, i;
+
+g_return_val_if_fail(GVIR_IS_NETWORK(network), NULL);
+g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+num_leases = virNetworkGetDHCPLeases(network-priv-handle, mac,
leases, flags);
+if (num_leases 0) {
+gvir_set_error_literal(err, GVIR_NETWORK_ERROR,
+ 0,
+ Unable to get network DHCP leases);
+return NULL;
+}
+
+if (num_leases == 0)
+return NULL;
+
+for (i = 0; i num_leases; i++) {
+GVirNetworkDHCPLease *lease;
+
+lease = gvir_network_dhcp_lease_new(leases[i]);
+ret = g_list_prepend(ret, lease);
+}
+ret = g_list_reverse(ret);
+free(leases);
+
+return ret;
+}
diff --git a/libvirt-gobject/libvirt-gobject-network.h
b/libvirt-gobject/libvirt-gobject-network.h
index 9f746c0..5617ed6 100644
--- a/libvirt-gobject/libvirt-gobject-network.h
+++ b/libvirt-gobject/libvirt-gobject-network.h
@@ -71,6 +71,10 @@ const gchar *gvir_network_get_uuid(GVirNetwork *network);
GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network,
guint flags,
GError **err);
+GList *gvir_network_get_dhcp_leases(GVirNetwork *network,
+const char* mac,
+guint flags,
+GError **err);
G_END_DECLS
diff --git a/libvirt-gobject/libvirt-gobject.sym
b/libvirt-gobject/libvirt-gobject.sym
index e35130b..7518422 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -285,6 +285,9 @@ LIBVIRT_GOBJECT_0.2.2 {
gvir_interface_get_mac;
gvir_ip_addr_type_get_type;
+
+ gvir_network_get_dhcp_leases;
+
This needs to come after the gvir_network_dhcp_* symbols or this breaks
make distcheck ('make -C libvirt-gobject check-symsorting' from the
toplevel directory).
Looks good otherwise.
Christophe
pgpBg6ArXEF2d.pgp
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list