virt-v2v/SOURCES/0006-virt-v2v-i-vmx-Add-the...

126 lines
4.9 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 60e72acb344e89656f7b13d9e360d05cc983a419 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 15 Jan 2024 16:14:10 +0000
Subject: [PATCH] virt-v2v: -i vmx: Add the input password to vmx_source
Since we use the input password in various places in the VMX module,
store the input password in vmx_source. This neutral refactoring
makes later changes simpler.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
input/input_vmx.ml | 13 ++++++-------
input/parse_domain_from_vmx.ml | 12 ++++++------
input/parse_domain_from_vmx.mli | 7 ++++---
3 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/input/input_vmx.ml b/input/input_vmx.ml
index bd20420c..b9cce10f 100644
--- a/input/input_vmx.ml
+++ b/input/input_vmx.ml
@@ -45,13 +45,17 @@ module VMX = struct
let vmx_source =
match args with
| [arg] ->
+ let input_password =
+ match options.input_password with
+ | None -> Nbdkit_ssh.NoPassword
+ | Some ip -> Nbdkit_ssh.PasswordFile ip in
let input_transport =
match options.input_transport with
| None -> None
| Some `SSH -> Some `SSH
| Some `VDDK ->
error (f_"-i vmx: cannot use -it vddk in this input mode") in
- vmx_source_of_arg input_transport arg
+ vmx_source_of_arg input_password input_transport arg
| _ ->
error (f_"-i vmx: expecting a VMX file or ssh:// URI") in
@@ -73,7 +77,7 @@ module VMX = struct
On_exit.kill pid
) filenames
- | SSH uri ->
+ | SSH (password, uri) ->
List.iteri (
fun i filename ->
let socket = sprintf "%s/in%d" dir i in
@@ -95,11 +99,6 @@ module VMX = struct
let server = Ssh.server_of_uri uri in
let port = Option.map string_of_int (Ssh.port_of_uri uri) in
let user = uri.Xml.uri_user in
- let password =
- match options.input_password with
- | None -> Nbdkit_ssh.NoPassword
- | Some ip -> Nbdkit_ssh.PasswordFile ip in
-
let cor = dir // "convert" in
let bandwidth = options.bandwidth in
let nbdkit = Nbdkit_ssh.create_ssh ?bandwidth ~cor ~password
diff --git a/input/parse_domain_from_vmx.ml b/input/parse_domain_from_vmx.ml
index e6500da6..0719738c 100644
--- a/input/parse_domain_from_vmx.ml
+++ b/input/parse_domain_from_vmx.ml
@@ -29,13 +29,13 @@ open Utils
open Name_from_disk
type vmx_source =
- | File of string (* local file or NFS *)
- | SSH of Xml.uri (* SSH URI *)
+ | File of string (* local file or NFS *)
+ | SSH of Nbdkit_ssh.password * Xml.uri (* SSH URI *)
(* The single filename on the command line is intepreted either as
* a local file or a remote SSH URI (only if -it ssh).
*)
-let vmx_source_of_arg input_transport arg =
+let vmx_source_of_arg input_password input_transport arg =
match input_transport, arg with
| None, arg -> File arg
| Some `SSH, arg ->
@@ -49,7 +49,7 @@ let vmx_source_of_arg input_transport arg =
error (f_"vmx URI remote server name omitted");
if uri.Xml.uri_path = None || uri.Xml.uri_path = Some "/" then
error (f_"vmx URI path component looks incorrect");
- SSH uri
+ SSH (input_password, uri)
let rec find_disks vmx vmx_source =
(* Set the s_disk_id field to an incrementing number. *)
@@ -334,7 +334,7 @@ let parse_domain_from_vmx vmx_source =
let vmx =
match vmx_source with
| File filename -> Parse_vmx.parse_file filename
- | SSH uri ->
+ | SSH (_, uri) ->
let filename = tmpdir // "source.vmx" in
Ssh.download_file uri filename;
Parse_vmx.parse_file filename in
@@ -346,7 +346,7 @@ let parse_domain_from_vmx vmx_source =
warning (f_"no displayName key found in VMX file");
match vmx_source with
| File filename -> name_from_disk filename
- | SSH uri -> name_from_disk (Ssh.path_of_uri uri) in
+ | SSH (_, uri) -> name_from_disk (Ssh.path_of_uri uri) in
let genid =
(* See: https://lists.nongnu.org/archive/html/qemu-devel/2018-07/msg02019.html *)
diff --git a/input/parse_domain_from_vmx.mli b/input/parse_domain_from_vmx.mli
index 42f8100e..208797a7 100644
--- a/input/parse_domain_from_vmx.mli
+++ b/input/parse_domain_from_vmx.mli
@@ -17,8 +17,9 @@
*)
type vmx_source =
- | File of string (** local file or NFS *)
- | SSH of Xml.uri (** SSH URI *)
+ | File of string (** local file or NFS *)
+ | SSH of Nbdkit_ssh.password * Xml.uri (** SSH URI *)
-val vmx_source_of_arg : [`SSH] option -> string -> vmx_source
+val vmx_source_of_arg : Nbdkit_ssh.password -> [`SSH] option -> string ->
+ vmx_source
val parse_domain_from_vmx : vmx_source -> Types.source * string list