mclu list: Ignore libguestfs temporary guestfs-* when displaying active guests.
authorRichard W.M. Jones <rjones@redhat.com>
Sat, 4 Apr 2015 21:16:15 +0000 (22:16 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Sat, 4 Apr 2015 21:16:28 +0000 (22:16 +0100)
mclu_list.ml
utils.ml
utils.mli

index f685f54..21d55d0 100644 (file)
@@ -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. *)
           | 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) ->
               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)
             ) dominfos
           | None -> [] in
         (node, dominfo)
index fd92b79..87c4002 100644 (file)
--- a/utils.ml
+++ b/utils.ml
@@ -33,6 +33,13 @@ let ( /^ ) = Int64.div
 let ( &^ ) = Int64.logand
 let ( ~^ ) = Int64.lognot
 
 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
 
 let human_size i =
   let sign, i = if i < 0L then "-", Int64.neg i else "", i in
 
index e3800cf..ae84c74 100644 (file)
--- a/utils.mli
+++ b/utils.mli
@@ -29,6 +29,9 @@ val ( &^ ) : int64 -> int64 -> int64
 val ( ~^ ) : int64 -> int64
 (** Various int64 operators. *)
 
 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]). *)
 
 val human_size : int64 -> string
 (** Turn a bytes count into a human-readable string (eg. [4.0G]). *)