1 (* Simple demo program showing how to list out domains.
2 Usage: list_domains [URI]
3 (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
5 $Id: list_domains.ml,v 1.1 2007/08/06 10:16:53 rjones Exp $
10 module C = Libvirt.Connect
11 module D = Libvirt.Domain
12 module N = Libvirt.Network
17 if Array.length Sys.argv >= 2 then
21 let conn = C.connect ?name () in
23 (* List running domains. *)
24 let n = C.num_of_domains conn in
25 let ids = C.list_domains conn n in
26 let domains = Array.map (D.lookup_by_id conn) ids in
29 printf "%8d %s\n%!" (D.get_id dom) (D.get_name dom)
32 (* List inactive domains. *)
33 let n = C.num_of_defined_domains conn in
34 let names = C.list_defined_domains conn n in
37 printf "inactive %s\n%!" name
40 Libvirt.Virterror err ->
41 eprintf "error: %s\n" (Libvirt.Virterror.to_string err)
44 (* Run the garbage collector which is a good way to check for
45 * memory corruption errors and reference counting issues in libvirt.