[Libguestfs] [PATCH v4 03/12] v2v: nbdkit: Add support for nbdkit-ssh-plugin.

Richard W.M. Jones rjones at redhat.com
Fri Sep 20 09:28:14 UTC 2019


---
 v2v/nbdkit.ml  | 26 ++++++++++++++++++++++++++
 v2v/nbdkit.mli | 18 ++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/v2v/nbdkit.ml b/v2v/nbdkit.ml
index 8ae6549e9..44fe0e8e7 100644
--- a/v2v/nbdkit.ml
+++ b/v2v/nbdkit.ml
@@ -29,6 +29,11 @@ open Utils
 let nbdkit_min_version = (1, 2)
 let nbdkit_min_version_string = "1.2"
 
+type password =
+| NoPassword                    (* no password option at all *)
+| AskForPassword                (* password=- *)
+| PasswordFile of string        (* password=+file *)
+
 type t = {
   (* The nbdkit plugin name. *)
   plugin_name : string;
@@ -235,6 +240,27 @@ See also the virt-v2v-input-vmware(1) manual.") libNN
 
   common_create "vddk" (get_args ()) env
 
+(* Create an nbdkit module specialized for reading from SSH sources. *)
+let create_ssh ~password ?port ~server ?user path =
+  let add_arg, get_args =
+    let args = ref [] in
+    let add_arg a = List.push_front a args in
+    let get_args () = List.rev !args in
+    add_arg, get_args in
+
+  add_arg (sprintf "host=%s" server);
+  Option.may (fun s -> add_arg (sprintf "port=%s" s)) port;
+  Option.may (fun s -> add_arg (sprintf "user=%s" s)) user;
+  (match password with
+   | NoPassword -> ()
+   | AskForPassword -> add_arg "password=-"
+   | PasswordFile password_file ->
+      add_arg (sprintf "password=+%s" password_file)
+  );
+  add_arg (sprintf "path=%s" path);
+
+  common_create "ssh" (get_args ()) []
+
 let run { args; env } =
   (* Create a temporary directory where we place the sockets. *)
   let tmpdir =
diff --git a/v2v/nbdkit.mli b/v2v/nbdkit.mli
index 3bdec1b56..36faff03b 100644
--- a/v2v/nbdkit.mli
+++ b/v2v/nbdkit.mli
@@ -41,6 +41,24 @@ val create_vddk : ?config:string ->
 
     Note this doesn't run nbdkit yet, it just creates the object. *)
 
+type password =
+| NoPassword
+| AskForPassword
+| PasswordFile of string
+
+val create_ssh : password:password ->
+                 ?port:string ->
+                 server:string ->
+                 ?user:string ->
+                 string -> t
+(** Create a nbdkit object using the SSH plugin.  The required
+    string parameter is the remote path.
+
+    This can fail (calling [error]) for a variety of reasons, such
+    as nbdkit not being available, wrong version, missing plugin, etc.
+
+    Note this doesn't run nbdkit yet, it just creates the object. *)
+
 val run : t -> string
 (** Start running nbdkit.
 
-- 
2.23.0




More information about the Libguestfs mailing list