Blame SOURCES/0017-v2v-Refactor-Xen-and-vCenter-code.patch

0d20ef
From e95e92ff06a0ef9edb3d3107e8bbc9acc8748f18 Mon Sep 17 00:00:00 2001
0d20ef
From: "Richard W.M. Jones" <rjones@redhat.com>
0d20ef
Date: Mon, 20 Oct 2014 19:35:23 +0100
0d20ef
Subject: [PATCH] v2v: Refactor Xen and vCenter code.
0d20ef
0d20ef
This refactors the code into more logical units, based on the previous
0d20ef
commits.  So Xen + the input_libvirt Xen code is grouped and moved
0d20ef
into a new module called Input_libvirt_xen_ssh.  Similarly VCenter +
0d20ef
input_libvirt vCenter code is moved to Input_libvirt_vcenter_https.
0d20ef
0d20ef
There is no change here, purely code motion.
0d20ef
0d20ef
(cherry picked from commit a468fde01687914de501f0a95cd5a40986daec29)
0d20ef
---
0d20ef
 po/POTFILES-ml                      |   5 +-
0d20ef
 v2v/Makefile.am                     |  10 +-
0d20ef
 v2v/input_libvirt.ml                | 145 +------------------
0d20ef
 v2v/input_libvirt_other.ml          |  76 ++++++++++
0d20ef
 v2v/input_libvirt_other.mli         |  30 ++++
0d20ef
 v2v/input_libvirt_vcenter_https.ml  | 270 ++++++++++++++++++++++++++++++++++++
0d20ef
 v2v/input_libvirt_vcenter_https.mli |  21 +++
0d20ef
 v2v/input_libvirt_xen_ssh.ml        | 103 ++++++++++++++
0d20ef
 v2v/input_libvirt_xen_ssh.mli       |  21 +++
0d20ef
 v2v/vCenter.ml                      | 211 ----------------------------
0d20ef
 v2v/vCenter.mli                     |  23 ---
0d20ef
 v2v/xen.ml                          |  71 ----------
0d20ef
 v2v/xen.mli                         |  22 ---
0d20ef
 13 files changed, 537 insertions(+), 471 deletions(-)
0d20ef
 create mode 100644 v2v/input_libvirt_other.ml
0d20ef
 create mode 100644 v2v/input_libvirt_other.mli
0d20ef
 create mode 100644 v2v/input_libvirt_vcenter_https.ml
0d20ef
 create mode 100644 v2v/input_libvirt_vcenter_https.mli
0d20ef
 create mode 100644 v2v/input_libvirt_xen_ssh.ml
0d20ef
 create mode 100644 v2v/input_libvirt_xen_ssh.mli
0d20ef
 delete mode 100644 v2v/vCenter.ml
0d20ef
 delete mode 100644 v2v/vCenter.mli
0d20ef
 delete mode 100644 v2v/xen.ml
0d20ef
 delete mode 100644 v2v/xen.mli
0d20ef
0d20ef
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
0d20ef
index d919b6f..7403497 100644
0d20ef
--- a/po/POTFILES-ml
0d20ef
+++ b/po/POTFILES-ml
0d20ef
@@ -91,6 +91,9 @@ v2v/convert_windows.ml
0d20ef
 v2v/domainxml.ml
0d20ef
 v2v/input_disk.ml
0d20ef
 v2v/input_libvirt.ml
0d20ef
+v2v/input_libvirt_other.ml
0d20ef
+v2v/input_libvirt_vcenter_https.ml
0d20ef
+v2v/input_libvirt_xen_ssh.ml
0d20ef
 v2v/input_libvirtxml.ml
0d20ef
 v2v/input_ova.ml
0d20ef
 v2v/kvmuid.ml
0d20ef
@@ -107,6 +110,4 @@ v2v/stringMap.ml
0d20ef
 v2v/types.ml
0d20ef
 v2v/utils.ml
0d20ef
 v2v/v2v.ml
0d20ef
-v2v/vCenter.ml
0d20ef
-v2v/xen.ml
0d20ef
 v2v/xml.ml
0d20ef
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
0d20ef
index c311623..921fb93 100644
0d20ef
--- a/v2v/Makefile.am
0d20ef
+++ b/v2v/Makefile.am
0d20ef
@@ -42,6 +42,9 @@ SOURCES_MLI = \
0d20ef
 	domainxml.mli \
0d20ef
 	input_disk.mli \
0d20ef
 	input_libvirt.mli \
0d20ef
+	input_libvirt_other.mli \
0d20ef
+	input_libvirt_vcenter_https.mli \
0d20ef
+	input_libvirt_xen_ssh.mli \
0d20ef
 	input_libvirtxml.mli \
0d20ef
 	input_ova.mli \
0d20ef
 	kvmuid.mli \
0d20ef
@@ -57,8 +60,6 @@ SOURCES_MLI = \
0d20ef
 	OVF.mli \
0d20ef
 	stringMap.mli \
0d20ef
 	types.mli \
0d20ef
-	vCenter.mli \
0d20ef
-	xen.mli \
0d20ef
 	xml.mli
0d20ef
 
0d20ef
 SOURCES_ML = \
0d20ef
@@ -69,13 +70,14 @@ SOURCES_ML = \
0d20ef
 	domainxml.ml \
0d20ef
 	DOM.ml \
0d20ef
 	kvmuid.ml \
0d20ef
-	vCenter.ml \
0d20ef
-	xen.ml \
0d20ef
 	OVF.ml \
0d20ef
 	linux.ml \
0d20ef
 	modules_list.ml \
0d20ef
 	input_disk.ml \
0d20ef
 	input_libvirtxml.ml \
0d20ef
+	input_libvirt_other.ml \
0d20ef
+	input_libvirt_vcenter_https.ml \
0d20ef
+	input_libvirt_xen_ssh.ml \
0d20ef
 	input_libvirt.ml \
0d20ef
 	input_ova.ml \
0d20ef
 	convert_linux.ml \
0d20ef
diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml
0d20ef
index 93d96b7..60e88ac 100644
0d20ef
--- a/v2v/input_libvirt.ml
0d20ef
+++ b/v2v/input_libvirt.ml
0d20ef
@@ -16,6 +16,8 @@
0d20ef
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
  *)
0d20ef
 
0d20ef
+(** [-i libvirt] source. *)
0d20ef
+
0d20ef
 open Printf
0d20ef
 
0d20ef
 open Common_gettext.Gettext
0d20ef
@@ -24,144 +26,11 @@ open Common_utils
0d20ef
 open Types
0d20ef
 open Utils
0d20ef
 
