Previously the use of virDomainOpenGraphicsFD API from libvirt
1.2.8 was made to be conditionally compiled. Given this past
practice, make use of the virNetworkGetDHCPLeases API
conditional too, rather than requiring newer libvirt.
---
configure.ac | 6 ++-
.../libvirt-gobject-network-dhcp-lease.c | 50 ++++++++++++++++++++++
libvirt-gobject/libvirt-gobject-network.c | 12 ++++++
3 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 26beada..228788e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9,7 +9,7 @@ AC_CANONICAL_HOST
AM_SILENT_RULES([yes])
-LIBVIRT_REQUIRED=1.2.6
+LIBVIRT_REQUIRED=0.10.2
AC_SUBST([LIBVIRT_REQUIRED]) dnl used in the .spec file
GLIB2_REQUIRED=2.36.0
AC_SUBST([GLIB2_REQUIRED]) dnl used in the .spec file
@@ -97,6 +97,10 @@ PKG_CHECK_MODULES(LIBVIRT, libvirt >= $LIBVIRT_REQUIRED)
AC_CHECK_LIB([virt],
[virDomainOpenGraphicsFD],
[AC_DEFINE([HAVE_VIR_DOMAIN_OPEN_GRAPHICS_FD], 1, [Have
virDomainOpenGraphicsFD?])])
+# virNetworkGetDHCPLeases was introduced in libvirt 1.2.6
+AC_CHECK_LIB([virt],
+ [virNetworkGetDHCPLeases],
+ [AC_DEFINE([HAVE_VIR_NETWORK_GET_DHCP_LEASES], 1, [Have
virNetworkGetDHCPLeases?])])
enable_tests=no
PKG_CHECK_MODULES(GLIB2, glib-2.0 >= $GLIB2_TEST_REQUIRED,
[enable_tests=yes],
diff --git a/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c
b/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c
index 6ac3c14..90a402b 100644
--- a/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c
+++ b/libvirt-gobject/libvirt-gobject-network-dhcp-lease.c
@@ -30,14 +30,20 @@
#include "libvirt-glib/libvirt-glib.h"
#include "libvirt-gobject/libvirt-gobject.h"
#include "libvirt-gobject-compat.h"
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
#include "libvirt-gobject/libvirt-gobject-network-dhcp-lease-private.h"
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
#define GVIR_NETWORK_DHCP_LEASE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK_DHCP_LEASE,
GVirNetworkDHCPLeasePrivate))
struct _GVirNetworkDHCPLeasePrivate
{
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
virNetworkDHCPLeasePtr handle;
+#else
+ void *handle;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
};
G_DEFINE_TYPE(GVirNetworkDHCPLease, gvir_network_dhcp_lease, G_TYPE_OBJECT);
@@ -75,8 +81,10 @@ static void gvir_network_dhcp_lease_set_property(GObject *object,
switch (prop_id) {
case PROP_HANDLE:
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
if (priv->handle)
virNetworkDHCPLeaseFree(priv->handle);
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
priv->handle = g_value_get_pointer(value);
break;
@@ -89,11 +97,15 @@ static void gvir_network_dhcp_lease_set_property(GObject *object,
static void gvir_network_dhcp_lease_finalize(GObject *object)
{
GVirNetworkDHCPLease *lease = GVIR_NETWORK_DHCP_LEASE(object);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
GVirNetworkDHCPLeasePrivate *priv = lease->priv;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
g_debug("Finalize GVirNetworkDHCPLease=%p", lease);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
virNetworkDHCPLeaseFree(priv->handle);
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
G_OBJECT_CLASS(gvir_network_dhcp_lease_parent_class)->finalize(object);
}
@@ -127,12 +139,14 @@ static void gvir_network_dhcp_lease_init(GVirNetworkDHCPLease
*lease)
lease->priv = GVIR_NETWORK_DHCP_LEASE_GET_PRIVATE(lease);
}
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
GVirNetworkDHCPLease *gvir_network_dhcp_lease_new(virNetworkDHCPLeasePtr handle)
{
return g_object_new(GVIR_TYPE_NETWORK_DHCP_LEASE,
"handle", handle,
NULL);
}
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
/**
* gvir_network_dhcp_lease_get_iface:
@@ -144,7 +158,11 @@ const gchar *gvir_network_dhcp_lease_get_iface(GVirNetworkDHCPLease
*lease)
{
g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
return lease->priv->handle->iface;
+#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
+ return NULL;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
}
/**
@@ -157,7 +175,11 @@ gint64 gvir_network_dhcp_lease_get_expiry_time(GVirNetworkDHCPLease
*lease)
{
g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), -1);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
return lease->priv->handle->expirytime;
+#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
+ return -1;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
}
/**
@@ -170,7 +192,11 @@ gint gvir_network_dhcp_lease_get_ip_type(GVirNetworkDHCPLease
*lease)
{
g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), -1);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
return lease->priv->handle->type;
+#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
+ return -1;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
}
/**
@@ -183,7 +209,11 @@ const gchar *gvir_network_dhcp_lease_get_mac(GVirNetworkDHCPLease
*lease)
{
g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
return lease->priv->handle->mac;
+#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
+ return NULL;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
}
/**
@@ -196,7 +226,11 @@ const gchar *gvir_network_dhcp_lease_get_iaid(GVirNetworkDHCPLease
*lease)
{
g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
return lease->priv->handle->iaid;
+#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
+ return NULL;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
}
/**
@@ -209,7 +243,11 @@ const gchar *gvir_network_dhcp_lease_get_ip(GVirNetworkDHCPLease
*lease)
{
g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
return lease->priv->handle->ipaddr;
+#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
+ return NULL;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
}
/**
@@ -222,7 +260,11 @@ guint gvir_network_dhcp_lease_get_prefix(GVirNetworkDHCPLease
*lease)
{
g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), 0);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
return lease->priv->handle->prefix;
+#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
+ return 0;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
}
/**
@@ -235,7 +277,11 @@ const gchar
*gvir_network_dhcp_lease_get_hostname(GVirNetworkDHCPLease *lease)
{
g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
return lease->priv->handle->hostname;
+#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
+ return NULL;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
}
/**
@@ -248,5 +294,9 @@ const gchar
*gvir_network_dhcp_lease_get_client_id(GVirNetworkDHCPLease *lease)
{
g_return_val_if_fail(GVIR_IS_NETWORK_DHCP_LEASE(lease), NULL);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
return lease->priv->handle->clientid;
+#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
+ return NULL;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
}
diff --git a/libvirt-gobject/libvirt-gobject-network.c
b/libvirt-gobject/libvirt-gobject-network.c
index 45dbb71..a278105 100644
--- a/libvirt-gobject/libvirt-gobject-network.c
+++ b/libvirt-gobject/libvirt-gobject-network.c
@@ -29,7 +29,9 @@
#include "libvirt-glib/libvirt-glib.h"
#include "libvirt-gobject/libvirt-gobject.h"
#include "libvirt-gobject-compat.h"
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
#include "libvirt-gobject/libvirt-gobject-network-dhcp-lease-private.h"
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
#define GVIR_NETWORK_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_NETWORK, GVirNetworkPrivate))
@@ -249,14 +251,17 @@ GList *gvir_network_get_dhcp_leases(GVirNetwork *network,
guint flags,
GError **err)
{
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
virNetworkDHCPLeasePtr *leases;
GList *ret = NULL;
int num_leases, i;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
g_return_val_if_fail(GVIR_IS_NETWORK(network), NULL);
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
g_return_val_if_fail(flags == 0, NULL);
+#ifdef HAVE_VIR_NETWORK_GET_DHCP_LEASES
num_leases = virNetworkGetDHCPLeases(network->priv->handle, mac, &leases,
flags);
if (num_leases < 0) {
gvir_set_error_literal(err, GVIR_NETWORK_ERROR,
@@ -277,4 +282,11 @@ GList *gvir_network_get_dhcp_leases(GVirNetwork *network,
free(leases);
return g_list_reverse(ret);
+#else /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
+ (void)mac;
+ gvir_set_error_literal(err, GVIR_NETWORK_ERROR,
+ 0,
+ "Unable to get network DHCP leases");
+ return NULL;
+#endif /* HAVE_VIR_NETWORK_GET_DHCP_LEASES */
}
--
2.4.3