mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0051-v2v-vCenter-Factor-out-get_https_url-code.patch

151578
From 56835fbc66a9ae540764d1628922afaaa5b2fffc Mon Sep 17 00:00:00 2001
151578
From: "Richard W.M. Jones" <rjones@redhat.com>
151578
Date: Fri, 13 Oct 2017 17:08:23 +0100
151578
Subject: [PATCH] v2v: vCenter: Factor out get_https_url code.
151578
151578
Pure refactoring.
151578
151578
(cherry picked from commit 388a70139910ed4b03d9765e403c35bb26cbe422)
151578
---
151578
 v2v/vCenter.ml | 46 ++++++++++++++++++++++++----------------------
151578
 1 file changed, 24 insertions(+), 22 deletions(-)
151578
151578
diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml
151578
index 7fc0811a4..f53affb48 100644
151578
--- a/v2v/vCenter.ml
151578
+++ b/v2v/vCenter.ml
151578
@@ -58,28 +58,7 @@ let rec map_source ?readahead ?password dcPath uri scheme server path =
151578
        (* XXX only works if the query string is not URI-quoted *)
151578
        String.find query "no_verify=1" = -1 in
151578
 
151578
-  let https_url =
151578
-    if not (Str.string_match source_re path 0) then
151578
-      path
151578
-    else (
151578
-      let datastore = Str.matched_group 1 path
151578
-      and path = Str.matched_group 2 path in
151578
-
151578
-      let port =
151578
-        match uri.uri_port with
151578
-        | 443 -> ""
151578
-        | n when n >= 1 -> ":" ^ string_of_int n
151578
-        | _ -> "" in
151578
-
151578
-      (* XXX Old virt-v2v could also handle snapshots, ie:
151578
-       * "[datastore1] Fedora 20/Fedora 20-NNNNNN.vmdk"
151578
-       * XXX Need to handle templates.  The file is called "-delta.vmdk" in
151578
-       * place of "-flat.vmdk".
151578
-       *)
151578
-      sprintf "https://%s%s/folder/%s-flat.vmdk?dcPath=%s&dsName=%s"
151578
-              server port
151578
-              (uri_quote path) (uri_quote dcPath) (uri_quote datastore)
151578
-    ) in
151578
+  let https_url = get_https_url dcPath uri server path in
151578
 
151578
   let session_cookie =
151578
     get_session_cookie password scheme uri sslverify https_url in
151578
@@ -123,6 +102,29 @@ let rec map_source ?readahead ?password dcPath uri scheme server path =
151578
     session_cookie = session_cookie;
151578
     sslverify = sslverify }
151578
 
151578
+and get_https_url dcPath uri server path =
151578
+  if not (Str.string_match source_re path 0) then
151578
+    path
151578
+  else (
151578
+    let datastore = Str.matched_group 1 path
151578
+    and path = Str.matched_group 2 path in
151578
+
151578
+    let port =
151578
+      match uri.uri_port with
151578
+      | 443 -> ""
151578
+      | n when n >= 1 -> ":" ^ string_of_int n
151578
+      | _ -> "" in
151578
+
151578
+    (* XXX Old virt-v2v could also handle snapshots, ie:
151578
+     * "[datastore1] Fedora 20/Fedora 20-NNNNNN.vmdk"
151578
+     * XXX Need to handle templates.  The file is called "-delta.vmdk" in
151578
+     * place of "-flat.vmdk".
151578
+     *)
151578
+    sprintf "https://%s%s/folder/%s-flat.vmdk?dcPath=%s&dsName=%s"
151578
+            server port
151578
+            (uri_quote path) (uri_quote dcPath) (uri_quote datastore)
151578
+  )
151578
+
151578
 and get_session_cookie password scheme uri sslverify https_url =
151578
   let status, headers, dump_response =
151578
     fetch_headers_from_url password scheme uri sslverify https_url in
151578
-- 
151578
2.14.3
151578