0d20ef
-(* Check the backend is not libvirt.  Works around a libvirt bug
0d20ef
- * (RHBZ#1134592).  This can be removed once the libvirt bug is fixed.
0d20ef
- *)
0d20ef
-let error_if_libvirt_backend () =
0d20ef
-  let libguestfs_backend = (new Guestfs.guestfs ())#get_backend () in
0d20ef
-  if libguestfs_backend = "libvirt" then (
0d20ef
-    error (f_"because of libvirt bug https://bugzilla.redhat.com/show_bug.cgi?id=1134592 you must set this environment variable:\n\nexport LIBGUESTFS_BACKEND=direct\n\nand then rerun the virt-v2v command.")
0d20ef
-  )
0d20ef
-
0d20ef
-(* xen+ssh URLs use the SSH driver in CURL.  Currently this requires
0d20ef
- * ssh-agent authentication.  Give a clear error if this hasn't been
0d20ef
- * set up (RHBZ#1139973).
0d20ef
- *)
0d20ef
-let error_if_no_ssh_agent () =
0d20ef
-  try ignore (Sys.getenv "SSH_AUTH_SOCK")
0d20ef
-  with Not_found ->
0d20ef
-    error (f_"ssh-agent authentication has not been set up ($SSH_AUTH_SOCK is not set).  Please read \"INPUT FROM RHEL 5 XEN\" in the virt-v2v(1) man page.")
0d20ef
-
0d20ef
-(* Superclass. *)
0d20ef
-class virtual input_libvirt verbose libvirt_uri guest =
0d20ef
-object
0d20ef
-  inherit input verbose
0d20ef
-
0d20ef
-  method as_options =
0d20ef
-    sprintf "-i libvirt%s %s"
0d20ef
-      (match libvirt_uri with
0d20ef
-      | None -> ""
0d20ef
-      | Some uri -> " -ic " ^ uri)
0d20ef
-      guest
0d20ef
-end
0d20ef
-
0d20ef
-(* Subclass specialized for handling anything that's *not* VMware vCenter
0d20ef
- * or Xen.
0d20ef
- *)
0d20ef
-class input_libvirt_other verbose libvirt_uri guest =
0d20ef
-object
0d20ef
-  inherit input_libvirt verbose libvirt_uri guest
0d20ef
-
0d20ef
-  method source () =
0d20ef
-    if verbose then printf "input_libvirt_other: source()\n%!";
0d20ef
-
0d20ef
-    (* Get the libvirt XML.  This also checks (as a side-effect)
0d20ef
-     * that the domain is not running.  (RHBZ#1138586)
0d20ef
-     *)
0d20ef
-    let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
0d20ef
-
0d20ef
-    Input_libvirtxml.parse_libvirt_xml ~verbose xml
0d20ef
-end
0d20ef
-
0d20ef
-(* Subclass specialized for handling VMware vCenter over https. *)
0d20ef
-class input_libvirt_vcenter_https
0d20ef
-  verbose libvirt_uri parsed_uri scheme server guest =
0d20ef
-object
0d20ef
-  inherit input_libvirt verbose libvirt_uri guest
0d20ef
-
0d20ef
-  val mutable mapf = fun ?readahead uri format -> uri, format
0d20ef
-  val saved_uri = Hashtbl.create 13
0d20ef
-
0d20ef
-  method source () =
0d20ef
-    if verbose then printf "input_libvirt_vcenter_https: source()\n%!";
0d20ef
-
0d20ef
-    error_if_libvirt_backend ();
0d20ef
-
0d20ef
-    (* Get the libvirt XML.  This also checks (as a side-effect)
0d20ef
-     * that the domain is not running.  (RHBZ#1138586)
0d20ef
-     *)
0d20ef
-    let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
0d20ef
-    let { s_disks = disks } as source =
0d20ef
-      Input_libvirtxml.parse_libvirt_xml ~verbose xml in
0d20ef
-
0d20ef
-    (* Save the mapf function and the original s_qemu_uri fields, so
0d20ef
-     * we can get them in the adjust_overlay_parameters method below.
0d20ef
-     *)
0d20ef
-    mapf <- VCenter.map_path_to_uri verbose parsed_uri scheme server;
0d20ef
-    List.iter (
0d20ef
-      fun disk ->
0d20ef
-        Hashtbl.add saved_uri disk.s_disk_id (disk.s_qemu_uri, disk.s_format)
0d20ef
-    ) disks;
0d20ef
-
0d20ef
-    let disks = List.map (
0d20ef
-      fun ({ s_qemu_uri = uri; s_format = format } as disk) ->
0d20ef
-        let uri, format = mapf uri format in
0d20ef
-        { disk with s_qemu_uri = uri; s_format = format }
0d20ef
-    ) disks in
0d20ef
-
0d20ef
-    { source with s_disks = disks }
0d20ef
-
0d20ef
-  (* See RHBZ#1151033 and RHBZ#1153589 for why this is necessary. *)
0d20ef
-  method adjust_overlay_parameters overlay =
0d20ef
-    let orig_uri, orig_format =
0d20ef
-      try Hashtbl.find saved_uri overlay.ov_source.s_disk_id
0d20ef
-      with Not_found -> failwith "internal error in adjust_overlay_parameters" in
0d20ef
-    let backing_file, _ =
0d20ef
-      mapf ~readahead:(64 * 1024 * 1024) orig_uri orig_format in
0d20ef
-
0d20ef
-    (* Rebase the qcow2 overlay to adjust the readahead parameter. *)
0d20ef
-    let cmd =
0d20ef
-      sprintf "qemu-img rebase -u -b %s %s"
0d20ef
-        (quote backing_file) (quote overlay.ov_overlay_file) in
0d20ef
-    if verbose then printf "%s\n%!" cmd;
0d20ef
-    if Sys.command cmd <> 0 then
0d20ef
-      warning ~prog (f_"qemu-img rebase failed, see earlier errors")
0d20ef
-end
0d20ef
-
0d20ef
-(* Subclass specialized for handling Xen over SSH. *)
0d20ef
-class input_libvirt_xen_ssh
0d20ef
-  verbose libvirt_uri parsed_uri scheme server guest =
0d20ef
-object
0d20ef
-  inherit input_libvirt verbose libvirt_uri guest
0d20ef
-
0d20ef
-  method source () =
0d20ef
-    if verbose then printf "input_libvirt_xen_ssh: source()\n%!";
0d20ef
-
0d20ef
-    error_if_libvirt_backend ();
0d20ef
-    error_if_no_ssh_agent ();
0d20ef
-
0d20ef
-    (* Get the libvirt XML.  This also checks (as a side-effect)
0d20ef
-     * that the domain is not running.  (RHBZ#1138586)
0d20ef
-     *)
0d20ef
-    let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
0d20ef
-    let { s_disks = disks } as source =
0d20ef
-      Input_libvirtxml.parse_libvirt_xml ~verbose xml in
0d20ef
-
0d20ef
-    let mapf = Xen.map_path_to_uri verbose parsed_uri scheme server in
0d20ef
-    let disks = List.map (
0d20ef
-      fun ({ s_qemu_uri = uri; s_format = format } as disk) ->
0d20ef
-        let uri, format = mapf uri format in
0d20ef
-        { disk with s_qemu_uri = uri; s_format = format }
0d20ef
-    ) disks in
0d20ef
-
0d20ef
-    { source with s_disks = disks }
0d20ef
-end
0d20ef
-
0d20ef
 (* Choose the right subclass based on the URI. *)
0d20ef
 let input_libvirt verbose libvirt_uri guest =
0d20ef
   match libvirt_uri with
0d20ef
   | None ->
0d20ef
-    new input_libvirt_other verbose libvirt_uri guest
0d20ef
+    Input_libvirt_other.input_libvirt_other verbose libvirt_uri guest
0d20ef
 
0d20ef
   | Some orig_uri ->
0d20ef
     let { Xml.uri_server = server; uri_scheme = scheme } as parsed_uri =
0d20ef
@@ -176,14 +45,14 @@ let input_libvirt verbose libvirt_uri guest =
0d20ef
 
0d20ef
     | Some _, None                      (* No scheme? *)
0d20ef
     | Some _, Some "" ->
0d20ef
-      new input_libvirt_other verbose libvirt_uri guest
0d20ef
+      Input_libvirt_other.input_libvirt_other verbose libvirt_uri guest
0d20ef
 
0d20ef
     | Some server, Some ("esx"|"gsx"|"vpx" as scheme) -> (* vCenter over https *)
0d20ef
-      new input_libvirt_vcenter_https
0d20ef
+      Input_libvirt_vcenter_https.input_libvirt_vcenter_https
0d20ef
         verbose libvirt_uri parsed_uri scheme server guest
0d20ef
 
0d20ef
     | Some server, Some ("xen+ssh" as scheme) -> (* Xen over SSH *)
0d20ef
-      new input_libvirt_xen_ssh
0d20ef
+      Input_libvirt_xen_ssh.input_libvirt_xen_ssh
0d20ef
         verbose libvirt_uri parsed_uri scheme server guest
0d20ef
 
0d20ef
     (* Old virt-v2v also supported qemu+ssh://.  However I am
0d20ef
@@ -194,6 +63,6 @@ let input_libvirt verbose libvirt_uri guest =
0d20ef
     | Some _, Some _ ->             (* Unknown remote scheme. *)
0d20ef
       warning ~prog (f_"no support for remote libvirt connections to '-ic %s'.  The conversion may fail when it tries to read the source disks.")
0d20ef
         orig_uri;
0d20ef
-      new input_libvirt_other verbose libvirt_uri guest
0d20ef
+      Input_libvirt_other.input_libvirt_other verbose libvirt_uri guest
0d20ef
 
0d20ef
 let () = Modules_list.register_input_module "libvirt"
0d20ef
diff --git a/v2v/input_libvirt_other.ml b/v2v/input_libvirt_other.ml
0d20ef
new file mode 100644
0d20ef
index 0000000..a771aa1
0d20ef
--- /dev/null
0d20ef
+++ b/v2v/input_libvirt_other.ml
0d20ef
@@ -0,0 +1,76 @@
0d20ef
+(* virt-v2v
0d20ef
+ * Copyright (C) 2009-2014 Red Hat Inc.
0d20ef
+ *
0d20ef
+ * This program is free software; you can redistribute it and/or modify
0d20ef
+ * it under the terms of the GNU General Public License as published by
0d20ef
+ * the Free Software Foundation; either version 2 of the License, or
0d20ef
+ * (at your option) any later version.
0d20ef
+ *
0d20ef
+ * This program is distributed in the hope that it will be useful,
0d20ef
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
+ * GNU General Public License for more details.
0d20ef
+ *
0d20ef
+ * You should have received a copy of the GNU General Public License along
0d20ef
+ * with this program; if not, write to the Free Software Foundation, Inc.,
0d20ef
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
+ *)
0d20ef
+
0d20ef
+open Printf
0d20ef
+
0d20ef
+open Common_gettext.Gettext
0d20ef
+open Common_utils
0d20ef
+
0d20ef
+open Types
0d20ef
+open Utils
0d20ef
+
0d20ef
+(* Check the backend is not libvirt.  Works around a libvirt bug
0d20ef
+ * (RHBZ#1134592).  This can be removed once the libvirt bug is fixed.
0d20ef
+ *)
0d20ef
+let error_if_libvirt_backend () =
0d20ef
+  let libguestfs_backend = (new Guestfs.guestfs ())#get_backend () in
0d20ef
+  if libguestfs_backend = "libvirt" then (
0d20ef
+    error (f_"because of libvirt bug https://bugzilla.redhat.com/show_bug.cgi?id=1134592 you must set this environment variable:\n\nexport LIBGUESTFS_BACKEND=direct\n\nand then rerun the virt-v2v command.")
0d20ef
+  )
0d20ef
+
0d20ef
+(* xen+ssh URLs use the SSH driver in CURL.  Currently this requires
0d20ef
+ * ssh-agent authentication.  Give a clear error if this hasn't been
0d20ef
+ * set up (RHBZ#1139973).
0d20ef
+ *)
0d20ef
+let error_if_no_ssh_agent () =
0d20ef
+  try ignore (Sys.getenv "SSH_AUTH_SOCK")
0d20ef
+  with Not_found ->
0d20ef
+    error (f_"ssh-agent authentication has not been set up ($SSH_AUTH_SOCK is not set).  Please read \"INPUT FROM RHEL 5 XEN\" in the virt-v2v(1) man page.")
0d20ef
+
0d20ef
+(* Superclass. *)
0d20ef
+class virtual input_libvirt verbose libvirt_uri guest =
0d20ef
+object
0d20ef
+  inherit input verbose
0d20ef
+
0d20ef
+  method as_options =
0d20ef
+    sprintf "-i libvirt%s %s"
0d20ef
+      (match libvirt_uri with
0d20ef
+      | None -> ""
0d20ef
+      | Some uri -> " -ic " ^ uri)
0d20ef
+      guest
0d20ef
+end
0d20ef
+
0d20ef
+(* Subclass specialized for handling anything that's *not* VMware vCenter
0d20ef
+ * or Xen.
0d20ef
+ *)
0d20ef
+class input_libvirt_other verbose libvirt_uri guest =
0d20ef
+object
0d20ef
+  inherit input_libvirt verbose libvirt_uri guest
0d20ef
+
0d20ef
+  method source () =
0d20ef
+    if verbose then printf "input_libvirt_other: source()\n%!";
0d20ef
+
0d20ef
+    (* Get the libvirt XML.  This also checks (as a side-effect)
0d20ef
+     * that the domain is not running.  (RHBZ#1138586)
0d20ef
+     *)
0d20ef
+    let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
0d20ef
+
0d20ef
+    Input_libvirtxml.parse_libvirt_xml ~verbose xml
0d20ef
+end
0d20ef
+
0d20ef
+let input_libvirt_other = new input_libvirt_other
0d20ef
diff --git a/v2v/input_libvirt_other.mli b/v2v/input_libvirt_other.mli
0d20ef
new file mode 100644
0d20ef
index 0000000..013d3bb
0d20ef
--- /dev/null
0d20ef
+++ b/v2v/input_libvirt_other.mli
0d20ef
@@ -0,0 +1,30 @@
0d20ef
+(* virt-v2v
0d20ef
+ * Copyright (C) 2009-2014 Red Hat Inc.
0d20ef
+ *
0d20ef
+ * This program is free software; you can redistribute it and/or modify
0d20ef
+ * it under the terms of the GNU General Public License as published by
0d20ef
+ * the Free Software Foundation; either version 2 of the License, or
0d20ef
+ * (at your option) any later version.
0d20ef
+ *
0d20ef
+ * This program is distributed in the hope that it will be useful,
0d20ef
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
+ * GNU General Public License for more details.
0d20ef
+ *
0d20ef
+ * You should have received a copy of the GNU General Public License along
0d20ef
+ * with this program; if not, write to the Free Software Foundation, Inc.,
0d20ef
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
+ *)
0d20ef
+
0d20ef
+(** [-i libvirt] source. *)
0d20ef
+
0d20ef
+val error_if_libvirt_backend : unit -> unit
0d20ef
+val error_if_no_ssh_agent : unit -> unit
0d20ef
+
0d20ef
+class virtual input_libvirt : bool -> string option -> string -> object
0d20ef
+  method as_options : string
0d20ef
+  method virtual source : unit -> Types.source
0d20ef
+  method adjust_overlay_parameters : Types.overlay -> unit
0d20ef
+end
0d20ef
+
0d20ef
+val input_libvirt_other : bool -> string option -> string -> Types.input
0d20ef
diff --git a/v2v/input_libvirt_vcenter_https.ml b/v2v/input_libvirt_vcenter_https.ml
0d20ef
new file mode 100644
0d20ef
index 0000000..7dde9be
0d20ef
--- /dev/null
0d20ef
+++ b/v2v/input_libvirt_vcenter_https.ml
0d20ef
@@ -0,0 +1,270 @@
0d20ef
+(* virt-v2v
0d20ef
+ * Copyright (C) 2009-2014 Red Hat Inc.
0d20ef
+ *
0d20ef
+ * This program is free software; you can redistribute it and/or modify
0d20ef
+ * it under the terms of the GNU General Public License as published by
0d20ef
+ * the Free Software Foundation; either version 2 of the License, or
0d20ef
+ * (at your option) any later version.
0d20ef
+ *
0d20ef
+ * This program is distributed in the hope that it will be useful,
0d20ef
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
+ * GNU General Public License for more details.
0d20ef
+ *
0d20ef
+ * You should have received a copy of the GNU General Public License along
0d20ef
+ * with this program; if not, write to the Free Software Foundation, Inc.,
0d20ef
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
+ *)
0d20ef
+
0d20ef
+(** [-i libvirt] when the source is VMware vCenter *)
0d20ef
+
0d20ef
+open Common_gettext.Gettext
0d20ef
+open Common_utils
0d20ef
+
0d20ef
+open Types
0d20ef
+open Xml
0d20ef
+open Utils
0d20ef
+open Input_libvirt_other
0d20ef
+
0d20ef
+open Printf
0d20ef
+
0d20ef
+let esx_re = Str.regexp "^\\[\\(.*\\)\\] \\(.*\\)\\.vmdk$"
0d20ef
+
0d20ef
+let session_cookie = ref ""
0d20ef
+
0d20ef
+(* Map an ESX <source/> to a qemu URI using the cURL driver
0d20ef
+ * in qemu.  The 'path' will be something like
0d20ef
+ *
0d20ef
+ *   "[datastore1] Fedora 20/Fedora 20.vmdk"
0d20ef
+ *
0d20ef
+ * including those literal spaces in the string.
0d20ef
+ *
0d20ef
+ * XXX Old virt-v2v could also handle snapshots, ie:
0d20ef
+ *
0d20ef
+ *   "[datastore1] Fedora 20/Fedora 20-NNNNNN.vmdk"
0d20ef
+ *
0d20ef
+ * XXX Need to handle templates.  The file is called "-delta.vmdk" in
0d20ef
+ * place of "-flat.vmdk".
0d20ef
+ *)
0d20ef
+let rec map_path_to_uri verbose uri scheme server ?readahead path format =
0d20ef
+  if not (Str.string_match esx_re path 0) then
0d20ef
+    path, format
0d20ef
+  else (
0d20ef
+    let datastore = Str.matched_group 1 path
0d20ef
+    and path = Str.matched_group 2 path in
0d20ef
+
0d20ef
+    (* Get the datacenter. *)
0d20ef
+    let datacenter = get_datacenter uri scheme in
0d20ef
+
0d20ef
+    let port =
0d20ef
+      match uri.uri_port with
0d20ef
+      | 443 -> ""
0d20ef
+      | n when n >= 1 -> ":" ^ string_of_int n
0d20ef
+      | _ -> "" in
0d20ef
+
0d20ef
+    let url =
0d20ef
+      sprintf
0d20ef
+        "https://%s%s/folder/%s-flat.vmdk?dcPath=%s&dsName=%s"
0d20ef
+        server port
0d20ef
+        (uri_quote path) (uri_quote datacenter) (uri_quote datastore) in
0d20ef
+
0d20ef
+    (* If no_verify=1 was passed in the libvirt URI, then we have to
0d20ef
+     * turn off certificate verification here too.
0d20ef
+     *)
0d20ef
+    let sslverify =
0d20ef
+      match uri.uri_query_raw with
0d20ef
+      | None -> true
0d20ef
+      | Some query ->
0d20ef
+        (* XXX only works if the query string is not URI-quoted *)
0d20ef
+        string_find query "no_verify=1" = -1 in
0d20ef
+
0d20ef
+    (* Now we have to query the server to get the session cookie. *)
0d20ef
+    let session_cookie = get_session_cookie verbose scheme uri sslverify url in
0d20ef
+
0d20ef
+    (* Construct the JSON parameters. *)
0d20ef
+    let json_params = [
0d20ef
+      "file.driver", JSON.String "https";
0d20ef
+      "file.url", JSON.String url;
0d20ef
+      "file.timeout", JSON.Int 600;
0d20ef
+    ] in
0d20ef
+
0d20ef
+    let json_params =
0d20ef
+      match readahead with
0d20ef
+      | None -> json_params
0d20ef
+      | Some readahead ->
0d20ef
+        ("file.readahead", JSON.Int readahead) :: json_params in
0d20ef
+
0d20ef
+    let json_params =
0d20ef
+      if sslverify then json_params
0d20ef
+      else ("file.sslverify", JSON.String "off") :: json_params in
0d20ef
+
0d20ef
+    let json_params =
0d20ef
+      match session_cookie with
0d20ef
+      | None -> json_params
0d20ef
+      | Some cookie -> ("file.cookie", JSON.String cookie) :: json_params in
0d20ef
+
0d20ef
+    if verbose then
0d20ef
+      printf "esx: json parameters: %s\n" (JSON.string_of_doc json_params);
0d20ef
+
0d20ef
+    (* Turn the JSON parameters into a 'json:' protocol string.
0d20ef
+     * Note this requires qemu-img >= 2.1.0.
0d20ef
+     *)
0d20ef
+    let qemu_uri = "json: " ^ JSON.string_of_doc json_params in
0d20ef
+
0d20ef
+    (* The libvirt ESX driver doesn't normally specify a format, but
0d20ef
+     * the format of the -flat file is *always* raw, so force it here.
0d20ef
+     *)
0d20ef
+    qemu_uri, Some "raw"
0d20ef
+  )
0d20ef
+
0d20ef
+and get_datacenter uri scheme =
0d20ef
+  let default_dc = "ha-datacenter" in
0d20ef
+  match scheme with
0d20ef
+  | "vpx" ->           (* Hopefully the first part of the path. *)
0d20ef
+    (match uri.uri_path with
0d20ef
+    | None ->
0d20ef
+      warning ~prog (f_"esx: URI (-ic parameter) contains no path, so we cannot determine the datacenter name");
0d20ef
+      default_dc
0d20ef
+    | Some path ->
0d20ef
+      let path =
0d20ef
+        let len = String.length path in
0d20ef
+        if len > 0 && path.[0] = '/' then
0d20ef
+          String.sub path 1 (len-1)
0d20ef
+        else path in
0d20ef
+      let len =
0d20ef
+        try String.index path '/' with Not_found -> String.length path in
0d20ef
+      String.sub path 0 len
0d20ef
+    );
0d20ef
+  | "esx" -> (* Connecting to an ESXi hypervisor directly, so it's fixed. *)
0d20ef
+    default_dc
0d20ef
+  | _ ->                            (* Don't know, so guess. *)
0d20ef
+    default_dc
0d20ef
+
0d20ef
+and get_session_cookie verbose scheme uri sslverify url =
0d20ef
+  (* Memoize the session cookie. *)
0d20ef
+  if !session_cookie <> "" then
0d20ef
+    Some !session_cookie
0d20ef
+  else (
0d20ef
+    let cmd =
0d20ef
+      sprintf "curl -s%s%s%s -I %s ||:"
0d20ef
+        (if not sslverify then " --insecure" else "")
0d20ef
+        (match uri.uri_user with Some _ -> " -u" | None -> "")
0d20ef
+        (match uri.uri_user with Some user -> " " ^ quote user | None -> "")
0d20ef
+        (quote url) in
0d20ef
+    let lines = external_command ~prog cmd in
0d20ef
+
0d20ef
+    let dump_response chan =
0d20ef
+      fprintf chan "%s\n" cmd;
0d20ef
+      List.iter (fun x -> fprintf chan "%s\n" x) lines
0d20ef
+    in
0d20ef
+
0d20ef
+    if verbose then dump_response stdout;
0d20ef
+
0d20ef
+    (* Look for the last HTTP/x.y NNN status code in the output. *)
0d20ef
+    let status = ref "" in
0d20ef
+    List.iter (
0d20ef
+      fun line ->
0d20ef
+        let len = String.length line in
0d20ef
+        if len >= 12 && String.sub line 0 5 = "HTTP/" then
0d20ef
+          status := String.sub line 9 3
0d20ef
+    ) lines;
0d20ef
+    let status = !status in
0d20ef
+    if status = "" then (
0d20ef
+      dump_response stderr;
0d20ef
+      error (f_"esx: no status code in output of 'curl' command.  Is 'curl' installed?")
0d20ef
+    );
0d20ef
+
0d20ef
+    if status = "401" then (
0d20ef
+      dump_response stderr;
0d20ef
+      if uri.uri_user <> None then
0d20ef
+        error (f_"esx: incorrect username or password")
0d20ef
+      else
0d20ef
+        error (f_"esx: incorrect username or password.  You might need to specify the username in the URI like this: %s://USERNAME@[etc]")
0d20ef
+          scheme
0d20ef
+    );
0d20ef
+
0d20ef
+    if status = "404" then (
0d20ef
+      dump_response stderr;
0d20ef
+      error (f_"esx: URL not found: %s") url
0d20ef
+    );
0d20ef
+
0d20ef
+    if status <> "200" then (
0d20ef
+      dump_response stderr;
0d20ef
+      error (f_"esx: invalid response from server")
0d20ef
+    );
0d20ef
+
0d20ef
+    (* Get the cookie. *)
0d20ef
+    List.iter (
0d20ef
+      fun line ->
0d20ef
+        let len = String.length line in
0d20ef
+        if len >= 12 && String.sub line 0 12 = "Set-Cookie: " then (
0d20ef
+          let line = String.sub line 12 (len-12) in
0d20ef
+          let cookie, _ = string_split ";" line in
0d20ef
+          session_cookie := cookie
0d20ef
+        )
0d20ef
+    ) lines;
0d20ef
+    if !session_cookie = "" then (
0d20ef
+      dump_response stderr;
0d20ef
+      warning ~prog (f_"esx: could not read session cookie from the vCenter Server, conversion may consume all sessions on the server and fail part way through");
0d20ef
+      None
0d20ef
+    )
0d20ef
+    else
0d20ef
+      Some !session_cookie
0d20ef
+  )
0d20ef
+
0d20ef
+(* Subclass specialized for handling VMware vCenter over https. *)
0d20ef
+class input_libvirt_vcenter_https
0d20ef
+  verbose libvirt_uri parsed_uri scheme server guest =
0d20ef
+object
0d20ef
+  inherit input_libvirt verbose libvirt_uri guest
0d20ef
+
0d20ef
+  val mutable mapf = fun ?readahead uri format -> uri, format
0d20ef
+  val saved_uri = Hashtbl.create 13
0d20ef
+
0d20ef
+  method source () =
0d20ef
+    if verbose then printf "input_libvirt_vcenter_https: source()\n%!";
0d20ef
+
0d20ef
+    error_if_libvirt_backend ();
0d20ef
+
0d20ef
+    (* Get the libvirt XML.  This also checks (as a side-effect)
0d20ef
+     * that the domain is not running.  (RHBZ#1138586)
0d20ef
+     *)
0d20ef
+    let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
0d20ef
+    let { s_disks = disks } as source =
0d20ef
+      Input_libvirtxml.parse_libvirt_xml ~verbose xml in
0d20ef
+
0d20ef
+    (* Save the mapf function and the original s_qemu_uri fields, so
0d20ef
+     * we can get them in the adjust_overlay_parameters method below.
0d20ef
+     *)
0d20ef
+    mapf <- map_path_to_uri verbose parsed_uri scheme server;
0d20ef
+    List.iter (
0d20ef
+      fun disk ->
0d20ef
+        Hashtbl.add saved_uri disk.s_disk_id (disk.s_qemu_uri, disk.s_format)
0d20ef
+    ) disks;
0d20ef
+
0d20ef
+    let disks = List.map (
0d20ef
+      fun ({ s_qemu_uri = uri; s_format = format } as disk) ->
0d20ef
+        let uri, format = mapf uri format in
0d20ef
+        { disk with s_qemu_uri = uri; s_format = format }
0d20ef
+    ) disks in
0d20ef
+
0d20ef
+    { source with s_disks = disks }
0d20ef
+
0d20ef
+  (* See RHBZ#1151033 and RHBZ#1153589 for why this is necessary. *)
0d20ef
+  method adjust_overlay_parameters overlay =
0d20ef
+    let orig_uri, orig_format =
0d20ef
+      try Hashtbl.find saved_uri overlay.ov_source.s_disk_id
0d20ef
+      with Not_found -> failwith "internal error in adjust_overlay_parameters" in
0d20ef
+    let backing_file, _ =
0d20ef
+      mapf ~readahead:(64 * 1024 * 1024) orig_uri orig_format in
0d20ef
+
0d20ef
+    (* Rebase the qcow2 overlay to adjust the readahead parameter. *)
0d20ef
+    let cmd =
0d20ef
+      sprintf "qemu-img rebase -u -b %s %s"
0d20ef
+        (quote backing_file) (quote overlay.ov_overlay_file) in
0d20ef
+    if verbose then printf "%s\n%!" cmd;
0d20ef
+    if Sys.command cmd <> 0 then
0d20ef
+      warning ~prog (f_"qemu-img rebase failed, see earlier errors")
0d20ef
+end
0d20ef
+
0d20ef
+let input_libvirt_vcenter_https = new input_libvirt_vcenter_https
0d20ef
diff --git a/v2v/input_libvirt_vcenter_https.mli b/v2v/input_libvirt_vcenter_https.mli
0d20ef
new file mode 100644
0d20ef
index 0000000..82dce53
0d20ef
--- /dev/null
0d20ef
+++ b/v2v/input_libvirt_vcenter_https.mli
0d20ef
@@ -0,0 +1,21 @@
0d20ef
+(* virt-v2v
0d20ef
+ * Copyright (C) 2009-2014 Red Hat Inc.
0d20ef
+ *
0d20ef
+ * This program is free software; you can redistribute it and/or modify
0d20ef
+ * it under the terms of the GNU General Public License as published by
0d20ef
+ * the Free Software Foundation; either version 2 of the License, or
0d20ef
+ * (at your option) any later version.
0d20ef
+ *
0d20ef
+ * This program is distributed in the hope that it will be useful,
0d20ef
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
+ * GNU General Public License for more details.
0d20ef
+ *
0d20ef
+ * You should have received a copy of the GNU General Public License along
0d20ef
+ * with this program; if not, write to the Free Software Foundation, Inc.,
0d20ef
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
+ *)
0d20ef
+
0d20ef
+(** [-i libvirt] when the source is VMware vCenter *)
0d20ef
+
0d20ef
+val input_libvirt_vcenter_https : bool -> string option -> Xml.uri -> string -> string -> string -> Types.input
0d20ef
diff --git a/v2v/input_libvirt_xen_ssh.ml b/v2v/input_libvirt_xen_ssh.ml
0d20ef
new file mode 100644
0d20ef
index 0000000..081317d
0d20ef
--- /dev/null
0d20ef
+++ b/v2v/input_libvirt_xen_ssh.ml
0d20ef
@@ -0,0 +1,103 @@
0d20ef
+(* virt-v2v
0d20ef
+ * Copyright (C) 2009-2014 Red Hat Inc.
0d20ef
+ *
0d20ef
+ * This program is free software; you can redistribute it and/or modify
0d20ef
+ * it under the terms of the GNU General Public License as published by
0d20ef
+ * the Free Software Foundation; either version 2 of the License, or
0d20ef
+ * (at your option) any later version.
0d20ef
+ *
0d20ef
+ * This program is distributed in the hope that it will be useful,
0d20ef
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
+ * GNU General Public License for more details.
0d20ef
+ *
0d20ef
+ * You should have received a copy of the GNU General Public License along
0d20ef
+ * with this program; if not, write to the Free Software Foundation, Inc.,
0d20ef
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
+ *)
0d20ef
+
0d20ef
+(** [-i libvirt] when the source is Xen *)
0d20ef
+
0d20ef
+open Common_gettext.Gettext
0d20ef
+open Common_utils
0d20ef
+
0d20ef
+open Types
0d20ef
+open Xml
0d20ef
+open Utils
0d20ef
+open Input_libvirt_other
0d20ef
+
0d20ef
+open Printf
0d20ef
+
0d20ef
+(* Map a Xen <source/> to a qemu URI using the SSH driver in qemu.
0d20ef
+ * This code assumes (and the caller checks) that the Xen URI is
0d20ef
+ * remotely accessible over ssh, so we can map the path to the qemu
0d20ef
+ * URI:
0d20ef
+ *
0d20ef
+ * json: {
0d20ef
+ *   "file.driver": "ssh",
0d20ef
+ *   "file.user": "username",
0d20ef
+ *   "file.host": "xen-host",
0d20ef
+ *   "file.port": 123,
0d20ef
+ *   "file.path": "path",
0d20ef
+ *   "file.host_key_check": "no"
0d20ef
+ * }
0d20ef
+ *)
0d20ef
+let map_path_to_uri verbose uri scheme server path format =
0d20ef
+  (* Construct the JSON parameters. *)
0d20ef
+  let json_params = [
0d20ef
+    "file.driver", JSON.String "ssh";
0d20ef
+    "file.path", JSON.String path;
0d20ef
+    "file.host", JSON.String server;
0d20ef
+    "file.host_key_check", JSON.String "no";
0d20ef
+  ] in
0d20ef
+
0d20ef
+  let json_params =
0d20ef
+    match uri.uri_port with
0d20ef
+    | 0 | 22 -> json_params
0d20ef
+    (* qemu will actually assert-fail if you send the port number as a
0d20ef
+     * string ...
0d20ef
+     *)
0d20ef
+    | i -> ("file.port", JSON.Int i) :: json_params in
0d20ef
+
0d20ef
+  let json_params =
0d20ef
+    match uri.uri_user with
0d20ef
+    | None -> json_params
0d20ef
+    | Some user -> ("file.user", JSON.String user) :: json_params in
0d20ef
+
0d20ef
+  if verbose then
0d20ef
+    printf "ssh: json parameters: %s\n" (JSON.string_of_doc json_params);
0d20ef
+
0d20ef
+  (* Turn the JSON parameters into a 'json:' protocol string. *)
0d20ef
+  let qemu_uri = "json: " ^ JSON.string_of_doc json_params in
0d20ef
+
0d20ef
+  qemu_uri, format
0d20ef
+
0d20ef
+(* Subclass specialized for handling Xen over SSH. *)
0d20ef
+class input_libvirt_xen_ssh verbose libvirt_uri parsed_uri scheme server guest =
0d20ef
+object
0d20ef
+  inherit input_libvirt verbose libvirt_uri guest
0d20ef
+
0d20ef
+  method source () =
0d20ef
+    if verbose then printf "input_libvirt_xen_ssh: source()\n%!";
0d20ef
+
0d20ef
+    error_if_libvirt_backend ();
0d20ef
+    error_if_no_ssh_agent ();
0d20ef
+
0d20ef
+    (* Get the libvirt XML.  This also checks (as a side-effect)
0d20ef
+     * that the domain is not running.  (RHBZ#1138586)
0d20ef
+     *)
0d20ef
+    let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
0d20ef
+    let { s_disks = disks } as source =
0d20ef
+      Input_libvirtxml.parse_libvirt_xml ~verbose xml in
0d20ef
+
0d20ef
+    let mapf = map_path_to_uri verbose parsed_uri scheme server in
0d20ef
+    let disks = List.map (
0d20ef
+      fun ({ s_qemu_uri = uri; s_format = format } as disk) ->
0d20ef
+        let uri, format = mapf uri format in
0d20ef
+        { disk with s_qemu_uri = uri; s_format = format }
0d20ef
+    ) disks in
0d20ef
+
0d20ef
+    { source with s_disks = disks }
0d20ef
+end
0d20ef
+
0d20ef
+let input_libvirt_xen_ssh = new input_libvirt_xen_ssh
0d20ef
diff --git a/v2v/input_libvirt_xen_ssh.mli b/v2v/input_libvirt_xen_ssh.mli
0d20ef
new file mode 100644
0d20ef
index 0000000..85473ed
0d20ef
--- /dev/null
0d20ef
+++ b/v2v/input_libvirt_xen_ssh.mli
0d20ef
@@ -0,0 +1,21 @@
0d20ef
+(* virt-v2v
0d20ef
+ * Copyright (C) 2009-2014 Red Hat Inc.
0d20ef
+ *
0d20ef
+ * This program is free software; you can redistribute it and/or modify
0d20ef
+ * it under the terms of the GNU General Public License as published by
0d20ef
+ * the Free Software Foundation; either version 2 of the License, or
0d20ef
+ * (at your option) any later version.
0d20ef
+ *
0d20ef
+ * This program is distributed in the hope that it will be useful,
0d20ef
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
+ * GNU General Public License for more details.
0d20ef
+ *
0d20ef
+ * You should have received a copy of the GNU General Public License along
0d20ef
+ * with this program; if not, write to the Free Software Foundation, Inc.,
0d20ef
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
+ *)
0d20ef
+
0d20ef
+(** [-i libvirt] when the source is Xen *)
0d20ef
+
0d20ef
+val input_libvirt_xen_ssh : bool -> string option -> Xml.uri -> string -> string -> string -> Types.input
0d20ef
diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml
0d20ef
deleted file mode 100644
0d20ef
index dc29863..0000000
0d20ef
--- a/v2v/vCenter.ml
0d20ef
+++ /dev/null
0d20ef
@@ -1,211 +0,0 @@
0d20ef
-(* virt-v2v
0d20ef
- * Copyright (C) 2009-2014 Red Hat Inc.
0d20ef
- *
0d20ef
- * This program is free software; you can redistribute it and/or modify
0d20ef
- * it under the terms of the GNU General Public License as published by
0d20ef
- * the Free Software Foundation; either version 2 of the License, or
0d20ef
- * (at your option) any later version.
0d20ef
- *
0d20ef
- * This program is distributed in the hope that it will be useful,
0d20ef
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
- * GNU General Public License for more details.
0d20ef
- *
0d20ef
- * You should have received a copy of the GNU General Public License along
0d20ef
- * with this program; if not, write to the Free Software Foundation, Inc.,
0d20ef
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
- *)
0d20ef
-
0d20ef
-(** Functions for dealing with ESX. *)
0d20ef
-
0d20ef
-open Common_gettext.Gettext
0d20ef
-open Common_utils
0d20ef
-
0d20ef
-open Xml
0d20ef
-open Utils
0d20ef
-
0d20ef
-open Printf
0d20ef
-
0d20ef
-let esx_re = Str.regexp "^\\[\\(.*\\)\\] \\(.*\\)\\.vmdk$"
0d20ef
-
0d20ef
-let session_cookie = ref ""
0d20ef
-
0d20ef
-(* Map an ESX <source/> to a qemu URI using the cURL driver
0d20ef
- * in qemu.  The 'path' will be something like
0d20ef
- *
0d20ef
- *   "[datastore1] Fedora 20/Fedora 20.vmdk"
0d20ef
- *
0d20ef
- * including those literal spaces in the string.
0d20ef
- *
0d20ef
- * XXX Old virt-v2v could also handle snapshots, ie:
0d20ef
- *
0d20ef
- *   "[datastore1] Fedora 20/Fedora 20-NNNNNN.vmdk"
0d20ef
- *
0d20ef
- * XXX Need to handle templates.  The file is called "-delta.vmdk" in
0d20ef
- * place of "-flat.vmdk".
0d20ef
- *)
0d20ef
-let rec map_path_to_uri verbose uri scheme server ?readahead path format =
0d20ef
-  if not (Str.string_match esx_re path 0) then
0d20ef
-    path, format
0d20ef
-  else (
0d20ef
-    let datastore = Str.matched_group 1 path
0d20ef
-    and path = Str.matched_group 2 path in
0d20ef
-
0d20ef
-    (* Get the datacenter. *)
0d20ef
-    let datacenter = get_datacenter uri scheme in
0d20ef
-
0d20ef
-    let port =
0d20ef
-      match uri.uri_port with
0d20ef
-      | 443 -> ""
0d20ef
-      | n when n >= 1 -> ":" ^ string_of_int n
0d20ef
-      | _ -> "" in
0d20ef
-
0d20ef
-    let url =
0d20ef
-      sprintf
0d20ef
-        "https://%s%s/folder/%s-flat.vmdk?dcPath=%s&dsName=%s"
0d20ef
-        server port
0d20ef
-        (uri_quote path) (uri_quote datacenter) (uri_quote datastore) in
0d20ef
-
0d20ef
-    (* If no_verify=1 was passed in the libvirt URI, then we have to
0d20ef
-     * turn off certificate verification here too.
0d20ef
-     *)
0d20ef
-    let sslverify =
0d20ef
-      match uri.uri_query_raw with
0d20ef
-      | None -> true
0d20ef
-      | Some query ->
0d20ef
-        (* XXX only works if the query string is not URI-quoted *)
0d20ef
-        string_find query "no_verify=1" = -1 in
0d20ef
-
0d20ef
-    (* Now we have to query the server to get the session cookie. *)
0d20ef
-    let session_cookie = get_session_cookie verbose scheme uri sslverify url in
0d20ef
-
0d20ef
-    (* Construct the JSON parameters. *)
0d20ef
-    let json_params = [
0d20ef
-      "file.driver", JSON.String "https";
0d20ef
-      "file.url", JSON.String url;
0d20ef
-      "file.timeout", JSON.Int 600;
0d20ef
-    ] in
0d20ef
-
0d20ef
-    let json_params =
0d20ef
-      match readahead with
0d20ef
-      | None -> json_params
0d20ef
-      | Some readahead ->
0d20ef
-        ("file.readahead", JSON.Int readahead) :: json_params in
0d20ef
-
0d20ef
-    let json_params =
0d20ef
-      if sslverify then json_params
0d20ef
-      else ("file.sslverify", JSON.String "off") :: json_params in
0d20ef
-
0d20ef
-    let json_params =
0d20ef
-      match session_cookie with
0d20ef
-      | None -> json_params
0d20ef
-      | Some cookie -> ("file.cookie", JSON.String cookie) :: json_params in
0d20ef
-
0d20ef
-    if verbose then
0d20ef
-      printf "esx: json parameters: %s\n" (JSON.string_of_doc json_params);
0d20ef
-
0d20ef
-    (* Turn the JSON parameters into a 'json:' protocol string.
0d20ef
-     * Note this requires qemu-img >= 2.1.0.
0d20ef
-     *)
0d20ef
-    let qemu_uri = "json: " ^ JSON.string_of_doc json_params in
0d20ef
-
0d20ef
-    (* The libvirt ESX driver doesn't normally specify a format, but
0d20ef
-     * the format of the -flat file is *always* raw, so force it here.
0d20ef
-     *)
0d20ef
-    qemu_uri, Some "raw"
0d20ef
-  )
0d20ef
-
0d20ef
-and get_datacenter uri scheme =
0d20ef
-  let default_dc = "ha-datacenter" in
0d20ef
-  match scheme with
0d20ef
-  | "vpx" ->           (* Hopefully the first part of the path. *)
0d20ef
-    (match uri.uri_path with
0d20ef
-    | None ->
0d20ef
-      warning ~prog (f_"esx: URI (-ic parameter) contains no path, so we cannot determine the datacenter name");
0d20ef
-      default_dc
0d20ef
-    | Some path ->
0d20ef
-      let path =
0d20ef
-        let len = String.length path in
0d20ef
-        if len > 0 && path.[0] = '/' then
0d20ef
-          String.sub path 1 (len-1)
0d20ef
-        else path in
0d20ef
-      let len =
0d20ef
-        try String.index path '/' with Not_found -> String.length path in
0d20ef
-      String.sub path 0 len
0d20ef
-    );
0d20ef
-  | "esx" -> (* Connecting to an ESXi hypervisor directly, so it's fixed. *)
0d20ef
-    default_dc
0d20ef
-  | _ ->                            (* Don't know, so guess. *)
0d20ef
-    default_dc
0d20ef
-
0d20ef
-and get_session_cookie verbose scheme uri sslverify url =
0d20ef
-  (* Memoize the session cookie. *)
0d20ef
-  if !session_cookie <> "" then
0d20ef
-    Some !session_cookie
0d20ef
-  else (
0d20ef
-    let cmd =
0d20ef
-      sprintf "curl -s%s%s%s -I %s ||:"
0d20ef
-        (if not sslverify then " --insecure" else "")
0d20ef
-        (match uri.uri_user with Some _ -> " -u" | None -> "")
0d20ef
-        (match uri.uri_user with Some user -> " " ^ quote user | None -> "")
0d20ef
-        (quote url) in
0d20ef
-    let lines = external_command ~prog cmd in
0d20ef
-
0d20ef
-    let dump_response chan =
0d20ef
-      fprintf chan "%s\n" cmd;
0d20ef
-      List.iter (fun x -> fprintf chan "%s\n" x) lines
0d20ef
-    in
0d20ef
-
0d20ef
-    if verbose then dump_response stdout;
0d20ef
-
0d20ef
-    (* Look for the last HTTP/x.y NNN status code in the output. *)
0d20ef
-    let status = ref "" in
0d20ef
-    List.iter (
0d20ef
-      fun line ->
0d20ef
-        let len = String.length line in
0d20ef
-        if len >= 12 && String.sub line 0 5 = "HTTP/" then
0d20ef
-          status := String.sub line 9 3
0d20ef
-    ) lines;
0d20ef
-    let status = !status in
0d20ef
-    if status = "" then (
0d20ef
-      dump_response stderr;
0d20ef
-      error (f_"esx: no status code in output of 'curl' command.  Is 'curl' installed?")
0d20ef
-    );
0d20ef
-
0d20ef
-    if status = "401" then (
0d20ef
-      dump_response stderr;
0d20ef
-      if uri.uri_user <> None then
0d20ef
-        error (f_"esx: incorrect username or password")
0d20ef
-      else
0d20ef
-        error (f_"esx: incorrect username or password.  You might need to specify the username in the URI like this: %s://USERNAME@[etc]")
0d20ef
-          scheme
0d20ef
-    );
0d20ef
-
0d20ef
-    if status = "404" then (
0d20ef
-      dump_response stderr;
0d20ef
-      error (f_"esx: URL not found: %s") url
0d20ef
-    );
0d20ef
-
0d20ef
-    if status <> "200" then (
0d20ef
-      dump_response stderr;
0d20ef
-      error (f_"esx: invalid response from server")
0d20ef
-    );
0d20ef
-
0d20ef
-    (* Get the cookie. *)
0d20ef
-    List.iter (
0d20ef
-      fun line ->
0d20ef
-        let len = String.length line in
0d20ef
-        if len >= 12 && String.sub line 0 12 = "Set-Cookie: " then (
0d20ef
-          let line = String.sub line 12 (len-12) in
0d20ef
-          let cookie, _ = string_split ";" line in
0d20ef
-          session_cookie := cookie
0d20ef
-        )
0d20ef
-    ) lines;
0d20ef
-    if !session_cookie = "" then (
0d20ef
-      dump_response stderr;
0d20ef
-      warning ~prog (f_"esx: could not read session cookie from the vCenter Server, conversion may consume all sessions on the server and fail part way through");
0d20ef
-      None
0d20ef
-    )
0d20ef
-    else
0d20ef
-      Some !session_cookie
0d20ef
-  )
0d20ef
diff --git a/v2v/vCenter.mli b/v2v/vCenter.mli
0d20ef
deleted file mode 100644
0d20ef
index 06ba452..0000000
0d20ef
--- a/v2v/vCenter.mli
0d20ef
+++ /dev/null
0d20ef
@@ -1,23 +0,0 @@
0d20ef
-(* virt-v2v
0d20ef
- * Copyright (C) 2009-2014 Red Hat Inc.
0d20ef
- *
0d20ef
- * This program is free software; you can redistribute it and/or modify
0d20ef
- * it under the terms of the GNU General Public License as published by
0d20ef
- * the Free Software Foundation; either version 2 of the License, or
0d20ef
- * (at your option) any later version.
0d20ef
- *
0d20ef
- * This program is distributed in the hope that it will be useful,
0d20ef
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
- * GNU General Public License for more details.
0d20ef
- *
0d20ef
- * You should have received a copy of the GNU General Public License along
0d20ef
- * with this program; if not, write to the Free Software Foundation, Inc.,
0d20ef
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
- *)
0d20ef
-
0d20ef
-(** Functions for dealing with ESX. *)
0d20ef
-
0d20ef
-val map_path_to_uri : bool -> Xml.uri -> string -> string -> ?readahead:int -> string -> string option -> string * string option
0d20ef
-(** Map a VMware path like "[datastore1] guest/guest.vmdk" to the
0d20ef
-    URL where we can fetch the data. *)
0d20ef
diff --git a/v2v/xen.ml b/v2v/xen.ml
0d20ef
deleted file mode 100644
0d20ef
index 332cdd6..0000000
0d20ef
--- a/v2v/xen.ml
0d20ef
+++ /dev/null
0d20ef
@@ -1,71 +0,0 @@
0d20ef
-(* virt-v2v
0d20ef
- * Copyright (C) 2009-2014 Red Hat Inc.
0d20ef
- *
0d20ef
- * This program is free software; you can redistribute it and/or modify
0d20ef
- * it under the terms of the GNU General Public License as published by
0d20ef
- * the Free Software Foundation; either version 2 of the License, or
0d20ef
- * (at your option) any later version.
0d20ef
- *
0d20ef
- * This program is distributed in the hope that it will be useful,
0d20ef
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
- * GNU General Public License for more details.
0d20ef
- *
0d20ef
- * You should have received a copy of the GNU General Public License along
0d20ef
- * with this program; if not, write to the Free Software Foundation, Inc.,
0d20ef
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
- *)
0d20ef
-
0d20ef
-(** Functions for dealing with Xen. *)
0d20ef
-
0d20ef
-open Common_gettext.Gettext
0d20ef
-open Common_utils
0d20ef
-
0d20ef
-open Xml
0d20ef
-open Utils
0d20ef
-
0d20ef
-open Printf
0d20ef
-
0d20ef
-(* Map a Xen <source/> to a qemu URI using the SSH driver in qemu.
0d20ef
- * This code assumes (and the caller checks) that the Xen URI is
0d20ef
- * remotely accessible over ssh, so we can map the path to the qemu
0d20ef
- * URI:
0d20ef
- *
0d20ef
- * json: {
0d20ef
- *   "file.driver": "ssh",
0d20ef
- *   "file.user": "username",
0d20ef
- *   "file.host": "xen-host",
0d20ef
- *   "file.port": 123,
0d20ef
- *   "file.path": "path",
0d20ef
- *   "file.host_key_check": "no"
0d20ef
- * }
0d20ef
- *)
0d20ef
-let rec map_path_to_uri verbose uri scheme server path format =
0d20ef
-  (* Construct the JSON parameters. *)
0d20ef
-  let json_params = [
0d20ef
-    "file.driver", JSON.String "ssh";
0d20ef
-    "file.path", JSON.String path;
0d20ef
-    "file.host", JSON.String server;
0d20ef
-    "file.host_key_check", JSON.String "no";
0d20ef
-  ] in
0d20ef
-
0d20ef
-  let json_params =
0d20ef
-    match uri.uri_port with
0d20ef
-    | 0 | 22 -> json_params
0d20ef
-    (* qemu will actually assert-fail if you send the port number as a
0d20ef
-     * string ...
0d20ef
-     *)
0d20ef
-    | i -> ("file.port", JSON.Int i) :: json_params in
0d20ef
-
0d20ef
-  let json_params =
0d20ef
-    match uri.uri_user with
0d20ef
-    | None -> json_params
0d20ef
-    | Some user -> ("file.user", JSON.String user) :: json_params in
0d20ef
-
0d20ef
-  if verbose then
0d20ef
-    printf "ssh: json parameters: %s\n" (JSON.string_of_doc json_params);
0d20ef
-
0d20ef
-  (* Turn the JSON parameters into a 'json:' protocol string. *)
0d20ef
-  let qemu_uri = "json: " ^ JSON.string_of_doc json_params in
0d20ef
-
0d20ef
-  qemu_uri, format
0d20ef
diff --git a/v2v/xen.mli b/v2v/xen.mli
0d20ef
deleted file mode 100644
0d20ef
index 440d226..0000000
0d20ef
--- a/v2v/xen.mli
0d20ef
+++ /dev/null
0d20ef
@@ -1,22 +0,0 @@
0d20ef
-(* virt-v2v
0d20ef
- * Copyright (C) 2009-2014 Red Hat Inc.
0d20ef
- *
0d20ef
- * This program is free software; you can redistribute it and/or modify
0d20ef
- * it under the terms of the GNU General Public License as published by
0d20ef
- * the Free Software Foundation; either version 2 of the License, or
0d20ef
- * (at your option) any later version.
0d20ef
- *
0d20ef
- * This program is distributed in the hope that it will be useful,
0d20ef
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
0d20ef
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0d20ef
- * GNU General Public License for more details.
0d20ef
- *
0d20ef
- * You should have received a copy of the GNU General Public License along
0d20ef
- * with this program; if not, write to the Free Software Foundation, Inc.,
0d20ef
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0d20ef
- *)
0d20ef
-
0d20ef
-(** Functions for dealing with Xen. *)
0d20ef
-
0d20ef
-val map_path_to_uri : bool -> Xml.uri -> string -> string -> string -> string option -> string * string option
0d20ef
-(** Map a Xen path to the SSH URL where we can fetch the data. *)
0d20ef
-- 
0d20ef
1.8.3.1
0d20ef