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.
9 module C = Libvirt.Connect
10 module D = Libvirt.Domain
11 module N = Libvirt.Network
16 if Array.length Sys.argv >= 2 then
20 let conn = C.connect_readonly ?name () in
22 (* List running domains. *)
23 let n = C.num_of_domains conn in
24 let ids = C.list_domains conn n in
25 let domains = Array.map (D.lookup_by_id conn) ids in
28 printf "%8d %s\n%!" (D.get_id dom) (D.get_name dom)
31 (* List inactive domains. *)
32 let n = C.num_of_defined_domains conn in
33 let names = C.list_defined_domains conn n in
36 printf "inactive %s\n%!" name
39 Libvirt.Virterror err ->
40 eprintf "error: %s\n" (Libvirt.Virterror.to_string err)
43 (* Run the garbage collector which is a good way to check for
44 * memory corruption errors and reference counting issues in libvirt.