[Libguestfs] [PATCH v3 3/5] mllib: Add a function to test if a guest is "unix-like".

Richard W.M. Jones rjones at redhat.com
Wed Dec 14 16:55:43 UTC 2016


This is not a precise replacement, since we now allow SSH key
injection into Minix, but that is probably correct anyway.
---
 customize/customize_run.ml | 7 +++----
 mllib/common_utils.ml      | 8 ++++++++
 mllib/common_utils.mli     | 4 ++++
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/customize/customize_run.ml b/customize/customize_run.ml
index 32a2027..5cc60a4 100644
--- a/customize/customize_run.ml
+++ b/customize/customize_run.ml
@@ -346,12 +346,11 @@ exec >>%s 2>&1
       do_run ~display:cmd ~warn_failed_no_network:true cmd
 
     | `SSHInject (user, selector) ->
-      (match g#inspect_get_type root with
-      | "linux" | "freebsd" | "netbsd" | "openbsd" | "hurd" ->
+      if unix_like (g#inspect_get_type root) then (
         message (f_"SSH key inject: %s") user;
         Ssh_key.do_ssh_inject_unix g user selector
-      | _ ->
-        warning (f_"SSH key could be injected for this type of guest"))
+      ) else
+        warning (f_"SSH key could be injected for this type of guest")
 
     | `Truncate path ->
       message (f_"Truncating: %s") path;
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index f948dce..1838333 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -1079,6 +1079,14 @@ let guest_arch_compatible guest_arch =
   | "x86_64", "i386" -> true
   | _ -> false
 
+(* Is the guest OS "Unix-like"? *)
+let unix_like = function
+  | "hurd"
+  | "linux"
+  | "minix" -> true
+  | typ when String.is_suffix typ "bsd" -> true
+  | _ -> false
+
 (** Return the last part of a string, after the specified separator. *)
 let last_part_of str sep =
   try
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index 4a6ddd6..019070d 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -426,6 +426,10 @@ val guest_arch_compatible : string -> bool
 (** Are guest arch and host_cpu compatible, in terms of being able
     to run commands in the libguestfs appliance? *)
 
+val unix_like : string -> bool
+(** Is the guest OS "Unix-like"?  Call this with the result of
+    {!Guestfs.inspect_get_type}. *)
+
 val last_part_of : string -> char -> string option
 (** Return the last part of a string, after the specified separator. *)
 
-- 
2.10.2




More information about the Libguestfs mailing list