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 (* Internal API needed for get_auth_default. *)
131 external _credtypes_from_auth_default : unit -> credential_type list = "ocaml_libvirt_connect_credtypes_from_auth_default"
132 external _call_auth_default_callback : credential list -> string option list = "ocaml_libvirt_connect_call_auth_default_callback"
133 let get_auth_default () =
135 credtype = _credtypes_from_auth_default ();
136 cb = _call_auth_default_callback;
139 external const : [>`R] t -> ro t = "%identity"
146 | VIR_ERR_INTERNAL_ERROR
149 | VIR_ERR_UNKNOWN_HOST
151 | VIR_ERR_INVALID_CONN
152 | VIR_ERR_INVALID_DOMAIN
153 | VIR_ERR_INVALID_ARG
154 | VIR_ERR_OPERATION_FAILED
156 | VIR_ERR_POST_FAILED
158 | VIR_ERR_SEXPR_SERIAL
169 | VIR_ERR_NO_XENSTORE
170 | VIR_ERR_DRIVER_FULL
171 | VIR_ERR_CALL_FAILED
174 | VIR_ERR_OPERATION_DENIED
175 | VIR_ERR_OPEN_FAILED
176 | VIR_ERR_READ_FAILED
177 | VIR_ERR_PARSE_FAILED
178 | VIR_ERR_CONF_SYNTAX
179 | VIR_ERR_WRITE_FAILED
181 | VIR_ERR_INVALID_NETWORK
182 | VIR_ERR_NETWORK_EXIST
183 | VIR_ERR_SYSTEM_ERROR
185 | VIR_ERR_GNUTLS_ERROR
189 | VIR_ERR_INVALID_MAC
190 | VIR_ERR_AUTH_FAILED
191 | VIR_ERR_INVALID_STORAGE_POOL
192 | VIR_ERR_INVALID_STORAGE_VOL
194 | VIR_ERR_NO_STORAGE_POOL
195 | VIR_ERR_NO_STORAGE_VOL
197 | VIR_ERR_INVALID_NODE_DEVICE
198 | VIR_ERR_NO_NODE_DEVICE
199 | VIR_ERR_NO_SECURITY_MODEL
200 | VIR_ERR_OPERATION_INVALID
201 | VIR_WAR_NO_INTERFACE
202 | VIR_ERR_NO_INTERFACE
203 | VIR_ERR_INVALID_INTERFACE
204 | VIR_ERR_MULTIPLE_INTERFACES
205 | VIR_WAR_NO_NWFILTER
206 | VIR_ERR_INVALID_NWFILTER
207 | VIR_ERR_NO_NWFILTER
208 | VIR_ERR_BUILD_FIREWALL
210 | VIR_ERR_INVALID_SECRET
212 | VIR_ERR_CONFIG_UNSUPPORTED
213 | VIR_ERR_OPERATION_TIMEOUT
214 | VIR_ERR_MIGRATE_PERSIST_FAILED
215 | VIR_ERR_HOOK_SCRIPT_FAILED
216 | VIR_ERR_INVALID_DOMAIN_SNAPSHOT
217 | VIR_ERR_NO_DOMAIN_SNAPSHOT
218 | VIR_ERR_INVALID_STREAM
219 | VIR_ERR_ARGUMENT_UNSUPPORTED
220 | VIR_ERR_STORAGE_PROBE_FAILED
221 | VIR_ERR_STORAGE_POOL_BUILT
222 | VIR_ERR_SNAPSHOT_REVERT_RISKY
223 | VIR_ERR_OPERATION_ABORTED
224 | VIR_ERR_AUTH_CANCELLED
225 | VIR_ERR_NO_DOMAIN_METADATA
226 | VIR_ERR_MIGRATE_UNSAFE
228 | VIR_ERR_BLOCK_COPY_ACTIVE
229 | VIR_ERR_OPERATION_UNSUPPORTED
231 | VIR_ERR_AGENT_UNRESPONSIVE
232 | VIR_ERR_RESOURCE_BUSY
233 | VIR_ERR_ACCESS_DENIED
234 | VIR_ERR_DBUS_SERVICE
235 | VIR_ERR_STORAGE_VOL_EXIST
236 | VIR_ERR_CPU_INCOMPATIBLE
237 | VIR_ERR_XML_INVALID_SCHEMA
238 | VIR_ERR_MIGRATE_FINISH_OK
239 | VIR_ERR_AUTH_UNAVAILABLE
242 | VIR_ERR_AGENT_UNSYNCED
244 | VIR_ERR_DEVICE_MISSING
245 | VIR_ERR_INVALID_NWFILTER_BINDING
246 | VIR_ERR_NO_NWFILTER_BINDING
247 | VIR_ERR_UNKNOWN of int
249 let string_of_code = function
250 | VIR_ERR_OK -> "VIR_ERR_OK"
251 | VIR_ERR_INTERNAL_ERROR -> "VIR_ERR_INTERNAL_ERROR"
252 | VIR_ERR_NO_MEMORY -> "VIR_ERR_NO_MEMORY"
253 | VIR_ERR_NO_SUPPORT -> "VIR_ERR_NO_SUPPORT"
254 | VIR_ERR_UNKNOWN_HOST -> "VIR_ERR_UNKNOWN_HOST"
255 | VIR_ERR_NO_CONNECT -> "VIR_ERR_NO_CONNECT"
256 | VIR_ERR_INVALID_CONN -> "VIR_ERR_INVALID_CONN"
257 | VIR_ERR_INVALID_DOMAIN -> "VIR_ERR_INVALID_DOMAIN"
258 | VIR_ERR_INVALID_ARG -> "VIR_ERR_INVALID_ARG"
259 | VIR_ERR_OPERATION_FAILED -> "VIR_ERR_OPERATION_FAILED"
260 | VIR_ERR_GET_FAILED -> "VIR_ERR_GET_FAILED"
261 | VIR_ERR_POST_FAILED -> "VIR_ERR_POST_FAILED"
262 | VIR_ERR_HTTP_ERROR -> "VIR_ERR_HTTP_ERROR"
263 | VIR_ERR_SEXPR_SERIAL -> "VIR_ERR_SEXPR_SERIAL"
264 | VIR_ERR_NO_XEN -> "VIR_ERR_NO_XEN"
265 | VIR_ERR_XEN_CALL -> "VIR_ERR_XEN_CALL"
266 | VIR_ERR_OS_TYPE -> "VIR_ERR_OS_TYPE"
267 | VIR_ERR_NO_KERNEL -> "VIR_ERR_NO_KERNEL"
268 | VIR_ERR_NO_ROOT -> "VIR_ERR_NO_ROOT"
269 | VIR_ERR_NO_SOURCE -> "VIR_ERR_NO_SOURCE"
270 | VIR_ERR_NO_TARGET -> "VIR_ERR_NO_TARGET"
271 | VIR_ERR_NO_NAME -> "VIR_ERR_NO_NAME"
272 | VIR_ERR_NO_OS -> "VIR_ERR_NO_OS"
273 | VIR_ERR_NO_DEVICE -> "VIR_ERR_NO_DEVICE"
274 | VIR_ERR_NO_XENSTORE -> "VIR_ERR_NO_XENSTORE"
275 | VIR_ERR_DRIVER_FULL -> "VIR_ERR_DRIVER_FULL"
276 | VIR_ERR_CALL_FAILED -> "VIR_ERR_CALL_FAILED"
277 | VIR_ERR_XML_ERROR -> "VIR_ERR_XML_ERROR"
278 | VIR_ERR_DOM_EXIST -> "VIR_ERR_DOM_EXIST"
279 | VIR_ERR_OPERATION_DENIED -> "VIR_ERR_OPERATION_DENIED"
280 | VIR_ERR_OPEN_FAILED -> "VIR_ERR_OPEN_FAILED"
281 | VIR_ERR_READ_FAILED -> "VIR_ERR_READ_FAILED"
282 | VIR_ERR_PARSE_FAILED -> "VIR_ERR_PARSE_FAILED"
283 | VIR_ERR_CONF_SYNTAX -> "VIR_ERR_CONF_SYNTAX"
284 | VIR_ERR_WRITE_FAILED -> "VIR_ERR_WRITE_FAILED"
285 | VIR_ERR_XML_DETAIL -> "VIR_ERR_XML_DETAIL"
286 | VIR_ERR_INVALID_NETWORK -> "VIR_ERR_INVALID_NETWORK"
287 | VIR_ERR_NETWORK_EXIST -> "VIR_ERR_NETWORK_EXIST"
288 | VIR_ERR_SYSTEM_ERROR -> "VIR_ERR_SYSTEM_ERROR"
289 | VIR_ERR_RPC -> "VIR_ERR_RPC"
290 | VIR_ERR_GNUTLS_ERROR -> "VIR_ERR_GNUTLS_ERROR"
291 | VIR_WAR_NO_NETWORK -> "VIR_WAR_NO_NETWORK"
292 | VIR_ERR_NO_DOMAIN -> "VIR_ERR_NO_DOMAIN"
293 | VIR_ERR_NO_NETWORK -> "VIR_ERR_NO_NETWORK"
294 | VIR_ERR_INVALID_MAC -> "VIR_ERR_INVALID_MAC"
295 | VIR_ERR_AUTH_FAILED -> "VIR_ERR_AUTH_FAILED"
296 | VIR_ERR_INVALID_STORAGE_POOL -> "VIR_ERR_INVALID_STORAGE_POOL"
297 | VIR_ERR_INVALID_STORAGE_VOL -> "VIR_ERR_INVALID_STORAGE_VOL"
298 | VIR_WAR_NO_STORAGE -> "VIR_WAR_NO_STORAGE"
299 | VIR_ERR_NO_STORAGE_POOL -> "VIR_ERR_NO_STORAGE_POOL"
300 | VIR_ERR_NO_STORAGE_VOL -> "VIR_ERR_NO_STORAGE_VOL"
301 | VIR_WAR_NO_NODE -> "VIR_WAR_NO_NODE"
302 | VIR_ERR_INVALID_NODE_DEVICE -> "VIR_ERR_INVALID_NODE_DEVICE"
303 | VIR_ERR_NO_NODE_DEVICE -> "VIR_ERR_NO_NODE_DEVICE"
304 | VIR_ERR_NO_SECURITY_MODEL -> "VIR_ERR_NO_SECURITY_MODEL"
305 | VIR_ERR_OPERATION_INVALID -> "VIR_ERR_OPERATION_INVALID"
306 | VIR_WAR_NO_INTERFACE -> "VIR_WAR_NO_INTERFACE"
307 | VIR_ERR_NO_INTERFACE -> "VIR_ERR_NO_INTERFACE"
308 | VIR_ERR_INVALID_INTERFACE -> "VIR_ERR_INVALID_INTERFACE"
309 | VIR_ERR_MULTIPLE_INTERFACES -> "VIR_ERR_MULTIPLE_INTERFACES"
310 | VIR_WAR_NO_NWFILTER -> "VIR_WAR_NO_NWFILTER"
311 | VIR_ERR_INVALID_NWFILTER -> "VIR_ERR_INVALID_NWFILTER"
312 | VIR_ERR_NO_NWFILTER -> "VIR_ERR_NO_NWFILTER"
313 | VIR_ERR_BUILD_FIREWALL -> "VIR_ERR_BUILD_FIREWALL"
314 | VIR_WAR_NO_SECRET -> "VIR_WAR_NO_SECRET"
315 | VIR_ERR_INVALID_SECRET -> "VIR_ERR_INVALID_SECRET"
316 | VIR_ERR_NO_SECRET -> "VIR_ERR_NO_SECRET"
317 | VIR_ERR_CONFIG_UNSUPPORTED -> "VIR_ERR_CONFIG_UNSUPPORTED"
318 | VIR_ERR_OPERATION_TIMEOUT -> "VIR_ERR_OPERATION_TIMEOUT"
319 | VIR_ERR_MIGRATE_PERSIST_FAILED -> "VIR_ERR_MIGRATE_PERSIST_FAILED"
320 | VIR_ERR_HOOK_SCRIPT_FAILED -> "VIR_ERR_HOOK_SCRIPT_FAILED"
321 | VIR_ERR_INVALID_DOMAIN_SNAPSHOT -> "VIR_ERR_INVALID_DOMAIN_SNAPSHOT"
322 | VIR_ERR_NO_DOMAIN_SNAPSHOT -> "VIR_ERR_NO_DOMAIN_SNAPSHOT"
323 | VIR_ERR_INVALID_STREAM -> "VIR_ERR_INVALID_STREAM"
324 | VIR_ERR_ARGUMENT_UNSUPPORTED -> "VIR_ERR_ARGUMENT_UNSUPPORTED"
325 | VIR_ERR_STORAGE_PROBE_FAILED -> "VIR_ERR_STORAGE_PROBE_FAILED"
326 | VIR_ERR_STORAGE_POOL_BUILT -> "VIR_ERR_STORAGE_POOL_BUILT"
327 | VIR_ERR_SNAPSHOT_REVERT_RISKY -> "VIR_ERR_SNAPSHOT_REVERT_RISKY"
328 | VIR_ERR_OPERATION_ABORTED -> "VIR_ERR_OPERATION_ABORTED"
329 | VIR_ERR_AUTH_CANCELLED -> "VIR_ERR_AUTH_CANCELLED"
330 | VIR_ERR_NO_DOMAIN_METADATA -> "VIR_ERR_NO_DOMAIN_METADATA"
331 | VIR_ERR_MIGRATE_UNSAFE -> "VIR_ERR_MIGRATE_UNSAFE"
332 | VIR_ERR_OVERFLOW -> "VIR_ERR_OVERFLOW"
333 | VIR_ERR_BLOCK_COPY_ACTIVE -> "VIR_ERR_BLOCK_COPY_ACTIVE"
334 | VIR_ERR_OPERATION_UNSUPPORTED -> "VIR_ERR_OPERATION_UNSUPPORTED"
335 | VIR_ERR_SSH -> "VIR_ERR_SSH"
336 | VIR_ERR_AGENT_UNRESPONSIVE -> "VIR_ERR_AGENT_UNRESPONSIVE"
337 | VIR_ERR_RESOURCE_BUSY -> "VIR_ERR_RESOURCE_BUSY"
338 | VIR_ERR_ACCESS_DENIED -> "VIR_ERR_ACCESS_DENIED"
339 | VIR_ERR_DBUS_SERVICE -> "VIR_ERR_DBUS_SERVICE"
340 | VIR_ERR_STORAGE_VOL_EXIST -> "VIR_ERR_STORAGE_VOL_EXIST"
341 | VIR_ERR_CPU_INCOMPATIBLE -> "VIR_ERR_CPU_INCOMPATIBLE"
342 | VIR_ERR_XML_INVALID_SCHEMA -> "VIR_ERR_XML_INVALID_SCHEMA"
343 | VIR_ERR_MIGRATE_FINISH_OK -> "VIR_ERR_MIGRATE_FINISH_OK"
344 | VIR_ERR_AUTH_UNAVAILABLE -> "VIR_ERR_AUTH_UNAVAILABLE"
345 | VIR_ERR_NO_SERVER -> "VIR_ERR_NO_SERVER"
346 | VIR_ERR_NO_CLIENT -> "VIR_ERR_NO_CLIENT"
347 | VIR_ERR_AGENT_UNSYNCED -> "VIR_ERR_AGENT_UNSYNCED"
348 | VIR_ERR_LIBSSH -> "VIR_ERR_LIBSSH"
349 | VIR_ERR_DEVICE_MISSING -> "VIR_ERR_DEVICE_MISSING"
350 | VIR_ERR_INVALID_NWFILTER_BINDING -> "VIR_ERR_INVALID_NWFILTER_BINDING"
351 | VIR_ERR_NO_NWFILTER_BINDING -> "VIR_ERR_NO_NWFILTER_BINDING"
352 | VIR_ERR_UNKNOWN i -> "VIR_ERR_" ^ string_of_int i
371 | VIR_FROM_STATS_LINUX
378 | VIR_FROM_XEN_INOTIFY
390 | VIR_FROM_DOMAIN_SNAPSHOT
399 | VIR_FROM_CAPABILITIES
423 | VIR_FROM_UNKNOWN of int
425 let string_of_domain = function
426 | VIR_FROM_NONE -> "VIR_FROM_NONE"
427 | VIR_FROM_XEN -> "VIR_FROM_XEN"
428 | VIR_FROM_XEND -> "VIR_FROM_XEND"
429 | VIR_FROM_XENSTORE -> "VIR_FROM_XENSTORE"
430 | VIR_FROM_SEXPR -> "VIR_FROM_SEXPR"
431 | VIR_FROM_XML -> "VIR_FROM_XML"
432 | VIR_FROM_DOM -> "VIR_FROM_DOM"
433 | VIR_FROM_RPC -> "VIR_FROM_RPC"
434 | VIR_FROM_PROXY -> "VIR_FROM_PROXY"
435 | VIR_FROM_CONF -> "VIR_FROM_CONF"
436 | VIR_FROM_QEMU -> "VIR_FROM_QEMU"
437 | VIR_FROM_NET -> "VIR_FROM_NET"
438 | VIR_FROM_TEST -> "VIR_FROM_TEST"
439 | VIR_FROM_REMOTE -> "VIR_FROM_REMOTE"
440 | VIR_FROM_OPENVZ -> "VIR_FROM_OPENVZ"
441 | VIR_FROM_XENXM -> "VIR_FROM_XENXM"
442 | VIR_FROM_STATS_LINUX -> "VIR_FROM_STATS_LINUX"
443 | VIR_FROM_LXC -> "VIR_FROM_LXC"
444 | VIR_FROM_STORAGE -> "VIR_FROM_STORAGE"
445 | VIR_FROM_NETWORK -> "VIR_FROM_NETWORK"
446 | VIR_FROM_DOMAIN -> "VIR_FROM_DOMAIN"
447 | VIR_FROM_UML -> "VIR_FROM_UML"
448 | VIR_FROM_NODEDEV -> "VIR_FROM_NODEDEV"
449 | VIR_FROM_XEN_INOTIFY -> "VIR_FROM_XEN_INOTIFY"
450 | VIR_FROM_SECURITY -> "VIR_FROM_SECURITY"
451 | VIR_FROM_VBOX -> "VIR_FROM_VBOX"
452 | VIR_FROM_INTERFACE -> "VIR_FROM_INTERFACE"
453 | VIR_FROM_ONE -> "VIR_FROM_ONE"
454 | VIR_FROM_ESX -> "VIR_FROM_ESX"
455 | VIR_FROM_PHYP -> "VIR_FROM_PHYP"
456 | VIR_FROM_SECRET -> "VIR_FROM_SECRET"
457 | VIR_FROM_CPU -> "VIR_FROM_CPU"
458 | VIR_FROM_XENAPI -> "VIR_FROM_XENAPI"
459 | VIR_FROM_NWFILTER -> "VIR_FROM_NWFILTER"
460 | VIR_FROM_HOOK -> "VIR_FROM_HOOK"
461 | VIR_FROM_DOMAIN_SNAPSHOT -> "VIR_FROM_DOMAIN_SNAPSHOT"
462 | VIR_FROM_AUDIT -> "VIR_FROM_AUDIT"
463 | VIR_FROM_SYSINFO -> "VIR_FROM_SYSINFO"
464 | VIR_FROM_STREAMS -> "VIR_FROM_STREAMS"
465 | VIR_FROM_VMWARE -> "VIR_FROM_VMWARE"
466 | VIR_FROM_EVENT -> "VIR_FROM_EVENT"
467 | VIR_FROM_LIBXL -> "VIR_FROM_LIBXL"
468 | VIR_FROM_LOCKING -> "VIR_FROM_LOCKING"
469 | VIR_FROM_HYPERV -> "VIR_FROM_HYPERV"
470 | VIR_FROM_CAPABILITIES -> "VIR_FROM_CAPABILITIES"
471 | VIR_FROM_URI -> "VIR_FROM_URI"
472 | VIR_FROM_AUTH -> "VIR_FROM_AUTH"
473 | VIR_FROM_DBUS -> "VIR_FROM_DBUS"
474 | VIR_FROM_PARALLELS -> "VIR_FROM_PARALLELS"
475 | VIR_FROM_DEVICE -> "VIR_FROM_DEVICE"
476 | VIR_FROM_SSH -> "VIR_FROM_SSH"
477 | VIR_FROM_LOCKSPACE -> "VIR_FROM_LOCKSPACE"
478 | VIR_FROM_INITCTL -> "VIR_FROM_INITCTL"
479 | VIR_FROM_IDENTITY -> "VIR_FROM_IDENTITY"
480 | VIR_FROM_CGROUP -> "VIR_FROM_CGROUP"
481 | VIR_FROM_ACCESS -> "VIR_FROM_ACCESS"
482 | VIR_FROM_SYSTEMD -> "VIR_FROM_SYSTEMD"
483 | VIR_FROM_BHYVE -> "VIR_FROM_BHYVE"
484 | VIR_FROM_CRYPTO -> "VIR_FROM_CRYPTO"
485 | VIR_FROM_FIREWALL -> "VIR_FROM_FIREWALL"
486 | VIR_FROM_POLKIT -> "VIR_FROM_POLKIT"
487 | VIR_FROM_THREAD -> "VIR_FROM_THREAD"
488 | VIR_FROM_ADMIN -> "VIR_FROM_ADMIN"
489 | VIR_FROM_LOGGING -> "VIR_FROM_LOGGING"
490 | VIR_FROM_XENXL -> "VIR_FROM_XENXL"
491 | VIR_FROM_PERF -> "VIR_FROM_PERF"
492 | VIR_FROM_LIBSSH -> "VIR_FROM_LIBSSH"
493 | VIR_FROM_RESCTRL -> "VIR_FROM_RESCTRL"
494 | VIR_FROM_UNKNOWN i -> "VIR_FROM_" ^ string_of_int i
500 | VIR_ERR_UNKNOWN_LEVEL of int
502 let string_of_level = function
503 | VIR_ERR_NONE -> "VIR_ERR_NONE"
504 | VIR_ERR_WARNING -> "VIR_ERR_WARNING"
505 | VIR_ERR_ERROR -> "VIR_ERR_ERROR"
506 | VIR_ERR_UNKNOWN_LEVEL i -> "VIR_ERR_LEVEL_" ^ string_of_int i
511 message : string option;
513 str1 : string option;
514 str2 : string option;
515 str3 : string option;
520 let to_string { code = code; domain = domain; message = message } =
521 let buf = Buffer.create 128 in
522 Buffer.add_string buf "libvirt: ";
523 Buffer.add_string buf (string_of_code code);
524 Buffer.add_string buf ": ";
525 Buffer.add_string buf (string_of_domain domain);
526 Buffer.add_string buf ": ";
527 (match message with Some msg -> Buffer.add_string buf msg | None -> ());
530 external get_last_error : unit -> t option = "ocaml_libvirt_virterror_get_last_error"
531 external get_last_conn_error : [>`R] Connect.t -> t option = "ocaml_libvirt_virterror_get_last_conn_error"
532 external reset_last_error : unit -> unit = "ocaml_libvirt_virterror_reset_last_error"
533 external reset_last_conn_error : [>`R] Connect.t -> unit = "ocaml_libvirt_virterror_reset_last_conn_error"
536 { code = VIR_ERR_OK; domain = VIR_FROM_NONE;
537 message = None; level = VIR_ERR_NONE;
538 str1 = None; str2 = None; str3 = None;
539 int1 = 0_l; int2 = 0_l }
542 exception Virterror of Virterror.t
543 exception Not_supported of string
545 let rec map_ignore_errors f = function
548 try f x :: map_ignore_errors f xs
549 with Virterror _ -> map_ignore_errors f xs
556 | InfoNoState | InfoRunning | InfoBlocked | InfoPaused
557 | InfoShutdown | InfoShutoff | InfoCrashed
567 type vcpu_state = VcpuOffline | VcpuRunning | VcpuBlocked
571 vcpu_state : vcpu_state;
576 type domain_create_flag =
582 let rec int_of_domain_create_flags = function
584 | START_PAUSED :: flags -> 1 lor int_of_domain_create_flags flags
585 | START_AUTODESTROY :: flags -> 2 lor int_of_domain_create_flags flags
586 | START_BYPASS_CACHE :: flags -> 4 lor int_of_domain_create_flags flags
587 | START_FORCE_BOOT :: flags -> 8 lor int_of_domain_create_flags flags
588 | START_VALIDATE :: flags -> 16 lor int_of_domain_create_flags flags
590 type sched_param = string * sched_param_value
591 and sched_param_value =
592 | SchedFieldInt32 of int32 | SchedFieldUInt32 of int32
593 | SchedFieldInt64 of int64 | SchedFieldUInt64 of int64
594 | SchedFieldFloat of float | SchedFieldBool of bool
596 type typed_param = string * typed_param_value
597 and typed_param_value =
598 | TypedFieldInt32 of int32 | TypedFieldUInt32 of int32
599 | TypedFieldInt64 of int64 | TypedFieldUInt64 of int64
600 | TypedFieldFloat of float | TypedFieldBool of bool
601 | TypedFieldString of string
603 type migrate_flag = Live
605 type memory_flag = Virtual
620 type interface_stats = {
631 type get_all_domain_stats_flag =
632 | GetAllDomainsStatsActive
633 | GetAllDomainsStatsInactive
634 | GetAllDomainsStatsOther
635 | GetAllDomainsStatsPaused
636 | GetAllDomainsStatsPersistent
637 | GetAllDomainsStatsRunning
638 | GetAllDomainsStatsShutoff
639 | GetAllDomainsStatsTransient
640 | GetAllDomainsStatsBacking
641 | GetAllDomainsStatsEnforceStats
644 | StatsState | StatsCpuTotal | StatsBalloon | StatsVcpu
645 | StatsInterface | StatsBlock | StatsPerf
647 type domain_stats_record = {
649 params : typed_param array;
658 (* The maximum size for Domain.memory_peek and Domain.block_peek
659 * supported by libvirt. This may change with different versions
660 * of libvirt in the future, hence it's a function.
662 let max_peek _ = 65536
664 external create_linux : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_domain_create_linux"
665 external _create_xml : [>`W] Connect.t -> xml -> int -> rw t = "ocaml_libvirt_domain_create_xml"
666 let create_xml conn xml flags =
667 _create_xml conn xml (int_of_domain_create_flags flags)
668 external lookup_by_id : 'a Connect.t -> int -> 'a t = "ocaml_libvirt_domain_lookup_by_id"
669 external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_domain_lookup_by_uuid"
670 external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_domain_lookup_by_uuid_string"
671 external lookup_by_name : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_domain_lookup_by_name"
672 external destroy : [>`W] t -> unit = "ocaml_libvirt_domain_destroy"
673 external free : [>`R] t -> unit = "ocaml_libvirt_domain_free"
674 external suspend : [>`W] t -> unit = "ocaml_libvirt_domain_suspend"
675 external resume : [>`W] t -> unit = "ocaml_libvirt_domain_resume"
676 external save : [>`W] t -> filename -> unit = "ocaml_libvirt_domain_save"
677 external restore : [>`W] Connect.t -> filename -> unit = "ocaml_libvirt_domain_restore"
678 external core_dump : [>`W] t -> filename -> unit = "ocaml_libvirt_domain_core_dump"
679 external shutdown : [>`W] t -> unit = "ocaml_libvirt_domain_shutdown"
680 external reboot : [>`W] t -> unit = "ocaml_libvirt_domain_reboot"
681 external get_name : [>`R] t -> string = "ocaml_libvirt_domain_get_name"
682 external get_uuid : [>`R] t -> uuid = "ocaml_libvirt_domain_get_uuid"
683 external get_uuid_string : [>`R] t -> string = "ocaml_libvirt_domain_get_uuid_string"
684 external get_id : [>`R] t -> int = "ocaml_libvirt_domain_get_id"
685 external get_os_type : [>`R] t -> string = "ocaml_libvirt_domain_get_os_type"
686 external get_max_memory : [>`R] t -> int64 = "ocaml_libvirt_domain_get_max_memory"
687 external set_max_memory : [>`W] t -> int64 -> unit = "ocaml_libvirt_domain_set_max_memory"
688 external set_memory : [>`W] t -> int64 -> unit = "ocaml_libvirt_domain_set_memory"
689 external get_info : [>`R] t -> info = "ocaml_libvirt_domain_get_info"
690 external get_xml_desc : [>`R] t -> xml = "ocaml_libvirt_domain_get_xml_desc"
691 external get_xml_desc_flags : [>`W] t -> xml_desc_flag list -> xml = "ocaml_libvirt_domain_get_xml_desc_flags"
692 external get_scheduler_type : [>`R] t -> string * int = "ocaml_libvirt_domain_get_scheduler_type"
693 external get_scheduler_parameters : [>`R] t -> int -> sched_param array = "ocaml_libvirt_domain_get_scheduler_parameters"
694 external set_scheduler_parameters : [>`W] t -> sched_param array -> unit = "ocaml_libvirt_domain_set_scheduler_parameters"
695 external define_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_domain_define_xml"
696 external undefine : [>`W] t -> unit = "ocaml_libvirt_domain_undefine"
697 external create : [>`W] t -> unit = "ocaml_libvirt_domain_create"
698 external get_autostart : [>`R] t -> bool = "ocaml_libvirt_domain_get_autostart"
699 external set_autostart : [>`W] t -> bool -> unit = "ocaml_libvirt_domain_set_autostart"
700 external set_vcpus : [>`W] t -> int -> unit = "ocaml_libvirt_domain_set_vcpus"
701 external pin_vcpu : [>`W] t -> int -> string -> unit = "ocaml_libvirt_domain_pin_vcpu"
702 external get_vcpus : [>`R] t -> int -> int -> int * vcpu_info array * string = "ocaml_libvirt_domain_get_vcpus"
703 external get_cpu_stats : [>`R] t -> typed_param list array = "ocaml_libvirt_domain_get_cpu_stats"
704 external get_max_vcpus : [>`R] t -> int = "ocaml_libvirt_domain_get_max_vcpus"
705 external attach_device : [>`W] t -> xml -> unit = "ocaml_libvirt_domain_attach_device"
706 external detach_device : [>`W] t -> xml -> unit = "ocaml_libvirt_domain_detach_device"
707 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"
708 external block_stats : [>`R] t -> string -> block_stats = "ocaml_libvirt_domain_block_stats"
709 external interface_stats : [>`R] t -> string -> interface_stats = "ocaml_libvirt_domain_interface_stats"
710 external block_peek : [>`W] t -> string -> int64 -> int -> string -> int -> unit = "ocaml_libvirt_domain_block_peek_bytecode" "ocaml_libvirt_domain_block_peek_native"
711 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"
713 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"
715 external const : [>`R] t -> ro t = "%identity"
717 let get_domains conn flags =
718 (* Old/slow/inefficient method. *)
719 let get_active, get_inactive =
720 if List.mem ListAll flags then
723 (List.mem ListActive flags, List.mem ListInactive flags) in
726 let n = Connect.num_of_domains conn in
727 let ids = Connect.list_domains conn n in
728 let ids = Array.to_list ids in
729 map_ignore_errors (lookup_by_id conn) ids
733 if get_inactive then (
734 let n = Connect.num_of_defined_domains conn in
735 let names = Connect.list_defined_domains conn n in
736 let names = Array.to_list names in
737 map_ignore_errors (lookup_by_name conn) names
740 active_doms @ inactive_doms
742 let get_domains_and_infos conn flags =
743 (* Old/slow/inefficient method. *)
744 let get_active, get_inactive =
745 if List.mem ListAll flags then
747 else (List.mem ListActive flags, List.mem ListInactive flags) in
750 let n = Connect.num_of_domains conn in
751 let ids = Connect.list_domains conn n in
752 let ids = Array.to_list ids in
753 map_ignore_errors (lookup_by_id conn) ids
757 if get_inactive then (
758 let n = Connect.num_of_defined_domains conn in
759 let names = Connect.list_defined_domains conn n in
760 let names = Array.to_list names in
761 map_ignore_errors (lookup_by_name conn) names
764 let doms = active_doms @ inactive_doms in
766 map_ignore_errors (fun dom -> (dom, get_info dom)) doms
772 module Defined = struct
779 let to_string = function
781 | `Updated -> "Updated"
782 | `Unknown x -> Printf.sprintf "Unknown Defined.detail: %d" x
787 | x -> `Unknown x (* newer libvirt *)
790 module Undefined = struct
796 let to_string = function
797 | `Removed -> "UndefinedRemoved"
798 | `Unknown x -> Printf.sprintf "Unknown Undefined.detail: %d" x
802 | x -> `Unknown x (* newer libvirt *)
805 module Started = struct
815 let to_string = function
816 | `Booted -> "Booted"
817 | `Migrated -> "Migrated"
818 | `Restored -> "Restored"
819 | `FromSnapshot -> "FromSnapshot"
820 | `Wakeup -> "Wakeup"
821 | `Unknown x -> Printf.sprintf "Unknown Started.detail: %d" x
829 | x -> `Unknown x (* newer libvirt *)
832 module Suspended = struct
841 | `Unknown of int (* newer libvirt *)
844 let to_string = function
845 | `Paused -> "Paused"
846 | `Migrated -> "Migrated"
847 | `IOError -> "IOError"
848 | `Watchdog -> "Watchdog"
849 | `Restored -> "Restored"
850 | `FromSnapshot -> "FromSnapshot"
851 | `APIError -> "APIError"
852 | `Unknown x -> Printf.sprintf "Unknown Suspended.detail: %d" x
862 | x -> `Unknown x (* newer libvirt *)
865 module Resumed = struct
870 | `Unknown of int (* newer libvirt *)
873 let to_string = function
874 | `Unpaused -> "Unpaused"
875 | `Migrated -> "Migrated"
876 | `FromSnapshot -> "FromSnapshot"
877 | `Unknown x -> Printf.sprintf "Unknown Resumed.detail: %d" x
883 | x -> `Unknown x (* newer libvirt *)
886 module Stopped = struct
897 let to_string = function
898 | `Shutdown -> "Shutdown"
899 | `Destroyed -> "Destroyed"
900 | `Crashed -> "Crashed"
901 | `Migrated -> "Migrated"
903 | `Failed -> "Failed"
904 | `FromSnapshot -> "FromSnapshot"
905 | `Unknown x -> Printf.sprintf "Unknown Stopped.detail: %d" x
915 | x -> `Unknown x (* newer libvirt *)
918 module PM_suspended = struct
922 | `Unknown of int (* newer libvirt *)
925 let to_string = function
926 | `Memory -> "Memory"
928 | `Unknown x -> Printf.sprintf "Unknown PM_suspended.detail: %d" x
933 | x -> `Unknown x (* newer libvirt *)
936 let string_option x = match x with
938 | Some x' -> "Some " ^ x'
940 module Lifecycle = struct
942 | `Defined of Defined.t
943 | `Undefined of Undefined.t
944 | `Started of Started.t
945 | `Suspended of Suspended.t
946 | `Resumed of Resumed.t
947 | `Stopped of Stopped.t
948 | `Shutdown (* no detail defined yet *)
949 | `PMSuspended of PM_suspended.t
950 | `Unknown of int (* newer libvirt *)
953 let to_string = function
954 | `Defined x -> "Defined " ^ (Defined.to_string x)
955 | `Undefined x -> "Undefined " ^ (Undefined.to_string x)
956 | `Started x -> "Started " ^ (Started.to_string x)
957 | `Suspended x -> "Suspended " ^ (Suspended.to_string x)
958 | `Resumed x -> "Resumed " ^ (Resumed.to_string x)
959 | `Stopped x -> "Stopped " ^ (Stopped.to_string x)
960 | `Shutdown -> "Shutdown"
961 | `PMSuspended x -> "PMSuspended " ^ (PM_suspended.to_string x)
962 | `Unknown x -> Printf.sprintf "Unknown Lifecycle event: %d" x
964 let make (ty, detail) = match ty with
965 | 0 -> `Defined (Defined.make detail)
966 | 1 -> `Undefined (Undefined.make detail)
967 | 2 -> `Started (Started.make detail)
968 | 3 -> `Suspended (Suspended.make detail)
969 | 4 -> `Resumed (Resumed.make detail)
970 | 5 -> `Stopped (Stopped.make detail)
972 | 7 -> `PMSuspended (PM_suspended.make detail)
976 module Reboot = struct
979 let to_string _ = "()"
984 module Rtc_change = struct
987 let to_string = Int64.to_string
992 module Watchdog = struct
1003 let to_string = function
1007 | `Poweroff -> "Poweroff"
1008 | `Shutdown -> "Shutdown"
1010 | `Unknown x -> Printf.sprintf "Unknown watchdog_action: %d" x
1019 | x -> `Unknown x (* newer libvirt *)
1022 module Io_error = struct
1027 | `Unknown of int (* newer libvirt *)
1030 let string_of_action = function
1033 | `Report -> "Report"
1034 | `Unknown x -> Printf.sprintf "Unknown Io_error.action: %d" x
1036 let action_of_int = function
1043 src_path: string option;
1044 dev_alias: string option;
1046 reason: string option;
1049 let to_string t = Printf.sprintf
1050 "{ Io_error.src_path = %s; dev_alias = %s; action = %s; reason = %s }"
1051 (string_option t.src_path)
1052 (string_option t.dev_alias)
1053 (string_of_action t.action)
1054 (string_option t.reason)
1056 let make (src_path, dev_alias, action, reason) = {
1057 src_path = src_path;
1058 dev_alias = dev_alias;
1059 action = action_of_int action;
1063 let make_noreason (src_path, dev_alias, action) =
1064 make (src_path, dev_alias, action, None)
1067 module Graphics_address = struct
1072 | `Unknown of int (* newer libvirt *)
1075 let string_of_family = function
1079 | `Unknown x -> Printf.sprintf "Unknown Graphics_address.family: %d" x
1081 let family_of_int = function
1089 family: family; (** Address family *)
1090 node: string option; (** Address of node (eg IP address, or UNIX path *)
1091 service: string option; (** Service name/number (eg TCP port, or NULL) *)
1094 let to_string t = Printf.sprintf
1095 "{ family = %s; node = %s; service = %s }"
1096 (string_of_family t.family)
1097 (string_option t.node)
1098 (string_option t.service)
1100 let make (family, node, service) = {
1101 family = family_of_int family;
1107 module Graphics_subject = struct
1110 name: string option;
1113 let string_of_identity t = Printf.sprintf
1114 "{ ty = %s; name = %s }"
1115 (string_option t.ty)
1116 (string_option t.name)
1118 type t = identity list
1121 "[ " ^ (String.concat "; " (List.map string_of_identity ts)) ^ " ]"
1124 List.map (fun (ty, name) -> { ty = ty; name = name })
1128 module Graphics = struct
1133 | `Unknown of int (** newer libvirt *)
1136 let string_of_phase = function
1137 | `Connect -> "Connect"
1138 | `Initialize -> "Initialize"
1139 | `Disconnect -> "Disconnect"
1140 | `Unknown x -> Printf.sprintf "Unknown Graphics.phase: %d" x
1142 let phase_of_int = function
1149 phase: phase; (** the phase of the connection *)
1150 local: Graphics_address.t; (** the local server address *)
1151 remote: Graphics_address.t; (** the remote client address *)
1152 auth_scheme: string option; (** the authentication scheme activated *)
1153 subject: Graphics_subject.t; (** the authenticated subject (user) *)
1157 let phase = Printf.sprintf "phase = %s"
1158 (string_of_phase t.phase) in
1159 let local = Printf.sprintf "local = %s"
1160 (Graphics_address.to_string t.local) in
1161 let remote = Printf.sprintf "remote = %s"
1162 (Graphics_address.to_string t.remote) in
1163 let auth_scheme = Printf.sprintf "auth_scheme = %s"
1164 (string_option t.auth_scheme) in
1165 let subject = Printf.sprintf "subject = %s"
1166 (Graphics_subject.to_string t.subject) in
1167 "{ " ^ (String.concat "; " [ phase; local; remote; auth_scheme; subject ]) ^ " }"
1169 let make (phase, local, remote, auth_scheme, subject) = {
1170 phase = phase_of_int phase;
1171 local = Graphics_address.make local;
1172 remote = Graphics_address.make remote;
1173 auth_scheme = auth_scheme;
1174 subject = Graphics_subject.make subject;
1178 module Control_error = struct
1181 let to_string () = "()"
1186 module Block_job = struct
1188 | `KnownUnknown (* explicitly named UNKNOWN in the spec *)
1192 | `Unknown of int (* newer libvirt *)
1195 let string_of_ty = function
1196 | `KnownUnknown -> "KnownUnknown"
1199 | `Commit -> "Commit"
1200 | `Unknown x -> Printf.sprintf "Unknown Block_job.ty: %d" x
1202 let ty_of_int = function
1203 | 0 -> `KnownUnknown
1207 | x -> `Unknown x (* newer libvirt *)
1217 let string_of_status = function
1218 | `Completed -> "Completed"
1219 | `Failed -> "Failed"
1220 | `Cancelled -> "Cancelled"
1222 | `Unknown x -> Printf.sprintf "Unknown Block_job.status: %d" x
1224 let status_of_int = function
1232 disk: string option;
1237 let to_string t = Printf.sprintf "{ disk = %s; ty = %s; status = %s }"
1238 (string_option t.disk)
1240 (string_of_status t.status)
1242 let make (disk, ty, status) = {
1245 status = status_of_int ty;
1249 module Disk_change = struct
1255 let string_of_reason = function
1256 | `MissingOnStart -> "MissingOnStart"
1257 | `Unknown x -> Printf.sprintf "Unknown Disk_change.reason: %d" x
1259 let reason_of_int = function
1260 | 0 -> `MissingOnStart
1264 old_src_path: string option;
1265 new_src_path: string option;
1266 dev_alias: string option;
1271 let o = Printf.sprintf "old_src_path = %s" (string_option t.old_src_path) in
1272 let n = Printf.sprintf "new_src_path = %s" (string_option t.new_src_path) in
1273 let d = Printf.sprintf "dev_alias = %s" (string_option t.dev_alias) in
1274 let r = string_of_reason t.reason in
1275 "{ " ^ (String.concat "; " [ o; n; d; r ]) ^ " }"
1277 let make (o, n, d, r) = {
1281 reason = reason_of_int r;
1285 module Tray_change = struct
1292 let string_of_reason = function
1295 | `Unknown x -> Printf.sprintf "Unknown Tray_change.reason: %d" x
1297 let reason_of_int = function
1303 dev_alias: string option;
1307 let to_string t = Printf.sprintf
1308 "{ dev_alias = %s; reason = %s }"
1309 (string_option t.dev_alias)
1310 (string_of_reason t.reason)
1312 let make (dev_alias, reason) = {
1313 dev_alias = dev_alias;
1314 reason = reason_of_int reason;
1318 module PM_wakeup = struct
1325 let to_string = function
1326 | `Unknown x -> Printf.sprintf "Unknown PM_wakeup.reason: %d" x
1328 let make x = `Unknown x
1331 module PM_suspend = struct
1338 let to_string = function
1339 | `Unknown x -> Printf.sprintf "Unknown PM_suspend.reason: %d" x
1341 let make x = `Unknown x
1344 module Balloon_change = struct
1347 let to_string = Int64.to_string
1351 module PM_suspend_disk = struct
1358 let to_string = function
1359 | `Unknown x -> Printf.sprintf "Unknown PM_suspend_disk.reason: %d" x
1361 let make x = `Unknown x
1365 | Lifecycle of ([`R] Domain.t -> Lifecycle.t -> unit)
1366 | Reboot of ([`R] Domain.t -> Reboot.t -> unit)
1367 | RtcChange of ([`R] Domain.t -> Rtc_change.t -> unit)
1368 | Watchdog of ([`R] Domain.t -> Watchdog.t -> unit)
1369 | IOError of ([`R] Domain.t -> Io_error.t -> unit)
1370 | Graphics of ([`R] Domain.t -> Graphics.t -> unit)
1371 | IOErrorReason of ([`R] Domain.t -> Io_error.t -> unit)
1372 | ControlError of ([`R] Domain.t -> Control_error.t -> unit)
1373 | BlockJob of ([`R] Domain.t -> Block_job.t -> unit)
1374 | DiskChange of ([`R] Domain.t -> Disk_change.t -> unit)
1375 | TrayChange of ([`R] Domain.t -> Tray_change.t -> unit)
1376 | PMWakeUp of ([`R] Domain.t -> PM_wakeup.t -> unit)
1377 | PMSuspend of ([`R] Domain.t -> PM_suspend.t -> unit)
1378 | BalloonChange of ([`R] Domain.t -> Balloon_change.t -> unit)
1379 | PMSuspendDisk of ([`R] Domain.t -> PM_suspend_disk.t -> unit)
1381 type callback_id = int64
1383 let fresh_callback_id =
1384 let next = ref 0L in
1386 let result = !next in
1387 next := Int64.succ !next;
1390 let make_table value_name =
1391 let table = Hashtbl.create 16 in
1392 let callback callback_id generic x =
1393 if Hashtbl.mem table callback_id
1394 then Hashtbl.find table callback_id generic x in
1395 let _ = Callback.register value_name callback in
1398 let u_table = make_table "Libvirt.u_callback"
1399 let i_table = make_table "Libvirt.i_callback"
1400 let i64_table = make_table "Libvirt.i64_callback"
1401 let i_i_table = make_table "Libvirt.i_i_callback"
1402 let s_i_table = make_table "Libvirt.s_i_callback"
1403 let s_i_i_table = make_table "Libvirt.s_i_i_callback"
1404 let s_s_i_table = make_table "Libvirt.s_s_i_callback"
1405 let s_s_i_s_table = make_table "Libvirt.s_s_i_s_callback"
1406 let s_s_s_i_table = make_table "Libvirt.s_s_s_i_callback"
1407 let i_ga_ga_s_gs_table = make_table "Libvirt.i_ga_ga_s_gs_callback"
1409 external register_default_impl : unit -> unit = "ocaml_libvirt_event_register_default_impl"
1411 external run_default_impl : unit -> unit = "ocaml_libvirt_event_run_default_impl"
1413 external register_any' : 'a Connect.t -> 'a Domain.t option -> callback -> callback_id -> int = "ocaml_libvirt_connect_domain_event_register_any"
1415 external deregister_any' : 'a Connect.t -> int -> unit = "ocaml_libvirt_connect_domain_event_deregister_any"
1417 let our_id_to_libvirt_id = Hashtbl.create 16
1419 let register_any conn ?dom callback =
1420 let id = fresh_callback_id () in
1421 begin match callback with
1423 Hashtbl.add i_i_table id (fun dom x ->
1424 f dom (Lifecycle.make x)
1427 Hashtbl.add u_table id (fun dom x ->
1428 f dom (Reboot.make x)
1431 Hashtbl.add i64_table id (fun dom x ->
1432 f dom (Rtc_change.make x)
1435 Hashtbl.add i_table id (fun dom x ->
1436 f dom (Watchdog.make x)
1439 Hashtbl.add s_s_i_table id (fun dom x ->
1440 f dom (Io_error.make_noreason x)
1443 Hashtbl.add i_ga_ga_s_gs_table id (fun dom x ->
1444 f dom (Graphics.make x)
1446 | IOErrorReason f ->
1447 Hashtbl.add s_s_i_s_table id (fun dom x ->
1448 f dom (Io_error.make x)
1451 Hashtbl.add u_table id (fun dom x ->
1452 f dom (Control_error.make x)
1455 Hashtbl.add s_i_i_table id (fun dom x ->
1456 f dom (Block_job.make x)
1459 Hashtbl.add s_s_s_i_table id (fun dom x ->
1460 f dom (Disk_change.make x)
1463 Hashtbl.add s_i_table id (fun dom x ->
1464 f dom (Tray_change.make x)
1467 Hashtbl.add i_table id (fun dom x ->
1468 f dom (PM_wakeup.make x)
1471 Hashtbl.add i_table id (fun dom x ->
1472 f dom (PM_suspend.make x)
1474 | BalloonChange f ->
1475 Hashtbl.add i64_table id (fun dom x ->
1476 f dom (Balloon_change.make x)
1478 | PMSuspendDisk f ->
1479 Hashtbl.add i_table id (fun dom x ->
1480 f dom (PM_suspend_disk.make x)
1483 let libvirt_id = register_any' conn dom callback id in
1484 Hashtbl.replace our_id_to_libvirt_id id libvirt_id;
1487 let deregister_any conn id =
1488 if Hashtbl.mem our_id_to_libvirt_id id then begin
1489 let libvirt_id = Hashtbl.find our_id_to_libvirt_id id in
1490 deregister_any' conn libvirt_id
1492 Hashtbl.remove our_id_to_libvirt_id id;
1493 Hashtbl.remove u_table id;
1494 Hashtbl.remove i_table id;
1495 Hashtbl.remove i64_table id;
1496 Hashtbl.remove i_i_table id;
1497 Hashtbl.remove s_i_table id;
1498 Hashtbl.remove s_i_i_table id;
1499 Hashtbl.remove s_s_i_table id;
1500 Hashtbl.remove s_s_i_s_table id;
1501 Hashtbl.remove s_s_s_i_table id;
1502 Hashtbl.remove i_ga_ga_s_gs_table id
1504 let timeout_table = Hashtbl.create 16
1507 if Hashtbl.mem timeout_table x
1508 then Hashtbl.find timeout_table x () in
1509 Callback.register "Libvirt.timeout_callback" callback
1511 type timer_id = int64
1513 external add_timeout' : 'a Connect.t -> int -> int64 -> int = "ocaml_libvirt_event_add_timeout"
1515 external remove_timeout' : 'a Connect.t -> int -> unit = "ocaml_libvirt_event_remove_timeout"
1517 let our_id_to_timer_id = Hashtbl.create 16
1518 let add_timeout conn ms fn =
1519 let id = fresh_callback_id () in
1520 Hashtbl.add timeout_table id fn;
1521 let timer_id = add_timeout' conn ms id in
1522 Hashtbl.add our_id_to_timer_id id timer_id;
1525 let remove_timeout conn id =
1526 if Hashtbl.mem our_id_to_timer_id id then begin
1527 let timer_id = Hashtbl.find our_id_to_timer_id id in
1528 remove_timeout' conn timer_id
1530 Hashtbl.remove our_id_to_timer_id id;
1531 Hashtbl.remove timeout_table id
1538 external lookup_by_name : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_network_lookup_by_name"
1539 external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_network_lookup_by_uuid"
1540 external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_network_lookup_by_uuid_string"
1541 external create_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_network_create_xml"
1542 external define_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_network_define_xml"
1543 external undefine : [>`W] t -> unit = "ocaml_libvirt_network_undefine"
1544 external create : [>`W] t -> unit = "ocaml_libvirt_network_create"
1545 external destroy : [>`W] t -> unit = "ocaml_libvirt_network_destroy"
1546 external free : [>`R] t -> unit = "ocaml_libvirt_network_free"
1547 external get_name : [>`R] t -> string = "ocaml_libvirt_network_get_name"
1548 external get_uuid : [>`R] t -> uuid = "ocaml_libvirt_network_get_uuid"
1549 external get_uuid_string : [>`R] t -> string = "ocaml_libvirt_network_get_uuid_string"
1550 external get_xml_desc : [>`R] t -> xml = "ocaml_libvirt_network_get_xml_desc"
1551 external get_bridge_name : [>`R] t -> string = "ocaml_libvirt_network_get_bridge_name"
1552 external get_autostart : [>`R] t -> bool = "ocaml_libvirt_network_get_autostart"
1553 external set_autostart : [>`W] t -> bool -> unit = "ocaml_libvirt_network_set_autostart"
1555 external const : [>`R] t -> ro t = "%identity"
1561 type pool_state = Inactive | Building | Running | Degraded
1562 type pool_build_flags = New | Repair | Resize
1563 type pool_delete_flags = Normal | Zeroed
1571 external lookup_by_name : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_storage_pool_lookup_by_name"
1572 external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_storage_pool_lookup_by_uuid"
1573 external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_storage_pool_lookup_by_uuid_string"
1574 external create_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_storage_pool_create_xml"
1575 external define_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_storage_pool_define_xml"
1576 external build : [>`W] t -> pool_build_flags -> unit = "ocaml_libvirt_storage_pool_build"
1577 external undefine : [>`W] t -> unit = "ocaml_libvirt_storage_pool_undefine"
1578 external create : [>`W] t -> unit = "ocaml_libvirt_storage_pool_create"
1579 external destroy : [>`W] t -> unit = "ocaml_libvirt_storage_pool_destroy"
1580 external delete : [>`W] t -> unit = "ocaml_libvirt_storage_pool_delete"
1581 external free : [>`R] t -> unit = "ocaml_libvirt_storage_pool_free"
1582 external refresh : [`R] t -> unit = "ocaml_libvirt_storage_pool_refresh"
1583 external get_name : [`R] t -> string = "ocaml_libvirt_storage_pool_get_name"
1584 external get_uuid : [`R] t -> uuid = "ocaml_libvirt_storage_pool_get_uuid"
1585 external get_uuid_string : [`R] t -> string = "ocaml_libvirt_storage_pool_get_uuid_string"
1586 external get_info : [`R] t -> pool_info = "ocaml_libvirt_storage_pool_get_info"
1587 external get_xml_desc : [`R] t -> xml = "ocaml_libvirt_storage_pool_get_xml_desc"
1588 external get_autostart : [`R] t -> bool = "ocaml_libvirt_storage_pool_get_autostart"
1589 external set_autostart : [>`W] t -> bool -> unit = "ocaml_libvirt_storage_pool_set_autostart"
1590 external num_of_volumes : [`R] t -> int = "ocaml_libvirt_storage_pool_num_of_volumes"
1591 external list_volumes : [`R] t -> int -> string array = "ocaml_libvirt_storage_pool_list_volumes"
1592 external const : [>`R] t -> ro t = "%identity"
1598 type vol_type = File | Block
1599 type vol_delete_flags = Normal | Zeroed
1606 external lookup_by_name : 'a Pool.t -> string -> 'a t = "ocaml_libvirt_storage_vol_lookup_by_name"
1607 external lookup_by_key : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_storage_vol_lookup_by_key"
1608 external lookup_by_path : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_storage_vol_lookup_by_path"
1609 external pool_of_volume : 'a t -> 'a Pool.t = "ocaml_libvirt_storage_pool_lookup_by_volume"
1610 external get_name : [`R] t -> string = "ocaml_libvirt_storage_vol_get_name"
1611 external get_key : [`R] t -> string = "ocaml_libvirt_storage_vol_get_key"
1612 external get_path : [`R] t -> string = "ocaml_libvirt_storage_vol_get_path"
1613 external get_info : [`R] t -> vol_info = "ocaml_libvirt_storage_vol_get_info"
1614 external get_xml_desc : [`R] t -> xml = "ocaml_libvirt_storage_vol_get_xml_desc"
1615 external create_xml : [>`W] Pool.t -> xml -> unit = "ocaml_libvirt_storage_vol_create_xml"
1616 external delete : [>`W] t -> vol_delete_flags -> unit = "ocaml_libvirt_storage_vol_delete"
1617 external free : [>`R] t -> unit = "ocaml_libvirt_storage_vol_free"
1618 external const : [>`R] t -> ro t = "%identity"
1621 (* Initialization. *)
1622 external c_init : unit -> unit = "ocaml_libvirt_init"
1624 Callback.register_exception
1625 "ocaml_libvirt_virterror" (Virterror (Virterror.no_error ()));
1626 Callback.register_exception
1627 "ocaml_libvirt_not_supported" (Not_supported "");
1629 Printexc.register_printer (
1631 | Virterror e -> Some (Virterror.to_string e)