cc7a962a79f5ebee1527f01d21f8324766d50cc5
[ocaml-libvirt.git] / libvirt / libvirt.mli
1 (** OCaml bindings for libvirt. *)
2 (* (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
3    https://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 {{:https://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    {{:https://libvirt.org/html/libvirt-libvirt-host.html}virConnect*},
62    {{:https://libvirt.org/html/libvirt-libvirt-domain.html}virDomain*}, and
63    {{:https://libvirt.org/html/libvirt-libvirt-network.html}virNetwork*}
64    functions from libvirt.
65    For brevity I usually rename these modules like this:
66
67 {[
68 module C = Libvirt.Connect
69 module D = Libvirt.Domain
70 module N = Libvirt.Network
71 ]}
72
73    To get a connection handle, assuming a Xen hypervisor:
74
75 {[
76 let name = "xen:///"
77 let conn = C.connect_readonly ~name ()
78 ]}
79
80    {3 Example: List running domains}
81
82 {[
83 open Printf
84
85 let domains = D.get_domains conn [D.ListActive] in
86 List.iter (
87   fun dom ->
88     printf "%8d %s\n%!" (D.get_id dom) (D.get_name dom)
89 ) domains;
90 ]}
91
92    {3 Example: List inactive domains}
93
94 {[
95 let domains = D.get_domains conn [D.ListInactive] in
96 List.iter (
97   fun dom ->
98     printf "inactive %s\n%!" (D.get_name dom)
99 ) domains;
100 ]}
101
102    {3 Example: Print node info}
103
104 {[
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 ]}
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 raise odd exceptions at any time.
144     This is just the nature of virtualisation.
145
146     {3 Backwards and forwards compatibility}
147
148     OCaml-libvirt requires libvirt version 1.0.2 or later. Future
149     releases of OCaml-libvirt will use newer features of libvirt
150     and therefore will require later versions of libvirt. It is always
151     possible to dynamically link your application against a newer
152     libvirt than OCaml-libvirt was originally compiled against.
153
154     {3 Get list of domains and domain infos}
155
156     This is a very common operation, and libvirt supports various
157     different methods to do it.  We have hidden the complexity in a
158     flexible {!Libvirt.Domain.get_domains} and
159     {!Libvirt.Domain.get_domains_and_infos} calls which is easy to use and
160     automatically chooses the most efficient method depending on the
161     version of libvirt in use.
162
163     {3 Threads}
164
165     You can issue multiple concurrent libvirt requests in
166     different threads.  However you must follow this rule:
167     Each thread must have its own separate libvirt connection, {i or}
168     you must implement your own mutex scheme to ensure that no
169     two threads can ever make concurrent calls using the same
170     libvirt connection.
171
172     (Note that multithreaded code is not well tested.  If you find
173     bugs please report them.)
174
175     {3 Initialisation}
176
177     Libvirt requires all callers to call virInitialize before
178     using the library.  This is done automatically for you by
179     these bindings when the program starts up, and we believe
180     that the way this is done is safe.
181
182     {2 Reference}
183 *)
184
185 type uuid = string
186     (** This is a "raw" UUID, ie. a packed string of bytes. *)
187
188 type xml = string
189     (** Type of XML (an uninterpreted string of bytes).  Use PXP, expat,
190         xml-light, etc. if you want to do anything useful with the XML.
191     *)
192
193 type filename = string
194     (** A filename. *)
195
196 val get_version : ?driver:string -> unit -> int * int
197   (** [get_version ()] returns the library version in the first part
198       of the tuple, and [0] in the second part.
199
200       [get_version ~driver ()] returns the library version in the first
201       part of the tuple, and the version of the driver called [driver]
202       in the second part.
203
204       The version numbers are encoded as
205       1,000,000 * major + 1,000 * minor + release.
206   *)
207
208 val uuid_length : int
209   (** Length of packed UUIDs. *)
210
211 val uuid_string_length : int
212   (** Length of UUID strings. *)
213
214 type rw = [`R|`W]
215 type ro = [`R]
216     (** These
217         {{:https://caml.inria.fr/pub/ml-archives/caml-list/2004/07/80683af867cce6bf8fff273973f70c95.en.html}phantom types}
218         are used to ensure the type-safety of read-only
219         versus read-write connections.
220
221         All connection/domain/etc. objects are marked with
222         a phantom read-write or read-only type, and trying to
223         pass a read-only object into a function which could
224         mutate the object will cause a compile time error.
225
226         Each module provides a function like {!Libvirt.Connect.const}
227         to demote a read-write object into a read-only object.  The
228         opposite operation is, of course, not allowed.
229
230         If you want to handle both read-write and read-only
231         connections at runtime, use a variant similar to this:
232 {[
233 type conn_t =
234     | No_connection
235     | Read_only of Libvirt.ro Libvirt.Connect.t
236     | Read_write of Libvirt.rw Libvirt.Connect.t
237 ]}
238     *)
239
240 (** {3 Forward definitions}
241
242     These definitions are placed here to avoid the need to
243     use recursive module dependencies.
244 *)
245
246 (** {3 Connections} *)
247
248 module Connect :
249 sig
250   type 'rw t
251     (** Connection.  Read-only connections have type [ro Connect.t] and
252         read-write connections have type [rw Connect.t].
253       *)
254
255   type node_info = {
256     model : string;                     (** CPU model *)
257     memory : int64;                     (** memory size in kilobytes *)
258     cpus : int;                         (** number of active CPUs *)
259     mhz : int;                          (** expected CPU frequency *)
260     nodes : int;                        (** number of NUMA nodes (1 = UMA) *)
261     sockets : int;                      (** number of CPU sockets per node *)
262     cores : int;                        (** number of cores per socket *)
263     threads : int;                      (** number of threads per core *)
264   }
265
266   type credential_type =
267     | CredentialUsername                (** Identity to act as *)
268     | CredentialAuthname                (** Identify to authorize as *)
269     | CredentialLanguage                (** RFC 1766 languages, comma separated *)
270     | CredentialCnonce                  (** client supplies a nonce *)
271     | CredentialPassphrase              (** Passphrase secret *)
272     | CredentialEchoprompt              (** Challenge response *)
273     | CredentialNoechoprompt            (** Challenge response *)
274     | CredentialRealm                   (** Authentication realm *)
275     | CredentialExternal                (** Externally managed credential *)
276
277   type credential = {
278     typ : credential_type;              (** The type of credential *)
279     prompt : string;                    (** Prompt to show to user *)
280     challenge : string option;          (** Additional challenge to show *)
281     defresult : string option;          (** Optional default result *)
282   }
283
284   type auth = {
285     credtype : credential_type list;    (** List of supported credential_type values *)
286     cb : (credential list -> string option list);
287     (** Callback used to collect credentials.
288
289         The input is a list of all the requested credentials.
290
291         The function returns a list of all the results from the
292         requested credentials, so the number of results {e must} match
293         the number of input credentials.  Each result is optional,
294         and in case it is [None] it means there was no result.
295      *)
296   }
297
298   val connect : ?name:string -> unit -> rw t
299   val connect_readonly : ?name:string -> unit -> ro t
300     (** [connect ~name ()] connects to the hypervisor with URI [name].
301
302         [connect ()] connects to the default hypervisor.
303
304         [connect_readonly] is the same but connects in read-only mode.
305     *)
306
307   val connect_auth : ?name:string -> auth -> rw t
308   val connect_auth_readonly : ?name:string -> auth -> ro t
309
310   val close : [>`R] t -> unit
311     (** [close conn] closes and frees the connection object in memory.
312
313         The connection is automatically closed if it is garbage
314         collected.  This function just forces it to be closed
315         and freed right away.
316     *)
317
318   val get_type : [>`R] t -> string
319     (** Returns the name of the driver (hypervisor). *)
320
321   val get_version : [>`R] t -> int
322     (** Returns the driver version
323         [major * 1_000_000 + minor * 1000 + release]
324     *)
325   val get_hostname : [>`R] t -> string
326     (** Returns the hostname of the physical server. *)
327   val get_uri : [>`R] t -> string
328     (** Returns the canonical connection URI. *)
329   val get_max_vcpus : [>`R] t -> ?type_:string -> unit -> int
330     (** Returns the maximum number of virtual CPUs
331         supported by a guest VM of a particular type. *)
332   val list_domains : [>`R] t -> int -> int array
333     (** [list_domains conn max] returns the running domain IDs,
334         up to a maximum of [max] entries.
335
336         Call {!num_of_domains} first to get a value for [max].
337
338         See also:
339         {!Libvirt.Domain.get_domains},
340         {!Libvirt.Domain.get_domains_and_infos}.
341     *)
342   val num_of_domains : [>`R] t -> int
343     (** Returns the number of running domains. *)
344   val get_capabilities : [>`R] t -> xml
345     (** Returns the hypervisor capabilities (as XML). *)
346   val num_of_defined_domains : [>`R] t -> int
347     (** Returns the number of inactive (shutdown) domains. *)
348   val list_defined_domains : [>`R] t -> int -> string array
349     (** [list_defined_domains conn max]
350         returns the names of the inactive domains, up to
351         a maximum of [max] entries.
352
353         Call {!num_of_defined_domains} first to get a value for [max].
354
355         See also:
356         {!Libvirt.Domain.get_domains},
357         {!Libvirt.Domain.get_domains_and_infos}.
358     *)
359   val num_of_networks : [>`R] t -> int
360     (** Returns the number of networks. *)
361   val list_networks : [>`R] t -> int -> string array
362     (** [list_networks conn max]
363         returns the names of the networks, up to a maximum
364         of [max] entries.
365         Call {!num_of_networks} first to get a value for [max].
366     *)
367   val num_of_defined_networks : [>`R] t -> int
368     (** Returns the number of inactive networks. *)
369   val list_defined_networks : [>`R] t -> int -> string array
370     (** [list_defined_networks conn max]
371         returns the names of the inactive networks, up to a maximum
372         of [max] entries.
373         Call {!num_of_defined_networks} first to get a value for [max].
374     *)
375
376   val num_of_pools : [>`R] t -> int
377     (** Returns the number of storage pools. *)
378   val list_pools : [>`R] t -> int -> string array
379     (** Return list of storage pools. *)
380   val num_of_defined_pools : [>`R] t -> int
381     (** Returns the number of storage pools. *)
382   val list_defined_pools : [>`R] t -> int -> string array
383     (** Return list of storage pools. *)
384
385     (* The name of this function is inconsistent, but the inconsistency
386      * is really in libvirt itself.
387      *)
388   val num_of_secrets : [>`R] t -> int
389     (** Returns the number of secrets. *)
390   val list_secrets : [>`R] t -> int -> string array
391     (** Returns the list of secrets. *)
392   val get_node_info : [>`R] t -> node_info
393     (** Return information about the physical server. *)
394
395   val node_get_free_memory : [> `R] t -> int64
396     (**
397        [node_get_free_memory conn]
398        returns the amount of free memory (not allocated to any guest)
399        in the machine.
400     *)
401
402   val node_get_cells_free_memory : [> `R] t -> int -> int -> int64 array
403     (**
404        [node_get_cells_free_memory conn start max]
405        returns the amount of free memory on each NUMA cell in kilobytes.
406        [start] is the first cell for which we return free memory.
407        [max] is the maximum number of cells for which we return free memory.
408        Returns an array of up to [max] entries in length.
409     *)
410
411   val maxcpus_of_node_info : node_info -> int
412     (** Calculate the total number of CPUs supported (but not necessarily
413         active) in the host.
414     *)
415
416   val cpumaplen : int -> int
417     (** Calculate the length (in bytes) required to store the complete
418         CPU map between a single virtual and all physical CPUs of a domain.
419     *)
420
421   val use_cpu : bytes -> int -> unit
422     (** [use_cpu cpumap cpu] marks [cpu] as usable in [cpumap]. *)
423   val unuse_cpu : bytes -> int -> unit
424     (** [unuse_cpu cpumap cpu] marks [cpu] as not usable in [cpumap]. *)
425   val cpu_usable : bytes -> int -> int -> int -> bool
426     (** [cpu_usable cpumaps maplen vcpu cpu] checks returns true iff the
427         [cpu] is usable by [vcpu]. *)
428
429   val set_keep_alive : [>`R] t -> int -> int -> unit
430     (** [set_keep_alive conn interval count] starts sending keepalive
431         messages after [interval] seconds of inactivity and consider the
432         connection to be broken when no response is received after [count]
433         keepalive messages.
434         Note: the client has to implement and run an event loop to
435         be able to use keep-alive messages. *)
436
437   val get_auth_default : unit -> auth
438     (** [get_auth_default ()] returns the default authentication handler
439         of libvirt.
440       *)
441
442   external const : [>`R] t -> ro t = "%identity"
443     (** [const conn] turns a read/write connection into a read-only
444         connection.  Note that the opposite operation is impossible.
445       *)
446 end
447   (** Module dealing with connections.  [Connect.t] is the
448       connection object. *)
449
450 (** {3 Domains} *)
451
452 module Domain :
453 sig
454   type 'rw t
455     (** Domain handle.  Read-only handles have type [ro Domain.t] and
456         read-write handles have type [rw Domain.t].
457     *)
458
459   type state =
460     | InfoNoState | InfoRunning | InfoBlocked | InfoPaused
461     | InfoShutdown | InfoShutoff | InfoCrashed | InfoPMSuspended
462
463   type info = {
464     state : state;                      (** running state *)
465     max_mem : int64;                    (** maximum memory in kilobytes *)
466     memory : int64;                     (** memory used in kilobytes *)
467     nr_virt_cpu : int;                  (** number of virtual CPUs *)
468     cpu_time : int64;                   (** CPU time used in nanoseconds *)
469   }
470
471   type vcpu_state = VcpuOffline | VcpuRunning | VcpuBlocked
472
473   type vcpu_info = {
474     number : int;                       (** virtual CPU number *)
475     vcpu_state : vcpu_state;            (** state *)
476     vcpu_time : int64;                  (** CPU time used in nanoseconds *)
477     cpu : int;                          (** real CPU number, -1 if offline *)
478   }
479
480   type domain_create_flag =
481   | START_PAUSED                        (** Launch guest in paused state *)
482   | START_AUTODESTROY                   (** Automatically kill guest on close *)
483   | START_BYPASS_CACHE                  (** Avoid filesystem cache pollution *)
484   | START_FORCE_BOOT                    (** Discard any managed save *)
485   | START_VALIDATE                      (** Validate XML against schema *)
486
487   type sched_param = string * sched_param_value
488   and sched_param_value =
489     | SchedFieldInt32 of int32 | SchedFieldUInt32 of int32
490     | SchedFieldInt64 of int64 | SchedFieldUInt64 of int64
491     | SchedFieldFloat of float | SchedFieldBool of bool
492
493   type typed_param = string * typed_param_value
494   and typed_param_value =
495     | TypedFieldInt32 of int32 | TypedFieldUInt32 of int32
496     | TypedFieldInt64 of int64 | TypedFieldUInt64 of int64
497     | TypedFieldFloat of float | TypedFieldBool of bool
498     | TypedFieldString of string
499
500   type migrate_flag = Live
501
502   type memory_flag = Virtual
503
504   type list_flag =
505     | ListActive
506     | ListInactive
507     | ListAll
508
509   type block_stats = {
510     rd_req : int64;
511     rd_bytes : int64;
512     wr_req : int64;
513     wr_bytes : int64;
514     errs : int64;
515   }
516
517   type interface_stats = {
518     rx_bytes : int64;
519     rx_packets : int64;
520     rx_errs : int64;
521     rx_drop : int64;
522     tx_bytes : int64;
523     tx_packets : int64;
524     tx_errs : int64;
525     tx_drop : int64;
526   }
527
528   type get_all_domain_stats_flag =
529     | GetAllDomainsStatsActive
530     | GetAllDomainsStatsInactive
531     | GetAllDomainsStatsOther
532     | GetAllDomainsStatsPaused
533     | GetAllDomainsStatsPersistent
534     | GetAllDomainsStatsRunning
535     | GetAllDomainsStatsShutoff
536     | GetAllDomainsStatsTransient
537     | GetAllDomainsStatsBacking
538     | GetAllDomainsStatsEnforceStats
539
540   type stats_type =
541     | StatsState | StatsCpuTotal | StatsBalloon | StatsVcpu
542     | StatsInterface | StatsBlock | StatsPerf
543
544   type domain_stats_record = {
545     dom_uuid : uuid;
546     params : typed_param array;
547   }
548
549   type xml_desc_flag =
550     | XmlSecure                 (* dump security sensitive information too *)
551     | XmlInactive               (* dump inactive domain information *)
552     | XmlUpdateCPU              (* update guest CPU requirements according to host CPU *)
553     | XmlMigratable             (* dump XML suitable for migration *)
554
555   val max_peek : [>`R] t -> int
556     (** Maximum size supported by the {!block_peek} and {!memory_peek}
557         functions.  If you want to peek more than this then you must
558         break your request into chunks. *)
559
560   val create_linux : [>`W] Connect.t -> xml -> rw t
561     (** Create a new guest domain (not necessarily a Linux one)
562         from the given XML.  Use {!create_xml} instead.
563     *)
564   val create_xml : [>`W] Connect.t -> xml -> domain_create_flag list -> rw t
565     (** Create a new guest domain from the given XML. *)
566   val lookup_by_id : 'a Connect.t -> int -> 'a t
567     (** Lookup a domain by ID. *)
568   val lookup_by_uuid : 'a Connect.t -> uuid -> 'a t
569     (** Lookup a domain by UUID.  This uses the packed byte array UUID. *)
570   val lookup_by_uuid_string : 'a Connect.t -> string -> 'a t
571     (** Lookup a domain by (string) UUID. *)
572   val lookup_by_name : 'a Connect.t -> string -> 'a t
573     (** Lookup a domain by name. *)
574   val destroy : [>`W] t -> unit
575     (** Abruptly destroy a domain. *)
576   val free : [>`R] t -> unit
577     (** [free domain] frees the domain object in memory.
578
579         The domain object is automatically freed if it is garbage
580         collected.  This function just forces it to be freed right
581         away.
582     *)
583
584   val suspend : [>`W] t -> unit
585     (** Suspend a domain. *)
586   val resume : [>`W] t -> unit
587     (** Resume a domain. *)
588   val save : [>`W] t -> filename -> unit
589     (** Suspend a domain, then save it to the file. *)
590   val restore : [>`W] Connect.t -> filename -> unit
591     (** Restore a domain from a file. *)
592   val core_dump : [>`W] t -> filename -> unit
593     (** Force a domain to core dump to the named file. *)
594   val shutdown : [>`W] t -> unit
595     (** Shutdown a domain. *)
596   val reboot : [>`W] t -> unit
597     (** Reboot a domain. *)
598   val get_name : [>`R] t -> string
599     (** Get the domain name. *)
600   val get_uuid : [>`R] t -> uuid
601     (** Get the domain UUID (as a packed byte array). *)
602   val get_uuid_string : [>`R] t -> string
603     (** Get the domain UUID (as a printable string). *)
604   val get_id : [>`R] t -> int
605     (** [get_id dom] returns the ID of the domain.  In most cases
606         this returns [-1] if the domain is not running. *)
607   val get_os_type : [>`R] t -> string
608     (** Get the operating system type. *)
609   val get_max_memory : [>`R] t -> int64
610     (** Get the maximum memory allocation. *)
611   val set_max_memory : [>`W] t -> int64 -> unit
612     (** Set the maximum memory allocation. *)
613   val set_memory : [>`W] t -> int64 -> unit
614     (** Set the normal memory allocation. *)
615   val get_info : [>`R] t -> info
616     (** Get information about a domain. *)
617   val get_xml_desc : [>`R] t -> xml
618     (** Get the XML description of a domain. *)
619   val get_xml_desc_flags : [>`W] t -> xml_desc_flag list -> xml
620     (** Get the XML description of a domain, with the possibility
621         to specify flags. *)
622   val get_scheduler_type : [>`R] t -> string * int
623     (** Get the scheduler type. *)
624   val get_scheduler_parameters : [>`R] t -> int -> sched_param array
625     (** Get the array of scheduler parameters. *)
626   val set_scheduler_parameters : [>`W] t -> sched_param array -> unit
627     (** Set the array of scheduler parameters. *)
628   val define_xml : [>`W] Connect.t -> xml -> rw t
629     (** Define a new domain (but don't start it up) from the XML. *)
630   val undefine : [>`W] t -> unit
631     (** Undefine a domain - removes its configuration. *)
632   val create : [>`W] t -> unit
633     (** Launch a defined (inactive) domain. *)
634   val get_autostart : [>`R] t -> bool
635     (** Get the autostart flag for a domain. *)
636   val set_autostart : [>`W] t -> bool -> unit
637     (** Set the autostart flag for a domain. *)
638   val set_vcpus : [>`W] t -> int -> unit
639     (** Change the number of vCPUs available to a domain. *)
640   val pin_vcpu : [>`W] t -> int -> string -> unit
641     (** [pin_vcpu dom vcpu bitmap] pins a domain vCPU to a bitmap of physical
642         CPUs.  See the libvirt documentation for details of the
643         layout of the bitmap. *)
644   val get_vcpus : [>`R] t -> int -> int -> int * vcpu_info array * string
645     (** [get_vcpus dom maxinfo maplen] returns the pinning information
646         for a domain.  See the libvirt documentation for details
647         of the array and bitmap returned from this function.
648     *)
649   val get_cpu_stats : [>`R] t -> typed_param list array
650     (** [get_pcpu_stats dom] returns the physical CPU stats
651         for a domain.  See the libvirt documentation for details.
652     *)
653   val get_max_vcpus : [>`R] t -> int
654     (** Returns the maximum number of vCPUs supported for this domain. *)
655   val attach_device : [>`W] t -> xml -> unit
656     (** Attach a device (described by the device XML) to a domain. *)
657   val detach_device : [>`W] t -> xml -> unit
658     (** Detach a device (described by the device XML) from a domain. *)
659
660   val migrate : [>`W] t -> [>`W] Connect.t -> migrate_flag list ->
661     ?dname:string -> ?uri:string -> ?bandwidth:int -> unit -> rw t
662     (** [migrate dom dconn flags ()] migrates a domain to a
663         destination host described by [dconn].
664
665         The optional flag [?dname] is used to rename the domain.
666
667         The optional flag [?uri] is used to route the migration.
668
669         The optional flag [?bandwidth] is used to limit the bandwidth
670         used for migration (in Mbps). *)
671
672   val block_stats : [>`R] t -> string -> block_stats
673     (** Returns block device stats. *)
674   val interface_stats : [>`R] t -> string -> interface_stats
675     (** Returns network interface stats. *)
676
677   val block_peek : [>`W] t -> string -> int64 -> int -> string -> int -> unit
678     (** [block_peek dom path offset size buf boff] reads [size] bytes at
679         [offset] in the domain's [path] block device.
680
681         If successful then the data is written into [buf] starting
682         at offset [boff], for [size] bytes.
683
684         See also {!max_peek}. *)
685   val memory_peek : [>`W] t -> memory_flag list -> int64 -> int ->
686     string -> int -> unit
687     (** [memory_peek dom Virtual offset size] reads [size] bytes
688         at [offset] in the domain's virtual memory.
689
690         If successful then the data is written into [buf] starting
691         at offset [boff], for [size] bytes.
692
693         See also {!max_peek}. *)
694
695   external get_all_domain_stats : [>`R] Connect.t -> stats_type list -> get_all_domain_stats_flag list -> domain_stats_record array = "ocaml_libvirt_domain_get_all_domain_stats"
696     (** [get_all_domain_stats conn stats flags] allows you to read
697         all stats across multiple/all domains in a single call.
698
699         See the libvirt documentation for
700         [virConnectGetAllDomainStats]. *)
701
702   external const : [>`R] t -> ro t = "%identity"
703     (** [const dom] turns a read/write domain handle into a read-only
704         domain handle.  Note that the opposite operation is impossible.
705       *)
706
707   val get_domains : ([>`R] as 'a) Connect.t -> list_flag list -> 'a t list
708     (** Get the active and/or inactive domains using the most
709         efficient method available.
710
711         See also:
712         {!get_domains_and_infos},
713         {!Connect.list_domains},
714         {!Connect.list_defined_domains}.
715   *)
716
717   val get_domains_and_infos : ([>`R] as 'a) Connect.t -> list_flag list ->
718     ('a t * info) list
719     (** This gets the active and/or inactive domains and the
720         domain info for each one using the most efficient
721         method available.
722
723         See also:
724         {!get_domains},
725         {!Connect.list_domains},
726         {!Connect.list_defined_domains},
727         {!get_info}.
728     *)
729
730 end
731   (** Module dealing with domains.  [Domain.t] is the
732       domain object. *)
733
734 module Event :
735 sig
736
737   module Defined : sig
738     type t = [
739       | `Added          (** Newly created config file *)
740       | `Updated        (** Changed config file *)
741       | `Unknown of int
742     ]
743
744     val to_string: t -> string
745   end
746
747   module Undefined : sig
748     type t = [
749       | `Removed        (** Deleted the config file *)
750       | `Unknown of int
751     ]
752
753     val to_string: t -> string
754   end
755
756   module Started : sig
757     type t = [
758       | `Booted         (** Normal startup from boot *)
759       | `Migrated       (** Incoming migration from another host *)
760       | `Restored       (** Restored from a state file *)
761       | `FromSnapshot   (** Restored from snapshot *)
762       | `Wakeup         (** Started due to wakeup event *)
763       | `Unknown of int
764     ]
765
766     val to_string: t -> string
767   end
768
769   module Suspended : sig
770     type t = [
771       | `Paused        (** Normal suspend due to admin pause *)
772       | `Migrated      (** Suspended for offline migration *)
773       | `IOError       (** Suspended due to a disk I/O error *)
774       | `Watchdog      (** Suspended due to a watchdog firing *)
775       | `Restored      (** Restored from paused state file *)
776       | `FromSnapshot  (** Restored from paused snapshot *)
777       | `APIError      (** suspended after failure during libvirt API call *)
778       | `Unknown of int
779     ]
780
781     val to_string: t -> string
782   end
783
784   module Resumed : sig
785     type t = [
786       | `Unpaused      (** Normal resume due to admin unpause *)
787       | `Migrated      (** Resumed for completion of migration *)
788       | `FromSnapshot  (** Resumed from snapshot *)
789       | `Unknown of int
790     ]
791
792     val to_string: t -> string
793   end
794
795   module Stopped : sig
796     type t = [
797       | `Shutdown     (** Normal shutdown *)
798       | `Destroyed    (** Forced poweroff from host *)
799       | `Crashed      (** Guest crashed *)
800       | `Migrated     (** Migrated off to another host *)
801       | `Saved        (** Saved to a state file *)
802       | `Failed       (** Host emulator/mgmt failed *)
803       | `FromSnapshot (** offline snapshot loaded *)
804       | `Unknown of int
805     ]
806
807     val to_string: t -> string
808   end
809
810   module PM_suspended : sig
811     type t = [
812       | `Memory       (** Guest was PM suspended to memory *)
813       | `Disk         (** Guest was PM suspended to disk *)
814       | `Unknown of int
815     ]
816
817     val to_string: t -> string
818   end
819
820   module Lifecycle : sig
821     type t = [
822       | `Defined of Defined.t
823       | `Undefined of Undefined.t
824       | `Started of Started.t
825       | `Suspended of Suspended.t
826       | `Resumed of Resumed.t
827       | `Stopped of Stopped.t
828       | `Shutdown (* no detail defined yet *)
829       | `PMSuspended of PM_suspended.t
830       | `Unknown of int
831     ]
832
833     val to_string: t -> string
834   end
835
836   module Reboot : sig
837     type t = unit
838
839     val to_string: t -> string
840   end
841
842   module Rtc_change : sig
843     type t = int64
844
845     val to_string: t -> string
846   end
847
848   module Watchdog : sig
849     type t = [
850       | `None           (** No action, watchdog ignored *)
851       | `Pause          (** Guest CPUs are paused *)
852       | `Reset          (** Guest CPUs are reset *)
853       | `Poweroff       (** Guest is forcably powered off *)
854       | `Shutdown       (** Guest is requested to gracefully shutdown *)
855       | `Debug          (** No action, a debug message logged *)
856       | `Unknown of int (** newer libvirt *)
857     ]
858
859     val to_string: t -> string
860   end
861
862   module Io_error : sig
863     (** Represents both IOError and IOErrorReason *)
864     type action = [
865       | `None           (** No action, IO error ignored *)
866       | `Pause          (** Guest CPUs are paused *)
867       | `Report         (** IO error reported to guest OS *)
868       | `Unknown of int (** newer libvirt *)
869     ]
870
871     type t = {
872       src_path: string option;  (** The host file on which the I/O error occurred *)
873       dev_alias: string option; (** The guest device alias associated with the path *)
874       action: action;    (** The action that is to be taken due to the IO error *)
875       reason: string option;    (** The cause of the IO error *)
876     }
877
878     val to_string: t -> string
879   end
880
881   module Graphics_address : sig
882     type family = [
883       | `Ipv4           (** IPv4 address *)
884       | `Ipv6           (** IPv6 address *)
885       | `Unix           (** UNIX socket path *)
886       | `Unknown of int (** newer libvirt *)
887     ]
888
889     type t = {
890       family: family;         (** Address family *)
891       node: string option;    (** Address of node (eg IP address, or UNIX path *)
892       service: string option; (** Service name/number (eg TCP port, or NULL) *)
893     }
894
895     val to_string: t -> string
896   end
897
898   module Graphics_subject : sig
899     type identity = {
900       ty: string option;   (** Type of identity *)
901       name: string option; (** Identity value *)
902     }
903
904     type t = identity list
905
906     val to_string: t -> string
907   end
908
909   module Graphics : sig
910     type phase = [
911       | `Connect        (** Initial socket connection established *)
912       | `Initialize     (** Authentication & setup completed *)
913       | `Disconnect     (** Final socket disconnection *)
914       | `Unknown of int (** newer libvirt *)
915     ]
916
917     type t = {
918       phase: phase;                (** the phase of the connection *)
919       local: Graphics_address.t;   (** the local server address *)
920       remote: Graphics_address.t;  (** the remote client address *)
921       auth_scheme: string option;  (** the authentication scheme activated *)
922       subject: Graphics_subject.t; (** the authenticated subject (user) *)
923     }
924
925     val to_string: t -> string
926   end
927
928   module Control_error : sig
929     type t = unit
930
931     val to_string: t -> string
932   end
933
934   module Block_job : sig
935     type ty = [
936       | `KnownUnknown (** explicitly named UNKNOWN in the spec *)
937       | `Pull
938       | `Copy
939       | `Commit
940       | `Unknown of int
941     ]
942
943     type status = [
944       | `Completed
945       | `Failed
946       | `Cancelled
947       | `Ready
948       | `Unknown of int
949     ]
950
951     type t = {
952       disk: string option; (** fully-qualified name of the affected disk *)     
953       ty: ty;              (** type of block job *)
954       status: status;      (** final status of the operation *)
955     }
956
957     val to_string: t -> string
958   end
959
960   module Disk_change : sig
961     type reason = [
962       | `MissingOnStart
963       | `Unknown of int
964     ]
965
966     type t = {
967       old_src_path: string option; (** old source path *)
968       new_src_path: string option; (** new source path *)
969       dev_alias: string option;    (** device alias name *)
970       reason: reason;              (** reason why this callback was called *)
971     }
972
973     val to_string: t -> string
974   end
975
976   module Tray_change : sig
977     type reason = [
978       | `Open
979       | `Close
980       | `Unknown of int
981     ]
982
983     type t = {
984       dev_alias: string option; (** device alias *)
985       reason: reason;           (** why the tray status was changed *)
986     }
987
988     val to_string: t -> string
989   end
990
991   module PM_wakeup : sig
992     type reason = [
993       | `Unknown of int
994     ]
995
996     type t = reason
997
998     val to_string: t -> string
999   end
1000
1001   module PM_suspend : sig
1002     type reason = [
1003       | `Unknown of int
1004     ]
1005
1006     type t = reason
1007
1008     val to_string: t -> string
1009   end
1010
1011   module Balloon_change : sig
1012     type t = int64
1013
1014     val to_string: t -> string
1015   end
1016
1017   module PM_suspend_disk : sig
1018     type reason = [
1019       | `Unknown of int
1020     ]
1021
1022     type t = reason
1023
1024     val to_string: t -> string
1025   end
1026
1027
1028   type callback =
1029     | Lifecycle     of ([`R] Domain.t -> Lifecycle.t -> unit)
1030     | Reboot        of ([`R] Domain.t -> Reboot.t -> unit)
1031     | RtcChange     of ([`R] Domain.t -> Rtc_change.t -> unit)
1032     | Watchdog      of ([`R] Domain.t -> Watchdog.t -> unit)
1033     | IOError       of ([`R] Domain.t -> Io_error.t -> unit)
1034     | Graphics      of ([`R] Domain.t -> Graphics.t -> unit)
1035     | IOErrorReason of ([`R] Domain.t -> Io_error.t -> unit)
1036     | ControlError  of ([`R] Domain.t -> Control_error.t -> unit)
1037     | BlockJob      of ([`R] Domain.t -> Block_job.t -> unit)
1038     | DiskChange    of ([`R] Domain.t -> Disk_change.t -> unit)
1039     | TrayChange    of ([`R] Domain.t -> Tray_change.t -> unit)
1040     | PMWakeUp      of ([`R] Domain.t -> PM_wakeup.t -> unit)
1041     | PMSuspend     of ([`R] Domain.t -> PM_suspend.t -> unit)
1042     | BalloonChange of ([`R] Domain.t -> Balloon_change.t -> unit)
1043     | PMSuspendDisk of ([`R] Domain.t -> PM_suspend_disk.t -> unit)
1044
1045     (** type of a registered call back function *)
1046
1047   val register_default_impl : unit -> unit
1048     (** Registers the default event loop based on poll(). This
1049         must be done before connections are opened.
1050
1051         Once registered call run_default_impl in a loop. *)
1052
1053   val run_default_impl : unit -> unit
1054     (** Runs one iteration of the event loop. Applications will
1055         generally want to have a thread which invokes this in an
1056         infinite loop. *)
1057
1058   type callback_id
1059     (** an individual event registration *)
1060
1061   val register_any : 'a Connect.t -> ?dom:'a Domain.t -> callback -> callback_id
1062     (** [register_any con ?dom callback] registers [callback]
1063         to receive notification of arbitrary domain events. Return
1064         a registration id which can be used in [deregister_any].
1065
1066         If [?dom] is None then register for this kind of event on
1067         all domains. If [dom] is [Some d] then register for this
1068         kind of event only on [d].
1069     *)
1070
1071   val deregister_any : 'a Connect.t -> callback_id -> unit
1072     (** [deregister_any con id] deregisters the previously registered
1073         callback with id [id]. *)
1074
1075   type timer_id
1076     (** an individual timer event *)
1077
1078   val add_timeout : 'a Connect.t -> int -> (unit -> unit) -> timer_id
1079     (** [add_timeout con ms cb] registers [cb] as a timeout callback
1080         which will be called every [ms] milliseconds *)
1081
1082   val remove_timeout : 'a Connect.t -> timer_id -> unit
1083     (** [remove_timeout con t] deregisters timeout callback [t]. *)
1084
1085 end
1086   (** Module dealing with events generated by domain
1087       state changes. *)
1088
1089 (** {3 Networks} *)
1090
1091 module Network : 
1092 sig
1093   type 'rw t
1094     (** Network handle.  Read-only handles have type [ro Network.t] and
1095         read-write handles have type [rw Network.t].
1096     *)
1097
1098   val lookup_by_name : 'a Connect.t -> string -> 'a t
1099     (** Lookup a network by name. *)
1100   val lookup_by_uuid : 'a Connect.t -> uuid -> 'a t
1101     (** Lookup a network by (packed) UUID. *)
1102   val lookup_by_uuid_string : 'a Connect.t -> string -> 'a t
1103     (** Lookup a network by UUID string. *)
1104   val create_xml : [>`W] Connect.t -> xml -> rw t
1105     (** Create a network. *)
1106   val define_xml : [>`W] Connect.t -> xml -> rw t
1107     (** Define but don't activate a network. *)
1108   val undefine : [>`W] t -> unit
1109     (** Undefine configuration of a network. *)
1110   val create : [>`W] t -> unit
1111     (** Start up a defined (inactive) network. *)
1112   val destroy : [>`W] t -> unit
1113     (** Destroy a network. *)
1114   val free : [>`R] t -> unit
1115     (** [free network] frees the network object in memory.
1116
1117         The network object is automatically freed if it is garbage
1118         collected.  This function just forces it to be freed right
1119         away.
1120     *)
1121
1122   val get_name : [>`R] t -> string
1123     (** Get network name. *)
1124   val get_uuid : [>`R] t -> uuid
1125     (** Get network packed UUID. *)
1126   val get_uuid_string : [>`R] t -> string
1127     (** Get network UUID as a printable string. *)
1128   val get_xml_desc : [>`R] t -> xml
1129     (** Get XML description of a network. *)
1130   val get_bridge_name : [>`R] t -> string
1131     (** Get bridge device name of a network. *)
1132   val get_autostart : [>`R] t -> bool
1133     (** Get the autostart flag for a network. *)
1134   val set_autostart : [>`W] t -> bool -> unit
1135     (** Set the autostart flag for a network. *)
1136
1137   external const : [>`R] t -> ro t = "%identity"
1138     (** [const network] turns a read/write network handle into a read-only
1139         network handle.  Note that the opposite operation is impossible.
1140       *)
1141 end
1142   (** Module dealing with networks.  [Network.t] is the
1143       network object. *)
1144
1145 (** {3 Storage pools} *)
1146
1147 module Pool :
1148 sig
1149   type 'rw t
1150     (** Storage pool handle. *)
1151
1152   type pool_state = Inactive | Building | Running | Degraded | Inaccessible
1153     (** State of the storage pool. *)
1154
1155   type pool_build_flags = New | Repair | Resize
1156     (** Flags for creating a storage pool. *)
1157
1158   type pool_delete_flags = Normal | Zeroed
1159     (** Flags for deleting a storage pool. *)
1160
1161   type pool_info = {
1162     state : pool_state;                 (** Pool state. *)
1163     capacity : int64;                   (** Logical size in bytes. *)
1164     allocation : int64;                 (** Currently allocated in bytes. *)
1165     available : int64;                  (** Remaining free space bytes. *)
1166   }
1167
1168   val lookup_by_name : 'a Connect.t -> string -> 'a t
1169   val lookup_by_uuid : 'a Connect.t -> uuid -> 'a t
1170   val lookup_by_uuid_string : 'a Connect.t -> string -> 'a t
1171     (** Look up a storage pool by name, UUID or UUID string. *)
1172
1173   val create_xml : [>`W] Connect.t -> xml -> rw t
1174     (** Create a storage pool. *)
1175   val define_xml : [>`W] Connect.t -> xml -> rw t
1176     (** Define but don't activate a storage pool. *)
1177   val build : [>`W] t -> pool_build_flags -> unit
1178     (** Build a storage pool. *)
1179   val undefine : [>`W] t -> unit
1180     (** Undefine configuration of a storage pool. *)
1181   val create : [>`W] t -> unit
1182     (** Start up a defined (inactive) storage pool. *)
1183   val destroy : [>`W] t -> unit
1184     (** Destroy a storage pool. *)
1185   val delete : [>`W] t -> unit
1186     (** Delete a storage pool. *)
1187   val free : [>`R] t -> unit
1188     (** Free a storage pool object in memory.
1189
1190         The storage pool object is automatically freed if it is garbage
1191         collected.  This function just forces it to be freed right
1192         away.
1193     *)
1194   val refresh : [`R] t -> unit
1195     (** Refresh the list of volumes in the storage pool. *)
1196
1197   val get_name : [`R] t -> string
1198     (** Name of the pool. *)
1199   val get_uuid : [`R] t -> uuid
1200     (** Get the UUID (as a packed byte array). *)
1201   val get_uuid_string : [`R] t -> string
1202     (** Get the UUID (as a printable string). *)
1203   val get_info : [`R] t -> pool_info
1204     (** Get information about the pool. *)
1205   val get_xml_desc : [`R] t -> xml
1206     (** Get the XML description. *)
1207   val get_autostart : [`R] t -> bool
1208     (** Get the autostart flag for the storage pool. *)
1209   val set_autostart : [>`W] t -> bool -> unit
1210     (** Set the autostart flag for the storage pool. *)
1211
1212   val num_of_volumes : [`R] t -> int
1213     (** Returns the number of storage volumes within the storage pool. *)
1214   val list_volumes : [`R] t -> int -> string array
1215     (** Return list of storage volumes. *)
1216
1217   external const : [>`R] t -> ro t = "%identity"
1218     (** [const conn] turns a read/write storage pool into a read-only
1219         pool.  Note that the opposite operation is impossible.
1220       *)
1221 end
1222   (** Module dealing with storage pools. *)
1223
1224 (** {3 Storage volumes} *)
1225
1226 module Volume :
1227 sig
1228   type 'rw t
1229     (** Storage volume handle. *)
1230
1231   type vol_type = File | Block | Dir | Network | NetDir | Ploop
1232     (** Type of a storage volume. *)
1233
1234   type vol_delete_flags = Normal | Zeroed
1235     (** Flags for deleting a storage volume. *)
1236
1237   type vol_info = {
1238     typ : vol_type;                     (** Type of storage volume. *)
1239     capacity : int64;                   (** Logical size in bytes. *)
1240     allocation : int64;                 (** Currently allocated in bytes. *)
1241   }
1242
1243   val lookup_by_name : 'a Pool.t -> string -> 'a t
1244   val lookup_by_key : 'a Connect.t -> string -> 'a t
1245   val lookup_by_path : 'a Connect.t -> string -> 'a t
1246     (** Look up a storage volume by name, key or path volume. *)
1247
1248   val pool_of_volume : 'a t -> 'a Pool.t
1249     (** Get the storage pool containing this volume. *)
1250
1251   val get_name : [`R] t -> string
1252     (** Name of the volume. *)
1253   val get_key : [`R] t -> string
1254     (** Key of the volume. *)
1255   val get_path : [`R] t -> string
1256     (** Path of the volume. *)
1257   val get_info : [`R] t -> vol_info
1258     (** Get information about the storage volume. *)
1259   val get_xml_desc : [`R] t -> xml
1260     (** Get the XML description. *)
1261
1262   val create_xml : [>`W] Pool.t -> xml -> unit
1263     (** Create a storage volume. *)
1264   val delete : [>`W] t -> vol_delete_flags -> unit
1265     (** Delete a storage volume. *)
1266   val free : [>`R] t -> unit
1267     (** Free a storage volume object in memory.
1268
1269         The storage volume object is automatically freed if it is garbage
1270         collected.  This function just forces it to be freed right
1271         away.
1272     *)
1273
1274   external const : [>`R] t -> ro t = "%identity"
1275     (** [const conn] turns a read/write storage volume into a read-only
1276         volume.  Note that the opposite operation is impossible.
1277       *)
1278 end
1279   (** Module dealing with storage volumes. *)
1280
1281 (** {3 Secrets} *)
1282
1283 module Secret :
1284 sig
1285   type 'rw t
1286     (** Secret handle. *)
1287
1288   type secret_usage_type =
1289     | NoType
1290     | Volume
1291     | Ceph
1292     | ISCSI
1293     | TLS
1294     (** Usage type of a secret. *)
1295
1296   val lookup_by_uuid : 'a Connect.t -> uuid -> 'a t
1297     (** Lookup a secret by UUID.  This uses the packed byte array UUID. *)
1298   val lookup_by_uuid_string : 'a Connect.t -> string -> 'a t
1299     (** Lookup a secret by (string) UUID. *)
1300   val lookup_by_usage : 'a Connect.t -> secret_usage_type -> string -> 'a t
1301     (** Lookup a secret by usage type, and usage ID. *)
1302
1303   val define_xml : [>`W] Connect.t -> xml -> rw t
1304     (** Define a secret. *)
1305
1306   val get_uuid : [>`R] t -> uuid
1307     (** Get the UUID (as a packed byte array) of the secret. *)
1308   val get_uuid_string : [>`R] t -> string
1309     (** Get the UUID (as a printable string) of the secret. *)
1310   val get_usage_type : [>`R] t -> secret_usage_type
1311     (** Get the usage type of the secret. *)
1312   val get_usage_id : [>`R] t -> string
1313     (** Get the usage ID of the secret. *)
1314   val get_xml_desc : [>`R] t -> xml
1315     (** Get the XML description. *)
1316
1317   val set_value : [>`W] t -> bytes -> unit
1318     (** Set a new value for the secret. *)
1319   val get_value : [>`R] t -> bytes
1320     (** Get the value of the secret. *)
1321
1322   val undefine : [>`W] t -> unit
1323     (** Undefine a secret. *)
1324
1325   val free : [>`R] t -> unit
1326     (** Free a secret object in memory.
1327
1328         The secret object is automatically freed if it is garbage
1329         collected.  This function just forces it to be freed right
1330         away.
1331     *)
1332
1333   external const : [>`R] t -> ro t = "%identity"
1334     (** [const conn] turns a read/write secret into a read-only
1335         secret.  Note that the opposite operation is impossible.
1336       *)
1337 end
1338   (** Module dealing with secrets. *)
1339
1340 (** {3 Error handling and exceptions} *)
1341
1342 module Virterror :
1343 sig
1344   type code =
1345     | VIR_ERR_OK
1346     | VIR_ERR_INTERNAL_ERROR
1347     | VIR_ERR_NO_MEMORY
1348     | VIR_ERR_NO_SUPPORT
1349     | VIR_ERR_UNKNOWN_HOST
1350     | VIR_ERR_NO_CONNECT
1351     | VIR_ERR_INVALID_CONN
1352     | VIR_ERR_INVALID_DOMAIN
1353     | VIR_ERR_INVALID_ARG
1354     | VIR_ERR_OPERATION_FAILED
1355     | VIR_ERR_GET_FAILED
1356     | VIR_ERR_POST_FAILED
1357     | VIR_ERR_HTTP_ERROR
1358     | VIR_ERR_SEXPR_SERIAL
1359     | VIR_ERR_NO_XEN
1360     | VIR_ERR_XEN_CALL
1361     | VIR_ERR_OS_TYPE
1362     | VIR_ERR_NO_KERNEL
1363     | VIR_ERR_NO_ROOT
1364     | VIR_ERR_NO_SOURCE
1365     | VIR_ERR_NO_TARGET
1366     | VIR_ERR_NO_NAME
1367     | VIR_ERR_NO_OS
1368     | VIR_ERR_NO_DEVICE
1369     | VIR_ERR_NO_XENSTORE
1370     | VIR_ERR_DRIVER_FULL
1371     | VIR_ERR_CALL_FAILED
1372     | VIR_ERR_XML_ERROR
1373     | VIR_ERR_DOM_EXIST
1374     | VIR_ERR_OPERATION_DENIED
1375     | VIR_ERR_OPEN_FAILED
1376     | VIR_ERR_READ_FAILED
1377     | VIR_ERR_PARSE_FAILED
1378     | VIR_ERR_CONF_SYNTAX
1379     | VIR_ERR_WRITE_FAILED
1380     | VIR_ERR_XML_DETAIL
1381     | VIR_ERR_INVALID_NETWORK
1382     | VIR_ERR_NETWORK_EXIST
1383     | VIR_ERR_SYSTEM_ERROR
1384     | VIR_ERR_RPC
1385     | VIR_ERR_GNUTLS_ERROR
1386     | VIR_WAR_NO_NETWORK
1387     | VIR_ERR_NO_DOMAIN
1388     | VIR_ERR_NO_NETWORK
1389     | VIR_ERR_INVALID_MAC
1390     | VIR_ERR_AUTH_FAILED
1391     | VIR_ERR_INVALID_STORAGE_POOL
1392     | VIR_ERR_INVALID_STORAGE_VOL
1393     | VIR_WAR_NO_STORAGE
1394     | VIR_ERR_NO_STORAGE_POOL
1395     | VIR_ERR_NO_STORAGE_VOL
1396     | VIR_WAR_NO_NODE
1397     | VIR_ERR_INVALID_NODE_DEVICE
1398     | VIR_ERR_NO_NODE_DEVICE
1399     | VIR_ERR_NO_SECURITY_MODEL
1400     | VIR_ERR_OPERATION_INVALID
1401     | VIR_WAR_NO_INTERFACE
1402     | VIR_ERR_NO_INTERFACE
1403     | VIR_ERR_INVALID_INTERFACE
1404     | VIR_ERR_MULTIPLE_INTERFACES
1405     | VIR_WAR_NO_NWFILTER
1406     | VIR_ERR_INVALID_NWFILTER
1407     | VIR_ERR_NO_NWFILTER
1408     | VIR_ERR_BUILD_FIREWALL
1409     | VIR_WAR_NO_SECRET
1410     | VIR_ERR_INVALID_SECRET
1411     | VIR_ERR_NO_SECRET
1412     | VIR_ERR_CONFIG_UNSUPPORTED
1413     | VIR_ERR_OPERATION_TIMEOUT
1414     | VIR_ERR_MIGRATE_PERSIST_FAILED
1415     | VIR_ERR_HOOK_SCRIPT_FAILED
1416     | VIR_ERR_INVALID_DOMAIN_SNAPSHOT
1417     | VIR_ERR_NO_DOMAIN_SNAPSHOT
1418     | VIR_ERR_INVALID_STREAM
1419     | VIR_ERR_ARGUMENT_UNSUPPORTED
1420     | VIR_ERR_STORAGE_PROBE_FAILED
1421     | VIR_ERR_STORAGE_POOL_BUILT
1422     | VIR_ERR_SNAPSHOT_REVERT_RISKY
1423     | VIR_ERR_OPERATION_ABORTED
1424     | VIR_ERR_AUTH_CANCELLED
1425     | VIR_ERR_NO_DOMAIN_METADATA
1426     | VIR_ERR_MIGRATE_UNSAFE
1427     | VIR_ERR_OVERFLOW
1428     | VIR_ERR_BLOCK_COPY_ACTIVE
1429     | VIR_ERR_OPERATION_UNSUPPORTED
1430     | VIR_ERR_SSH
1431     | VIR_ERR_AGENT_UNRESPONSIVE
1432     | VIR_ERR_RESOURCE_BUSY
1433     | VIR_ERR_ACCESS_DENIED
1434     | VIR_ERR_DBUS_SERVICE
1435     | VIR_ERR_STORAGE_VOL_EXIST
1436     | VIR_ERR_CPU_INCOMPATIBLE
1437     | VIR_ERR_XML_INVALID_SCHEMA
1438     | VIR_ERR_MIGRATE_FINISH_OK
1439     | VIR_ERR_AUTH_UNAVAILABLE
1440     | VIR_ERR_NO_SERVER
1441     | VIR_ERR_NO_CLIENT
1442     | VIR_ERR_AGENT_UNSYNCED
1443     | VIR_ERR_LIBSSH
1444     | VIR_ERR_DEVICE_MISSING
1445     | VIR_ERR_INVALID_NWFILTER_BINDING
1446     | VIR_ERR_NO_NWFILTER_BINDING
1447         (* ^^ NB: If you add a variant you MUST edit
1448            libvirt_c_epilogue.c:MAX_VIR_* *)
1449     | VIR_ERR_UNKNOWN of int
1450         (** See [<libvirt/virterror.h>] for meaning of these codes. *)
1451
1452   val string_of_code : code -> string
1453
1454   type domain =
1455     | VIR_FROM_NONE
1456     | VIR_FROM_XEN
1457     | VIR_FROM_XEND
1458     | VIR_FROM_XENSTORE
1459     | VIR_FROM_SEXPR
1460     | VIR_FROM_XML
1461     | VIR_FROM_DOM
1462     | VIR_FROM_RPC
1463     | VIR_FROM_PROXY
1464     | VIR_FROM_CONF
1465     | VIR_FROM_QEMU
1466     | VIR_FROM_NET
1467     | VIR_FROM_TEST
1468     | VIR_FROM_REMOTE
1469     | VIR_FROM_OPENVZ
1470     | VIR_FROM_XENXM
1471     | VIR_FROM_STATS_LINUX
1472     | VIR_FROM_LXC
1473     | VIR_FROM_STORAGE
1474     | VIR_FROM_NETWORK
1475     | VIR_FROM_DOMAIN
1476     | VIR_FROM_UML
1477     | VIR_FROM_NODEDEV
1478     | VIR_FROM_XEN_INOTIFY
1479     | VIR_FROM_SECURITY
1480     | VIR_FROM_VBOX
1481     | VIR_FROM_INTERFACE
1482     | VIR_FROM_ONE
1483     | VIR_FROM_ESX
1484     | VIR_FROM_PHYP
1485     | VIR_FROM_SECRET
1486     | VIR_FROM_CPU
1487     | VIR_FROM_XENAPI
1488     | VIR_FROM_NWFILTER
1489     | VIR_FROM_HOOK
1490     | VIR_FROM_DOMAIN_SNAPSHOT
1491     | VIR_FROM_AUDIT
1492     | VIR_FROM_SYSINFO
1493     | VIR_FROM_STREAMS
1494     | VIR_FROM_VMWARE
1495     | VIR_FROM_EVENT
1496     | VIR_FROM_LIBXL
1497     | VIR_FROM_LOCKING
1498     | VIR_FROM_HYPERV
1499     | VIR_FROM_CAPABILITIES
1500     | VIR_FROM_URI
1501     | VIR_FROM_AUTH
1502     | VIR_FROM_DBUS
1503     | VIR_FROM_PARALLELS
1504     | VIR_FROM_DEVICE
1505     | VIR_FROM_SSH
1506     | VIR_FROM_LOCKSPACE
1507     | VIR_FROM_INITCTL
1508     | VIR_FROM_IDENTITY
1509     | VIR_FROM_CGROUP
1510     | VIR_FROM_ACCESS
1511     | VIR_FROM_SYSTEMD
1512     | VIR_FROM_BHYVE
1513     | VIR_FROM_CRYPTO
1514     | VIR_FROM_FIREWALL
1515     | VIR_FROM_POLKIT
1516     | VIR_FROM_THREAD
1517     | VIR_FROM_ADMIN
1518     | VIR_FROM_LOGGING
1519     | VIR_FROM_XENXL
1520     | VIR_FROM_PERF
1521     | VIR_FROM_LIBSSH
1522     | VIR_FROM_RESCTRL
1523         (* ^^ NB: If you add a variant you MUST edit
1524            libvirt_c_epilogue.c: MAX_VIR_* *)
1525     | VIR_FROM_UNKNOWN of int
1526         (** Subsystem / driver which produced the error. *)
1527
1528   val string_of_domain : domain -> string
1529
1530   type level =
1531     | VIR_ERR_NONE
1532     | VIR_ERR_WARNING
1533     | VIR_ERR_ERROR
1534         (* ^^ NB: If you add a variant you MUST edit libvirt_c.c: MAX_VIR_* *)
1535     | VIR_ERR_UNKNOWN_LEVEL of int
1536         (** No error, a warning or an error. *)
1537
1538   val string_of_level : level -> string
1539
1540   type t = {
1541     code : code;                        (** Error code. *)
1542     domain : domain;                    (** Origin of the error. *)
1543     message : string option;            (** Human-readable message. *)
1544     level : level;                      (** Error or warning. *)
1545     str1 : string option;               (** Informational string. *)
1546     str2 : string option;               (** Informational string. *)
1547     str3 : string option;               (** Informational string. *)
1548     int1 : int32;                       (** Informational integer. *)
1549     int2 : int32;                       (** Informational integer. *)
1550   }
1551     (** An error object. *)
1552
1553   val to_string : t -> string
1554     (** Turn the exception into a printable string. *)
1555
1556   val get_last_error : unit -> t option
1557   val get_last_conn_error : [>`R] Connect.t -> t option
1558     (** Get the last error at a global or connection level.
1559
1560         Normally you do not need to use these functions because
1561         the library automatically turns errors into exceptions.
1562     *)
1563
1564   val reset_last_error : unit -> unit
1565   val reset_last_conn_error : [>`R] Connect.t -> unit
1566     (** Reset the error at a global or connection level.
1567
1568         Normally you do not need to use these functions.
1569     *)
1570
1571   val no_error : unit -> t
1572     (** Creates an empty error message.
1573
1574         Normally you do not need to use this function.
1575     *)
1576 end
1577   (** Module dealing with errors. *)
1578
1579 exception Virterror of Virterror.t
1580 (** This exception can be raised by any library function that detects
1581     an error.  To get a printable error message, call
1582     {!Virterror.to_string} on the content of this exception.
1583 *)
1584
1585 exception Not_supported of string
1586 (**
1587     Functions may raise
1588     [Not_supported "virFoo"]
1589     (where [virFoo] is the libvirt function name) if a function is
1590     not supported at either compile or run time.  This applies to
1591     any libvirt function added after version 0.2.1.
1592
1593     See also {{:https://libvirt.org/hvsupport.html}https://libvirt.org/hvsupport.html}
1594 *)
1595
1596 (** {3 Utility functions} *)
1597
1598 val map_ignore_errors : ('a -> 'b) -> 'a list -> 'b list
1599 (** [map_ignore_errors f xs] calls function [f] for each element of [xs].
1600
1601     This is just like [List.map] except that if [f x] throws a
1602     {!Virterror.t} exception, the error is ignored and [f x]
1603     is not returned in the final list.
1604
1605     This function is primarily useful when dealing with domains which
1606     might 'disappear' asynchronously from the currently running
1607     program.
1608 *)