From: Richard W.M. Jones Date: Sat, 4 Apr 2015 21:16:15 +0000 (+0100) Subject: mclu list: Ignore libguestfs temporary guestfs-* when displaying active guests. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=0828c34208a46b7a2e1b03b7c93f907bf900c050;p=mclu.git mclu list: Ignore libguestfs temporary guestfs-* when displaying active guests. --- diff --git a/mclu_list.ml b/mclu_list.ml index f685f54..21d55d0 100644 --- a/mclu_list.ml +++ b/mclu_list.ml @@ -65,9 +65,14 @@ let active_guests ?(verbose = false) ?(nodes = Mclu_conf.nodes ()) () = | Some conn -> let dominfos = D.get_domains_and_infos conn [D.ListActive] in (* D.t is abstract so we cannot marshal it. *) - List.map ( + filter_map ( fun (dom, info) -> - { dom_name = D.get_name dom; dom_info = info } + let name = D.get_name dom in + let name_len = String.length name in + if name_len > 8 && String.sub name 0 8 = "guestfs-" then + None + else + Some { dom_name = D.get_name dom; dom_info = info } ) dominfos | None -> [] in (node, dominfo) diff --git a/utils.ml b/utils.ml index fd92b79..87c4002 100644 --- a/utils.ml +++ b/utils.ml @@ -33,6 +33,13 @@ let ( /^ ) = Int64.div let ( &^ ) = Int64.logand let ( ~^ ) = Int64.lognot +let rec filter_map f = function + | [] -> [] + | x :: xs -> + match f x with + | Some y -> y :: filter_map f xs + | None -> filter_map f xs + let human_size i = let sign, i = if i < 0L then "-", Int64.neg i else "", i in diff --git a/utils.mli b/utils.mli index e3800cf..ae84c74 100644 --- a/utils.mli +++ b/utils.mli @@ -29,6 +29,9 @@ val ( &^ ) : int64 -> int64 -> int64 val ( ~^ ) : int64 -> int64 (** Various int64 operators. *) +val filter_map : ('a -> 'b option) -> 'a list -> 'b list +(** {!List.map} + {!List.filter} *) + val human_size : int64 -> string (** Turn a bytes count into a human-readable string (eg. [4.0G]). *)