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,
9 with the OCaml linking exception described in ../COPYING.LIB.
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.
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
22 {2 Introduction and examples}
24 This is a set of bindings for writing OCaml programs to
25 manage virtual machines through {{:http://libvirt.org/}libvirt}.
27 {3 Using libvirt interactively}
29 Using the interactive toplevel:
33 Objective Caml version 3.10.0
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}
49 {3 Compiling libvirt programs}
51 This command compiles a program to native code:
54 ocamlopt -I +libvirt mllibvirt.cmxa list_domains.ml -o list_domains
57 {3 Example: Connect to the hypervisor}
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:
65 module C = Libvirt.Connect
66 module D = Libvirt.Domain
67 module N = Libvirt.Network
70 To get a connection handle, assuming a Xen hypervisor:
74 let conn = C.connect_readonly ~name ()
77 {3 Example: List running domains}
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
87 printf "%8d %s\n%!" (D.get_id dom) (D.get_name dom)
91 {3 Example: List inactive domains}
94 let n = C.num_of_defined_domains conn in
95 let names = C.list_defined_domains conn n in
98 printf "inactive %s\n%!" name
102 {3 Example: Print node info}
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;
115 let hostname = C.get_hostname conn in
116 printf "hostname = %s\n%!" hostname;
118 let uri = C.get_uri conn in
119 printf "uri = %s\n%!" uri
125 (** {2 Programming issues}
127 {3 General safety issues}
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.
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.
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.
146 {3 Backwards and forwards compatibility}
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
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}
159 We don't support libvirt < 0.2.1, and never will so don't ask us.
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
170 (Note that multithreaded code is not well tested. If you find
171 bugs please report them.)
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.
184 (** This is a "raw" UUID, ie. a packed string of bytes. *)
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.
191 type filename = string
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.
198 [get_version ~driver ()] returns the library version in the first
199 part of the tuple, and the version of the driver called [driver]
202 The version numbers are encoded as
203 1,000,000 * major + 1,000 * minor + release.
206 val uuid_length : int
207 (** Length of packed UUIDs. *)
209 val uuid_string_length : int
210 (** Length of UUID strings. *)
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.
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.
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.
228 If you want to handle both read-write and read-only
229 connections at runtime, use a variant similar to this:
233 | Read_only of Libvirt.ro Libvirt.Connect.t
234 | Read_write of Libvirt.rw Libvirt.Connect.t
236 See also the source of [mlvirsh].
240 (** Forward definition of {!Job.t} to avoid recursive module dependencies. *)
242 (** {3 Connections} *)
247 (** Connection. Read-only connections have type [ro Connect.t] and
248 read-write connections have type [rw Connect.t].
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 *)
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].
266 [connect ()] connects to the default hypervisor.
268 [connect_readonly] is the same but connects in read-only mode.
271 val close : [>`R] t -> unit
272 (** [close conn] closes and frees the connection object in memory.
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.
279 val get_type : [>`R] t -> string
280 (** Returns the name of the driver (hypervisor). *)
282 val get_version : [>`R] t -> int
283 (** Returns the driver version
284 [major * 1_000_000 + minor * 1000 + release]
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].
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].
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
316 Call {!num_of_networks} first to get a value for [max].
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
324 Call {!num_of_defined_networks} first to get a value for [max].
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. *)
336 (* The name of this function is inconsistent, but the inconsistency
337 * is really in libvirt itself.
339 val get_node_info : [>`R] t -> node_info
340 (** Return information about the physical server. *)
342 val node_get_free_memory : [> `R] t -> int64
344 [node_get_free_memory conn]
345 returns the amount of free memory (not allocated to any guest)
349 val node_get_cells_free_memory : [> `R] t -> int -> int -> int64 array
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.
358 val maxcpus_of_node_info : node_info -> int
359 (** Calculate the total number of CPUs supported (but not necessarily
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.
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]. *)
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.
381 (** Module dealing with connections. [Connect.t] is the
382 connection object. *)
389 (** Domain handle. Read-only handles have type [ro Domain.t] and
390 read-write handles have type [rw Domain.t].
394 | InfoNoState | InfoRunning | InfoBlocked | InfoPaused
395 | InfoShutdown | InfoShutoff | InfoCrashed
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 *)
405 type vcpu_state = VcpuOffline | VcpuRunning | VcpuBlocked
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 *)
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
420 type migrate_flag = Live
422 type memory_flag = Virtual
432 type interface_stats = {
443 val create_linux : [>`W] Connect.t -> xml -> rw t
444 (** Create a new guest domain (not necessarily a Linux one)
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.
462 The domain object is automatically freed if it is garbage
463 collected. This function just forces it to be freed right
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.
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.
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.
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. *)
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].
553 The optional flag [?dname] is used to rename the domain.
555 The optional flag [?uri] is used to route the migration.
557 The optional flag [?bandwidth] is used to limit the bandwidth
558 used for migration (in Mbps). *)
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. *)
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.
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.
576 If successful then the data is written into [buf] starting
577 at offset [boff], for [size] bytes. *)
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.
584 (** Module dealing with domains. [Domain.t] is the
592 (** Network handle. Read-only handles have type [ro Network.t] and
593 read-write handles have type [rw Network.t].
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.
619 The network object is automatically freed if it is garbage
620 collected. This function just forces it to be freed right
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. *)
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.
644 (** Module dealing with networks. [Network.t] is the
647 (** {3 Storage pools} *)
652 (** Storage pool handle. *)
654 type pool_state = Inactive | Building | Running | Degraded
655 (** State of the storage pool. *)
657 type pool_build_flags = New | Repair | Resize
658 (** Flags for creating a storage pool. *)
660 type pool_delete_flags = Normal | Zeroed
661 (** Flags for deleting a storage pool. *)
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. *)
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. *)
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.
692 The storage pool object is automatically freed if it is garbage
693 collected. This function just forces it to be freed right
696 val refresh : [`R] t -> unit
697 (** Refresh the list of volumes in the storage pool. *)
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. *)
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. *)
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.
724 (** Module dealing with storage pools. *)
726 (** {3 Storage volumes} *)
731 (** Storage volume handle. *)
733 type vol_type = File | Block
734 (** Type of a storage volume. *)
736 type vol_delete_flags = Normal | Zeroed
737 (** Flags for deleting a storage volume. *)
740 typ : vol_type; (** Type of storage volume. *)
741 capacity : int64; (** Logical size in bytes. *)
742 allocation : int64; (** Currently allocated in bytes. *)
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. *)
750 val pool_of_volume : 'a t -> 'a Pool.t
751 (** Get the storage pool containing this volume. *)
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. *)
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.
771 The storage volume object is automatically freed if it is garbage
772 collected. This function just forces it to be freed right
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.
781 (** Module dealing with storage volumes. *)
783 (** {3 Jobs and asynchronous processing} *)
787 type ('jobclass, 'rw) t = ('jobclass, 'rw) job_t
788 (** A background asynchronous job.
790 Jobs represent a pending operation such as domain creation.
791 The possible types for a job are:
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
801 type job_type = Bounded | Unbounded
802 (** A Bounded job is one where we can estimate time to completion. *)
804 type job_state = Running | Complete | Failed | Cancelled
805 (** State of the job. *)
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 *)
816 val get_info : ('a,'b) t -> job_info
817 (** Get information and status about the job. *)
819 val get_domain : ([`Domain], 'a) t -> 'a Domain.t
820 (** Get the completed domain from a job.
822 You should only call it on a job in state Complete. *)
824 val get_network : ([`Network], 'a) t -> 'a Network.t
825 (** Get the completed network from a job.
827 You should only call it on a job in state Complete. *)
829 val cancel : ('a,'b) t -> unit
832 val free : ('a, [>`R]) t -> unit
833 (** Free a job object in memory.
835 The job object is automatically freed if it is garbage
836 collected. This function just forces it to be freed right
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.
845 (** Module dealing with asynchronous jobs. *)
847 (** {3 Error handling and exceptions} *)
853 | VIR_ERR_INTERNAL_ERROR
856 | VIR_ERR_UNKNOWN_HOST
858 | VIR_ERR_INVALID_CONN
859 | VIR_ERR_INVALID_DOMAIN
860 | VIR_ERR_INVALID_ARG
861 | VIR_ERR_OPERATION_FAILED
863 | VIR_ERR_POST_FAILED
865 | VIR_ERR_SEXPR_SERIAL
876 | VIR_ERR_NO_XENSTORE
877 | VIR_ERR_DRIVER_FULL
878 | VIR_ERR_CALL_FAILED
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
888 | VIR_ERR_INVALID_NETWORK
889 | VIR_ERR_NETWORK_EXIST
890 | VIR_ERR_SYSTEM_ERROR
892 | VIR_ERR_GNUTLS_ERROR
896 | VIR_ERR_INVALID_MAC
897 | VIR_ERR_AUTH_FAILED
898 | VIR_ERR_INVALID_STORAGE_POOL
899 | VIR_ERR_INVALID_STORAGE_VOL
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. *)
908 val string_of_code : code -> string
927 | VIR_FROM_STATS_LINUX
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. *)
934 val string_of_domain : domain -> string
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. *)
944 val string_of_level : level -> string
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. *)
957 (** An error object. *)
959 val to_string : t -> string
960 (** Turn the exception into a printable string. *)
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.
966 Normally you do not need to use these functions because
967 the library automatically turns errors into exceptions.
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.
974 Normally you do not need to use these functions.
977 val no_error : unit -> t
978 (** Creates an empty error message.
980 Normally you do not need to use this function.
983 (** Module dealing with errors. *)
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.
991 exception Not_supported of string
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.
999 See also {{:http://libvirt.org/hvsupport.html}http://libvirt.org/hvsupport.html}