[libvirt] [libvirt-snmp][PATCH] New environment variable managing connection URI.

Add environment variable LIBVIRT_MIB_CONNECT_URI to control URI which snmp agent is connecting to. It is now possible to connect to all hypervisors (including test:///) instead of hardcoded qemu:///system, which is used now by default when variable is not set. --- src/libvirtSnmp.c | 5 ++++- src/libvirtSnmp.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletions(-) diff --git a/src/libvirtSnmp.c b/src/libvirtSnmp.c index ce21369..7652da0 100644 --- a/src/libvirtSnmp.c +++ b/src/libvirtSnmp.c @@ -180,7 +180,10 @@ int libvirtSnmpInit(void) /* virConnectOpenAuth is called here with all default parameters, * except, possibly, the URI of the hypervisor. */ /* TODO: configure the URI */ - conn = virConnectOpenAuth("qemu:///system", virConnectAuthPtrDefault, 0); + /* A simple workaround for testing - environment variable */ + char *connect_uri = getenv(CONNECT_URI_ENV); + + conn = virConnectOpenAuth((connect_uri ? connect_uri : "qemu:///system"), virConnectAuthPtrDefault, 0); if (NULL == conn) { printf("No connection to hypervisor\n"); diff --git a/src/libvirtSnmp.h b/src/libvirtSnmp.h index 4ac6130..67b6125 100644 --- a/src/libvirtSnmp.h +++ b/src/libvirtSnmp.h @@ -10,6 +10,9 @@ #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> +/* Environment variable to control connection URI */ +#define CONNECT_URI_ENV "LIBVIRT_MIB_CONNECT_URI" + /* * Populate libvirtGuestTable into given container. */ -- 1.7.3.5

On Wed, Feb 09, 2011 at 04:43:25PM +0100, Michal Privoznik wrote:
Add environment variable LIBVIRT_MIB_CONNECT_URI to control URI which snmp agent is connecting to. It is now possible to connect to all hypervisors (including test:///) instead of hardcoded qemu:///system, which is used now by default when variable is not set.
Should this use the existing LIBVIRT_DEFAULT_URI if set instead ? That's the current way to define the default URI for the stack, so why would you want a different one for SNMP ? Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Thu, Feb 10, 2011 at 10:43:08AM +0800, Daniel Veillard wrote:
On Wed, Feb 09, 2011 at 04:43:25PM +0100, Michal Privoznik wrote:
Add environment variable LIBVIRT_MIB_CONNECT_URI to control URI which snmp agent is connecting to. It is now possible to connect to all hypervisors (including test:///) instead of hardcoded qemu:///system, which is used now by default when variable is not set.
Should this use the existing LIBVIRT_DEFAULT_URI if set instead ? That's the current way to define the default URI for the stack, so why would you want a different one for SNMP ?
Yes, the problem is that the current code is passing an explicit qemu:///system in to virConnectOpen, so libvirt's default logic is being bypassed. If the SNMP agent just passed 'NULL' then libvirt would auto-pick the hypervisor, and LIBVIRT_DEFAULT_URI would also 'just work'. So NACK to this patch, ust replace qemu:///system with NULL. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Daniel P. Berrange
-
Daniel Veillard
-
Michal Privoznik