[Pkg-libvirt-commits] [libguestfs] 199/266: v2v: -i libvirt: Allow map_source* functions to map the format as well as the path.
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:42:01 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.
commit 3fa4fff9b485d8d8b92d5d925b4e047358e63175
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Thu Aug 28 15:05:17 2014 +0100
v2v: -i libvirt: Allow map_source* functions to map the format as well as the path.
For ESX we need to map the format (which is usually unspecified) to raw.
---
v2v/input_libvirtxml.ml | 16 ++++++++++------
v2v/input_libvirtxml.mli | 6 +++++-
v2v/lib_esx.ml | 16 +++++++++++-----
v2v/lib_esx.mli | 2 +-
4 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
index 663a2f5..4f9cc15 100644
--- a/v2v/input_libvirtxml.ml
+++ b/v2v/input_libvirtxml.ml
@@ -24,9 +24,11 @@ open Common_utils
open Types
open Utils
-let identity x = x
+type map_source = string -> string option -> string * string option
-let parse_libvirt_xml ?(map_source_file = identity) ?(map_source_dev = identity)
+let no_map : map_source = fun x y -> x, y
+
+let parse_libvirt_xml ?(map_source_file = no_map) ?(map_source_dev = no_map)
xml =
let doc = Xml.parse_memory xml in
let xpathctx = Xml.xpath_new_context doc in
@@ -137,13 +139,13 @@ let parse_libvirt_xml ?(map_source_file = identity) ?(map_source_dev = identity)
| "block" ->
let path = xpath_to_string "source/@dev" "" in
if path <> "" then (
- let path = map_source_dev path in
+ let path, format = map_source_dev path format in
add_disk path format target_dev
)
| "file" ->
let path = xpath_to_string "source/@file" "" in
if path <> "" then (
- let path = map_source_file path in
+ let path, format = map_source_file path format in
add_disk path format target_dev
)
| "network" ->
@@ -265,8 +267,10 @@ object
* when writing the XML by hand.
*)
let dir = Filename.dirname (absolute_path file) in
- let map_source_file path =
- if not (Filename.is_relative path) then path else dir // path
+ let map_source_file path format =
+ let path =
+ if not (Filename.is_relative path) then path else dir // path in
+ path, format
in
parse_libvirt_xml ~map_source_file xml
diff --git a/v2v/input_libvirtxml.mli b/v2v/input_libvirtxml.mli
index 7faef35..f8a69ab 100644
--- a/v2v/input_libvirtxml.mli
+++ b/v2v/input_libvirtxml.mli
@@ -18,7 +18,11 @@
(** [-i libvirtxml] source. *)
-val parse_libvirt_xml : ?map_source_file:(string -> string) -> ?map_source_dev:(string -> string) -> string -> Types.source
+type map_source = string -> string option -> string * string option
+(** Map function that takes [path] and [format] parameters, and
+ returns the possibly rewritten [qemu_uri, format] pair. *)
+
+val parse_libvirt_xml : ?map_source_file:map_source -> ?map_source_dev:map_source -> string -> Types.source
(** Take libvirt XML and parse it into a {!Types.source} structure.
The optional [?map_source_file] and [?map_source_dev] functions
diff --git a/v2v/lib_esx.ml b/v2v/lib_esx.ml
index df5ee4d..feef090 100644
--- a/v2v/lib_esx.ml
+++ b/v2v/lib_esx.ml
@@ -46,9 +46,9 @@ let esx_re = Str.regexp "^\\[\\(.*\\)\\] \\(.*\\)\\.vmdk$"
* However this requires access to the server which we don't necessarily
* have here.
*)
-let map_path_to_uri uri path =
+let map_path_to_uri uri path format =
if not (Str.string_match esx_re path 0) then
- path
+ path, format
else (
let datastore = Str.matched_group 1 path
and vmdk = Str.matched_group 2 path in
@@ -67,7 +67,13 @@ let map_path_to_uri uri path =
| n when n >= 1 -> ":" ^ string_of_int n
| _ -> "" in
- sprintf
- "https://%s%s%s/folder/%s-flat.vmdk?dcPath=ha-datacenter&dsName=%s"
- user server port vmdk (uri_quote datastore)
+ let qemu_uri =
+ sprintf
+ "https://%s%s%s/folder/%s-flat.vmdk?dcPath=ha-datacenter&dsName=%s"
+ user server port vmdk (uri_quote datastore) in
+
+ (* The libvirt ESX driver doesn't normally specify a format, but
+ * the format of the -flat file is *always* raw, so force it here.
+ *)
+ qemu_uri, Some "raw"
)
diff --git a/v2v/lib_esx.mli b/v2v/lib_esx.mli
index 9a3f7e5..626ebd9 100644
--- a/v2v/lib_esx.mli
+++ b/v2v/lib_esx.mli
@@ -18,6 +18,6 @@
(** Functions for dealing with ESX. *)
-val map_path_to_uri : Xml.uri -> string -> string
+val map_path_to_uri : Xml.uri -> string -> string option -> string * string option
(** Map a VMware path like "[datastore1] guest/guest.vmdk" to the
URL where we can fetch the data. *)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list