[Libguestfs] [PATCH 3/3] v2v: Refactor order of parameters to input objects.

Richard W.M. Jones rjones at redhat.com
Tue Jun 5 09:52:25 UTC 2018


Simple refactoring of the order of parameters to input objects
so they are always in the order:

  input_foo          ; class name
    input_conn       ; command line -iX parameters, alphabetically
    input_password   ;
    ...              ;
    vddk_options     ; extra class parameters
    ...              ;
    guestname        ; remaining command line parameters
---
 v2v/cmdline.ml                     |  2 +-
 v2v/input_libvirt.ml               | 18 +++++++++---------
 v2v/input_libvirt.mli              |  2 +-
 v2v/input_libvirt_other.ml         | 12 ++++++------
 v2v/input_libvirt_vcenter_https.ml |  8 ++++----
 v2v/input_libvirt_vddk.ml          | 14 +++++++-------
 v2v/input_libvirt_vddk.mli         |  4 ++--
 v2v/input_libvirt_xen_ssh.ml       |  8 ++++----
 8 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index 5414029d5..eaa11dba0 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -456,7 +456,7 @@ read the man page virt-v2v(1).
         | (Some (`VDDK _) as vddk) -> vddk
         | Some `SSH ->
            error (f_"only ‘-it vddk’ can be used here") in
-      Input_libvirt.input_libvirt input_password input_conn input_transport
+      Input_libvirt.input_libvirt input_conn input_password input_transport
                                   guest
 
     | `LibvirtXML ->
diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml
index 23ca0e281..2803c00f9 100644
--- a/v2v/input_libvirt.ml
+++ b/v2v/input_libvirt.ml
@@ -27,10 +27,10 @@ open Types
 open Utils
 
 (* Choose the right subclass based on the URI. *)
-let input_libvirt input_password libvirt_uri input_transport guest =
-  match libvirt_uri with
+let input_libvirt input_conn input_password input_transport guest =
+  match input_conn with
   | None ->
-    Input_libvirt_other.input_libvirt_other input_password libvirt_uri guest
+    Input_libvirt_other.input_libvirt_other input_conn input_password guest
 
   | Some orig_uri ->
     let { Xml.uri_server = server; uri_scheme = scheme } as parsed_uri =
@@ -45,22 +45,22 @@ let input_libvirt input_password libvirt_uri input_transport guest =
 
     | Some _, None, _                   (* No scheme? *)
     | Some _, Some "", _ ->
-      Input_libvirt_other.input_libvirt_other input_password libvirt_uri guest
+      Input_libvirt_other.input_libvirt_other input_conn input_password guest
 
     (* vCenter over https. *)
     | Some server, Some ("esx"|"gsx"|"vpx"), None ->
        Input_libvirt_vcenter_https.input_libvirt_vcenter_https
-         input_password libvirt_uri parsed_uri server guest
+         input_conn input_password parsed_uri server guest
 
     (* vCenter or ESXi using nbdkit vddk plugin *)
     | Some server, Some ("esx"|"gsx"|"vpx"), Some (`VDDK vddk_options) ->
-       Input_libvirt_vddk.input_libvirt_vddk vddk_options input_password
-                                             libvirt_uri parsed_uri guest
+       Input_libvirt_vddk.input_libvirt_vddk input_conn input_password
+                                             vddk_options parsed_uri guest
 
     (* Xen over SSH *)
     | Some server, Some "xen+ssh", _ ->
       Input_libvirt_xen_ssh.input_libvirt_xen_ssh
-        input_password libvirt_uri parsed_uri server guest
+        input_conn input_password parsed_uri server guest
 
     (* Old virt-v2v also supported qemu+ssh://.  However I am
      * deliberately not supporting this in new virt-v2v.  Don't
@@ -71,6 +71,6 @@ let input_libvirt input_password libvirt_uri input_transport guest =
     | Some _, Some _, _ ->
       warning (f_"no support for remote libvirt connections to '-ic %s'.  The conversion may fail when it tries to read the source disks.")
         orig_uri;
-      Input_libvirt_other.input_libvirt_other input_password libvirt_uri guest
+      Input_libvirt_other.input_libvirt_other input_conn input_password guest
 
 let () = Modules_list.register_input_module "libvirt"
diff --git a/v2v/input_libvirt.mli b/v2v/input_libvirt.mli
index 7b486532b..1a5e8f3a1 100644
--- a/v2v/input_libvirt.mli
+++ b/v2v/input_libvirt.mli
@@ -19,6 +19,6 @@
 (** [-i libvirt] source. *)
 
 val input_libvirt : string option -> string option -> [`VDDK of Input_libvirt_vddk.vddk_options] option -> string -> Types.input
-(** [input_libvirt input_password libvirt_uri input_transport guest]
+(** [input_libvirt input_conn input_password input_transport guest]
     creates and returns a new {!Types.input} object specialized for reading
     input from libvirt sources. *)
diff --git a/v2v/input_libvirt_other.ml b/v2v/input_libvirt_other.ml
index 25714d2c3..1414fe4f9 100644
--- a/v2v/input_libvirt_other.ml
+++ b/v2v/input_libvirt_other.ml
@@ -40,13 +40,13 @@ let error_if_libvirt_does_not_support_json_backingfile () =
     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.")
 
 (* Superclass. *)
-class virtual input_libvirt (input_password : string option) libvirt_uri guest =
+class virtual input_libvirt input_conn (input_password : string option) guest =
 object
   inherit input
 
   method as_options =
     sprintf "-i libvirt%s %s"
-      (match libvirt_uri with
+      (match input_conn with
       | None -> ""
       | Some uri -> " -ic " ^ uri)
       guest
@@ -55,9 +55,9 @@ end
 (* Subclass specialized for handling anything that's *not* VMware vCenter
  * or Xen.
  *)
-class input_libvirt_other input_password libvirt_uri guest =
+class input_libvirt_other input_conn input_password guest =
 object
-  inherit input_libvirt input_password libvirt_uri guest
+  inherit input_libvirt input_conn input_password guest
 
   method source () =
     debug "input_libvirt_other: source ()";
@@ -66,9 +66,9 @@ object
      * that the domain is not running.  (RHBZ#1138586)
      *)
     let xml = Libvirt_utils.dumpxml ?password_file:input_password
-                                    ?conn:libvirt_uri guest in
+                                    ?conn:input_conn guest in
 
-    let source, disks = parse_libvirt_xml ?conn:libvirt_uri xml in
+    let source, disks = parse_libvirt_xml ?conn:input_conn xml in
     let disks = List.map (fun { p_source_disk = disk } -> disk) disks in
     { source with s_disks = disks }
 end
diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml
index dfe3dcf96..edde185cd 100644
--- a/v2v/input_libvirt_vcenter_https.ml
+++ b/v2v/input_libvirt_vcenter_https.ml
@@ -36,9 +36,9 @@ let readahead_for_copying = Some (64 * 1024 * 1024)
 
 (* Subclass specialized for handling VMware vCenter over https. *)
 class input_libvirt_vcenter_https
-        input_password libvirt_uri parsed_uri server guest =
+        input_conn input_password parsed_uri server guest =
 object
-  inherit input_libvirt input_password libvirt_uri guest
+  inherit input_libvirt input_conn input_password guest
 
   val saved_source_paths = Hashtbl.create 13
   val mutable dcPath = ""
@@ -65,8 +65,8 @@ object
      * that the domain is not running.  (RHBZ#1138586)
      *)
     let xml = Libvirt_utils.dumpxml ?password_file:input_password
-                                    ?conn:libvirt_uri guest in
-    let source, disks = parse_libvirt_xml ?conn:libvirt_uri xml in
+                                    ?conn:input_conn guest in
+    let source, disks = parse_libvirt_xml ?conn:input_conn xml in
 
     (* Find the <vmware:datacenterpath> element from the XML.  This
      * was added in libvirt >= 1.2.20.
diff --git a/v2v/input_libvirt_vddk.ml b/v2v/input_libvirt_vddk.ml
index d0633d958..630a07e26 100644
--- a/v2v/input_libvirt_vddk.ml
+++ b/v2v/input_libvirt_vddk.ml
@@ -95,7 +95,7 @@ let parse_input_options options =
   options
 
 (* Subclass specialized for handling VMware via nbdkit vddk plugin. *)
-class input_libvirt_vddk vddk_options input_password libvirt_uri parsed_uri
+class input_libvirt_vddk input_conn input_password vddk_options parsed_uri
                          guest =
   (* The VDDK path. *)
   let libdir =
@@ -200,7 +200,7 @@ See also \"INPUT FROM VDDK\" in the virt-v2v(1) manual.") libNN
   in
 
 object
-  inherit input_libvirt input_password libvirt_uri guest as super
+  inherit input_libvirt input_conn input_password guest as super
 
   method precheck () =
     error_unless_vddk_libdir ();
@@ -224,8 +224,8 @@ object
      * that the domain is not running.  (RHBZ#1138586)
      *)
     let xml = Libvirt_utils.dumpxml ?password_file:input_password
-                                    ?conn:libvirt_uri guest in
-    let source, disks = parse_libvirt_xml ?conn:libvirt_uri xml in
+                                    ?conn:input_conn guest in
+    let source, disks = parse_libvirt_xml ?conn:input_conn xml in
 
     (* Find the <vmware:moref> element from the XML.  This was added
      * in libvirt >= 3.7 and is required.
@@ -270,10 +270,10 @@ object
         match parsed_uri.Xml.uri_server with
         | Some server -> server
         | None ->
-           match libvirt_uri with
-           | Some libvirt_uri ->
+           match input_conn with
+           | Some input_conn ->
               error (f_"‘-ic %s’ URL does not contain a host name field")
-                    libvirt_uri
+                    input_conn
            | None ->
               error (f_"you must use the ‘-ic’ parameter.  See \"INPUT FROM VDDK\" in the virt-v2v(1) manual.") in
 
diff --git a/v2v/input_libvirt_vddk.mli b/v2v/input_libvirt_vddk.mli
index ef975c280..d321677d8 100644
--- a/v2v/input_libvirt_vddk.mli
+++ b/v2v/input_libvirt_vddk.mli
@@ -25,7 +25,7 @@ val print_input_options : unit -> unit
 val parse_input_options : (string * string) list -> vddk_options
 (** Print and parse vddk -io options. *)
 
-val input_libvirt_vddk : vddk_options -> string option -> string option -> Xml.uri -> string -> Types.input
-(** [input_libvirt_vddk vddk_options input_password libvirt_uri parsed_uri guest]
+val input_libvirt_vddk : string option -> string option -> vddk_options -> Xml.uri -> string -> Types.input
+(** [input_libvirt_vddk input_conn input_password vddk_options parsed_uri guest]
     creates and returns a {!Types.input} object specialized for reading
     the guest disks using the nbdkit vddk plugin. *)
diff --git a/v2v/input_libvirt_xen_ssh.ml b/v2v/input_libvirt_xen_ssh.ml
index 2e769cd0b..597957f92 100644
--- a/v2v/input_libvirt_xen_ssh.ml
+++ b/v2v/input_libvirt_xen_ssh.ml
@@ -30,9 +30,9 @@ open Input_libvirt_other
 open Printf
 
 (* Subclass specialized for handling Xen over SSH. *)
-class input_libvirt_xen_ssh input_password libvirt_uri parsed_uri server guest =
+class input_libvirt_xen_ssh input_conn input_password parsed_uri server guest =
 object
-  inherit input_libvirt input_password libvirt_uri guest
+  inherit input_libvirt input_conn input_password guest
 
   method precheck () =
     if backend_is_libvirt () then
@@ -47,8 +47,8 @@ object
      * that the domain is not running.  (RHBZ#1138586)
      *)
     let xml = Libvirt_utils.dumpxml ?password_file:input_password
-                                    ?conn:libvirt_uri guest in
-    let source, disks = parse_libvirt_xml ?conn:libvirt_uri xml in
+                                    ?conn:input_conn guest in
+    let source, disks = parse_libvirt_xml ?conn:input_conn xml in
 
     (* Map the <source/> filename (which is relative to the remote
      * Xen server) to an ssh URI.  This is a JSON URI looking something
-- 
2.16.2




More information about the Libguestfs mailing list