1 (** OCaml bindings for libvirt.
2 (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
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.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 (** This is a "raw" UUID, ie. a packed string of bytes. *)
24 (** Type of XML (an uninterpreted string of bytes). Use PXP, expat,
25 xml-light, etc. if you want to do anything useful with the XML.
28 val get_version : ?driver:string -> unit -> int * int
29 (** [get_version ()] returns the library version in the first part
30 of the tuple, and [0] in the second part.
32 [get_version ~driver ()] returns the library version in the first
33 part of the tuple, and the version of the driver called [driver]
36 The version numbers are encoded as
37 1,000,000 * major + 1,000 * minor + release.
41 (** Length of packed UUIDs. *)
43 val uuid_string_length : int
44 (** Length of UUID strings. *)
46 (* These phantom types are used to ensure the type-safety of read-only
47 * versus read-write connections. For more information see:
48 * http://caml.inria.fr/pub/ml-archives/caml-list/2004/07/80683af867cce6bf8fff273973f70c95.en.html
56 (** Connection. Read-only connections have type [ro Connect.t] and
57 read-write connections have type [rw Connect.t].
61 model : string; (** CPU model *)
62 memory : int64; (** memory size in kilobytes *)
63 cpus : int; (** number of active CPUs *)
64 mhz : int; (** expected CPU frequency *)
65 nodes : int; (** number of NUMA nodes (1 = UMA) *)
66 sockets : int; (** number of CPU sockets per node *)
67 cores : int; (** number of cores per socket *)
68 threads : int; (** number of threads per core *)
71 val connect : ?name:string -> unit -> rw t
72 val connect_readonly : ?name:string -> unit -> ro t
73 (** [connect ~name ()] connects to the hypervisor with URI [name].
75 [connect ()] connects to the default hypervisor.
77 [connect_readonly] is the same but connects in read-only mode.
80 val close : [>`R] t -> unit
81 (** [close conn] closes and frees the connection object in memory.
83 The connection is automatically closed if it is garbage
84 collected. This function just forces it to be closed
88 val get_type : [>`R] t -> string
89 val get_version : [>`R] t -> int
90 val get_hostname : [>`R] t -> string
91 val get_uri : [>`R] t -> string
92 val get_max_vcpus : [>`R] t -> ?type_:string -> unit -> int
93 val list_domains : [>`R] t -> int -> int array
94 val num_of_domains : [>`R] t -> int
95 val get_capabilities : [>`R] t -> string
96 val num_of_defined_domains : [>`R] t -> int
97 val list_defined_domains : [>`R] t -> int -> string array
98 val num_of_networks : [>`R] t -> int
99 val list_networks : [>`R] t -> int -> string array
100 val num_of_defined_networks : [>`R] t -> int
101 val list_defined_networks : [>`R] t -> int -> string array
103 (* The name of this function is inconsistent, but the inconsistency
104 * is really in libvirt itself.
106 val get_node_info : [>`R] t -> node_info
108 val node_get_free_memory : [> `R] t -> int64
110 [node_get_free_memory conn]
111 returns the amount of free memory (not allocated to any guest)
115 val node_get_cells_free_memory : [> `R] t -> int -> int -> int64 array
117 [node_get_cells_free_memory conn start max]
118 returns the amount of free memory on each NUMA cell in kilobytes.
119 [start] is the first cell for which we return free memory.
120 [max] is the maximum number of cells for which we return free memory.
121 Returns an array of up to [max] entries in length.
124 val maxcpus_of_node_info : node_info -> int
125 (** Calculate the total number of CPUs supported (but not necessarily
129 val cpumaplen : int -> int
130 (** Calculate the length (in bytes) required to store the complete
131 CPU map between a single virtual and all physical CPUs of a domain.
134 val use_cpu : string -> int -> unit
135 (** [use_cpu cpumap cpu] marks [cpu] as usable in [cpumap]. *)
136 val unuse_cpu : string -> int -> unit
137 (** [unuse_cpu cpumap cpu] marks [cpu] as not usable in [cpumap]. *)
138 val cpu_usable : string -> int -> int -> int -> bool
139 (** [cpu_usable cpumaps maplen vcpu cpu] checks returns true iff the
140 [cpu] is usable by [vcpu]. *)
142 external const : [>`R] t -> ro t = "%identity"
143 (** [const conn] turns a read/write connection into a read-only
144 connection. Note that the opposite operation is impossible.
147 (** Module dealing with connections. [Connect.t] is the
154 (** Domain handle. Read-only handles have type [ro Domain.t] and
155 read-write handles have type [rw Domain.t].
159 | InfoNoState | InfoRunning | InfoBlocked | InfoPaused
160 | InfoShutdown | InfoShutoff | InfoCrashed
163 state : state; (** running state *)
164 max_mem : int64; (** maximum memory in kilobytes *)
165 memory : int64; (** memory used in kilobytes *)
166 nr_virt_cpu : int; (** number of virtual CPUs *)
167 cpu_time : int64; (** CPU time used in nanoseconds *)
170 type vcpu_state = VcpuOffline | VcpuRunning | VcpuBlocked
173 number : int; (** virtual CPU number *)
174 vcpu_state : vcpu_state; (** state *)
175 vcpu_time : int64; (** CPU time used in nanoseconds *)
176 cpu : int; (** real CPU number, -1 if offline *)
179 type sched_param = string * sched_param_value
180 and sched_param_value =
181 | SchedFieldInt32 of int32 | SchedFieldUInt32 of int32
182 | SchedFieldInt64 of int64 | SchedFieldUInt64 of int64
183 | SchedFieldFloat of float | SchedFieldBool of bool
185 type migrate_flag = Live
195 type interface_stats = {
206 val create_linux : [>`W] Connect.t -> xml -> rw t
207 val lookup_by_id : 'a Connect.t -> int -> 'a t
208 val lookup_by_uuid : 'a Connect.t -> uuid -> 'a t
209 val lookup_by_uuid_string : 'a Connect.t -> string -> 'a t
210 val lookup_by_name : 'a Connect.t -> string -> 'a t
211 val destroy : [>`W] t -> unit
212 val free : [>`R] t -> unit
213 (** [free domain] frees the domain object in memory.
215 The domain object is automatically freed if it is garbage
216 collected. This function just forces it to be freed right
220 val suspend : [>`W] t -> unit
221 val resume : [>`W] t -> unit
222 val save : [>`W] t -> string -> unit
223 val restore : [>`W] Connect.t -> string -> unit
224 val core_dump : [>`W] t -> string -> unit
225 val shutdown : [>`W] t -> unit
226 val reboot : [>`W] t -> unit
227 val get_name : [>`R] t -> string
228 val get_uuid : [>`R] t -> uuid
229 val get_uuid_string : [>`R] t -> string
230 val get_id : [>`R] t -> int
231 (** [getid dom] returns the ID of the domain.
233 Do not call this on a defined but not running domain. Those
234 domains don't have IDs, and you'll get an error here.
237 val get_os_type : [>`R] t -> string
238 val get_max_memory : [>`R] t -> int64
239 val set_max_memory : [>`W] t -> int64 -> unit
240 val set_memory : [>`W] t -> int64 -> unit
241 val get_info : [>`R] t -> info
242 val get_xml_desc : [>`R] t -> xml
243 val get_scheduler_type : [>`R] t -> string * int
244 val get_scheduler_parameters : [>`R] t -> int -> sched_param array
245 val set_scheduler_parameters : [>`W] t -> sched_param array -> unit
246 val define_xml : [>`W] Connect.t -> xml -> rw t
247 val undefine : [>`W] t -> unit
248 val create : [>`W] t -> unit
249 val get_autostart : [>`R] t -> bool
250 val set_autostart : [>`W] t -> bool -> unit
251 val set_vcpus : [>`W] t -> int -> unit
252 val pin_vcpu : [>`W] t -> int -> string -> unit
253 val get_vcpus : [>`R] t -> int -> int -> int * vcpu_info array * string
254 val get_max_vcpus : [>`R] t -> int
255 val attach_device : [>`W] t -> xml -> unit
256 val detach_device : [>`W] t -> xml -> unit
258 val migrate : [>`W] t -> [>`W] Connect.t -> migrate_flag list ->
259 ?dname:string -> ?uri:string -> ?bandwidth:int -> unit -> rw t
261 val block_stats : [>`R] t -> string -> block_stats
262 val interface_stats : [>`R] t -> string -> interface_stats
264 external const : [>`R] t -> ro t = "%identity"
265 (** [const dom] turns a read/write domain handle into a read-only
266 domain handle. Note that the opposite operation is impossible.
269 (** Module dealing with domains. [Domain.t] is the
276 (** Network handle. Read-only handles have type [ro Network.t] and
277 read-write handles have type [rw Network.t].
280 val lookup_by_name : 'a Connect.t -> string -> 'a t
281 val lookup_by_uuid : 'a Connect.t -> uuid -> 'a t
282 val lookup_by_uuid_string : 'a Connect.t -> string -> 'a t
283 val create_xml : [>`W] Connect.t -> xml -> rw t
284 val define_xml : [>`W] Connect.t -> xml -> rw t
285 val undefine : [>`W] t -> unit
286 val create : [>`W] t -> unit
287 val destroy : [>`W] t -> unit
288 val free : [>`R] t -> unit
289 (** [free network] frees the network object in memory.
291 The network object is automatically freed if it is garbage
292 collected. This function just forces it to be freed right
296 val get_name : [>`R] t -> string
297 val get_uuid : [>`R] t -> uuid
298 val get_uuid_string : [>`R] t -> string
299 val get_xml_desc : [>`R] t -> xml
300 val get_bridge_name : [>`R] t -> string
301 val get_autostart : [>`R] t -> bool
302 val set_autostart : [>`W] t -> bool -> unit
304 external const : [>`R] t -> ro t = "%identity"
305 (** [const network] turns a read/write network handle into a read-only
306 network handle. Note that the opposite operation is impossible.
309 (** Module dealing with networks. [Network.t] is the
317 | VIR_ERR_INTERNAL_ERROR
320 | VIR_ERR_UNKNOWN_HOST
322 | VIR_ERR_INVALID_CONN
323 | VIR_ERR_INVALID_DOMAIN
324 | VIR_ERR_INVALID_ARG
325 | VIR_ERR_OPERATION_FAILED
327 | VIR_ERR_POST_FAILED
329 | VIR_ERR_SEXPR_SERIAL
340 | VIR_ERR_NO_XENSTORE
341 | VIR_ERR_DRIVER_FULL
342 | VIR_ERR_CALL_FAILED
345 | VIR_ERR_OPERATION_DENIED
346 | VIR_ERR_OPEN_FAILED
347 | VIR_ERR_READ_FAILED
348 | VIR_ERR_PARSE_FAILED
349 | VIR_ERR_CONF_SYNTAX
350 | VIR_ERR_WRITE_FAILED
352 | VIR_ERR_INVALID_NETWORK
353 | VIR_ERR_NETWORK_EXIST
354 | VIR_ERR_SYSTEM_ERROR
356 | VIR_ERR_GNUTLS_ERROR
360 (** See [<libvirt/virterror.h>] for meaning of these codes. *)
362 val string_of_code : code -> string
368 (** No error, a warning or an error. *)
370 val string_of_level : level -> string
387 (** Subsystem / driver which produced the error. *)
389 val string_of_domain : domain -> string
392 code : code; (** Error code. *)
393 domain : domain; (** Origin of the error. *)
394 message : string option; (** Human-readable message. *)
395 level : level; (** Error or warning. *)
396 conn : ro Connect.t option; (** Associated connection. *)
397 dom : ro Domain.t option; (** Associated domain. *)
398 str1 : string option; (** Informational string. *)
399 str2 : string option; (** Informational string. *)
400 str3 : string option; (** Informational string. *)
401 int1 : int32; (** Informational integer. *)
402 int2 : int32; (** Informational integer. *)
403 net : ro Network.t option; (** Associated network. *)
405 (** An error object. *)
407 val to_string : t -> string
408 (** Turn the exception into a printable string. *)
410 val get_last_error : unit -> t option
411 val get_last_conn_error : [>`R] Connect.t -> t option
412 (** Get the last error at a global or connection level.
414 Normally you do not need to use these functions because
415 the library automatically turns errors into exceptions.
418 val reset_last_error : unit -> unit
419 val reset_last_conn_error : [>`R] Connect.t -> unit
420 (** Reset the error at a global or connection level.
422 Normally you do not need to use these functions.
425 val no_error : unit -> t
426 (** Creates an empty error message.
428 Normally you do not need to use this function.
431 (** Module dealing with errors. *)
433 exception Virterror of Virterror.t
434 (** This exception can be raised by any library function that detects
435 an error. To get a printable error message, call
436 {!Virterror.to_string} on the content of this exception.
438 Note that functions may also raise
439 [Invalid_argument "virFoo not supported"]
440 (where virFoo is the libvirt function name) if a function is
441 not supported at either compile or runtime. This applies to
442 any libvirt function added after version 0.2.1.
443 See also [http://libvirt.org/hvsupport.html]