1 (* OCaml bindings for libvirt.
2 (C) Copyright 2007-2015 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
25 type filename = string
27 external get_version : ?driver:string -> unit -> int * int = "ocaml_libvirt_get_version"
30 let uuid_string_length = 36
32 (* http://caml.inria.fr/pub/ml-archives/caml-list/2004/07/80683af867cce6bf8fff273973f70c95.en.html *)
51 type credential_type =
56 | CredentialPassphrase
57 | CredentialEchoprompt
58 | CredentialNoechoprompt
63 typ : credential_type;
65 challenge : string option;
66 defresult : string option;
70 credtype : credential_type list;
71 cb : (credential list -> string option list);
75 | ListNoState | ListRunning | ListBlocked
76 | ListPaused | ListShutdown | ListShutoff | ListCrashed
81 external connect : ?name:string -> unit -> rw t = "ocaml_libvirt_connect_open"
82 external connect_readonly : ?name:string -> unit -> ro t = "ocaml_libvirt_connect_open_readonly"
83 external connect_auth : ?name:string -> auth -> rw t = "ocaml_libvirt_connect_open_auth"
84 external connect_auth_readonly : ?name:string -> auth -> ro t = "ocaml_libvirt_connect_open_auth_readonly"
85 external close : [>`R] t -> unit = "ocaml_libvirt_connect_close"
86 external get_type : [>`R] t -> string = "ocaml_libvirt_connect_get_type"
87 external get_version : [>`R] t -> int = "ocaml_libvirt_connect_get_version"
88 external get_hostname : [>`R] t -> string = "ocaml_libvirt_connect_get_hostname"
89 external get_uri : [>`R] t -> string = "ocaml_libvirt_connect_get_uri"
90 external get_max_vcpus : [>`R] t -> ?type_:string -> unit -> int = "ocaml_libvirt_connect_get_max_vcpus"
91 external list_domains : [>`R] t -> int -> int array = "ocaml_libvirt_connect_list_domains"
92 external num_of_domains : [>`R] t -> int = "ocaml_libvirt_connect_num_of_domains"
93 external get_capabilities : [>`R] t -> xml = "ocaml_libvirt_connect_get_capabilities"
94 external num_of_defined_domains : [>`R] t -> int = "ocaml_libvirt_connect_num_of_defined_domains"
95 external list_defined_domains : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_defined_domains"
96 external num_of_networks : [>`R] t -> int = "ocaml_libvirt_connect_num_of_networks"
97 external list_networks : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_networks"
98 external num_of_defined_networks : [>`R] t -> int = "ocaml_libvirt_connect_num_of_defined_networks"
99 external list_defined_networks : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_defined_networks"
100 external num_of_pools : [>`R] t -> int = "ocaml_libvirt_connect_num_of_storage_pools"
101 external list_pools : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_storage_pools"
102 external num_of_defined_pools : [>`R] t -> int = "ocaml_libvirt_connect_num_of_defined_storage_pools"
103 external list_defined_pools : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_defined_storage_pools"
105 external get_node_info : [>`R] t -> node_info = "ocaml_libvirt_connect_get_node_info"
106 external node_get_free_memory : [> `R] t -> int64 = "ocaml_libvirt_connect_node_get_free_memory"
107 external node_get_cells_free_memory : [> `R] t -> int -> int -> int64 array = "ocaml_libvirt_connect_node_get_cells_free_memory"
109 (* See VIR_NODEINFO_MAXCPUS macro defined in <libvirt.h>. *)
110 let maxcpus_of_node_info { nodes = nodes; sockets = sockets;
111 cores = cores; threads = threads } =
112 nodes * sockets * cores * threads
114 (* See VIR_CPU_MAPLEN macro defined in <libvirt.h>. *)
115 let cpumaplen nr_cpus =
118 (* See VIR_USE_CPU, VIR_UNUSE_CPU, VIR_CPU_USABLE macros defined in <libvirt.h>. *)
119 let use_cpu cpumap cpu =
120 Bytes.set cpumap (cpu/8)
121 (Char.chr (Char.code (Bytes.get cpumap (cpu/8)) lor (1 lsl (cpu mod 8))))
122 let unuse_cpu cpumap cpu =
123 Bytes.set cpumap (cpu/8)
124 (Char.chr (Char.code (Bytes.get cpumap (cpu/8)) land (lnot (1 lsl (cpu mod 8)))))
125 let cpu_usable cpumaps maplen vcpu cpu =
126 Char.code (Bytes.get cpumaps (vcpu*maplen + cpu/8)) land (1 lsl (cpu mod 8)) <> 0
128 external set_keep_alive : [>`R] t -> int -> int -> unit = "ocaml_libvirt_connect_set_keep_alive"
130 external const : [>`R] t -> ro t = "%identity"
137 | VIR_ERR_INTERNAL_ERROR
140 | VIR_ERR_UNKNOWN_HOST
142 | VIR_ERR_INVALID_CONN
143 | VIR_ERR_INVALID_DOMAIN
144 | VIR_ERR_INVALID_ARG
145 | VIR_ERR_OPERATION_FAILED
147 | VIR_ERR_POST_FAILED
149 | VIR_ERR_SEXPR_SERIAL
160 | VIR_ERR_NO_XENSTORE
161 | VIR_ERR_DRIVER_FULL
162 | VIR_ERR_CALL_FAILED
165 | VIR_ERR_OPERATION_DENIED
166 | VIR_ERR_OPEN_FAILED
167 | VIR_ERR_READ_FAILED
168 | VIR_ERR_PARSE_FAILED
169 | VIR_ERR_CONF_SYNTAX
170 | VIR_ERR_WRITE_FAILED
172 | VIR_ERR_INVALID_NETWORK
173 | VIR_ERR_NETWORK_EXIST
174 | VIR_ERR_SYSTEM_ERROR
176 | VIR_ERR_GNUTLS_ERROR
180 | VIR_ERR_INVALID_MAC
181 | VIR_ERR_AUTH_FAILED
182 | VIR_ERR_INVALID_STORAGE_POOL
183 | VIR_ERR_INVALID_STORAGE_VOL
185 | VIR_ERR_NO_STORAGE_POOL
186 | VIR_ERR_NO_STORAGE_VOL
188 | VIR_ERR_INVALID_NODE_DEVICE
189 | VIR_ERR_NO_NODE_DEVICE
190 | VIR_ERR_NO_SECURITY_MODEL
191 | VIR_ERR_OPERATION_INVALID
192 | VIR_WAR_NO_INTERFACE
193 | VIR_ERR_NO_INTERFACE
194 | VIR_ERR_INVALID_INTERFACE
195 | VIR_ERR_MULTIPLE_INTERFACES
196 | VIR_WAR_NO_NWFILTER
197 | VIR_ERR_INVALID_NWFILTER
198 | VIR_ERR_NO_NWFILTER
199 | VIR_ERR_BUILD_FIREWALL
201 | VIR_ERR_INVALID_SECRET
203 | VIR_ERR_CONFIG_UNSUPPORTED
204 | VIR_ERR_OPERATION_TIMEOUT
205 | VIR_ERR_MIGRATE_PERSIST_FAILED
206 | VIR_ERR_HOOK_SCRIPT_FAILED
207 | VIR_ERR_INVALID_DOMAIN_SNAPSHOT
208 | VIR_ERR_NO_DOMAIN_SNAPSHOT
209 | VIR_ERR_INVALID_STREAM
210 | VIR_ERR_ARGUMENT_UNSUPPORTED
211 | VIR_ERR_STORAGE_PROBE_FAILED
212 | VIR_ERR_STORAGE_POOL_BUILT
213 | VIR_ERR_SNAPSHOT_REVERT_RISKY
214 | VIR_ERR_OPERATION_ABORTED
215 | VIR_ERR_AUTH_CANCELLED
216 | VIR_ERR_NO_DOMAIN_METADATA
217 | VIR_ERR_MIGRATE_UNSAFE
219 | VIR_ERR_BLOCK_COPY_ACTIVE
220 | VIR_ERR_OPERATION_UNSUPPORTED
222 | VIR_ERR_AGENT_UNRESPONSIVE
223 | VIR_ERR_RESOURCE_BUSY
224 | VIR_ERR_ACCESS_DENIED
225 | VIR_ERR_DBUS_SERVICE
226 | VIR_ERR_STORAGE_VOL_EXIST
227 | VIR_ERR_CPU_INCOMPATIBLE
228 | VIR_ERR_XML_INVALID_SCHEMA
229 | VIR_ERR_MIGRATE_FINISH_OK
230 | VIR_ERR_AUTH_UNAVAILABLE
233 | VIR_ERR_AGENT_UNSYNCED
235 | VIR_ERR_DEVICE_MISSING
236 | VIR_ERR_INVALID_NWFILTER_BINDING
237 | VIR_ERR_NO_NWFILTER_BINDING
238 | VIR_ERR_UNKNOWN of int
240 let string_of_code = function
241 | VIR_ERR_OK -> "VIR_ERR_OK"
242 | VIR_ERR_INTERNAL_ERROR -> "VIR_ERR_INTERNAL_ERROR"
243 | VIR_ERR_NO_MEMORY -> "VIR_ERR_NO_MEMORY"
244 | VIR_ERR_NO_SUPPORT -> "VIR_ERR_NO_SUPPORT"
245 | VIR_ERR_UNKNOWN_HOST -> "VIR_ERR_UNKNOWN_HOST"
246 | VIR_ERR_NO_CONNECT -> "VIR_ERR_NO_CONNECT"
247 | VIR_ERR_INVALID_CONN -> "VIR_ERR_INVALID_CONN"
248 | VIR_ERR_INVALID_DOMAIN -> "VIR_ERR_INVALID_DOMAIN"
249 | VIR_ERR_INVALID_ARG -> "VIR_ERR_INVALID_ARG"
250 | VIR_ERR_OPERATION_FAILED -> "VIR_ERR_OPERATION_FAILED"
251 | VIR_ERR_GET_FAILED -> "VIR_ERR_GET_FAILED"
252 | VIR_ERR_POST_FAILED -> "VIR_ERR_POST_FAILED"
253 | VIR_ERR_HTTP_ERROR -> "VIR_ERR_HTTP_ERROR"
254 | VIR_ERR_SEXPR_SERIAL -> "VIR_ERR_SEXPR_SERIAL"
255 | VIR_ERR_NO_XEN -> "VIR_ERR_NO_XEN"
256 | VIR_ERR_XEN_CALL -> "VIR_ERR_XEN_CALL"
257 | VIR_ERR_OS_TYPE -> "VIR_ERR_OS_TYPE"
258 | VIR_ERR_NO_KERNEL -> "VIR_ERR_NO_KERNEL"
259 | VIR_ERR_NO_ROOT -> "VIR_ERR_NO_ROOT"
260 | VIR_ERR_NO_SOURCE -> "VIR_ERR_NO_SOURCE"
261 | VIR_ERR_NO_TARGET -> "VIR_ERR_NO_TARGET"
262 | VIR_ERR_NO_NAME -> "VIR_ERR_NO_NAME"
263 | VIR_ERR_NO_OS -> "VIR_ERR_NO_OS"
264 | VIR_ERR_NO_DEVICE -> "VIR_ERR_NO_DEVICE"
265 | VIR_ERR_NO_XENSTORE -> "VIR_ERR_NO_XENSTORE"
266 | VIR_ERR_DRIVER_FULL -> "VIR_ERR_DRIVER_FULL"
267 | VIR_ERR_CALL_FAILED -> "VIR_ERR_CALL_FAILED"
268 | VIR_ERR_XML_ERROR -> "VIR_ERR_XML_ERROR"
269 | VIR_ERR_DOM_EXIST -> "VIR_ERR_DOM_EXIST"
270 | VIR_ERR_OPERATION_DENIED -> "VIR_ERR_OPERATION_DENIED"
271 | VIR_ERR_OPEN_FAILED -> "VIR_ERR_OPEN_FAILED"
272 | VIR_ERR_READ_FAILED -> "VIR_ERR_READ_FAILED"
273 | VIR_ERR_PARSE_FAILED -> "VIR_ERR_PARSE_FAILED"
274 | VIR_ERR_CONF_SYNTAX -> "VIR_ERR_CONF_SYNTAX"
275 | VIR_ERR_WRITE_FAILED -> "VIR_ERR_WRITE_FAILED"
276 | VIR_ERR_XML_DETAIL -> "VIR_ERR_XML_DETAIL"
277 | VIR_ERR_INVALID_NETWORK -> "VIR_ERR_INVALID_NETWORK"
278 | VIR_ERR_NETWORK_EXIST -> "VIR_ERR_NETWORK_EXIST"
279 | VIR_ERR_SYSTEM_ERROR -> "VIR_ERR_SYSTEM_ERROR"
280 | VIR_ERR_RPC -> "VIR_ERR_RPC"
281 | VIR_ERR_GNUTLS_ERROR -> "VIR_ERR_GNUTLS_ERROR"
282 | VIR_WAR_NO_NETWORK -> "VIR_WAR_NO_NETWORK"
283 | VIR_ERR_NO_DOMAIN -> "VIR_ERR_NO_DOMAIN"
284 | VIR_ERR_NO_NETWORK -> "VIR_ERR_NO_NETWORK"
285 | VIR_ERR_INVALID_MAC -> "VIR_ERR_INVALID_MAC"
286 | VIR_ERR_AUTH_FAILED -> "VIR_ERR_AUTH_FAILED"
287 | VIR_ERR_INVALID_STORAGE_POOL -> "VIR_ERR_INVALID_STORAGE_POOL"
288 | VIR_ERR_INVALID_STORAGE_VOL -> "VIR_ERR_INVALID_STORAGE_VOL"
289 | VIR_WAR_NO_STORAGE -> "VIR_WAR_NO_STORAGE"
290 | VIR_ERR_NO_STORAGE_POOL -> "VIR_ERR_NO_STORAGE_POOL"
291 | VIR_ERR_NO_STORAGE_VOL -> "VIR_ERR_NO_STORAGE_VOL"
292 | VIR_WAR_NO_NODE -> "VIR_WAR_NO_NODE"
293 | VIR_ERR_INVALID_NODE_DEVICE -> "VIR_ERR_INVALID_NODE_DEVICE"
294 | VIR_ERR_NO_NODE_DEVICE -> "VIR_ERR_NO_NODE_DEVICE"
295 | VIR_ERR_NO_SECURITY_MODEL -> "VIR_ERR_NO_SECURITY_MODEL"
296 | VIR_ERR_OPERATION_INVALID -> "VIR_ERR_OPERATION_INVALID"
297 | VIR_WAR_NO_INTERFACE -> "VIR_WAR_NO_INTERFACE"
298 | VIR_ERR_NO_INTERFACE -> "VIR_ERR_NO_INTERFACE"
299 | VIR_ERR_INVALID_INTERFACE -> "VIR_ERR_INVALID_INTERFACE"
300 | VIR_ERR_MULTIPLE_INTERFACES -> "VIR_ERR_MULTIPLE_INTERFACES"
301 | VIR_WAR_NO_NWFILTER -> "VIR_WAR_NO_NWFILTER"
302 | VIR_ERR_INVALID_NWFILTER -> "VIR_ERR_INVALID_NWFILTER"
303 | VIR_ERR_NO_NWFILTER -> "VIR_ERR_NO_NWFILTER"
304 | VIR_ERR_BUILD_FIREWALL -> "VIR_ERR_BUILD_FIREWALL"
305 | VIR_WAR_NO_SECRET -> "VIR_WAR_NO_SECRET"
306 | VIR_ERR_INVALID_SECRET -> "VIR_ERR_INVALID_SECRET"
307 | VIR_ERR_NO_SECRET -> "VIR_ERR_NO_SECRET"
308 | VIR_ERR_CONFIG_UNSUPPORTED -> "VIR_ERR_CONFIG_UNSUPPORTED"
309 | VIR_ERR_OPERATION_TIMEOUT -> "VIR_ERR_OPERATION_TIMEOUT"
310 | VIR_ERR_MIGRATE_PERSIST_FAILED -> "VIR_ERR_MIGRATE_PERSIST_FAILED"
311 | VIR_ERR_HOOK_SCRIPT_FAILED -> "VIR_ERR_HOOK_SCRIPT_FAILED"
312 | VIR_ERR_INVALID_DOMAIN_SNAPSHOT -> "VIR_ERR_INVALID_DOMAIN_SNAPSHOT"
313 | VIR_ERR_NO_DOMAIN_SNAPSHOT -> "VIR_ERR_NO_DOMAIN_SNAPSHOT"
314 | VIR_ERR_INVALID_STREAM -> "VIR_ERR_INVALID_STREAM"
315 | VIR_ERR_ARGUMENT_UNSUPPORTED -> "VIR_ERR_ARGUMENT_UNSUPPORTED"
316 | VIR_ERR_STORAGE_PROBE_FAILED -> "VIR_ERR_STORAGE_PROBE_FAILED"
317 | VIR_ERR_STORAGE_POOL_BUILT -> "VIR_ERR_STORAGE_POOL_BUILT"
318 | VIR_ERR_SNAPSHOT_REVERT_RISKY -> "VIR_ERR_SNAPSHOT_REVERT_RISKY"
319 | VIR_ERR_OPERATION_ABORTED -> "VIR_ERR_OPERATION_ABORTED"
320 | VIR_ERR_AUTH_CANCELLED -> "VIR_ERR_AUTH_CANCELLED"
321 | VIR_ERR_NO_DOMAIN_METADATA -> "VIR_ERR_NO_DOMAIN_METADATA"
322 | VIR_ERR_MIGRATE_UNSAFE -> "VIR_ERR_MIGRATE_UNSAFE"
323 | VIR_ERR_OVERFLOW -> "VIR_ERR_OVERFLOW"
324 | VIR_ERR_BLOCK_COPY_ACTIVE -> "VIR_ERR_BLOCK_COPY_ACTIVE"
325 | VIR_ERR_OPERATION_UNSUPPORTED -> "VIR_ERR_OPERATION_UNSUPPORTED"
326 | VIR_ERR_SSH -> "VIR_ERR_SSH"
327 | VIR_ERR_AGENT_UNRESPONSIVE -> "VIR_ERR_AGENT_UNRESPONSIVE"
328 | VIR_ERR_RESOURCE_BUSY -> "VIR_ERR_RESOURCE_BUSY"
329 | VIR_ERR_ACCESS_DENIED -> "VIR_ERR_ACCESS_DENIED"
330 | VIR_ERR_DBUS_SERVICE -> "VIR_ERR_DBUS_SERVICE"
331 | VIR_ERR_STORAGE_VOL_EXIST -> "VIR_ERR_STORAGE_VOL_EXIST"
332 | VIR_ERR_CPU_INCOMPATIBLE -> "VIR_ERR_CPU_INCOMPATIBLE"
333 | VIR_ERR_XML_INVALID_SCHEMA -> "VIR_ERR_XML_INVALID_SCHEMA"
334 | VIR_ERR_MIGRATE_FINISH_OK -> "VIR_ERR_MIGRATE_FINISH_OK"
335 | VIR_ERR_AUTH_UNAVAILABLE -> "VIR_ERR_AUTH_UNAVAILABLE"
336 | VIR_ERR_NO_SERVER -> "VIR_ERR_NO_SERVER"
337 | VIR_ERR_NO_CLIENT -> "VIR_ERR_NO_CLIENT"
338 | VIR_ERR_AGENT_UNSYNCED -> "VIR_ERR_AGENT_UNSYNCED"
339 | VIR_ERR_LIBSSH -> "VIR_ERR_LIBSSH"
340 | VIR_ERR_DEVICE_MISSING -> "VIR_ERR_DEVICE_MISSING"
341 | VIR_ERR_INVALID_NWFILTER_BINDING -> "VIR_ERR_INVALID_NWFILTER_BINDING"
342 | VIR_ERR_NO_NWFILTER_BINDING -> "VIR_ERR_NO_NWFILTER_BINDING"
343 | VIR_ERR_UNKNOWN i -> "VIR_ERR_" ^ string_of_int i
362 | VIR_FROM_STATS_LINUX
369 | VIR_FROM_XEN_INOTIFY
381 | VIR_FROM_DOMAIN_SNAPSHOT
390 | VIR_FROM_CAPABILITIES
414 | VIR_FROM_UNKNOWN of int
416 let string_of_domain = function
417 | VIR_FROM_NONE -> "VIR_FROM_NONE"
418 | VIR_FROM_XEN -> "VIR_FROM_XEN"
419 | VIR_FROM_XEND -> "VIR_FROM_XEND"
420 | VIR_FROM_XENSTORE -> "VIR_FROM_XENSTORE"
421 | VIR_FROM_SEXPR -> "VIR_FROM_SEXPR"
422 | VIR_FROM_XML -> "VIR_FROM_XML"
423 | VIR_FROM_DOM -> "VIR_FROM_DOM"
424 | VIR_FROM_RPC -> "VIR_FROM_RPC"
425 | VIR_FROM_PROXY -> "VIR_FROM_PROXY"
426 | VIR_FROM_CONF -> "VIR_FROM_CONF"
427 | VIR_FROM_QEMU -> "VIR_FROM_QEMU"
428 | VIR_FROM_NET -> "VIR_FROM_NET"
429 | VIR_FROM_TEST -> "VIR_FROM_TEST"
430 | VIR_FROM_REMOTE -> "VIR_FROM_REMOTE"
431 | VIR_FROM_OPENVZ -> "VIR_FROM_OPENVZ"
432 | VIR_FROM_XENXM -> "VIR_FROM_XENXM"
433 | VIR_FROM_STATS_LINUX -> "VIR_FROM_STATS_LINUX"
434 | VIR_FROM_LXC -> "VIR_FROM_LXC"
435 | VIR_FROM_STORAGE -> "VIR_FROM_STORAGE"
436 | VIR_FROM_NETWORK -> "VIR_FROM_NETWORK"
437 | VIR_FROM_DOMAIN -> "VIR_FROM_DOMAIN"
438 | VIR_FROM_UML -> "VIR_FROM_UML"
439 | VIR_FROM_NODEDEV -> "VIR_FROM_NODEDEV"
440 | VIR_FROM_XEN_INOTIFY -> "VIR_FROM_XEN_INOTIFY"
441 | VIR_FROM_SECURITY -> "VIR_FROM_SECURITY"
442 | VIR_FROM_VBOX -> "VIR_FROM_VBOX"
443 | VIR_FROM_INTERFACE -> "VIR_FROM_INTERFACE"
444 | VIR_FROM_ONE -> "VIR_FROM_ONE"
445 | VIR_FROM_ESX -> "VIR_FROM_ESX"
446 | VIR_FROM_PHYP -> "VIR_FROM_PHYP"
447 | VIR_FROM_SECRET -> "VIR_FROM_SECRET"
448 | VIR_FROM_CPU -> "VIR_FROM_CPU"
449 | VIR_FROM_XENAPI -> "VIR_FROM_XENAPI"
450 | VIR_FROM_NWFILTER -> "VIR_FROM_NWFILTER"
451 | VIR_FROM_HOOK -> "VIR_FROM_HOOK"
452 | VIR_FROM_DOMAIN_SNAPSHOT -> "VIR_FROM_DOMAIN_SNAPSHOT"
453 | VIR_FROM_AUDIT -> "VIR_FROM_AUDIT"
454 | VIR_FROM_SYSINFO -> "VIR_FROM_SYSINFO"
455 | VIR_FROM_STREAMS -> "VIR_FROM_STREAMS"
456 | VIR_FROM_VMWARE -> "VIR_FROM_VMWARE"
457 | VIR_FROM_EVENT -> "VIR_FROM_EVENT"
458 | VIR_FROM_LIBXL -> "VIR_FROM_LIBXL"
459 | VIR_FROM_LOCKING -> "VIR_FROM_LOCKING"
460 | VIR_FROM_HYPERV -> "VIR_FROM_HYPERV"
461 | VIR_FROM_CAPABILITIES -> "VIR_FROM_CAPABILITIES"
462 | VIR_FROM_URI -> "VIR_FROM_URI"
463 | VIR_FROM_AUTH -> "VIR_FROM_AUTH"
464 | VIR_FROM_DBUS -> "VIR_FROM_DBUS"
465 | VIR_FROM_PARALLELS -> "VIR_FROM_PARALLELS"
466 | VIR_FROM_DEVICE -> "VIR_FROM_DEVICE"
467 | VIR_FROM_SSH -> "VIR_FROM_SSH"
468 | VIR_FROM_LOCKSPACE -> "VIR_FROM_LOCKSPACE"
469 | VIR_FROM_INITCTL -> "VIR_FROM_INITCTL"
470 | VIR_FROM_IDENTITY -> "VIR_FROM_IDENTITY"
471 | VIR_FROM_CGROUP -> "VIR_FROM_CGROUP"
472 | VIR_FROM_ACCESS -> "VIR_FROM_ACCESS"
473 | VIR_FROM_SYSTEMD -> "VIR_FROM_SYSTEMD"
474 | VIR_FROM_BHYVE -> "VIR_FROM_BHYVE"
475 | VIR_FROM_CRYPTO -> "VIR_FROM_CRYPTO"
476 | VIR_FROM_FIREWALL -> "VIR_FROM_FIREWALL"
477 | VIR_FROM_POLKIT -> "VIR_FROM_POLKIT"
478 | VIR_FROM_THREAD -> "VIR_FROM_THREAD"
479 | VIR_FROM_ADMIN -> "VIR_FROM_ADMIN"
480 | VIR_FROM_LOGGING -> "VIR_FROM_LOGGING"
481 | VIR_FROM_XENXL -> "VIR_FROM_XENXL"
482 | VIR_FROM_PERF -> "VIR_FROM_PERF"
483 | VIR_FROM_LIBSSH -> "VIR_FROM_LIBSSH"
484 | VIR_FROM_RESCTRL -> "VIR_FROM_RESCTRL"
485 | VIR_FROM_UNKNOWN i -> "VIR_FROM_" ^ string_of_int i
491 | VIR_ERR_UNKNOWN_LEVEL of int
493 let string_of_level = function
494 | VIR_ERR_NONE -> "VIR_ERR_NONE"
495 | VIR_ERR_WARNING -> "VIR_ERR_WARNING"
496 | VIR_ERR_ERROR -> "VIR_ERR_ERROR"
497 | VIR_ERR_UNKNOWN_LEVEL i -> "VIR_ERR_LEVEL_" ^ string_of_int i
502 message : string option;
504 str1 : string option;
505 str2 : string option;
506 str3 : string option;
511 let to_string { code = code; domain = domain; message = message } =
512 let buf = Buffer.create 128 in
513 Buffer.add_string buf "libvirt: ";
514 Buffer.add_string buf (string_of_code code);
515 Buffer.add_string buf ": ";
516 Buffer.add_string buf (string_of_domain domain);
517 Buffer.add_string buf ": ";
518 (match message with Some msg -> Buffer.add_string buf msg | None -> ());
521 external get_last_error : unit -> t option = "ocaml_libvirt_virterror_get_last_error"
522 external get_last_conn_error : [>`R] Connect.t -> t option = "ocaml_libvirt_virterror_get_last_conn_error"
523 external reset_last_error : unit -> unit = "ocaml_libvirt_virterror_reset_last_error"
524 external reset_last_conn_error : [>`R] Connect.t -> unit = "ocaml_libvirt_virterror_reset_last_conn_error"
527 { code = VIR_ERR_OK; domain = VIR_FROM_NONE;
528 message = None; level = VIR_ERR_NONE;
529 str1 = None; str2 = None; str3 = None;
530 int1 = 0_l; int2 = 0_l }
533 exception Virterror of Virterror.t
534 exception Not_supported of string
536 let rec map_ignore_errors f = function
539 try f x :: map_ignore_errors f xs
540 with Virterror _ -> map_ignore_errors f xs
547 | InfoNoState | InfoRunning | InfoBlocked | InfoPaused
548 | InfoShutdown | InfoShutoff | InfoCrashed
558 type vcpu_state = VcpuOffline | VcpuRunning | VcpuBlocked
562 vcpu_state : vcpu_state;
567 type domain_create_flag =
573 let rec int_of_domain_create_flags = function
575 | START_PAUSED :: flags -> 1 lor int_of_domain_create_flags flags
576 | START_AUTODESTROY :: flags -> 2 lor int_of_domain_create_flags flags
577 | START_BYPASS_CACHE :: flags -> 4 lor int_of_domain_create_flags flags
578 | START_FORCE_BOOT :: flags -> 8 lor int_of_domain_create_flags flags
579 | START_VALIDATE :: flags -> 16 lor int_of_domain_create_flags flags
581 type sched_param = string * sched_param_value
582 and sched_param_value =
583 | SchedFieldInt32 of int32 | SchedFieldUInt32 of int32
584 | SchedFieldInt64 of int64 | SchedFieldUInt64 of int64
585 | SchedFieldFloat of float | SchedFieldBool of bool
587 type typed_param = string * typed_param_value
588 and typed_param_value =
589 | TypedFieldInt32 of int32 | TypedFieldUInt32 of int32
590 | TypedFieldInt64 of int64 | TypedFieldUInt64 of int64
591 | TypedFieldFloat of float | TypedFieldBool of bool
592 | TypedFieldString of string
594 type migrate_flag = Live
596 type memory_flag = Virtual
611 type interface_stats = {
622 type get_all_domain_stats_flag =
623 | GetAllDomainsStatsActive
624 | GetAllDomainsStatsInactive
625 | GetAllDomainsStatsOther
626 | GetAllDomainsStatsPaused
627 | GetAllDomainsStatsPersistent
628 | GetAllDomainsStatsRunning
629 | GetAllDomainsStatsShutoff
630 | GetAllDomainsStatsTransient
631 | GetAllDomainsStatsBacking
632 | GetAllDomainsStatsEnforceStats
635 | StatsState | StatsCpuTotal | StatsBalloon | StatsVcpu
636 | StatsInterface | StatsBlock | StatsPerf
638 type domain_stats_record = {
640 params : typed_param array;
649 (* The maximum size for Domain.memory_peek and Domain.block_peek
650 * supported by libvirt. This may change with different versions
651 * of libvirt in the future, hence it's a function.
653 let max_peek _ = 65536
655 external create_linux : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_domain_create_linux"
656 external _create_xml : [>`W] Connect.t -> xml -> int -> rw t = "ocaml_libvirt_domain_create_xml"
657 let create_xml conn xml flags =
658 _create_xml conn xml (int_of_domain_create_flags flags)
659 external lookup_by_id : 'a Connect.t -> int -> 'a t = "ocaml_libvirt_domain_lookup_by_id"
660 external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_domain_lookup_by_uuid"
661 external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_domain_lookup_by_uuid_string"
662 external lookup_by_name : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_domain_lookup_by_name"
663 external destroy : [>`W] t -> unit = "ocaml_libvirt_domain_destroy"
664 external free : [>`R] t -> unit = "ocaml_libvirt_domain_free"
665 external suspend : [>`W] t -> unit = "ocaml_libvirt_domain_suspend"
666 external resume : [>`W] t -> unit = "ocaml_libvirt_domain_resume"
667 external save : [>`W] t -> filename -> unit = "ocaml_libvirt_domain_save"
668 external restore : [>`W] Connect.t -> filename -> unit = "ocaml_libvirt_domain_restore"
669 external core_dump : [>`W] t -> filename -> unit = "ocaml_libvirt_domain_core_dump"
670 external shutdown : [>`W] t -> unit = "ocaml_libvirt_domain_shutdown"
671 external reboot : [>`W] t -> unit = "ocaml_libvirt_domain_reboot"
672 external get_name : [>`R] t -> string = "ocaml_libvirt_domain_get_name"
673 external get_uuid : [>`R] t -> uuid = "ocaml_libvirt_domain_get_uuid"
674 external get_uuid_string : [>`R] t -> string = "ocaml_libvirt_domain_get_uuid_string"
675 external get_id : [>`R] t -> int = "ocaml_libvirt_domain_get_id"
676 external get_os_type : [>`R] t -> string = "ocaml_libvirt_domain_get_os_type"
677 external get_max_memory : [>`R] t -> int64 = "ocaml_libvirt_domain_get_max_memory"
678 external set_max_memory : [>`W] t -> int64 -> unit = "ocaml_libvirt_domain_set_max_memory"
679 external set_memory : [>`W] t -> int64 -> unit = "ocaml_libvirt_domain_set_memory"
680 external get_info : [>`R] t -> info = "ocaml_libvirt_domain_get_info"
681 external get_xml_desc : [>`R] t -> xml = "ocaml_libvirt_domain_get_xml_desc"
682 external get_xml_desc_flags : [>`W] t -> xml_desc_flag list -> xml = "ocaml_libvirt_domain_get_xml_desc_flags"
683 external get_scheduler_type : [>`R] t -> string * int = "ocaml_libvirt_domain_get_scheduler_type"
684 external get_scheduler_parameters : [>`R] t -> int -> sched_param array = "ocaml_libvirt_domain_get_scheduler_parameters"
685 external set_scheduler_parameters : [>`W] t -> sched_param array -> unit = "ocaml_libvirt_domain_set_scheduler_parameters"
686 external define_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_domain_define_xml"
687 external undefine : [>`W] t -> unit = "ocaml_libvirt_domain_undefine"
688 external create : [>`W] t -> unit = "ocaml_libvirt_domain_create"
689 external get_autostart : [>`R] t -> bool = "ocaml_libvirt_domain_get_autostart"
690 external set_autostart : [>`W] t -> bool -> unit = "ocaml_libvirt_domain_set_autostart"
691 external set_vcpus : [>`W] t -> int -> unit = "ocaml_libvirt_domain_set_vcpus"
692 external pin_vcpu : [>`W] t -> int -> string -> unit = "ocaml_libvirt_domain_pin_vcpu"
693 external get_vcpus : [>`R] t -> int -> int -> int * vcpu_info array * string = "ocaml_libvirt_domain_get_vcpus"
694 external get_cpu_stats : [>`R] t -> typed_param list array = "ocaml_libvirt_domain_get_cpu_stats"
695 external get_max_vcpus : [>`R] t -> int = "ocaml_libvirt_domain_get_max_vcpus"
696 external attach_device : [>`W] t -> xml -> unit = "ocaml_libvirt_domain_attach_device"
697 external detach_device : [>`W] t -> xml -> unit = "ocaml_libvirt_domain_detach_device"
698 external migrate : [>`W] t -> [>`W] Connect.t -> migrate_flag list -> ?dname:string -> ?uri:string -> ?bandwidth:int -> unit -> rw t = "ocaml_libvirt_domain_migrate_bytecode" "ocaml_libvirt_domain_migrate_native"
699 external block_stats : [>`R] t -> string -> block_stats = "ocaml_libvirt_domain_block_stats"
700 external interface_stats : [>`R] t -> string -> interface_stats = "ocaml_libvirt_domain_interface_stats"
701 external block_peek : [>`W] t -> string -> int64 -> int -> string -> int -> unit = "ocaml_libvirt_domain_block_peek_bytecode" "ocaml_libvirt_domain_block_peek_native"
702 external memory_peek : [>`W] t -> memory_flag list -> int64 -> int -> string -> int -> unit = "ocaml_libvirt_domain_memory_peek_bytecode" "ocaml_libvirt_domain_memory_peek_native"
704 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"
706 external const : [>`R] t -> ro t = "%identity"
708 let get_domains conn flags =
709 (* Old/slow/inefficient method. *)
710 let get_active, get_inactive =
711 if List.mem ListAll flags then
714 (List.mem ListActive flags, List.mem ListInactive flags) in
717 let n = Connect.num_of_domains conn in
718 let ids = Connect.list_domains conn n in
719 let ids = Array.to_list ids in
720 map_ignore_errors (lookup_by_id conn) ids
724 if get_inactive then (
725 let n = Connect.num_of_defined_domains conn in
726 let names = Connect.list_defined_domains conn n in
727 let names = Array.to_list names in
728 map_ignore_errors (lookup_by_name conn) names
731 active_doms @ inactive_doms
733 let get_domains_and_infos conn flags =
734 (* Old/slow/inefficient method. *)
735 let get_active, get_inactive =
736 if List.mem ListAll flags then
738 else (List.mem ListActive flags, List.mem ListInactive flags) in
741 let n = Connect.num_of_domains conn in
742 let ids = Connect.list_domains conn n in
743 let ids = Array.to_list ids in
744 map_ignore_errors (lookup_by_id conn) ids
748 if get_inactive then (
749 let n = Connect.num_of_defined_domains conn in
750 let names = Connect.list_defined_domains conn n in
751 let names = Array.to_list names in
752 map_ignore_errors (lookup_by_name conn) names
755 let doms = active_doms @ inactive_doms in
757 map_ignore_errors (fun dom -> (dom, get_info dom)) doms
763 module Defined = struct
770 let to_string = function
772 | `Updated -> "Updated"
773 | `Unknown x -> Printf.sprintf "Unknown Defined.detail: %d" x
778 | x -> `Unknown x (* newer libvirt *)
781 module Undefined = struct
787 let to_string = function
788 | `Removed -> "UndefinedRemoved"
789 | `Unknown x -> Printf.sprintf "Unknown Undefined.detail: %d" x
793 | x -> `Unknown x (* newer libvirt *)
796 module Started = struct
806 let to_string = function
807 | `Booted -> "Booted"
808 | `Migrated -> "Migrated"
809 | `Restored -> "Restored"
810 | `FromSnapshot -> "FromSnapshot"
811 | `Wakeup -> "Wakeup"
812 | `Unknown x -> Printf.sprintf "Unknown Started.detail: %d" x
820 | x -> `Unknown x (* newer libvirt *)
823 module Suspended = struct
832 | `Unknown of int (* newer libvirt *)
835 let to_string = function
836 | `Paused -> "Paused"
837 | `Migrated -> "Migrated"
838 | `IOError -> "IOError"
839 | `Watchdog -> "Watchdog"
840 | `Restored -> "Restored"
841 | `FromSnapshot -> "FromSnapshot"
842 | `APIError -> "APIError"
843 | `Unknown x -> Printf.sprintf "Unknown Suspended.detail: %d" x
853 | x -> `Unknown x (* newer libvirt *)
856 module Resumed = struct
861 | `Unknown of int (* newer libvirt *)
864 let to_string = function
865 | `Unpaused -> "Unpaused"
866 | `Migrated -> "Migrated"
867 | `FromSnapshot -> "FromSnapshot"
868 | `Unknown x -> Printf.sprintf "Unknown Resumed.detail: %d" x
874 | x -> `Unknown x (* newer libvirt *)
877 module Stopped = struct
888 let to_string = function
889 | `Shutdown -> "Shutdown"
890 | `Destroyed -> "Destroyed"
891 | `Crashed -> "Crashed"
892 | `Migrated -> "Migrated"
894 | `Failed -> "Failed"
895 | `FromSnapshot -> "FromSnapshot"
896 | `Unknown x -> Printf.sprintf "Unknown Stopped.detail: %d" x
906 | x -> `Unknown x (* newer libvirt *)
909 module PM_suspended = struct
913 | `Unknown of int (* newer libvirt *)
916 let to_string = function
917 | `Memory -> "Memory"
919 | `Unknown x -> Printf.sprintf "Unknown PM_suspended.detail: %d" x
924 | x -> `Unknown x (* newer libvirt *)
927 let string_option x = match x with
929 | Some x' -> "Some " ^ x'
931 module Lifecycle = struct
933 | `Defined of Defined.t
934 | `Undefined of Undefined.t
935 | `Started of Started.t
936 | `Suspended of Suspended.t
937 | `Resumed of Resumed.t
938 | `Stopped of Stopped.t
939 | `Shutdown (* no detail defined yet *)
940 | `PMSuspended of PM_suspended.t
941 | `Unknown of int (* newer libvirt *)
944 let to_string = function
945 | `Defined x -> "Defined " ^ (Defined.to_string x)
946 | `Undefined x -> "Undefined " ^ (Undefined.to_string x)
947 | `Started x -> "Started " ^ (Started.to_string x)
948 | `Suspended x -> "Suspended " ^ (Suspended.to_string x)
949 | `Resumed x -> "Resumed " ^ (Resumed.to_string x)
950 | `Stopped x -> "Stopped " ^ (Stopped.to_string x)
951 | `Shutdown -> "Shutdown"
952 | `PMSuspended x -> "PMSuspended " ^ (PM_suspended.to_string x)
953 | `Unknown x -> Printf.sprintf "Unknown Lifecycle event: %d" x
955 let make (ty, detail) = match ty with
956 | 0 -> `Defined (Defined.make detail)
957 | 1 -> `Undefined (Undefined.make detail)
958 | 2 -> `Started (Started.make detail)
959 | 3 -> `Suspended (Suspended.make detail)
960 | 4 -> `Resumed (Resumed.make detail)
961 | 5 -> `Stopped (Stopped.make detail)
963 | 7 -> `PMSuspended (PM_suspended.make detail)
967 module Reboot = struct
970 let to_string _ = "()"
975 module Rtc_change = struct
978 let to_string = Int64.to_string
983 module Watchdog = struct
994 let to_string = function
998 | `Poweroff -> "Poweroff"
999 | `Shutdown -> "Shutdown"
1001 | `Unknown x -> Printf.sprintf "Unknown watchdog_action: %d" x
1010 | x -> `Unknown x (* newer libvirt *)
1013 module Io_error = struct
1018 | `Unknown of int (* newer libvirt *)
1021 let string_of_action = function
1024 | `Report -> "Report"
1025 | `Unknown x -> Printf.sprintf "Unknown Io_error.action: %d" x
1027 let action_of_int = function
1034 src_path: string option;
1035 dev_alias: string option;
1037 reason: string option;
1040 let to_string t = Printf.sprintf
1041 "{ Io_error.src_path = %s; dev_alias = %s; action = %s; reason = %s }"
1042 (string_option t.src_path)
1043 (string_option t.dev_alias)
1044 (string_of_action t.action)
1045 (string_option t.reason)
1047 let make (src_path, dev_alias, action, reason) = {
1048 src_path = src_path;
1049 dev_alias = dev_alias;
1050 action = action_of_int action;
1054 let make_noreason (src_path, dev_alias, action) =
1055 make (src_path, dev_alias, action, None)
1058 module Graphics_address = struct
1063 | `Unknown of int (* newer libvirt *)
1066 let string_of_family = function
1070 | `Unknown x -> Printf.sprintf "Unknown Graphics_address.family: %d" x
1072 let family_of_int = function
1080 family: family; (** Address family *)
1081 node: string option; (** Address of node (eg IP address, or UNIX path *)
1082 service: string option; (** Service name/number (eg TCP port, or NULL) *)
1085 let to_string t = Printf.sprintf
1086 "{ family = %s; node = %s; service = %s }"
1087 (string_of_family t.family)
1088 (string_option t.node)
1089 (string_option t.service)
1091 let make (family, node, service) = {
1092 family = family_of_int family;
1098 module Graphics_subject = struct
1101 name: string option;
1104 let string_of_identity t = Printf.sprintf
1105 "{ ty = %s; name = %s }"
1106 (string_option t.ty)
1107 (string_option t.name)
1109 type t = identity list
1112 "[ " ^ (String.concat "; " (List.map string_of_identity ts)) ^ " ]"
1115 List.map (fun (ty, name) -> { ty = ty; name = name })
1119 module Graphics = struct
1124 | `Unknown of int (** newer libvirt *)
1127 let string_of_phase = function
1128 | `Connect -> "Connect"
1129 | `Initialize -> "Initialize"
1130 | `Disconnect -> "Disconnect"
1131 | `Unknown x -> Printf.sprintf "Unknown Graphics.phase: %d" x
1133 let phase_of_int = function
1140 phase: phase; (** the phase of the connection *)
1141 local: Graphics_address.t; (** the local server address *)
1142 remote: Graphics_address.t; (** the remote client address *)
1143 auth_scheme: string option; (** the authentication scheme activated *)
1144 subject: Graphics_subject.t; (** the authenticated subject (user) *)
1148 let phase = Printf.sprintf "phase = %s"
1149 (string_of_phase t.phase) in
1150 let local = Printf.sprintf "local = %s"
1151 (Graphics_address.to_string t.local) in
1152 let remote = Printf.sprintf "remote = %s"
1153 (Graphics_address.to_string t.remote) in
1154 let auth_scheme = Printf.sprintf "auth_scheme = %s"
1155 (string_option t.auth_scheme) in
1156 let subject = Printf.sprintf "subject = %s"
1157 (Graphics_subject.to_string t.subject) in
1158 "{ " ^ (String.concat "; " [ phase; local; remote; auth_scheme; subject ]) ^ " }"
1160 let make (phase, local, remote, auth_scheme, subject) = {
1161 phase = phase_of_int phase;
1162 local = Graphics_address.make local;
1163 remote = Graphics_address.make remote;
1164 auth_scheme = auth_scheme;
1165 subject = Graphics_subject.make subject;
1169 module Control_error = struct
1172 let to_string () = "()"
1177 module Block_job = struct
1179 | `KnownUnknown (* explicitly named UNKNOWN in the spec *)
1183 | `Unknown of int (* newer libvirt *)
1186 let string_of_ty = function
1187 | `KnownUnknown -> "KnownUnknown"
1190 | `Commit -> "Commit"
1191 | `Unknown x -> Printf.sprintf "Unknown Block_job.ty: %d" x
1193 let ty_of_int = function
1194 | 0 -> `KnownUnknown
1198 | x -> `Unknown x (* newer libvirt *)
1208 let string_of_status = function
1209 | `Completed -> "Completed"
1210 | `Failed -> "Failed"
1211 | `Cancelled -> "Cancelled"
1213 | `Unknown x -> Printf.sprintf "Unknown Block_job.status: %d" x
1215 let status_of_int = function
1223 disk: string option;
1228 let to_string t = Printf.sprintf "{ disk = %s; ty = %s; status = %s }"
1229 (string_option t.disk)
1231 (string_of_status t.status)
1233 let make (disk, ty, status) = {
1236 status = status_of_int ty;
1240 module Disk_change = struct
1246 let string_of_reason = function
1247 | `MissingOnStart -> "MissingOnStart"
1248 | `Unknown x -> Printf.sprintf "Unknown Disk_change.reason: %d" x
1250 let reason_of_int = function
1251 | 0 -> `MissingOnStart
1255 old_src_path: string option;
1256 new_src_path: string option;
1257 dev_alias: string option;
1262 let o = Printf.sprintf "old_src_path = %s" (string_option t.old_src_path) in
1263 let n = Printf.sprintf "new_src_path = %s" (string_option t.new_src_path) in
1264 let d = Printf.sprintf "dev_alias = %s" (string_option t.dev_alias) in
1265 let r = string_of_reason t.reason in
1266 "{ " ^ (String.concat "; " [ o; n; d; r ]) ^ " }"
1268 let make (o, n, d, r) = {
1272 reason = reason_of_int r;
1276 module Tray_change = struct
1283 let string_of_reason = function
1286 | `Unknown x -> Printf.sprintf "Unknown Tray_change.reason: %d" x
1288 let reason_of_int = function
1294 dev_alias: string option;
1298 let to_string t = Printf.sprintf
1299 "{ dev_alias = %s; reason = %s }"
1300 (string_option t.dev_alias)
1301 (string_of_reason t.reason)
1303 let make (dev_alias, reason) = {
1304 dev_alias = dev_alias;
1305 reason = reason_of_int reason;
1309 module PM_wakeup = struct
1316 let to_string = function
1317 | `Unknown x -> Printf.sprintf "Unknown PM_wakeup.reason: %d" x
1319 let make x = `Unknown x
1322 module PM_suspend = struct
1329 let to_string = function
1330 | `Unknown x -> Printf.sprintf "Unknown PM_suspend.reason: %d" x
1332 let make x = `Unknown x
1335 module Balloon_change = struct
1338 let to_string = Int64.to_string
1342 module PM_suspend_disk = struct
1349 let to_string = function
1350 | `Unknown x -> Printf.sprintf "Unknown PM_suspend_disk.reason: %d" x
1352 let make x = `Unknown x
1356 | Lifecycle of ([`R] Domain.t -> Lifecycle.t -> unit)
1357 | Reboot of ([`R] Domain.t -> Reboot.t -> unit)
1358 | RtcChange of ([`R] Domain.t -> Rtc_change.t -> unit)
1359 | Watchdog of ([`R] Domain.t -> Watchdog.t -> unit)
1360 | IOError of ([`R] Domain.t -> Io_error.t -> unit)
1361 | Graphics of ([`R] Domain.t -> Graphics.t -> unit)
1362 | IOErrorReason of ([`R] Domain.t -> Io_error.t -> unit)
1363 | ControlError of ([`R] Domain.t -> Control_error.t -> unit)
1364 | BlockJob of ([`R] Domain.t -> Block_job.t -> unit)
1365 | DiskChange of ([`R] Domain.t -> Disk_change.t -> unit)
1366 | TrayChange of ([`R] Domain.t -> Tray_change.t -> unit)
1367 | PMWakeUp of ([`R] Domain.t -> PM_wakeup.t -> unit)
1368 | PMSuspend of ([`R] Domain.t -> PM_suspend.t -> unit)
1369 | BalloonChange of ([`R] Domain.t -> Balloon_change.t -> unit)
1370 | PMSuspendDisk of ([`R] Domain.t -> PM_suspend_disk.t -> unit)
1372 type callback_id = int64
1374 let fresh_callback_id =
1375 let next = ref 0L in
1377 let result = !next in
1378 next := Int64.succ !next;
1381 let make_table value_name =
1382 let table = Hashtbl.create 16 in
1383 let callback callback_id generic x =
1384 if Hashtbl.mem table callback_id
1385 then Hashtbl.find table callback_id generic x in
1386 let _ = Callback.register value_name callback in
1389 let u_table = make_table "Libvirt.u_callback"
1390 let i_table = make_table "Libvirt.i_callback"
1391 let i64_table = make_table "Libvirt.i64_callback"
1392 let i_i_table = make_table "Libvirt.i_i_callback"
1393 let s_i_table = make_table "Libvirt.s_i_callback"
1394 let s_i_i_table = make_table "Libvirt.s_i_i_callback"
1395 let s_s_i_table = make_table "Libvirt.s_s_i_callback"
1396 let s_s_i_s_table = make_table "Libvirt.s_s_i_s_callback"
1397 let s_s_s_i_table = make_table "Libvirt.s_s_s_i_callback"
1398 let i_ga_ga_s_gs_table = make_table "Libvirt.i_ga_ga_s_gs_callback"
1400 external register_default_impl : unit -> unit = "ocaml_libvirt_event_register_default_impl"
1402 external run_default_impl : unit -> unit = "ocaml_libvirt_event_run_default_impl"
1404 external register_any' : 'a Connect.t -> 'a Domain.t option -> callback -> callback_id -> int = "ocaml_libvirt_connect_domain_event_register_any"
1406 external deregister_any' : 'a Connect.t -> int -> unit = "ocaml_libvirt_connect_domain_event_deregister_any"
1408 let our_id_to_libvirt_id = Hashtbl.create 16
1410 let register_any conn ?dom callback =
1411 let id = fresh_callback_id () in
1412 begin match callback with
1414 Hashtbl.add i_i_table id (fun dom x ->
1415 f dom (Lifecycle.make x)
1418 Hashtbl.add u_table id (fun dom x ->
1419 f dom (Reboot.make x)
1422 Hashtbl.add i64_table id (fun dom x ->
1423 f dom (Rtc_change.make x)
1426 Hashtbl.add i_table id (fun dom x ->
1427 f dom (Watchdog.make x)
1430 Hashtbl.add s_s_i_table id (fun dom x ->
1431 f dom (Io_error.make_noreason x)
1434 Hashtbl.add i_ga_ga_s_gs_table id (fun dom x ->
1435 f dom (Graphics.make x)
1437 | IOErrorReason f ->
1438 Hashtbl.add s_s_i_s_table id (fun dom x ->
1439 f dom (Io_error.make x)
1442 Hashtbl.add u_table id (fun dom x ->
1443 f dom (Control_error.make x)
1446 Hashtbl.add s_i_i_table id (fun dom x ->
1447 f dom (Block_job.make x)
1450 Hashtbl.add s_s_s_i_table id (fun dom x ->
1451 f dom (Disk_change.make x)
1454 Hashtbl.add s_i_table id (fun dom x ->
1455 f dom (Tray_change.make x)
1458 Hashtbl.add i_table id (fun dom x ->
1459 f dom (PM_wakeup.make x)
1462 Hashtbl.add i_table id (fun dom x ->
1463 f dom (PM_suspend.make x)
1465 | BalloonChange f ->
1466 Hashtbl.add i64_table id (fun dom x ->
1467 f dom (Balloon_change.make x)
1469 | PMSuspendDisk f ->
1470 Hashtbl.add i_table id (fun dom x ->
1471 f dom (PM_suspend_disk.make x)
1474 let libvirt_id = register_any' conn dom callback id in
1475 Hashtbl.replace our_id_to_libvirt_id id libvirt_id;
1478 let deregister_any conn id =
1479 if Hashtbl.mem our_id_to_libvirt_id id then begin
1480 let libvirt_id = Hashtbl.find our_id_to_libvirt_id id in
1481 deregister_any' conn libvirt_id
1483 Hashtbl.remove our_id_to_libvirt_id id;
1484 Hashtbl.remove u_table id;
1485 Hashtbl.remove i_table id;
1486 Hashtbl.remove i64_table id;
1487 Hashtbl.remove i_i_table id;
1488 Hashtbl.remove s_i_table id;
1489 Hashtbl.remove s_i_i_table id;
1490 Hashtbl.remove s_s_i_table id;
1491 Hashtbl.remove s_s_i_s_table id;
1492 Hashtbl.remove s_s_s_i_table id;
1493 Hashtbl.remove i_ga_ga_s_gs_table id
1495 let timeout_table = Hashtbl.create 16
1498 if Hashtbl.mem timeout_table x
1499 then Hashtbl.find timeout_table x () in
1500 Callback.register "Libvirt.timeout_callback" callback
1502 type timer_id = int64
1504 external add_timeout' : 'a Connect.t -> int -> int64 -> int = "ocaml_libvirt_event_add_timeout"
1506 external remove_timeout' : 'a Connect.t -> int -> unit = "ocaml_libvirt_event_remove_timeout"
1508 let our_id_to_timer_id = Hashtbl.create 16
1509 let add_timeout conn ms fn =
1510 let id = fresh_callback_id () in
1511 Hashtbl.add timeout_table id fn;
1512 let timer_id = add_timeout' conn ms id in
1513 Hashtbl.add our_id_to_timer_id id timer_id;
1516 let remove_timeout conn id =
1517 if Hashtbl.mem our_id_to_timer_id id then begin
1518 let timer_id = Hashtbl.find our_id_to_timer_id id in
1519 remove_timeout' conn timer_id
1521 Hashtbl.remove our_id_to_timer_id id;
1522 Hashtbl.remove timeout_table id
1529 external lookup_by_name : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_network_lookup_by_name"
1530 external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_network_lookup_by_uuid"
1531 external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_network_lookup_by_uuid_string"
1532 external create_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_network_create_xml"
1533 external define_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_network_define_xml"
1534 external undefine : [>`W] t -> unit = "ocaml_libvirt_network_undefine"
1535 external create : [>`W] t -> unit = "ocaml_libvirt_network_create"
1536 external destroy : [>`W] t -> unit = "ocaml_libvirt_network_destroy"
1537 external free : [>`R] t -> unit = "ocaml_libvirt_network_free"
1538 external get_name : [>`R] t -> string = "ocaml_libvirt_network_get_name"
1539 external get_uuid : [>`R] t -> uuid = "ocaml_libvirt_network_get_uuid"
1540 external get_uuid_string : [>`R] t -> string = "ocaml_libvirt_network_get_uuid_string"
1541 external get_xml_desc : [>`R] t -> xml = "ocaml_libvirt_network_get_xml_desc"
1542 external get_bridge_name : [>`R] t -> string = "ocaml_libvirt_network_get_bridge_name"
1543 external get_autostart : [>`R] t -> bool = "ocaml_libvirt_network_get_autostart"
1544 external set_autostart : [>`W] t -> bool -> unit = "ocaml_libvirt_network_set_autostart"
1546 external const : [>`R] t -> ro t = "%identity"
1552 type pool_state = Inactive | Building | Running | Degraded
1553 type pool_build_flags = New | Repair | Resize
1554 type pool_delete_flags = Normal | Zeroed
1562 external lookup_by_name : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_storage_pool_lookup_by_name"
1563 external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_storage_pool_lookup_by_uuid"
1564 external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_storage_pool_lookup_by_uuid_string"
1565 external create_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_storage_pool_create_xml"
1566 external define_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_storage_pool_define_xml"
1567 external build : [>`W] t -> pool_build_flags -> unit = "ocaml_libvirt_storage_pool_build"
1568 external undefine : [>`W] t -> unit = "ocaml_libvirt_storage_pool_undefine"
1569 external create : [>`W] t -> unit = "ocaml_libvirt_storage_pool_create"
1570 external destroy : [>`W] t -> unit = "ocaml_libvirt_storage_pool_destroy"
1571 external delete : [>`W] t -> unit = "ocaml_libvirt_storage_pool_delete"
1572 external free : [>`R] t -> unit = "ocaml_libvirt_storage_pool_free"
1573 external refresh : [`R] t -> unit = "ocaml_libvirt_storage_pool_refresh"
1574 external get_name : [`R] t -> string = "ocaml_libvirt_storage_pool_get_name"
1575 external get_uuid : [`R] t -> uuid = "ocaml_libvirt_storage_pool_get_uuid"
1576 external get_uuid_string : [`R] t -> string = "ocaml_libvirt_storage_pool_get_uuid_string"
1577 external get_info : [`R] t -> pool_info = "ocaml_libvirt_storage_pool_get_info"
1578 external get_xml_desc : [`R] t -> xml = "ocaml_libvirt_storage_pool_get_xml_desc"
1579 external get_autostart : [`R] t -> bool = "ocaml_libvirt_storage_pool_get_autostart"
1580 external set_autostart : [>`W] t -> bool -> unit = "ocaml_libvirt_storage_pool_set_autostart"
1581 external num_of_volumes : [`R] t -> int = "ocaml_libvirt_storage_pool_num_of_volumes"
1582 external list_volumes : [`R] t -> int -> string array = "ocaml_libvirt_storage_pool_list_volumes"
1583 external const : [>`R] t -> ro t = "%identity"
1589 type vol_type = File | Block
1590 type vol_delete_flags = Normal | Zeroed
1597 external lookup_by_name : 'a Pool.t -> string -> 'a t = "ocaml_libvirt_storage_vol_lookup_by_name"
1598 external lookup_by_key : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_storage_vol_lookup_by_key"
1599 external lookup_by_path : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_storage_vol_lookup_by_path"
1600 external pool_of_volume : 'a t -> 'a Pool.t = "ocaml_libvirt_storage_pool_lookup_by_volume"
1601 external get_name : [`R] t -> string = "ocaml_libvirt_storage_vol_get_name"
1602 external get_key : [`R] t -> string = "ocaml_libvirt_storage_vol_get_key"
1603 external get_path : [`R] t -> string = "ocaml_libvirt_storage_vol_get_path"
1604 external get_info : [`R] t -> vol_info = "ocaml_libvirt_storage_vol_get_info"
1605 external get_xml_desc : [`R] t -> xml = "ocaml_libvirt_storage_vol_get_xml_desc"
1606 external create_xml : [>`W] Pool.t -> xml -> unit = "ocaml_libvirt_storage_vol_create_xml"
1607 external delete : [>`W] t -> vol_delete_flags -> unit = "ocaml_libvirt_storage_vol_delete"
1608 external free : [>`R] t -> unit = "ocaml_libvirt_storage_vol_free"
1609 external const : [>`R] t -> ro t = "%identity"
1612 (* Initialization. *)
1613 external c_init : unit -> unit = "ocaml_libvirt_init"
1615 Callback.register_exception
1616 "ocaml_libvirt_virterror" (Virterror (Virterror.no_error ()));
1617 Callback.register_exception
1618 "ocaml_libvirt_not_supported" (Not_supported "");