[Libvir] PATCH: RFC: env var to set default connection URI

Currently, if the app provides NULL as the connect URI, we always connect to a Xen hypervisor. virsh provides a VIR_DEFAULT_CONNECT_URI env var which can be used to override this. virt-install/virt-manager never use NULL, and now try to 'guess' a default URI based on whether /dev/kvm or /proc/xen exist. Users have requested that VIR_DEFAULT_CONNECT_URI apply to other apps besides virsh. So this patch adds support for LIBVIRT_DEFAULT_URI env variable which will be used if the connect URI is NULL. If that variable is not set it will still default to Xen. diff -r 673c98e11c78 src/libvirt.c --- a/src/libvirt.c Wed Jan 16 09:27:56 2008 -0500 +++ b/src/libvirt.c Wed Jan 16 09:28:00 2008 -0500 @@ -516,8 +516,13 @@ do_open (const char *name, xmlURIPtr uri; /* Convert NULL or "" to xen:/// for back compat */ - if (!name || name[0] == '\0') - name = "xen:///"; + if (!name || name[0] == '\0') { + char *defname = getenv("LIBVIRT_DEFAULT_URI"); + if (defname && *defname) + name = defname; + else + name = "xen:///"; + } /* Convert xen -> xen:/// for back compat */ if (!strcasecmp(name, "xen")) Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

On Sat, Jan 19, 2008 at 06:29:52PM +0000, Daniel P. Berrange wrote:
So this patch adds support for LIBVIRT_DEFAULT_URI env variable which will be used if the connect URI is NULL. If that variable is not set it will still default to Xen.
virsh needs to be made aware of this as well. Current behaviour for virsh is to connect readOnly if the connection uri is NULL and you're not root. That will cause quite unexpected problems, if LIBVIRT_DEFAULT_URI is set to e.g. qemu:///session. -- Soren Hansen Ubuntu Server Team http://www.ubuntu.com/

On Sat, Jan 19, 2008 at 11:07:18PM +0100, Soren Hansen wrote:
On Sat, Jan 19, 2008 at 06:29:52PM +0000, Daniel P. Berrange wrote:
So this patch adds support for LIBVIRT_DEFAULT_URI env variable which will be used if the connect URI is NULL. If that variable is not set it will still default to Xen.
virsh needs to be made aware of this as well. Current behaviour for virsh is to connect readOnly if the connection uri is NULL and you're not root. That will cause quite unexpected problems, if LIBVIRT_DEFAULT_URI is set to e.g. qemu:///session.
Yes, the automatic use of readOnly is not neccessary now that we have proper authentication support, because we can authenticate to get a full read-write connection if required. I'll cook up a new patch with this change & the uri.html docs update. Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|

Daniel P. Berrange wrote:
Currently, if the app provides NULL as the connect URI, we always connect to a Xen hypervisor.
virsh provides a VIR_DEFAULT_CONNECT_URI env var which can be used to override this. virt-install/virt-manager never use NULL, and now try to 'guess' a default URI based on whether /dev/kvm or /proc/xen exist.
Users have requested that VIR_DEFAULT_CONNECT_URI apply to other apps besides virsh.
So this patch adds support for LIBVIRT_DEFAULT_URI env variable which will be used if the connect URI is NULL. If that variable is not set it will still default to Xen.
diff -r 673c98e11c78 src/libvirt.c --- a/src/libvirt.c Wed Jan 16 09:27:56 2008 -0500 +++ b/src/libvirt.c Wed Jan 16 09:28:00 2008 -0500 @@ -516,8 +516,13 @@ do_open (const char *name, xmlURIPtr uri;
/* Convert NULL or "" to xen:/// for back compat */ - if (!name || name[0] == '\0') - name = "xen:///"; + if (!name || name[0] == '\0') { + char *defname = getenv("LIBVIRT_DEFAULT_URI"); + if (defname && *defname) + name = defname; + else + name = "xen:///"; + }
/* Convert xen -> xen:/// for back compat */ if (!strcasecmp(name, "xen"))
I agree with Soren's comment. The patch above is fine, but you'll also need to change virsh and don't forget to document this on the uri.html page. Rich. -- Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/ Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 03798903
participants (3)
-
Daniel P. Berrange
-
Richard W.M. Jones
-
Soren Hansen