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

Daniel P. Berrange berrange at redhat.com
Sat Jan 19 18:29:52 UTC 2008


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  -=| 




More information about the libvir-list mailing list