Switch all the links to https
[ocaml-libvirt.git] / libvirt / libvirt.ml
index d03a127..fb5803a 100644 (file)
@@ -1,6 +1,6 @@
 (* OCaml bindings for libvirt.
    (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
-   http://libvirt.org/
+   https://libvirt.org/
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -29,7 +29,7 @@ external get_version : ?driver:string -> unit -> int * int = "ocaml_libvirt_get_
 let uuid_length = 16
 let uuid_string_length = 36
 
-(* http://caml.inria.fr/pub/ml-archives/caml-list/2004/07/80683af867cce6bf8fff273973f70c95.en.html *)
+(* https://caml.inria.fr/pub/ml-archives/caml-list/2004/07/80683af867cce6bf8fff273973f70c95.en.html *)
 type rw = [`R|`W]
 type ro = [`R]
 
@@ -48,6 +48,29 @@ struct
     threads : int;
   }
 
+  type credential_type =
+    | CredentialUsername
+    | CredentialAuthname
+    | CredentialLanguage
+    | CredentialCnonce
+    | CredentialPassphrase
+    | CredentialEchoprompt
+    | CredentialNoechoprompt
+    | CredentialRealm
+    | CredentialExternal
+
+  type credential = {
+    typ : credential_type;
+    prompt : string;
+    challenge : string option;
+    defresult : string option;
+  }
+
+  type auth = {
+    credtype : credential_type list;
+    cb : (credential list -> string option list);
+  }
+
   type list_flag =
     | ListNoState | ListRunning | ListBlocked
     | ListPaused | ListShutdown | ListShutoff | ListCrashed
@@ -57,6 +80,8 @@ struct
 
   external connect : ?name:string -> unit -> rw t = "ocaml_libvirt_connect_open"
   external connect_readonly : ?name:string -> unit -> ro t = "ocaml_libvirt_connect_open_readonly"
+  external connect_auth : ?name:string -> auth -> rw t = "ocaml_libvirt_connect_open_auth"
+  external connect_auth_readonly : ?name:string -> auth -> ro t = "ocaml_libvirt_connect_open_auth_readonly"
   external close : [>`R] t -> unit = "ocaml_libvirt_connect_close"
   external get_type : [>`R] t -> string = "ocaml_libvirt_connect_get_type"
   external get_version : [>`R] t -> int = "ocaml_libvirt_connect_get_version"
@@ -76,6 +101,8 @@ struct
   external list_pools : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_storage_pools"
   external num_of_defined_pools : [>`R] t -> int = "ocaml_libvirt_connect_num_of_defined_storage_pools"
   external list_defined_pools : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_defined_storage_pools"
+  external num_of_secrets : [>`R] t -> int = "ocaml_libvirt_connect_num_of_secrets"
+  external list_secrets : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_secrets"
 
   external get_node_info : [>`R] t -> node_info = "ocaml_libvirt_connect_get_node_info"
   external node_get_free_memory : [> `R] t -> int64 = "ocaml_libvirt_connect_node_get_free_memory"
@@ -92,16 +119,25 @@ struct
 
   (* See VIR_USE_CPU, VIR_UNUSE_CPU, VIR_CPU_USABLE macros defined in <libvirt.h>. *)
   let use_cpu cpumap cpu =
-    cpumap.[cpu/8] <-
-      Char.chr (Char.code cpumap.[cpu/8] lor (1 lsl (cpu mod 8)))
+    Bytes.set cpumap (cpu/8)
+      (Char.chr (Char.code (Bytes.get cpumap (cpu/8)) lor (1 lsl (cpu mod 8))))
   let unuse_cpu cpumap cpu =
-    cpumap.[cpu/8] <-
-      Char.chr (Char.code cpumap.[cpu/8] land (lnot (1 lsl (cpu mod 8))))
+    Bytes.set cpumap (cpu/8)
+      (Char.chr (Char.code (Bytes.get cpumap (cpu/8)) land (lnot (1 lsl (cpu mod 8)))))
   let cpu_usable cpumaps maplen vcpu cpu =
-    Char.code cpumaps.[vcpu*maplen + cpu/8] land (1 lsl (cpu mod 8)) <> 0
+    Char.code (Bytes.get cpumaps (vcpu*maplen + cpu/8)) land (1 lsl (cpu mod 8)) <> 0
 
   external set_keep_alive : [>`R] t -> int -> int -> unit = "ocaml_libvirt_connect_set_keep_alive"
 
+  (* Internal API needed for get_auth_default. *)
+  external _credtypes_from_auth_default : unit -> credential_type list = "ocaml_libvirt_connect_credtypes_from_auth_default"
+  external _call_auth_default_callback : credential list -> string option list = "ocaml_libvirt_connect_call_auth_default_callback"
+  let get_auth_default () =
+    {
+      credtype = _credtypes_from_auth_default ();
+      cb = _call_auth_default_callback;
+    }
+
   external const : [>`R] t -> ro t = "%identity"
 end
 
@@ -159,6 +195,57 @@ struct
     | VIR_WAR_NO_STORAGE
     | VIR_ERR_NO_STORAGE_POOL
     | VIR_ERR_NO_STORAGE_VOL
+    | VIR_WAR_NO_NODE
+    | VIR_ERR_INVALID_NODE_DEVICE
+    | VIR_ERR_NO_NODE_DEVICE
+    | VIR_ERR_NO_SECURITY_MODEL
+    | VIR_ERR_OPERATION_INVALID
+    | VIR_WAR_NO_INTERFACE
+    | VIR_ERR_NO_INTERFACE
+    | VIR_ERR_INVALID_INTERFACE
+    | VIR_ERR_MULTIPLE_INTERFACES
+    | VIR_WAR_NO_NWFILTER
+    | VIR_ERR_INVALID_NWFILTER
+    | VIR_ERR_NO_NWFILTER
+    | VIR_ERR_BUILD_FIREWALL
+    | VIR_WAR_NO_SECRET
+    | VIR_ERR_INVALID_SECRET
+    | VIR_ERR_NO_SECRET
+    | VIR_ERR_CONFIG_UNSUPPORTED
+    | VIR_ERR_OPERATION_TIMEOUT
+    | VIR_ERR_MIGRATE_PERSIST_FAILED
+    | VIR_ERR_HOOK_SCRIPT_FAILED
+    | VIR_ERR_INVALID_DOMAIN_SNAPSHOT
+    | VIR_ERR_NO_DOMAIN_SNAPSHOT
+    | VIR_ERR_INVALID_STREAM
+    | VIR_ERR_ARGUMENT_UNSUPPORTED
+    | VIR_ERR_STORAGE_PROBE_FAILED
+    | VIR_ERR_STORAGE_POOL_BUILT
+    | VIR_ERR_SNAPSHOT_REVERT_RISKY
+    | VIR_ERR_OPERATION_ABORTED
+    | VIR_ERR_AUTH_CANCELLED
+    | VIR_ERR_NO_DOMAIN_METADATA
+    | VIR_ERR_MIGRATE_UNSAFE
+    | VIR_ERR_OVERFLOW
+    | VIR_ERR_BLOCK_COPY_ACTIVE
+    | VIR_ERR_OPERATION_UNSUPPORTED
+    | VIR_ERR_SSH
+    | VIR_ERR_AGENT_UNRESPONSIVE
+    | VIR_ERR_RESOURCE_BUSY
+    | VIR_ERR_ACCESS_DENIED
+    | VIR_ERR_DBUS_SERVICE
+    | VIR_ERR_STORAGE_VOL_EXIST
+    | VIR_ERR_CPU_INCOMPATIBLE
+    | VIR_ERR_XML_INVALID_SCHEMA
+    | VIR_ERR_MIGRATE_FINISH_OK
+    | VIR_ERR_AUTH_UNAVAILABLE
+    | VIR_ERR_NO_SERVER
+    | VIR_ERR_NO_CLIENT
+    | VIR_ERR_AGENT_UNSYNCED
+    | VIR_ERR_LIBSSH
+    | VIR_ERR_DEVICE_MISSING
+    | VIR_ERR_INVALID_NWFILTER_BINDING
+    | VIR_ERR_NO_NWFILTER_BINDING
     | VIR_ERR_UNKNOWN of int
 
   let string_of_code = function
@@ -213,6 +300,57 @@ struct
     | VIR_WAR_NO_STORAGE -> "VIR_WAR_NO_STORAGE"
     | VIR_ERR_NO_STORAGE_POOL -> "VIR_ERR_NO_STORAGE_POOL"
     | VIR_ERR_NO_STORAGE_VOL -> "VIR_ERR_NO_STORAGE_VOL"
+    | VIR_WAR_NO_NODE -> "VIR_WAR_NO_NODE"
+    | VIR_ERR_INVALID_NODE_DEVICE -> "VIR_ERR_INVALID_NODE_DEVICE"
+    | VIR_ERR_NO_NODE_DEVICE -> "VIR_ERR_NO_NODE_DEVICE"
+    | VIR_ERR_NO_SECURITY_MODEL -> "VIR_ERR_NO_SECURITY_MODEL"
+    | VIR_ERR_OPERATION_INVALID -> "VIR_ERR_OPERATION_INVALID"
+    | VIR_WAR_NO_INTERFACE -> "VIR_WAR_NO_INTERFACE"
+    | VIR_ERR_NO_INTERFACE -> "VIR_ERR_NO_INTERFACE"
+    | VIR_ERR_INVALID_INTERFACE -> "VIR_ERR_INVALID_INTERFACE"
+    | VIR_ERR_MULTIPLE_INTERFACES -> "VIR_ERR_MULTIPLE_INTERFACES"
+    | VIR_WAR_NO_NWFILTER -> "VIR_WAR_NO_NWFILTER"
+    | VIR_ERR_INVALID_NWFILTER -> "VIR_ERR_INVALID_NWFILTER"
+    | VIR_ERR_NO_NWFILTER -> "VIR_ERR_NO_NWFILTER"
+    | VIR_ERR_BUILD_FIREWALL -> "VIR_ERR_BUILD_FIREWALL"
+    | VIR_WAR_NO_SECRET -> "VIR_WAR_NO_SECRET"
+    | VIR_ERR_INVALID_SECRET -> "VIR_ERR_INVALID_SECRET"
+    | VIR_ERR_NO_SECRET -> "VIR_ERR_NO_SECRET"
+    | VIR_ERR_CONFIG_UNSUPPORTED -> "VIR_ERR_CONFIG_UNSUPPORTED"
+    | VIR_ERR_OPERATION_TIMEOUT -> "VIR_ERR_OPERATION_TIMEOUT"
+    | VIR_ERR_MIGRATE_PERSIST_FAILED -> "VIR_ERR_MIGRATE_PERSIST_FAILED"
+    | VIR_ERR_HOOK_SCRIPT_FAILED -> "VIR_ERR_HOOK_SCRIPT_FAILED"
+    | VIR_ERR_INVALID_DOMAIN_SNAPSHOT -> "VIR_ERR_INVALID_DOMAIN_SNAPSHOT"
+    | VIR_ERR_NO_DOMAIN_SNAPSHOT -> "VIR_ERR_NO_DOMAIN_SNAPSHOT"
+    | VIR_ERR_INVALID_STREAM -> "VIR_ERR_INVALID_STREAM"
+    | VIR_ERR_ARGUMENT_UNSUPPORTED -> "VIR_ERR_ARGUMENT_UNSUPPORTED"
+    | VIR_ERR_STORAGE_PROBE_FAILED -> "VIR_ERR_STORAGE_PROBE_FAILED"
+    | VIR_ERR_STORAGE_POOL_BUILT -> "VIR_ERR_STORAGE_POOL_BUILT"
+    | VIR_ERR_SNAPSHOT_REVERT_RISKY -> "VIR_ERR_SNAPSHOT_REVERT_RISKY"
+    | VIR_ERR_OPERATION_ABORTED -> "VIR_ERR_OPERATION_ABORTED"
+    | VIR_ERR_AUTH_CANCELLED -> "VIR_ERR_AUTH_CANCELLED"
+    | VIR_ERR_NO_DOMAIN_METADATA -> "VIR_ERR_NO_DOMAIN_METADATA"
+    | VIR_ERR_MIGRATE_UNSAFE -> "VIR_ERR_MIGRATE_UNSAFE"
+    | VIR_ERR_OVERFLOW -> "VIR_ERR_OVERFLOW"
+    | VIR_ERR_BLOCK_COPY_ACTIVE -> "VIR_ERR_BLOCK_COPY_ACTIVE"
+    | VIR_ERR_OPERATION_UNSUPPORTED -> "VIR_ERR_OPERATION_UNSUPPORTED"
+    | VIR_ERR_SSH -> "VIR_ERR_SSH"
+    | VIR_ERR_AGENT_UNRESPONSIVE -> "VIR_ERR_AGENT_UNRESPONSIVE"
+    | VIR_ERR_RESOURCE_BUSY -> "VIR_ERR_RESOURCE_BUSY"
+    | VIR_ERR_ACCESS_DENIED -> "VIR_ERR_ACCESS_DENIED"
+    | VIR_ERR_DBUS_SERVICE -> "VIR_ERR_DBUS_SERVICE"
+    | VIR_ERR_STORAGE_VOL_EXIST -> "VIR_ERR_STORAGE_VOL_EXIST"
+    | VIR_ERR_CPU_INCOMPATIBLE -> "VIR_ERR_CPU_INCOMPATIBLE"
+    | VIR_ERR_XML_INVALID_SCHEMA -> "VIR_ERR_XML_INVALID_SCHEMA"
+    | VIR_ERR_MIGRATE_FINISH_OK -> "VIR_ERR_MIGRATE_FINISH_OK"
+    | VIR_ERR_AUTH_UNAVAILABLE -> "VIR_ERR_AUTH_UNAVAILABLE"
+    | VIR_ERR_NO_SERVER -> "VIR_ERR_NO_SERVER"
+    | VIR_ERR_NO_CLIENT -> "VIR_ERR_NO_CLIENT"
+    | VIR_ERR_AGENT_UNSYNCED -> "VIR_ERR_AGENT_UNSYNCED"
+    | VIR_ERR_LIBSSH -> "VIR_ERR_LIBSSH"
+    | VIR_ERR_DEVICE_MISSING -> "VIR_ERR_DEVICE_MISSING"
+    | VIR_ERR_INVALID_NWFILTER_BINDING -> "VIR_ERR_INVALID_NWFILTER_BINDING"
+    | VIR_ERR_NO_NWFILTER_BINDING -> "VIR_ERR_NO_NWFILTER_BINDING"
     | VIR_ERR_UNKNOWN i -> "VIR_ERR_" ^ string_of_int i
 
   type domain =
@@ -233,7 +371,57 @@ struct
     | VIR_FROM_OPENVZ
     | VIR_FROM_XENXM
     | VIR_FROM_STATS_LINUX
+    | VIR_FROM_LXC
     | VIR_FROM_STORAGE
+    | VIR_FROM_NETWORK
+    | VIR_FROM_DOMAIN
+    | VIR_FROM_UML
+    | VIR_FROM_NODEDEV
+    | VIR_FROM_XEN_INOTIFY
+    | VIR_FROM_SECURITY
+    | VIR_FROM_VBOX
+    | VIR_FROM_INTERFACE
+    | VIR_FROM_ONE
+    | VIR_FROM_ESX
+    | VIR_FROM_PHYP
+    | VIR_FROM_SECRET
+    | VIR_FROM_CPU
+    | VIR_FROM_XENAPI
+    | VIR_FROM_NWFILTER
+    | VIR_FROM_HOOK
+    | VIR_FROM_DOMAIN_SNAPSHOT
+    | VIR_FROM_AUDIT
+    | VIR_FROM_SYSINFO
+    | VIR_FROM_STREAMS
+    | VIR_FROM_VMWARE
+    | VIR_FROM_EVENT
+    | VIR_FROM_LIBXL
+    | VIR_FROM_LOCKING
+    | VIR_FROM_HYPERV
+    | VIR_FROM_CAPABILITIES
+    | VIR_FROM_URI
+    | VIR_FROM_AUTH
+    | VIR_FROM_DBUS
+    | VIR_FROM_PARALLELS
+    | VIR_FROM_DEVICE
+    | VIR_FROM_SSH
+    | VIR_FROM_LOCKSPACE
+    | VIR_FROM_INITCTL
+    | VIR_FROM_IDENTITY
+    | VIR_FROM_CGROUP
+    | VIR_FROM_ACCESS
+    | VIR_FROM_SYSTEMD
+    | VIR_FROM_BHYVE
+    | VIR_FROM_CRYPTO
+    | VIR_FROM_FIREWALL
+    | VIR_FROM_POLKIT
+    | VIR_FROM_THREAD
+    | VIR_FROM_ADMIN
+    | VIR_FROM_LOGGING
+    | VIR_FROM_XENXL
+    | VIR_FROM_PERF
+    | VIR_FROM_LIBSSH
+    | VIR_FROM_RESCTRL
     | VIR_FROM_UNKNOWN of int
 
   let string_of_domain = function
@@ -254,7 +442,57 @@ struct
     | VIR_FROM_OPENVZ -> "VIR_FROM_OPENVZ"
     | VIR_FROM_XENXM -> "VIR_FROM_XENXM"
     | VIR_FROM_STATS_LINUX -> "VIR_FROM_STATS_LINUX"
+    | VIR_FROM_LXC -> "VIR_FROM_LXC"
     | VIR_FROM_STORAGE -> "VIR_FROM_STORAGE"
+    | VIR_FROM_NETWORK -> "VIR_FROM_NETWORK"
+    | VIR_FROM_DOMAIN -> "VIR_FROM_DOMAIN"
+    | VIR_FROM_UML -> "VIR_FROM_UML"
+    | VIR_FROM_NODEDEV -> "VIR_FROM_NODEDEV"
+    | VIR_FROM_XEN_INOTIFY -> "VIR_FROM_XEN_INOTIFY"
+    | VIR_FROM_SECURITY -> "VIR_FROM_SECURITY"
+    | VIR_FROM_VBOX -> "VIR_FROM_VBOX"
+    | VIR_FROM_INTERFACE -> "VIR_FROM_INTERFACE"
+    | VIR_FROM_ONE -> "VIR_FROM_ONE"
+    | VIR_FROM_ESX -> "VIR_FROM_ESX"
+    | VIR_FROM_PHYP -> "VIR_FROM_PHYP"
+    | VIR_FROM_SECRET -> "VIR_FROM_SECRET"
+    | VIR_FROM_CPU -> "VIR_FROM_CPU"
+    | VIR_FROM_XENAPI -> "VIR_FROM_XENAPI"
+    | VIR_FROM_NWFILTER -> "VIR_FROM_NWFILTER"
+    | VIR_FROM_HOOK -> "VIR_FROM_HOOK"
+    | VIR_FROM_DOMAIN_SNAPSHOT -> "VIR_FROM_DOMAIN_SNAPSHOT"
+    | VIR_FROM_AUDIT -> "VIR_FROM_AUDIT"
+    | VIR_FROM_SYSINFO -> "VIR_FROM_SYSINFO"
+    | VIR_FROM_STREAMS -> "VIR_FROM_STREAMS"
+    | VIR_FROM_VMWARE -> "VIR_FROM_VMWARE"
+    | VIR_FROM_EVENT -> "VIR_FROM_EVENT"
+    | VIR_FROM_LIBXL -> "VIR_FROM_LIBXL"
+    | VIR_FROM_LOCKING -> "VIR_FROM_LOCKING"
+    | VIR_FROM_HYPERV -> "VIR_FROM_HYPERV"
+    | VIR_FROM_CAPABILITIES -> "VIR_FROM_CAPABILITIES"
+    | VIR_FROM_URI -> "VIR_FROM_URI"
+    | VIR_FROM_AUTH -> "VIR_FROM_AUTH"
+    | VIR_FROM_DBUS -> "VIR_FROM_DBUS"
+    | VIR_FROM_PARALLELS -> "VIR_FROM_PARALLELS"
+    | VIR_FROM_DEVICE -> "VIR_FROM_DEVICE"
+    | VIR_FROM_SSH -> "VIR_FROM_SSH"
+    | VIR_FROM_LOCKSPACE -> "VIR_FROM_LOCKSPACE"
+    | VIR_FROM_INITCTL -> "VIR_FROM_INITCTL"
+    | VIR_FROM_IDENTITY -> "VIR_FROM_IDENTITY"
+    | VIR_FROM_CGROUP -> "VIR_FROM_CGROUP"
+    | VIR_FROM_ACCESS -> "VIR_FROM_ACCESS"
+    | VIR_FROM_SYSTEMD -> "VIR_FROM_SYSTEMD"
+    | VIR_FROM_BHYVE -> "VIR_FROM_BHYVE"
+    | VIR_FROM_CRYPTO -> "VIR_FROM_CRYPTO"
+    | VIR_FROM_FIREWALL -> "VIR_FROM_FIREWALL"
+    | VIR_FROM_POLKIT -> "VIR_FROM_POLKIT"
+    | VIR_FROM_THREAD -> "VIR_FROM_THREAD"
+    | VIR_FROM_ADMIN -> "VIR_FROM_ADMIN"
+    | VIR_FROM_LOGGING -> "VIR_FROM_LOGGING"
+    | VIR_FROM_XENXL -> "VIR_FROM_XENXL"
+    | VIR_FROM_PERF -> "VIR_FROM_PERF"
+    | VIR_FROM_LIBSSH -> "VIR_FROM_LIBSSH"
+    | VIR_FROM_RESCTRL -> "VIR_FROM_RESCTRL"
     | VIR_FROM_UNKNOWN i -> "VIR_FROM_" ^ string_of_int i
 
   type level =
@@ -413,6 +651,12 @@ struct
     params : typed_param array;
   }
 
+  type xml_desc_flag =
+    | XmlSecure
+    | XmlInactive
+    | XmlUpdateCPU
+    | XmlMigratable
+
   (* The maximum size for Domain.memory_peek and Domain.block_peek
    * supported by libvirt.  This may change with different versions
    * of libvirt in the future, hence it's a function.
@@ -446,6 +690,7 @@ struct
   external set_memory : [>`W] t -> int64 -> unit = "ocaml_libvirt_domain_set_memory"
   external get_info : [>`R] t -> info = "ocaml_libvirt_domain_get_info"
   external get_xml_desc : [>`R] t -> xml = "ocaml_libvirt_domain_get_xml_desc"
+  external get_xml_desc_flags : [>`W] t -> xml_desc_flag list -> xml = "ocaml_libvirt_domain_get_xml_desc_flags"
   external get_scheduler_type : [>`R] t -> string * int = "ocaml_libvirt_domain_get_scheduler_type"
   external get_scheduler_parameters : [>`R] t -> int -> sched_param array = "ocaml_libvirt_domain_get_scheduler_parameters"
   external set_scheduler_parameters : [>`W] t -> sched_param array -> unit = "ocaml_libvirt_domain_set_scheduler_parameters"
@@ -1375,6 +1620,32 @@ struct
   external const : [>`R] t -> ro t = "%identity"
 end
 
+module Secret =
+struct
+  type 'rw t
+  type secret_usage_type =
+    | NoType
+    | Volume
+    | Ceph
+    | ISCSI
+    | TLS
+
+  external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_secret_lookup_by_uuid"
+  external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_secret_lookup_by_uuid_string"
+  external lookup_by_usage : 'a Connect.t -> secret_usage_type -> string -> 'a t = "ocaml_libvirt_secret_lookup_by_usage"
+  external define_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_secret_define_xml"
+  external get_uuid : [>`R] t -> uuid = "ocaml_libvirt_secret_get_uuid"
+  external get_uuid_string : [>`R] t -> string = "ocaml_libvirt_secret_get_uuid_string"
+  external get_usage_type : [>`R] t -> secret_usage_type = "ocaml_libvirt_secret_get_usage_type"
+  external get_usage_id : [>`R] t -> string = "ocaml_libvirt_secret_get_usage_id"
+  external get_xml_desc : [>`R] t -> xml = "ocaml_libvirt_secret_get_xml_desc"
+  external set_value : [>`W] t -> bytes -> unit = "ocaml_libvirt_secret_set_value"
+  external get_value : [>`R] t -> bytes = "ocaml_libvirt_secret_get_value"
+  external undefine : [>`W] t -> unit = "ocaml_libvirt_secret_undefine"
+  external free : [>`R] t -> unit = "ocaml_libvirt_secret_free"
+  external const : [>`R] t -> ro t = "%identity"
+end
+
 (* Initialization. *)
 external c_init : unit -> unit = "ocaml_libvirt_init"
 let () =
@@ -1382,4 +1653,9 @@ let () =
     "ocaml_libvirt_virterror" (Virterror (Virterror.no_error ()));
   Callback.register_exception
     "ocaml_libvirt_not_supported" (Not_supported "");
-  c_init ()
+  c_init ();
+  Printexc.register_printer (
+    function
+    | Virterror e -> Some (Virterror.to_string e)
+    | _ -> None
+  )