blob: c97432c0938e7fff57f8c7fc9acd3bdf66ac8169 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
(* Simple demo program showing how to list out domains.
Usage: list_domains [URI]
(C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
http://libvirt.org/
*)
open Printf
module C = Libvirt.Connect
module D = Libvirt.Domain
module N = Libvirt.Network
let () =
try
let name =
if Array.length Sys.argv >= 2 then
Some (Sys.argv.(1))
else
None in
let conn = C.connect_readonly ?name () in
(* List running domains. *)
let n = C.num_of_domains conn in
let ids = C.list_domains conn n in
let domains = Array.map (D.lookup_by_id conn) ids in
Array.iter (
fun dom ->
printf "%8d %s\n%!" (D.get_id dom) (D.get_name dom)
) domains;
(* List inactive domains. *)
let n = C.num_of_defined_domains conn in
let names = C.list_defined_domains conn n in
Array.iter (
fun name ->
printf "inactive %s\n%!" name
) names;
with
Libvirt.Virterror err ->
eprintf "error: %s\n" (Libvirt.Virterror.to_string err)
let () =
(* Run the garbage collector which is a good way to check for
* memory corruption errors and reference counting issues in libvirt.
*)
Gc.compact ()
|