X-Git-Url: http://git.annexia.org/?p=virt-top.git;a=blobdiff_plain;f=libvirt%2Flibvirt.ml;h=d01db2f8566cfdb8812f6ac7b6cd01dd1cb9294b;hp=14dca54ec284d0f4713da7f91b0899cc1cbbeb89;hb=c46641acb5e29edfe3114ecb05614bfbff28372d;hpb=a8b837d5018c488a130fcbea425904817a862210 diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml index 14dca54..d01db2f 100644 --- a/libvirt/libvirt.ml +++ b/libvirt/libvirt.ml @@ -1,13 +1,28 @@ (* OCaml bindings for libvirt. (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc. http://libvirt.org/ - $Id: libvirt.ml,v 1.2 2007/08/21 13:24:08 rjones Exp $ + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *) type uuid = string type xml = string +type filename = string + external get_version : ?driver:string -> unit -> int * int = "ocaml_libvirt_get_version" let uuid_length = 16 @@ -17,6 +32,8 @@ let uuid_string_length = 36 type rw = [`R|`W] type ro = [`R] +type ('a, 'b) job_t + module Connect = struct type 'rw t @@ -42,14 +59,21 @@ struct external get_max_vcpus : [>`R] t -> ?type_:string -> unit -> int = "ocaml_libvirt_connect_get_max_vcpus" external list_domains : [>`R] t -> int -> int array = "ocaml_libvirt_connect_list_domains" external num_of_domains : [>`R] t -> int = "ocaml_libvirt_connect_num_of_domains" - external get_capabilities : [>`R] t -> string = "ocaml_libvirt_connect_get_capabilities" + external get_capabilities : [>`R] t -> xml = "ocaml_libvirt_connect_get_capabilities" external num_of_defined_domains : [>`R] t -> int = "ocaml_libvirt_connect_num_of_defined_domains" external list_defined_domains : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_defined_domains" external num_of_networks : [>`R] t -> int = "ocaml_libvirt_connect_num_of_networks" external list_networks : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_networks" external num_of_defined_networks : [>`R] t -> int = "ocaml_libvirt_connect_num_of_defined_networks" external list_defined_networks : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_defined_networks" + external num_of_pools : [>`R] t -> int = "ocaml_libvirt_connect_num_of_storage_pools" + 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 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" + external node_get_cells_free_memory : [> `R] t -> int -> int -> int64 array = "ocaml_libvirt_connect_node_get_cells_free_memory" (* See VIR_NODEINFO_MAXCPUS macro defined in . *) let maxcpus_of_node_info { nodes = nodes; sockets = sockets; @@ -75,8 +99,7 @@ end module Domain = struct - type 'rw dom - type 'rw t = 'rw dom * 'rw Connect.t + type 'rw t type state = | InfoNoState | InfoRunning | InfoBlocked | InfoPaused @@ -127,6 +150,7 @@ struct } external create_linux : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_domain_create_linux" + external create_linux_job : [>`W] Connect.t -> xml -> ([`Domain], rw) job_t = "ocaml_libvirt_domain_create_linux_job" external lookup_by_id : 'a Connect.t -> int -> 'a t = "ocaml_libvirt_domain_lookup_by_id" external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_domain_lookup_by_uuid" external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_domain_lookup_by_uuid_string" @@ -135,9 +159,12 @@ struct external free : [>`R] t -> unit = "ocaml_libvirt_domain_free" external suspend : [>`W] t -> unit = "ocaml_libvirt_domain_suspend" external resume : [>`W] t -> unit = "ocaml_libvirt_domain_resume" - external save : [>`W] t -> string -> unit = "ocaml_libvirt_domain_save" - external restore : [>`W] Connect.t -> string -> unit = "ocaml_libvirt_domain_restore" - external core_dump : [>`W] t -> string -> unit = "ocaml_libvirt_domain_core_dump" + external save : [>`W] t -> filename -> unit = "ocaml_libvirt_domain_save" + external save_job : [>`W] t -> filename -> ([`Domain_nocreate], rw) job_t = "ocaml_libvirt_domain_save_job" + external restore : [>`W] Connect.t -> filename -> unit = "ocaml_libvirt_domain_restore" + external restore_job : [>`W] Connect.t -> filename -> ([`Domain_nocreate], rw) job_t = "ocaml_libvirt_domain_restore_job" + external core_dump : [>`W] t -> filename -> unit = "ocaml_libvirt_domain_core_dump" + external core_dump_job : [>`W] t -> filename -> ([`Domain_nocreate], rw) job_t = "ocaml_libvirt_domain_core_dump_job" external shutdown : [>`W] t -> unit = "ocaml_libvirt_domain_shutdown" external reboot : [>`W] t -> unit = "ocaml_libvirt_domain_reboot" external get_name : [>`R] t -> string = "ocaml_libvirt_domain_get_name" @@ -156,6 +183,7 @@ struct external define_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_domain_define_xml" external undefine : [>`W] t -> unit = "ocaml_libvirt_domain_undefine" external create : [>`W] t -> unit = "ocaml_libvirt_domain_create" + external create_job : [>`W] t -> ([`Domain_nocreate], rw) job_t = "ocaml_libvirt_domain_create_job" external get_autostart : [>`R] t -> bool = "ocaml_libvirt_domain_get_autostart" external set_autostart : [>`W] t -> bool -> unit = "ocaml_libvirt_domain_set_autostart" external set_vcpus : [>`W] t -> int -> unit = "ocaml_libvirt_domain_set_vcpus" @@ -173,16 +201,17 @@ end module Network = struct - type 'rw net - type 'rw t = 'rw net * 'rw Connect.t + type 'rw t external lookup_by_name : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_network_lookup_by_name" external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_network_lookup_by_uuid" external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_network_lookup_by_uuid_string" external create_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_network_create_xml" + external create_xml_job : [>`W] Connect.t -> xml -> ([`Network], rw) job_t = "ocaml_libvirt_network_create_xml_job" external define_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_network_define_xml" external undefine : [>`W] t -> unit = "ocaml_libvirt_network_undefine" external create : [>`W] t -> unit = "ocaml_libvirt_network_create" + external create_job : [>`W] t -> ([`Network_nocreate], rw) job_t = "ocaml_libvirt_network_create_job" external destroy : [>`W] t -> unit = "ocaml_libvirt_network_destroy" external free : [>`R] t -> unit = "ocaml_libvirt_network_free" external get_name : [>`R] t -> string = "ocaml_libvirt_network_get_name" @@ -196,6 +225,82 @@ struct external const : [>`R] t -> ro t = "%identity" end +module Pool = +struct + type 'rw t + type pool_state = Inactive | Active + type pool_info = { + state : pool_state; + capacity : int64; + allocation : int64; + } + + external lookup_by_name : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_storage_pool_lookup_by_name" + external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_storage_pool_lookup_by_uuid" + external lookup_by_uuid_string : 'a Connect.t -> string -> 'a t = "ocaml_libvirt_storage_pool_lookup_by_uuid_string" + external create_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_storage_pool_create_xml" + external define_xml : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_storage_pool_define_xml" + external undefine : [>`W] t -> unit = "ocaml_libvirt_storage_pool_undefine" + external create : [>`W] t -> unit = "ocaml_libvirt_storage_pool_create" + external destroy : [>`W] t -> unit = "ocaml_libvirt_storage_pool_destroy" + external shutdown : [>`W] t -> unit = "ocaml_libvirt_storage_pool_shutdown" + external free : [>`R] t -> unit = "ocaml_libvirt_storage_pool_free" + external refresh : [`R] t -> unit = "ocaml_libvirt_storage_pool_refresh" + external get_name : [`R] t -> string = "ocaml_libvirt_storage_pool_get_name" + external get_uuid : [`R] t -> uuid = "ocaml_libvirt_storage_pool_get_uuid" + external get_uuid_string : [`R] t -> string = "ocaml_libvirt_storage_pool_get_uuid_string" + external get_info : [`R] t -> pool_info = "ocaml_libvirt_storage_pool_get_info" + external get_xml_desc : [`R] t -> xml = "ocaml_libvirt_storage_pool_get_xml_desc" + external get_autostart : [`R] t -> bool = "ocaml_libvirt_storage_pool_get_autostart" + external set_autostart : [`W] t -> bool -> unit = "ocaml_libvirt_storage_pool_set_autostart" + external const : [>`R] t -> ro t = "%identity" +end + +module Volume = +struct + type 'rw t + type vol_type = File | Block | Virtual + type vol_info = { + typ : vol_type; + capacity : int64; + allocation : int64; + } + + external lookup_by_name : 'a Pool.t -> string -> 'a t = "ocaml_libvirt_storage_vol_lookup_by_name" + external lookup_by_key : 'a Pool.t -> string -> 'a t = "ocaml_libvirt_storage_vol_lookup_by_key" + external lookup_by_path : 'a Pool.t -> string -> 'a t = "ocaml_libvirt_storage_vol_lookup_by_path" + external pool_of_volume : 'a t -> 'a Pool.t = "ocaml_libvirt_storage_pool_lookup_by_volume" + external get_name : [`R] t -> string = "ocaml_libvirt_storage_vol_get_name" + external get_key : [`R] t -> string = "ocaml_libvirt_storage_vol_get_key" + external get_path : [`R] t -> string = "ocaml_libvirt_storage_vol_get_path" + external get_info : [`R] t -> vol_info = "ocaml_libvirt_storage_vol_get_info" + external get_xml_desc : [`R] t -> xml = "ocaml_libvirt_storage_vol_get_xml_desc" + external create_xml : [`W] Pool.t -> xml -> unit = "ocaml_libvirt_storage_vol_create_xml" + external destroy : [`W] t -> unit = "ocaml_libvirt_storage_vol_destroy" + external free : [>`R] t -> unit = "ocaml_libvirt_storage_vol_free" + external const : [>`R] t -> ro t = "%identity" +end + +module Job = +struct + type ('jobclass, 'rw) t = ('jobclass, 'rw) job_t + type job_type = Bounded | Unbounded + type job_state = Running | Complete | Failed | Cancelled + type job_info = { + typ : job_type; + state : job_state; + running_time : int; + remaining_time : int; + percent_complete : int + } + external get_info : ('a,'b) t -> job_info = "ocaml_libvirt_job_get_info" + external get_domain : ([`Domain], 'a) t -> 'a Domain.t = "ocaml_libvirt_job_get_domain" + external get_network : ([`Network], 'a) t -> 'a Network.t = "ocaml_libvirt_job_get_network" + external cancel : ('a,'b) t -> unit = "ocaml_libvirt_job_cancel" + external free : ('a, [>`R]) t -> unit = "ocaml_libvirt_job_free" + external const : ('a, [>`R]) t -> ('a, ro) t = "%identity" +end + module Virterror = struct type code = @@ -243,6 +348,14 @@ struct | VIR_WAR_NO_NETWORK | VIR_ERR_NO_DOMAIN | VIR_ERR_NO_NETWORK + | VIR_ERR_INVALID_MAC + | VIR_ERR_AUTH_FAILED + | VIR_ERR_INVALID_STORAGE_POOL + | VIR_ERR_INVALID_STORAGE_VOL + | VIR_WAR_NO_STORAGE + | VIR_ERR_NO_STORAGE_POOL + | VIR_ERR_NO_STORAGE_VOL + | VIR_ERR_UNKNOWN of int let string_of_code = function | VIR_ERR_OK -> "VIR_ERR_OK" @@ -289,16 +402,14 @@ struct | VIR_WAR_NO_NETWORK -> "VIR_WAR_NO_NETWORK" | VIR_ERR_NO_DOMAIN -> "VIR_ERR_NO_DOMAIN" | VIR_ERR_NO_NETWORK -> "VIR_ERR_NO_NETWORK" - - type level = - | VIR_ERR_NONE - | VIR_ERR_WARNING - | VIR_ERR_ERROR - - let string_of_level = function - | VIR_ERR_NONE -> "VIR_ERR_NONE" - | VIR_ERR_WARNING -> "VIR_ERR_WARNING" - | VIR_ERR_ERROR -> "VIR_ERR_ERROR" + | VIR_ERR_INVALID_MAC -> "VIR_ERR_INVALID_MAC" + | VIR_ERR_AUTH_FAILED -> "VIR_ERR_AUTH_FAILED" + | VIR_ERR_INVALID_STORAGE_POOL -> "VIR_ERR_INVALID_STORAGE_POOL" + | VIR_ERR_INVALID_STORAGE_VOL -> "VIR_ERR_INVALID_STORAGE_VOL" + | 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_ERR_UNKNOWN i -> "VIR_ERR_" ^ string_of_int i type domain = | VIR_FROM_NONE @@ -315,6 +426,11 @@ struct | VIR_FROM_NET | VIR_FROM_TEST | VIR_FROM_REMOTE + | VIR_FROM_OPENVZ + | VIR_FROM_XENXM + | VIR_FROM_STATS_LINUX + | VIR_FROM_STORAGE + | VIR_FROM_UNKNOWN of int let string_of_domain = function | VIR_FROM_NONE -> "VIR_FROM_NONE" @@ -331,6 +447,23 @@ struct | VIR_FROM_NET -> "VIR_FROM_NET" | VIR_FROM_TEST -> "VIR_FROM_TEST" | VIR_FROM_REMOTE -> "VIR_FROM_REMOTE" + | VIR_FROM_OPENVZ -> "VIR_FROM_OPENVZ" + | VIR_FROM_XENXM -> "VIR_FROM_XENXM" + | VIR_FROM_STATS_LINUX -> "VIR_FROM_STATS_LINUX" + | VIR_FROM_STORAGE -> "VIR_FROM_STORAGE" + | VIR_FROM_UNKNOWN i -> "VIR_FROM_" ^ string_of_int i + + type level = + | VIR_ERR_NONE + | VIR_ERR_WARNING + | VIR_ERR_ERROR + | VIR_ERR_UNKNOWN_LEVEL of int + + let string_of_level = function + | VIR_ERR_NONE -> "VIR_ERR_NONE" + | VIR_ERR_WARNING -> "VIR_ERR_WARNING" + | VIR_ERR_ERROR -> "VIR_ERR_ERROR" + | VIR_ERR_UNKNOWN_LEVEL i -> "VIR_ERR_LEVEL_" ^ string_of_int i type t = { code : code; @@ -370,10 +503,13 @@ struct end exception Virterror of Virterror.t +exception Not_supported of string (* Initialization. *) external c_init : unit -> unit = "ocaml_libvirt_init" let () = Callback.register_exception "ocaml_libvirt_virterror" (Virterror (Virterror.no_error ())); + Callback.register_exception + "ocaml_libvirt_not_supported" (Not_supported ""); c_init ()