From ca0ce0c2ec7952f79416724f563a7c7cfcbbfb28 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 14 Dec 2016 16:49:14 +0000 Subject: [PATCH] mllib: Add a function to test if a guest is "unix-like". 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 32a202790..5cc60a471 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 f948dcea1..183833394 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 4a6ddd654..019070d39 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. *)