mlvirsh can compile without extlib
[virt-top.git] / README
1 ocaml-libvirt
2 ----------------------------------------------------------------------
3
4 Copyright (C) 2007 Richard W.M. Jones, Red Hat Inc.
5 http://libvirt.org/ocaml/
6 http://libvirt.org/
7
8 This is a complete set of OCaml bindings around libvirt, exposing all
9 known functionality to OCaml programs.
10
11
12 Requirements
13 ----------------------------------------------------------------------
14
15 To build the bindings, examples, and mlvirsh (required):
16
17   GNU make, gcc
18   libvirt >= 0.2.1 (from http://libvirt.org/,
19                     get the latest version if you can)
20   ocaml >= 3.08 (from http://caml.inria.fr/)
21
22 Optional, but highly recommended:
23
24   findlib (from http://www.ocaml-programming.de/packages/)
25
26 To build the OCaml interface documentation (optional):
27
28   ocamldoc (part of OCaml itself)
29
30 To build virt-top (optional):
31
32   ocaml-curses (from http://www.nongnu.org/ocaml-tmk/)
33   Extlib (from http://ocaml-lib.sourceforge.net/)
34   xml-light (from http://tech.motion-twin.com/doc/xml-light/)
35   ocaml CSV library (from http://merjis.com/developers/csv)
36   ocaml-calendar (http://www.lri.fr/~signoles/prog.en.html)
37
38   [Only ocaml-curses and Extlib are required for building virt-top.
39   The other packages are not required, but you will get reduced
40   functionality].
41
42 To build mlvirtmanager (optional):
43
44   GTK2 (from http://gtk.org/)
45   lablgtk2 (from http://wwwfun.kurims.kyoto-u.ac.jp/soft/lsl/lablgtk.html)
46
47 To build the manpages (optional):
48
49   perldoc (part of Perl)
50
51 OCaml packages are available for Fedora 7 and above (ocaml,
52 ocaml-findlib, ocaml-findlib-devel, ocaml-ocamldoc, ocaml-extlib,
53 ocaml-extlib-devel, ocaml-lablgtk, ocaml-lablgtk-devel, ocaml-curses,
54 ocaml-xml-light, ocaml-csv).
55
56   http://www.annexia.org/tmp/ocaml/
57   http://fedoraproject.org/wiki/SIGs/OCaml
58
59 Debian/Ubuntu have all the packages you require.
60
61
62 Building
63 ----------------------------------------------------------------------
64
65   ./configure           # Checks that you have all the required bits.
66
67   make all              # Builds the bytecode version of libs/programs.
68   make opt              # Builds the native code version of libs/programs.
69
70   make install          # Install in OCaml directory, and the binaries
71                         # in $prefix/bin.
72
73   make doc              # Build HTML documentation in html/ subdirectory.
74
75 Then have a look at the programs 'mlvirsh.opt' and 'mlvirtmanager.opt'.
76
77 Note: If you want to run the programs without first installing, you
78 may need to set your $LD_LIBRARY_PATH environment variable so it
79 contains the build directory.  eg:
80
81   LD_LIBRARY_PATH=libvirt/ mlvirsh/mlvirsh.opt
82
83
84 Windows
85 ----------------------------------------------------------------------
86
87 I have built libvirt (the bindings) and examples on Windows using the
88 MinGW port of OCaml.  It's quite likely that it will also work under
89 VC++, but I have not tested this.
90
91
92 mlvirsh
93 ----------------------------------------------------------------------
94
95 'mlvirsh' is an almost complete reimplementation of virsh, which is
96 mostly command compatible (there are a very few commands missing, and
97 some commands have a slightly different syntax, but broadly speaking
98 they are equivalent programs except that one is written in C and the
99 other in OCaml).
100
101 At the time of writing:
102
103               wc -c  wc -l
104
105   virsh     126,056  4,641
106   mlvirsh    19,427    598
107
108   % size        15%    13%
109
110
111 mlvirtmanager
112 ----------------------------------------------------------------------
113
114 'mlvirtmanager' is a demonstration implementation of virt-manager in
115 OCaml.  It is not feature-complete by any means, but does allow you to
116 show the running domains and start and stop defined domains.  The main
117 functionality _missing_ is the ability to define new virtual machines,
118 change the resources allocated to domains, or show the machine
119 console.
120
121
122 Programming
123 ----------------------------------------------------------------------
124
125 The interface is described in 'libvirt.mli'.  The main modules are
126 Libvirt.Connect, Libvirt.Domain and Libvirt.Network, corresponding
127 respectively to the virConnect*, virDomain*, and virNetwork*
128 functions.  For brevity I usually rename these modules like this:
129
130   module C = Libvirt.Connect
131   module D = Libvirt.Domain
132   module N = Libvirt.Network
133
134 To get a connection handle, do:
135
136   let name = "xen:///"
137   let conn = C.connect ~name ()
138
139 To list domains, do:
140
141   let n = C.num_of_domains conn
142   let ids = C.list_domains conn n
143   let domains = Array.map (D.lookup_by_id conn) ids
144   let () =
145     Array.iter (
146       fun dom ->
147         printf "%5d %s\n" (D.get_id dom) (D.get_name dom)
148     ) domains
149
150 (See also the program list_domains.ml).
151
152 For documentation on these bindings, read libvirt.mli and/or 'make
153 doc' and browse the HTML documentation in the html/ subdirectory.
154
155 For documentation on libvirt itself, see http://libvirt.org/html/
156
157
158 Subdirectories
159 ----------------------------------------------------------------------
160
161 libvirt/                The OCaml bindings.
162 examples/               Some example programs using the bindings.
163 mlvirsh/                'mlvirsh' command line tool.
164 mlvirtmanager/          'mlvirtmanager' graphical tool.
165 virt-top/               'virt-top' tool.