let domains = D.get_domains_and_infos conn [D.ListAll] in
List.iter (
fun (dom, info) ->
- if info.D.state <> D.InfoShutoff then
- printf "%8d %-20s %s\n%!"
- (D.get_id dom) (D.get_name dom) (string_of_state info.D.state)
+ let id = D.get_id dom in
+ let name = D.get_name dom in
+ let state = string_of_state info.D.state in
+ if id >= 0 then
+ printf "%8d %-20s %s\n%!" id name state
else
- printf "%8s %-20s shutoff\n%!" "" (D.get_name dom)
+ printf "%8s %-20s %s\n%!" "inactive" name state
) domains
with
Libvirt.Virterror err ->
val get_uuid_string : [>`R] t -> string
(** Get the domain UUID (as a printable string). *)
val get_id : [>`R] t -> int
- (** [getid dom] returns the ID of the domain.
-
- Do not call this on a defined but not running domain. Those
- domains don't have IDs, and you'll get an error here.
- *)
-
+ (** [get_id dom] returns the ID of the domain. In most cases
+ this returns [-1] if the domain is not running. *)
val get_os_type : [>`R] t -> string
(** Get the operating system type. *)
val get_max_memory : [>`R] t -> int64
{
CAMLparam1 (domv);
virDomainPtr dom = Domain_val (domv);
- virConnectPtr conn = Connect_domv (domv);
+ /*virConnectPtr conn = Connect_domv (domv);*/
unsigned int r;
NONBLOCKING (r = virDomainGetID (dom));
- /* There's a bug in libvirt which means that if you try to get
- * the ID of a defined-but-not-running domain, it returns -1,
- * and there's no way to distinguish that from an error.
+ /* In theory this could return -1 on error, but in practice
+ * libvirt never does this unless you call it with a corrupted
+ * or NULL dom object. So ignore errors here.
*/
- CHECK_ERROR (r == (unsigned int) -1, conn, "virDomainGetID");
CAMLreturn (Val_int ((int) r));
}