Blame SOURCES/0002-i-libvirt-print-URI-without-connecting-RHBZ-1839917.patch

61e9b3
From e04f4d6aa0e94a61b40fa6b10a5274ea89cd96a1 Mon Sep 17 00:00:00 2001
61e9b3
From: Pino Toscano <ptoscano@redhat.com>
61e9b3
Date: Mon, 25 May 2020 16:52:07 +0200
61e9b3
Subject: [PATCH] -i libvirt: print URI without connecting (RHBZ#1839917)
61e9b3
61e9b3
Pass (again) around the libvirt URI string in the various input_libvirt
61e9b3
subclasses so that input_libvirt#as_options does not need to connect to
61e9b3
print the connection URI.
61e9b3
61e9b3
As related change: pass input_conn as non-optional string parameter in
61e9b3
classes that require one (all but input_libvirt_other, basically). This
61e9b3
avoids the need for extra checks.
61e9b3
61e9b3
(cherry picked from commit 86d87563ee03e86ca9abdcad4f674af66a883006)
61e9b3
---
61e9b3
 v2v/input_libvirt.ml                | 10 +++++-----
61e9b3
 v2v/input_libvirt_other.ml          | 12 ++++++++----
61e9b3
 v2v/input_libvirt_other.mli         |  4 ++--
61e9b3
 v2v/input_libvirt_vcenter_https.ml  |  4 ++--
61e9b3
 v2v/input_libvirt_vcenter_https.mli |  2 +-
61e9b3
 v2v/input_libvirt_vddk.ml           |  9 ++-------
61e9b3
 v2v/input_libvirt_vddk.mli          |  4 ++--
61e9b3
 v2v/input_libvirt_xen_ssh.ml        |  4 ++--
61e9b3
 v2v/input_libvirt_xen_ssh.mli       |  2 +-
61e9b3
 9 files changed, 25 insertions(+), 26 deletions(-)
61e9b3
61e9b3
diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml
61e9b3
index cd5f351c..352fae94 100644
61e9b3
--- a/v2v/input_libvirt.ml
61e9b3
+++ b/v2v/input_libvirt.ml
61e9b3
@@ -53,22 +53,22 @@ let input_libvirt input_conn input_password input_transport guest =
61e9b3
 
61e9b3
     | Some _, None, _                   (* No scheme? *)
61e9b3
     | Some _, Some "", _ ->
61e9b3
-      Input_libvirt_other.input_libvirt_other libvirt_conn guest
61e9b3
+      Input_libvirt_other.input_libvirt_other libvirt_conn ?input_conn guest
61e9b3
 
61e9b3
     (* vCenter over https. *)
61e9b3
     | Some server, Some ("esx"|"gsx"|"vpx"), None ->
61e9b3
        Input_libvirt_vcenter_https.input_libvirt_vcenter_https
61e9b3
-         libvirt_conn input_password parsed_uri server guest
61e9b3
+         libvirt_conn orig_uri input_password parsed_uri server guest
61e9b3
 
61e9b3
     (* vCenter or ESXi using nbdkit vddk plugin *)
61e9b3
     | Some server, Some ("esx"|"gsx"|"vpx"), Some (`VDDK vddk_options) ->
61e9b3
        Input_libvirt_vddk.input_libvirt_vddk
61e9b3
-         libvirt_conn input_conn input_password vddk_options parsed_uri guest
61e9b3
+         libvirt_conn orig_uri input_password vddk_options parsed_uri guest
61e9b3
 
61e9b3
     (* Xen over SSH *)
61e9b3
     | Some server, Some "xen+ssh", _ ->
61e9b3
       Input_libvirt_xen_ssh.input_libvirt_xen_ssh
61e9b3
-        libvirt_conn input_password parsed_uri server guest
61e9b3
+        libvirt_conn orig_uri input_password parsed_uri server guest
61e9b3
 
61e9b3
     (* Old virt-v2v also supported qemu+ssh://.  However I am
61e9b3
      * deliberately not supporting this in new virt-v2v.  Don't
61e9b3
@@ -79,6 +79,6 @@ let input_libvirt input_conn input_password input_transport guest =
61e9b3
     | Some _, Some _, _ ->
61e9b3
       warning (f_"no support for remote libvirt connections to '-ic %s'.  The conversion may fail when it tries to read the source disks.")
61e9b3
         orig_uri;
61e9b3
-      Input_libvirt_other.input_libvirt_other libvirt_conn guest
61e9b3
+      Input_libvirt_other.input_libvirt_other libvirt_conn ?input_conn guest
61e9b3
 
61e9b3
 let () = Modules_list.register_input_module "libvirt"
61e9b3
diff --git a/v2v/input_libvirt_other.ml b/v2v/input_libvirt_other.ml
61e9b3
index e00944db..6a19ae52 100644
61e9b3
--- a/v2v/input_libvirt_other.ml
61e9b3
+++ b/v2v/input_libvirt_other.ml
61e9b3
@@ -40,12 +40,16 @@ let error_if_libvirt_does_not_support_json_backingfile () =
61e9b3
     error (f_"because of libvirt bug https://bugzilla.redhat.com/1134878 you must EITHER upgrade to libvirt >= 2.1.0 OR set this environment variable:\n\nexport LIBGUESTFS_BACKEND=direct\n\nand then rerun the virt-v2v command.")
61e9b3
 
61e9b3
 (* Superclass. *)
61e9b3
-class virtual input_libvirt libvirt_conn guest =
61e9b3
+class virtual input_libvirt libvirt_conn ?input_conn guest =
61e9b3
 object (self)
61e9b3
   inherit input
61e9b3
 
61e9b3
   method as_options =
61e9b3
-    sprintf "-i libvirt -ic %s %s" (Libvirt.Connect.get_uri self#conn) guest
61e9b3
+    sprintf "-i libvirt%s %s"
61e9b3
+      (match input_conn with
61e9b3
+      | None -> ""
61e9b3
+      | Some uri -> " -ic " ^ uri)
61e9b3
+      guest
61e9b3
 
61e9b3
   method private conn : Libvirt.rw Libvirt.Connect.t =
61e9b3
     Lazy.force libvirt_conn
61e9b3
@@ -54,9 +58,9 @@ end
61e9b3
 (* Subclass specialized for handling anything that's *not* VMware vCenter
61e9b3
  * or Xen.
61e9b3
  *)
61e9b3
-class input_libvirt_other libvirt_conn guest =
61e9b3
+class input_libvirt_other libvirt_conn ?input_conn guest =
61e9b3
 object (self)
61e9b3
-  inherit input_libvirt libvirt_conn guest
61e9b3
+  inherit input_libvirt libvirt_conn ?input_conn guest
61e9b3
 
61e9b3
   method source ?bandwidth () =
61e9b3
     debug "input_libvirt_other: source ()";
61e9b3
diff --git a/v2v/input_libvirt_other.mli b/v2v/input_libvirt_other.mli
61e9b3
index c528c3ee..ae2c0c6d 100644
61e9b3
--- a/v2v/input_libvirt_other.mli
61e9b3
+++ b/v2v/input_libvirt_other.mli
61e9b3
@@ -20,11 +20,11 @@
61e9b3
 
61e9b3
 val error_if_libvirt_does_not_support_json_backingfile : unit -> unit
61e9b3
 
61e9b3
-class virtual input_libvirt : Libvirt.rw Libvirt.Connect.t Lazy.t -> string -> object
61e9b3
+class virtual input_libvirt : Libvirt.rw Libvirt.Connect.t Lazy.t -> ?input_conn:string -> string -> object
61e9b3
   method precheck : unit -> unit
61e9b3
   method as_options : string
61e9b3
   method virtual source : ?bandwidth:Types.bandwidth -> unit -> Types.source * Types.source_disk list
61e9b3
   method private conn : Libvirt.rw Libvirt.Connect.t
61e9b3
 end
61e9b3
 
61e9b3
-val input_libvirt_other : Libvirt.rw Libvirt.Connect.t Lazy.t -> string -> Types.input
61e9b3
+val input_libvirt_other : Libvirt.rw Libvirt.Connect.t Lazy.t -> ?input_conn:string -> string -> Types.input
61e9b3
diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml
61e9b3
index 77bc315d..ed2e5eed 100644
61e9b3
--- a/v2v/input_libvirt_vcenter_https.ml
61e9b3
+++ b/v2v/input_libvirt_vcenter_https.ml
61e9b3
@@ -32,9 +32,9 @@ open Printf
61e9b3
 
61e9b3
 (* Subclass specialized for handling VMware vCenter over https. *)
61e9b3
 class input_libvirt_vcenter_https
61e9b3
-        libvirt_conn input_password parsed_uri server guest =
61e9b3
+        libvirt_conn input_conn input_password parsed_uri server guest =
61e9b3
 object (self)
61e9b3
-  inherit input_libvirt libvirt_conn guest
61e9b3
+  inherit input_libvirt libvirt_conn ~input_conn guest
61e9b3
 
61e9b3
   val mutable dcPath = ""
61e9b3
 
61e9b3
diff --git a/v2v/input_libvirt_vcenter_https.mli b/v2v/input_libvirt_vcenter_https.mli
61e9b3
index c2e0f3fe..a12a9815 100644
61e9b3
--- a/v2v/input_libvirt_vcenter_https.mli
61e9b3
+++ b/v2v/input_libvirt_vcenter_https.mli
61e9b3
@@ -18,4 +18,4 @@
61e9b3
 
61e9b3
 (** [-i libvirt] when the source is VMware vCenter *)
61e9b3
 
61e9b3
-val input_libvirt_vcenter_https : Libvirt.rw Libvirt.Connect.t Lazy.t -> string option -> Xml.uri -> string -> string -> Types.input
61e9b3
+val input_libvirt_vcenter_https : Libvirt.rw Libvirt.Connect.t Lazy.t -> string -> string option -> Xml.uri -> string -> string -> Types.input
61e9b3
diff --git a/v2v/input_libvirt_vddk.ml b/v2v/input_libvirt_vddk.ml
61e9b3
index fbd1e0c6..75fd146e 100644
61e9b3
--- a/v2v/input_libvirt_vddk.ml
61e9b3
+++ b/v2v/input_libvirt_vddk.ml
61e9b3
@@ -99,7 +99,7 @@ class input_libvirt_vddk libvirt_conn input_conn input_password vddk_options
61e9b3
   in
61e9b3
 
61e9b3
 object (self)
61e9b3
-  inherit input_libvirt libvirt_conn guest as super
61e9b3
+  inherit input_libvirt libvirt_conn ~input_conn guest as super
61e9b3
 
61e9b3
   method precheck () =
61e9b3
     error_unless_thumbprint ()
61e9b3
@@ -138,12 +138,7 @@ object (self)
61e9b3
       match parsed_uri.Xml.uri_server with
61e9b3
       | Some server -> server
61e9b3
       | None ->
61e9b3
-         match input_conn with
61e9b3
-         | Some input_conn ->
61e9b3
-            error (f_"‘-ic %s’ URL does not contain a host name field")
61e9b3
-                  input_conn
61e9b3
-         | None ->
61e9b3
-            error (f_"you must use the ‘-ic’ parameter.  See the virt-v2v-input-vmware(1) manual.") in
61e9b3
+         error (f_"‘-ic %s’ URL does not contain a host name field") input_conn in
61e9b3
 
61e9b3
     let user = parsed_uri.Xml.uri_user in
61e9b3
 
61e9b3
diff --git a/v2v/input_libvirt_vddk.mli b/v2v/input_libvirt_vddk.mli
61e9b3
index 2fc6e9cf..f37d88e7 100644
61e9b3
--- a/v2v/input_libvirt_vddk.mli
61e9b3
+++ b/v2v/input_libvirt_vddk.mli
61e9b3
@@ -25,7 +25,7 @@ val print_input_options : unit -> unit
61e9b3
 val parse_input_options : (string * string) list -> vddk_options
61e9b3
 (** Print and parse vddk -io options. *)
61e9b3
 
61e9b3
-val input_libvirt_vddk : Libvirt.rw Libvirt.Connect.t Lazy.t -> string option -> string option -> vddk_options -> Xml.uri -> string -> Types.input
61e9b3
-(** [input_libvirt_vddk libvirt_conn vddk_options parsed_uri guest]
61e9b3
+val input_libvirt_vddk : Libvirt.rw Libvirt.Connect.t Lazy.t -> string -> string option -> vddk_options -> Xml.uri -> string -> Types.input
61e9b3
+(** [input_libvirt_vddk libvirt_conn input_conn vddk_options parsed_uri guest]
61e9b3
     creates and returns a {!Types.input} object specialized for reading
61e9b3
     the guest disks using the nbdkit vddk plugin. *)
61e9b3
diff --git a/v2v/input_libvirt_xen_ssh.ml b/v2v/input_libvirt_xen_ssh.ml
61e9b3
index bd1235a6..ec366b4a 100644
61e9b3
--- a/v2v/input_libvirt_xen_ssh.ml
61e9b3
+++ b/v2v/input_libvirt_xen_ssh.ml
61e9b3
@@ -30,9 +30,9 @@ open Input_libvirt_other
61e9b3
 open Printf
61e9b3
 
61e9b3
 (* Subclass specialized for handling Xen over SSH. *)
61e9b3
-class input_libvirt_xen_ssh libvirt_conn input_password parsed_uri server guest =
61e9b3
+class input_libvirt_xen_ssh libvirt_conn input_conn input_password parsed_uri server guest =
61e9b3
 object (self)
61e9b3
-  inherit input_libvirt libvirt_conn guest
61e9b3
+  inherit input_libvirt libvirt_conn ~input_conn guest
61e9b3
 
61e9b3
   method precheck () =
61e9b3
     if backend_is_libvirt () then
61e9b3
diff --git a/v2v/input_libvirt_xen_ssh.mli b/v2v/input_libvirt_xen_ssh.mli
61e9b3
index 120a52f7..3cbca9d7 100644
61e9b3
--- a/v2v/input_libvirt_xen_ssh.mli
61e9b3
+++ b/v2v/input_libvirt_xen_ssh.mli
61e9b3
@@ -18,4 +18,4 @@
61e9b3
 
61e9b3
 (** [-i libvirt] when the source is Xen *)
61e9b3
 
61e9b3
-val input_libvirt_xen_ssh : Libvirt.rw Libvirt.Connect.t Lazy.t -> string option -> Xml.uri -> string -> string -> Types.input
61e9b3
+val input_libvirt_xen_ssh : Libvirt.rw Libvirt.Connect.t Lazy.t -> string -> string option -> Xml.uri -> string -> string -> Types.input
61e9b3
-- 
8984ae
2.31.1
61e9b3