89c6d9047c2ca6904a755920db70dd277632c244
[ocaml-libvirt.git] / libvirt / libvirt.mli
1 (** OCaml bindings for libvirt. *)
2 (* (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
3    http://libvirt.org/
4
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version,
9    with the OCaml linking exception described in ../COPYING.LIB.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with this library; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19 *)
20
21 (**
22    {2 Introduction and examples}
23
24    This is a set of bindings for writing OCaml programs to
25    manage virtual machines through {{:http://libvirt.org/}libvirt}.
26
27    {3 Using libvirt interactively}
28
29    Using the interactive toplevel:
30
31 {v
32 $ ocaml -I +libvirt
33         Objective Caml version 3.10.0
34
35 # #load "unix.cma";;
36 # #load "mllibvirt.cma";;
37 # let name = "test:///default";;
38 val name : string = "test:///default"
39 # let conn = Libvirt.Connect.connect_readonly ~name () ;;
40 val conn : Libvirt.ro Libvirt.Connect.t = <abstr>
41 # Libvirt.Connect.get_node_info conn;;
42   : Libvirt.Connect.node_info =
43 {Libvirt.Connect.model = "i686"; Libvirt.Connect.memory = 3145728L;
44  Libvirt.Connect.cpus = 16; Libvirt.Connect.mhz = 1400;
45  Libvirt.Connect.nodes = 2; Libvirt.Connect.sockets = 2;
46  Libvirt.Connect.cores = 2; Libvirt.Connect.threads = 2}
47 v}
48
49    {3 Compiling libvirt programs}
50
51    This command compiles a program to native code:
52
53 {v
54 ocamlopt -I +libvirt mllibvirt.cmxa list_domains.ml -o list_domains
55 v}
56
57    {3 Example: Connect to the hypervisor}
58
59    The main modules are {!Libvirt.Connect}, {!Libvirt.Domain} and
60    {!Libvirt.Network} corresponding respectively to the
61    {{:http://libvirt.org/html/libvirt-libvirt.html}virConnect*, virDomain* and virNetwork* functions from libvirt}.
62    For brevity I usually rename these modules like this:
63
64 {v
65 module C = Libvirt.Connect
66 module D = Libvirt.Domain
67 module N = Libvirt.Network
68 v}
69
70    To get a connection handle, assuming a Xen hypervisor:
71
72 {v
73 let name = "xen:///"
74 let conn = C.connect_readonly ~name ()
75 v}
76
77    {3 Example: List running domains}
78
79 {v
80 open Printf
81
82 let n = C.num_of_domains conn in
83 let ids = C.list_domains conn n in
84 let domains = Array.map (D.lookup_by_id conn) ids in
85 Array.iter (
86   fun dom ->
87     printf "%8d %s\n%!" (D.get_id dom) (D.get_name dom)
88 ) domains;
89 v}
90
91    {3 Example: List inactive domains}
92
93 {v
94 let n = C.num_of_defined_domains conn in
95 let names = C.list_defined_domains conn n in
96 Array.iter (
97   fun name ->
98     printf "inactive %s\n%!" name
99 ) names;
100 v}
101
102    {3 Example: Print node info}
103
104 {v
105 let node_info = C.get_node_info conn in
106 printf "model = %s\n" node_info.C.model;
107 printf "memory = %Ld K\n" node_info.C.memory;
108 printf "cpus = %d\n" node_info.C.cpus;
109 printf "mhz = %d\n" node_info.C.mhz;
110 printf "nodes = %d\n" node_info.C.nodes;
111 printf "sockets = %d\n" node_info.C.sockets;
112 printf "cores = %d\n" node_info.C.cores;
113 printf "threads = %d\n%!" node_info.C.threads;
114
115 let hostname = C.get_hostname conn in
116 printf "hostname = %s\n%!" hostname;
117
118 let uri = C.get_uri conn in
119 printf "uri = %s\n%!" uri
120 v}
121
122 *)
123
124
125 (** {2 Programming issues}
126
127     {3 General safety issues}
128
129     Memory allocation / automatic garbage collection of all libvirt
130     objects should be completely safe.  If you find any safety issues
131     or if your pure OCaml program ever segfaults, please contact the author.
132
133     You can force a libvirt object to be freed early by calling
134     the [close] function on the object.  This shouldn't affect
135     the safety of garbage collection and should only be used when
136     you want to explicitly free memory.  Note that explicitly
137     closing a connection object does nothing if there are still
138     unclosed domain or network objects referencing it.
139
140     Note that even though you hold open (eg) a domain object, that
141     doesn't mean that the domain (virtual machine) actually exists.
142     The domain could have been shut down or deleted by another user.
143     Thus domain objects can through odd exceptions at any time.
144     This is just the nature of virtualisation.
145
146     {3 Backwards and forwards compatibility}
147
148     OCaml-libvirt is backwards and forwards compatible with
149     any libvirt >= 0.2.1.  One consequence of this is that
150     your program can dynamically link to a {i newer} version of
151     libvirt than it was compiled with, and it should still
152     work.
153
154     When we link to an older version of libvirt.so, there may
155     be missing functions.  If ocaml-libvirt was compiled with
156     gcc, then these are turned into OCaml {!Libvirt.Not_supported}
157     exceptions.
158
159     We don't support libvirt < 0.2.1, and never will so don't ask us.
160
161     {3 Threads}
162
163     You can issue multiple concurrent libvirt requests in
164     different threads.  However you must follow this rule:
165     Each thread must have its own separate libvirt connection, {i or}
166     you must implement your own mutex scheme to ensure that no
167     two threads can ever make concurrent calls using the same
168     libvirt connection.
169
170     (Note that multithreaded code is not well tested.  If you find
171     bugs please report them.)
172
173     {3 Initialisation}
174
175     Libvirt requires all callers to call virInitialize before
176     using the library.  This is done automatically for you by
177     these bindings when the program starts up, and we believe
178     that the way this is done is safe.
179
180     {2 Reference}
181 *)
182
183 type uuid = string
184     (** This is a "raw" UUID, ie. a packed string of bytes. *)
185
186 type xml = string
187     (** Type of XML (an uninterpreted string of bytes).  Use PXP, expat,
188         xml-light, etc. if you want to do anything useful with the XML.
189     *)
190
191 type filename = string
192     (** A filename. *)
193
194 val get_version : ?driver:string -> unit -> int * int
195   (** [get_version ()] returns the library version in the first part
196       of the tuple, and [0] in the second part.
197
198       [get_version ~driver ()] returns the library version in the first
199       part of the tuple, and the version of the driver called [driver]
200       in the second part.
201
202       The version numbers are encoded as
203       1,000,000 * major + 1,000 * minor + release.
204   *)
205
206 val uuid_length : int
207   (** Length of packed UUIDs. *)
208
209 val uuid_string_length : int
210   (** Length of UUID strings. *)
211
212 type rw = [`R|`W]
213 type ro = [`R]
214     (** These
215         {{:http://caml.inria.fr/pub/ml-archives/caml-list/2004/07/80683af867cce6bf8fff273973f70c95.en.html}phantom types}
216         are used to ensure the type-safety of read-only
217         versus read-write connections.
218
219         All connection/domain/etc. objects are marked with
220         a phantom read-write or read-only type, and trying to
221         pass a read-only object into a function which could
222         mutate the object will cause a compile time error.
223
224         Each module provides a function like {!Libvirt.Connect.const}
225         to demote a read-write object into a read-only object.  The
226         opposite operation is, of course, not allowed.
227
228         If you want to handle both read-write and read-only
229         connections at runtime, use a variant similar to this:
230 {v
231 type conn_t =
232     | No_connection
233     | Read_only of Libvirt.ro Libvirt.Connect.t
234     | Read_write of Libvirt.rw Libvirt.Connect.t
235 v}
236         See also the source of [mlvirsh].
237     *)
238
239 type ('a, 'b) job_t
240 (** Forward definition of {!Job.t} to avoid recursive module dependencies. *)
241
242 (** {3 Connections} *)
243
244 module Connect :
245 sig
246   type 'rw t
247     (** Connection.  Read-only connections have type [ro Connect.t] and
248         read-write connections have type [rw Connect.t].
249       *)
250
251   type node_info = {
252     model : string;                     (** CPU model *)
253     memory : int64;                     (** memory size in kilobytes *)
254     cpus : int;                         (** number of active CPUs *)
255     mhz : int;                          (** expected CPU frequency *)
256     nodes : int;                        (** number of NUMA nodes (1 = UMA) *)
257     sockets : int;                      (** number of CPU sockets per node *)
258     cores : int;                        (** number of cores per socket *)
259     threads : int;                      (** number of threads per core *)
260   }
261
262   val connect : ?name:string -> unit -> rw t
263   val connect_readonly : ?name:string -> unit -> ro t
264     (** [connect ~name ()] connects to the hypervisor with URI [name].
265
266         [connect ()] connects to the default hypervisor.
267
268         [connect_readonly] is the same but connects in read-only mode.
269     *)
270
271   val close : [>`R] t -> unit
272     (** [close conn] closes and frees the connection object in memory.
273
274         The connection is automatically closed if it is garbage
275         collected.  This function just forces it to be closed
276         and freed right away.
277     *)
278
279   val get_type : [>`R] t -> string
280     (** Returns the name of the driver (hypervisor). *)
281
282   val get_version : [>`R] t -> int
283     (** Returns the driver version
284         [major * 1_000_000 + minor * 1000 + release]
285     *)
286   val get_hostname : [>`R] t -> string
287     (** Returns the hostname of the physical server. *)
288   val get_uri : [>`R] t -> string
289     (** Returns the canonical connection URI. *)
290   val get_max_vcpus : [>`R] t -> ?type_:string -> unit -> int
291     (** Returns the maximum number of virtual CPUs
292         supported by a guest VM of a particular type. *)
293   val list_domains : [>`R] t -> int -> int array
294     (** [list_domains conn max] returns the running domain IDs,
295         up to a maximum of [max] entries.
296         Call {!num_of_domains} first to get a value for [max].
297     *)
298   val num_of_domains : [>`R] t -> int
299     (** Returns the number of running domains. *)
300   val get_capabilities : [>`R] t -> xml
301     (** Returns the hypervisor capabilities (as XML). *)
302   val num_of_defined_domains : [>`R] t -> int
303     (** Returns the number of inactive (shutdown) domains. *)
304   val list_defined_domains : [>`R] t -> int -> string array
305     (** [list_defined_domains conn max]
306         returns the names of the inactive domains, up to
307         a maximum of [max] entries.
308         Call {!num_of_defined_domains} first to get a value for [max].
309     *)
310   val num_of_networks : [>`R] t -> int
311     (** Returns the number of networks. *)
312   val list_networks : [>`R] t -> int -> string array
313     (** [list_networks conn max]
314         returns the names of the networks, up to a maximum
315         of [max] entries.
316         Call {!num_of_networks} first to get a value for [max].
317     *)
318   val num_of_defined_networks : [>`R] t -> int
319     (** Returns the number of inactive networks. *)
320   val list_defined_networks : [>`R] t -> int -> string array
321     (** [list_defined_networks conn max]
322         returns the names of the inactive networks, up to a maximum
323         of [max] entries.
324         Call {!num_of_defined_networks} first to get a value for [max].
325     *)
326
327   val num_of_pools : [>`R] t -> int
328     (** Returns the number of storage pools. *)
329   val list_pools : [>`R] t -> int -> string array
330     (** Return list of storage pools. *)
331   val num_of_defined_pools : [>`R] t -> int
332     (** Returns the number of storage pools. *)
333   val list_defined_pools : [>`R] t -> int -> string array
334     (** Return list of storage pools. *)
335
336     (* The name of this function is inconsistent, but the inconsistency
337      * is really in libvirt itself.
338      *)
339   val get_node_info : [>`R] t -> node_info
340     (** Return information about the physical server. *)
341
342   val node_get_free_memory : [> `R] t -> int64
343     (**
344        [node_get_free_memory conn]
345        returns the amount of free memory (not allocated to any guest)
346        in the machine.
347     *)
348
349   val node_get_cells_free_memory : [> `R] t -> int -> int -> int64 array
350     (**
351        [node_get_cells_free_memory conn start max]
352        returns the amount of free memory on each NUMA cell in kilobytes.
353        [start] is the first cell for which we return free memory.
354        [max] is the maximum number of cells for which we return free memory.
355        Returns an array of up to [max] entries in length.
356     *)
357
358   val maxcpus_of_node_info : node_info -> int
359     (** Calculate the total number of CPUs supported (but not necessarily
360         active) in the host.
361     *)
362
363   val cpumaplen : int -> int
364     (** Calculate the length (in bytes) required to store the complete
365         CPU map between a single virtual and all physical CPUs of a domain.
366     *)
367
368   val use_cpu : string -> int -> unit
369     (** [use_cpu cpumap cpu] marks [cpu] as usable in [cpumap]. *)
370   val unuse_cpu : string -> int -> unit
371     (** [unuse_cpu cpumap cpu] marks [cpu] as not usable in [cpumap]. *)
372   val cpu_usable : string -> int -> int -> int -> bool
373     (** [cpu_usable cpumaps maplen vcpu cpu] checks returns true iff the
374         [cpu] is usable by [vcpu]. *)
375
376   external const : [>`R] t -> ro t = "%identity"
377     (** [const conn] turns a read/write connection into a read-only
378         connection.  Note that the opposite operation is impossible.
379       *)
380 end
381   (** Module dealing with connections.  [Connect.t] is the
382       connection object. *)
383
384 (** {3 Domains} *)
385
386 module Domain :
387 sig
388   type 'rw t
389     (** Domain handle.  Read-only handles have type [ro Domain.t] and
390         read-write handles have type [rw Domain.t].
391     *)
392
393   type state =
394     | InfoNoState | InfoRunning | InfoBlocked | InfoPaused
395     | InfoShutdown | InfoShutoff | InfoCrashed
396
397   type info = {
398     state : state;                      (** running state *)
399     max_mem : int64;                    (** maximum memory in kilobytes *)
400     memory : int64;                     (** memory used in kilobytes *)
401     nr_virt_cpu : int;                  (** number of virtual CPUs *)
402     cpu_time : int64;                   (** CPU time used in nanoseconds *)
403   }
404
405   type vcpu_state = VcpuOffline | VcpuRunning | VcpuBlocked
406
407   type vcpu_info = {
408     number : int;                       (** virtual CPU number *)
409     vcpu_state : vcpu_state;            (** state *)
410     vcpu_time : int64;                  (** CPU time used in nanoseconds *)
411     cpu : int;                          (** real CPU number, -1 if offline *)
412   }
413
414   type sched_param = string * sched_param_value
415   and sched_param_value =
416     | SchedFieldInt32 of int32 | SchedFieldUInt32 of int32
417     | SchedFieldInt64 of int64 | SchedFieldUInt64 of int64
418     | SchedFieldFloat of float | SchedFieldBool of bool
419
420   type migrate_flag = Live
421
422   type memory_flag = Virtual
423
424   type block_stats = {
425     rd_req : int64;
426     rd_bytes : int64;
427     wr_req : int64;
428     wr_bytes : int64;
429     errs : int64;
430   }
431
432   type interface_stats = {
433     rx_bytes : int64;
434     rx_packets : int64;
435     rx_errs : int64;
436     rx_drop : int64;
437     tx_bytes : int64;
438     tx_packets : int64;
439     tx_errs : int64;
440     tx_drop : int64;
441   }
442
443   val create_linux : [>`W] Connect.t -> xml -> rw t
444     (** Create a new guest domain (not necessarily a Linux one)
445         from the given XML.
446     *)
447   val create_linux_job : [>`W] Connect.t -> xml -> ([`Domain], rw) job_t
448     (** Asynchronous domain creation. *)
449   val lookup_by_id : 'a Connect.t -> int -> 'a t
450     (** Lookup a domain by ID. *)
451   val lookup_by_uuid : 'a Connect.t -> uuid -> 'a t
452     (** Lookup a domain by UUID.  This uses the packed byte array UUID. *)
453   val lookup_by_uuid_string : 'a Connect.t -> string -> 'a t
454     (** Lookup a domain by (string) UUID. *)
455   val lookup_by_name : 'a Connect.t -> string -> 'a t
456     (** Lookup a domain by name. *)
457   val destroy : [>`W] t -> unit
458     (** Abruptly destroy a domain. *)
459   val free : [>`R] t -> unit
460     (** [free domain] frees the domain object in memory.
461
462         The domain object is automatically freed if it is garbage
463         collected.  This function just forces it to be freed right
464         away.
465     *)
466
467   val suspend : [>`W] t -> unit
468     (** Suspend a domain. *)
469   val resume : [>`W] t -> unit
470     (** Resume a domain. *)
471   val save : [>`W] t -> filename -> unit
472     (** Suspend a domain, then save it to the file. *)
473   val save_job : [>`W] t -> filename -> ([`Domain_nocreate], rw) job_t
474     (** Asynchronous domain suspend. *)
475   val restore : [>`W] Connect.t -> filename -> unit
476     (** Restore a domain from a file. *)
477   val restore_job : [>`W] Connect.t -> filename -> ([`Domain_nocreate], rw) job_t
478     (** Asynchronous domain restore. *)
479   val core_dump : [>`W] t -> filename -> unit
480     (** Force a domain to core dump to the named file. *)
481   val core_dump_job : [>`W] t -> filename -> ([`Domain_nocreate], rw) job_t
482     (** Asynchronous core dump. *)
483   val shutdown : [>`W] t -> unit
484     (** Shutdown a domain. *)
485   val reboot : [>`W] t -> unit
486     (** Reboot a domain. *)
487   val get_name : [>`R] t -> string
488     (** Get the domain name. *)
489   val get_uuid : [>`R] t -> uuid
490     (** Get the domain UUID (as a packed byte array). *)
491   val get_uuid_string : [>`R] t -> string
492     (** Get the domain UUID (as a printable string). *)
493   val get_id : [>`R] t -> int
494     (** [getid dom] returns the ID of the domain.
495
496         Do not call this on a defined but not running domain.  Those
497         domains don't have IDs, and you'll get an error here.
498     *)
499
500   val get_os_type : [>`R] t -> string
501     (** Get the operating system type. *)
502   val get_max_memory : [>`R] t -> int64
503     (** Get the maximum memory allocation. *)
504   val set_max_memory : [>`W] t -> int64 -> unit
505     (** Set the maximum memory allocation. *)
506   val set_memory : [>`W] t -> int64 -> unit
507     (** Set the normal memory allocation. *)
508   val get_info : [>`R] t -> info
509     (** Get information about a domain. *)
510   val get_xml_desc : [>`R] t -> xml
511     (** Get the XML description of a domain. *)
512   val get_scheduler_type : [>`R] t -> string * int
513     (** Get the scheduler type. *)
514   val get_scheduler_parameters : [>`R] t -> int -> sched_param array
515     (** Get the array of scheduler parameters. *)
516   val set_scheduler_parameters : [>`W] t -> sched_param array -> unit
517     (** Set the array of scheduler parameters. *)
518   val define_xml : [>`W] Connect.t -> xml -> rw t
519     (** Define a new domain (but don't start it up) from the XML. *)
520   val undefine : [>`W] t -> unit
521     (** Undefine a domain - removes its configuration. *)
522   val create : [>`W] t -> unit
523     (** Launch a defined (inactive) domain. *)
524   val create_job : [>`W] t -> ([`Domain_nocreate], rw) job_t
525     (** Asynchronous launch domain. *)
526   val get_autostart : [>`R] t -> bool
527     (** Get the autostart flag for a domain. *)
528   val set_autostart : [>`W] t -> bool -> unit
529     (** Set the autostart flag for a domain. *)
530   val set_vcpus : [>`W] t -> int -> unit
531     (** Change the number of vCPUs available to a domain. *)
532   val pin_vcpu : [>`W] t -> int -> string -> unit
533     (** [pin_vcpu dom vcpu bitmap] pins a domain vCPU to a bitmap of physical
534         CPUs.  See the libvirt documentation for details of the
535         layout of the bitmap. *)
536   val get_vcpus : [>`R] t -> int -> int -> int * vcpu_info array * string
537     (** [get_vcpus dom maxinfo maplen] returns the pinning information
538         for a domain.  See the libvirt documentation for details
539         of the array and bitmap returned from this function.
540     *)
541   val get_max_vcpus : [>`R] t -> int
542     (** Returns the maximum number of vCPUs supported for this domain. *)
543   val attach_device : [>`W] t -> xml -> unit
544     (** Attach a device (described by the device XML) to a domain. *)
545   val detach_device : [>`W] t -> xml -> unit
546     (** Detach a device (described by the device XML) from a domain. *)
547
548   val migrate : [>`W] t -> [>`W] Connect.t -> migrate_flag list ->
549     ?dname:string -> ?uri:string -> ?bandwidth:int -> unit -> rw t
550     (** [migrate dom dconn flags ()] migrates a domain to a
551         destination host described by [dconn].
552
553         The optional flag [?dname] is used to rename the domain.
554
555         The optional flag [?uri] is used to route the migration.
556
557         The optional flag [?bandwidth] is used to limit the bandwidth
558         used for migration (in Mbps). *)
559
560   val block_stats : [>`R] t -> string -> block_stats
561     (** Returns block device stats. *)
562   val interface_stats : [>`R] t -> string -> interface_stats
563     (** Returns network interface stats. *)
564
565   val block_peek : [>`R] t -> string -> int64 -> int -> string -> int -> unit
566     (** [block_peek dom path offset size buf boff] reads [size] bytes at
567         [offset] in the domain's [path] block device.
568
569         If successful then the data is written into [buf] starting
570         at offset [boff], for [size] bytes. *)
571   val memory_peek : [>`R] t -> memory_flag list -> int64 -> int ->
572     string -> int -> unit
573     (** [memory_peek dom Virtual offset size] reads [size] bytes
574         at [offset] in the domain's virtual memory.
575
576         If successful then the data is written into [buf] starting
577         at offset [boff], for [size] bytes. *)
578
579   external const : [>`R] t -> ro t = "%identity"
580     (** [const dom] turns a read/write domain handle into a read-only
581         domain handle.  Note that the opposite operation is impossible.
582       *)
583 end
584   (** Module dealing with domains.  [Domain.t] is the
585       domain object. *)
586
587 (** {3 Networks} *)
588
589 module Network : 
590 sig
591   type 'rw t
592     (** Network handle.  Read-only handles have type [ro Network.t] and
593         read-write handles have type [rw Network.t].
594     *)
595
596   val lookup_by_name : 'a Connect.t -> string -> 'a t
597     (** Lookup a network by name. *)
598   val lookup_by_uuid : 'a Connect.t -> uuid -> 'a t
599     (** Lookup a network by (packed) UUID. *)
600   val lookup_by_uuid_string : 'a Connect.t -> string -> 'a t
601     (** Lookup a network by UUID string. *)
602   val create_xml : [>`W] Connect.t -> xml -> rw t
603     (** Create a network. *)
604   val create_xml_job : [>`W] Connect.t -> xml -> ([`Network], rw) job_t
605     (** Asynchronous create network. *)
606   val define_xml : [>`W] Connect.t -> xml -> rw t
607     (** Define but don't activate a network. *)
608   val undefine : [>`W] t -> unit
609     (** Undefine configuration of a network. *)
610   val create : [>`W] t -> unit
611     (** Start up a defined (inactive) network. *)
612   val create_job : [>`W] t -> ([`Network_nocreate], rw) job_t
613     (** Asynchronous start network. *)
614   val destroy : [>`W] t -> unit
615     (** Destroy a network. *)
616   val free : [>`R] t -> unit
617     (** [free network] frees the network object in memory.
618
619         The network object is automatically freed if it is garbage
620         collected.  This function just forces it to be freed right
621         away.
622     *)
623
624   val get_name : [>`R] t -> string
625     (** Get network name. *)
626   val get_uuid : [>`R] t -> uuid
627     (** Get network packed UUID. *)
628   val get_uuid_string : [>`R] t -> string
629     (** Get network UUID as a printable string. *)
630   val get_xml_desc : [>`R] t -> xml
631     (** Get XML description of a network. *)
632   val get_bridge_name : [>`R] t -> string
633     (** Get bridge device name of a network. *)
634   val get_autostart : [>`R] t -> bool
635     (** Get the autostart flag for a network. *)
636   val set_autostart : [>`W] t -> bool -> unit
637     (** Set the autostart flag for a network. *)
638
639   external const : [>`R] t -> ro t = "%identity"
640     (** [const network] turns a read/write network handle into a read-only
641         network handle.  Note that the opposite operation is impossible.
642       *)
643 end
644   (** Module dealing with networks.  [Network.t] is the
645       network object. *)
646
647 (** {3 Storage pools} *)
648
649 module Pool :
650 sig
651   type 'rw t
652     (** Storage pool handle. *)
653
654   type pool_state = Inactive | Building | Running | Degraded
655     (** State of the storage pool. *)
656
657   type pool_build_flags = New | Repair | Resize
658     (** Flags for creating a storage pool. *)
659
660   type pool_delete_flags = Normal | Zeroed
661     (** Flags for deleting a storage pool. *)
662
663   type pool_info = {
664     state : pool_state;                 (** Pool state. *)
665     capacity : int64;                   (** Logical size in bytes. *)
666     allocation : int64;                 (** Currently allocated in bytes. *)
667     available : int64;                  (** Remaining free space bytes. *)
668   }
669
670   val lookup_by_name : 'a Connect.t -> string -> 'a t
671   val lookup_by_uuid : 'a Connect.t -> uuid -> 'a t
672   val lookup_by_uuid_string : 'a Connect.t -> string -> 'a t
673     (** Look up a storage pool by name, UUID or UUID string. *)
674
675   val create_xml : [>`W] Connect.t -> xml -> rw t
676     (** Create a storage pool. *)
677   val define_xml : [>`W] Connect.t -> xml -> rw t
678     (** Define but don't activate a storage pool. *)
679   val build : [>`W] t -> pool_build_flags -> unit
680     (** Build a storage pool. *)
681   val undefine : [>`W] t -> unit
682     (** Undefine configuration of a storage pool. *)
683   val create : [>`W] t -> unit
684     (** Start up a defined (inactive) storage pool. *)
685   val destroy : [>`W] t -> unit
686     (** Destroy a storage pool. *)
687   val delete : [>`W] t -> unit
688     (** Delete a storage pool. *)
689   val free : [>`R] t -> unit
690     (** Free a storage pool object in memory.
691
692         The storage pool object is automatically freed if it is garbage
693         collected.  This function just forces it to be freed right
694         away.
695     *)
696   val refresh : [`R] t -> unit
697     (** Refresh the list of volumes in the storage pool. *)
698
699   val get_name : [`R] t -> string
700     (** Name of the pool. *)
701   val get_uuid : [`R] t -> uuid
702     (** Get the UUID (as a packed byte array). *)
703   val get_uuid_string : [`R] t -> string
704     (** Get the UUID (as a printable string). *)
705   val get_info : [`R] t -> pool_info
706     (** Get information about the pool. *)
707   val get_xml_desc : [`R] t -> xml
708     (** Get the XML description. *)
709   val get_autostart : [`R] t -> bool
710     (** Get the autostart flag for the storage pool. *)
711   val set_autostart : [`W] t -> bool -> unit
712     (** Set the autostart flag for the storage pool. *)
713
714   val num_of_volumes : [`R] t -> int
715     (** Returns the number of storage volumes within the storage pool. *)
716   val list_volumes : [`R] t -> int -> string array
717     (** Return list of storage volumes. *)
718
719   external const : [>`R] t -> ro t = "%identity"
720     (** [const conn] turns a read/write storage pool into a read-only
721         pool.  Note that the opposite operation is impossible.
722       *)
723 end
724   (** Module dealing with storage pools. *)
725
726 (** {3 Storage volumes} *)
727
728 module Volume :
729 sig
730   type 'rw t
731     (** Storage volume handle. *)
732
733   type vol_type = File | Block
734     (** Type of a storage volume. *)
735
736   type vol_delete_flags = Normal | Zeroed
737     (** Flags for deleting a storage volume. *)
738
739   type vol_info = {
740     typ : vol_type;                     (** Type of storage volume. *)
741     capacity : int64;                   (** Logical size in bytes. *)
742     allocation : int64;                 (** Currently allocated in bytes. *)
743   }
744
745   val lookup_by_name : 'a Pool.t -> string -> 'a t
746   val lookup_by_key : 'a Connect.t -> string -> 'a t
747   val lookup_by_path : 'a Connect.t -> string -> 'a t
748     (** Look up a storage volume by name, key or path volume. *)
749
750   val pool_of_volume : 'a t -> 'a Pool.t
751     (** Get the storage pool containing this volume. *)
752
753   val get_name : [`R] t -> string
754     (** Name of the volume. *)
755   val get_key : [`R] t -> string
756     (** Key of the volume. *)
757   val get_path : [`R] t -> string
758     (** Path of the volume. *)
759   val get_info : [`R] t -> vol_info
760     (** Get information about the storage volume. *)
761   val get_xml_desc : [`R] t -> xml
762     (** Get the XML description. *)
763
764   val create_xml : [`W] Pool.t -> xml -> unit
765     (** Create a storage volume. *)
766   val delete : [`W] t -> unit
767     (** Delete a storage volume. *)
768   val free : [>`R] t -> unit
769     (** Free a storage volume object in memory.
770
771         The storage volume object is automatically freed if it is garbage
772         collected.  This function just forces it to be freed right
773         away.
774     *)
775
776   external const : [>`R] t -> ro t = "%identity"
777     (** [const conn] turns a read/write storage volume into a read-only
778         volume.  Note that the opposite operation is impossible.
779       *)
780 end
781   (** Module dealing with storage volumes. *)
782
783 (** {3 Jobs and asynchronous processing} *)
784
785 module Job :
786 sig
787   type ('jobclass, 'rw) t = ('jobclass, 'rw) job_t
788     (** A background asynchronous job.
789
790         Jobs represent a pending operation such as domain creation.
791         The possible types for a job are:
792
793 {v
794 (`Domain, `W) Job.t            Job creating a new domain
795 (`Domain_nocreate, `W) Job.t   Job acting on an existing domain
796 (`Network, `W) Job.t           Job creating a new network
797 (`Network_nocreate, `W) Job.t  Job acting on an existing network
798 v}
799       *)
800
801   type job_type = Bounded | Unbounded
802     (** A Bounded job is one where we can estimate time to completion. *)
803
804   type job_state = Running | Complete | Failed | Cancelled
805     (** State of the job. *)
806
807   type job_info = {
808     typ : job_type;                     (** Job type (Bounded, Unbounded) *)
809     state : job_state;                  (** Job state (Running, etc.) *)
810     running_time : int;                 (** Actual running time (seconds) *)
811     (** The following fields are only available in Bounded jobs: *)
812     remaining_time : int;               (** Estimated time left (seconds) *)
813     percent_complete : int              (** Estimated percent complete *)
814   }
815
816   val get_info : ('a,'b) t -> job_info
817     (** Get information and status about the job. *)
818
819   val get_domain : ([`Domain], 'a) t -> 'a Domain.t
820     (** Get the completed domain from a job.
821
822         You should only call it on a job in state Complete. *)
823
824   val get_network : ([`Network], 'a) t -> 'a Network.t
825     (** Get the completed network from a job.
826
827         You should only call it on a job in state Complete. *)
828
829   val cancel : ('a,'b) t -> unit
830     (** Cancel a job. *)
831
832   val free : ('a, [>`R]) t -> unit
833     (** Free a job object in memory.
834
835         The job object is automatically freed if it is garbage
836         collected.  This function just forces it to be freed right
837         away.
838     *)
839
840   external const : ('a, [>`R]) t -> ('a, ro) t = "%identity"
841     (** [const conn] turns a read/write job into a read-only
842         job.  Note that the opposite operation is impossible.
843       *)
844 end
845   (** Module dealing with asynchronous jobs. *)
846
847 (** {3 Error handling and exceptions} *)
848
849 module Virterror :
850 sig
851   type code =
852     | VIR_ERR_OK
853     | VIR_ERR_INTERNAL_ERROR
854     | VIR_ERR_NO_MEMORY
855     | VIR_ERR_NO_SUPPORT
856     | VIR_ERR_UNKNOWN_HOST
857     | VIR_ERR_NO_CONNECT
858     | VIR_ERR_INVALID_CONN
859     | VIR_ERR_INVALID_DOMAIN
860     | VIR_ERR_INVALID_ARG
861     | VIR_ERR_OPERATION_FAILED
862     | VIR_ERR_GET_FAILED
863     | VIR_ERR_POST_FAILED
864     | VIR_ERR_HTTP_ERROR
865     | VIR_ERR_SEXPR_SERIAL
866     | VIR_ERR_NO_XEN
867     | VIR_ERR_XEN_CALL
868     | VIR_ERR_OS_TYPE
869     | VIR_ERR_NO_KERNEL
870     | VIR_ERR_NO_ROOT
871     | VIR_ERR_NO_SOURCE
872     | VIR_ERR_NO_TARGET
873     | VIR_ERR_NO_NAME
874     | VIR_ERR_NO_OS
875     | VIR_ERR_NO_DEVICE
876     | VIR_ERR_NO_XENSTORE
877     | VIR_ERR_DRIVER_FULL
878     | VIR_ERR_CALL_FAILED
879     | VIR_ERR_XML_ERROR
880     | VIR_ERR_DOM_EXIST
881     | VIR_ERR_OPERATION_DENIED
882     | VIR_ERR_OPEN_FAILED
883     | VIR_ERR_READ_FAILED
884     | VIR_ERR_PARSE_FAILED
885     | VIR_ERR_CONF_SYNTAX
886     | VIR_ERR_WRITE_FAILED
887     | VIR_ERR_XML_DETAIL
888     | VIR_ERR_INVALID_NETWORK
889     | VIR_ERR_NETWORK_EXIST
890     | VIR_ERR_SYSTEM_ERROR
891     | VIR_ERR_RPC
892     | VIR_ERR_GNUTLS_ERROR
893     | VIR_WAR_NO_NETWORK
894     | VIR_ERR_NO_DOMAIN
895     | VIR_ERR_NO_NETWORK
896     | VIR_ERR_INVALID_MAC
897     | VIR_ERR_AUTH_FAILED
898     | VIR_ERR_INVALID_STORAGE_POOL
899     | VIR_ERR_INVALID_STORAGE_VOL
900     | VIR_WAR_NO_STORAGE
901     | VIR_ERR_NO_STORAGE_POOL
902     | VIR_ERR_NO_STORAGE_VOL
903         (* ^^ NB: If you add a variant you MUST edit
904            libvirt_c_epilogue.c:MAX_VIR_* *)
905     | VIR_ERR_UNKNOWN of int
906         (** See [<libvirt/virterror.h>] for meaning of these codes. *)
907
908   val string_of_code : code -> string
909
910   type domain =
911     | VIR_FROM_NONE
912     | VIR_FROM_XEN
913     | VIR_FROM_XEND
914     | VIR_FROM_XENSTORE
915     | VIR_FROM_SEXPR
916     | VIR_FROM_XML
917     | VIR_FROM_DOM
918     | VIR_FROM_RPC
919     | VIR_FROM_PROXY
920     | VIR_FROM_CONF
921     | VIR_FROM_QEMU
922     | VIR_FROM_NET
923     | VIR_FROM_TEST
924     | VIR_FROM_REMOTE
925     | VIR_FROM_OPENVZ
926     | VIR_FROM_XENXM
927     | VIR_FROM_STATS_LINUX
928     | VIR_FROM_STORAGE
929         (* ^^ NB: If you add a variant you MUST edit
930            libvirt_c_epilogue.c: MAX_VIR_* *)
931     | VIR_FROM_UNKNOWN of int
932         (** Subsystem / driver which produced the error. *)
933
934   val string_of_domain : domain -> string
935
936   type level =
937     | VIR_ERR_NONE
938     | VIR_ERR_WARNING
939     | VIR_ERR_ERROR
940         (* ^^ NB: If you add a variant you MUST edit libvirt_c.c: MAX_VIR_* *)
941     | VIR_ERR_UNKNOWN_LEVEL of int
942         (** No error, a warning or an error. *)
943
944   val string_of_level : level -> string
945
946   type t = {
947     code : code;                        (** Error code. *)
948     domain : domain;                    (** Origin of the error. *)
949     message : string option;            (** Human-readable message. *)
950     level : level;                      (** Error or warning. *)
951     str1 : string option;               (** Informational string. *)
952     str2 : string option;               (** Informational string. *)
953     str3 : string option;               (** Informational string. *)
954     int1 : int32;                       (** Informational integer. *)
955     int2 : int32;                       (** Informational integer. *)
956   }
957     (** An error object. *)
958
959   val to_string : t -> string
960     (** Turn the exception into a printable string. *)
961
962   val get_last_error : unit -> t option
963   val get_last_conn_error : [>`R] Connect.t -> t option
964     (** Get the last error at a global or connection level.
965
966         Normally you do not need to use these functions because
967         the library automatically turns errors into exceptions.
968     *)
969
970   val reset_last_error : unit -> unit
971   val reset_last_conn_error : [>`R] Connect.t -> unit
972     (** Reset the error at a global or connection level.
973
974         Normally you do not need to use these functions.
975     *)
976
977   val no_error : unit -> t
978     (** Creates an empty error message.
979
980         Normally you do not need to use this function.
981     *)
982 end
983   (** Module dealing with errors. *)
984
985 exception Virterror of Virterror.t
986 (** This exception can be raised by any library function that detects
987     an error.  To get a printable error message, call
988     {!Virterror.to_string} on the content of this exception.
989 *)
990
991 exception Not_supported of string
992 (**
993     Functions may raise
994     [Not_supported "virFoo"]
995     (where [virFoo] is the libvirt function name) if a function is
996     not supported at either compile or run time.  This applies to
997     any libvirt function added after version 0.2.1.
998
999     See also {{:http://libvirt.org/hvsupport.html}http://libvirt.org/hvsupport.html}
1000 *)
1001