[Libvir] Allow default hypervisor URI to be set via ENV variable

Daniel P. Berrange berrange at redhat.com
Fri Aug 25 18:36:10 UTC 2006


And this time, with the patch attached :-)

Dan.

On Fri, Aug 25, 2006 at 07:35:29PM +0100, Daniel P. Berrange wrote:
> When using a non-Xen backend with virsh, it gets pretty tedious always 
> passing '--default test:///some/big/path' - particularly if you're never
> using Xen on that machine. Thus I figured it would be useful to allow
> the default Xen URI to be overridden via an environment variable. 
> 
>   [berrange at localhost src]$ unset VIRSH_DEFAULT_CONNECT_URI
>   [berrange at localhost src]$ ./virsh list
>   failed to find libvirt_proxy
>   libvir: error : no support for hypervisor
>   lt-virsh: error: failed to connect to the hypervisor
>   [berrange at localhost src]$ export VIRSH_DEFAULT_CONNECT_URI=test:///default
>   [berrange at localhost src]$ ./virsh list
>    Id Name                 State
>   ----------------------------------
>     0 Domain-0             running 
> 
> This will be even more useful when other real hypervisors are available
> for libvirt. 
> 
> The patch also removes the assumption in virsh that there is >= 1 guest
> domains - sure Xen always has a Domain-0, but its not guarenteed that
> other non-Xen HVs have a permanent Domain-0
> 
> 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  -=| 
> 
> --
> Libvir-list mailing list
> Libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

-- 
|=- 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  -=| 
-------------- next part --------------
Index: virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.35
diff -c -r1.35 virsh.c
*** virsh.c	21 Aug 2006 17:58:09 -0000	1.35
--- virsh.c	25 Aug 2006 19:26:57 -0000
***************
*** 319,342 ****
  static int
  cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
  {
!     int *ids, maxid, i;
  
      if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
          return FALSE;
  
      maxid = virConnectNumOfDomains(ctl->conn);
!     if (maxid <= 0) {
!         /* strange, there should be at least dom0... */
          vshError(ctl, FALSE, "failed to list active domains.");
          return FALSE;
      }
!     ids = vshMalloc(ctl, sizeof(int) * maxid);
  
!     if (virConnectListDomains(ctl->conn, &ids[0], maxid) < 0) {
!         vshError(ctl, FALSE, "failed to list active domains.");
!         return FALSE;
      }
- 
      vshPrintExtra(ctl, "%3s %-20s %s\n", "Id", "Name", "State");
      vshPrintExtra(ctl, "----------------------------------\n");
  
--- 319,342 ----
  static int
  cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
  {
!     int *ids = NULL, maxid, i;
  
      if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
          return FALSE;
  
      maxid = virConnectNumOfDomains(ctl->conn);
!     if (maxid < 0) {
          vshError(ctl, FALSE, "failed to list active domains.");
          return FALSE;
      }
!     if (maxid) {
!         ids = vshMalloc(ctl, sizeof(int) * maxid);
  
!         if (virConnectListDomains(ctl->conn, &ids[0], maxid) < 0) {
!             vshError(ctl, FALSE, "failed to list active domains.");
!             return FALSE;
!         }
      }
      vshPrintExtra(ctl, "%3s %-20s %s\n", "Id", "Name", "State");
      vshPrintExtra(ctl, "----------------------------------\n");
  
***************
*** 357,363 ****
                   0 ? "no state" : vshDomainStateToString(info.state));
          virDomainFree(dom);
      }
!     free(ids);
      return TRUE;
  }
  
--- 357,364 ----
                   0 ? "no state" : vshDomainStateToString(info.state));
          virDomainFree(dom);
      }
!     if (ids)
!         free(ids);
      return TRUE;
  }
  
***************
*** 2377,2382 ****
--- 2379,2385 ----
  main(int argc, char **argv)
  {
      vshControl _ctl, *ctl = &_ctl;
+     char *defaultConn;
      int ret = TRUE;
  
      if (!(progname = strrchr(argv[0], '/')))
***************
*** 2387,2392 ****
--- 2390,2399 ----
      memset(ctl, 0, sizeof(vshControl));
      ctl->imode = TRUE;          /* default is interactive mode */
  
+     if ((defaultConn = getenv("VIRSH_DEFAULT_CONNECT_URI"))) {
+       ctl->name = strdup(defaultConn);
+     }
+ 
      if (!vshParseArgv(ctl, argc, argv))
          exit(EXIT_FAILURE);
  


More information about the libvir-list mailing list