[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH v3 10/13] v2v: factor out opening and populating guestfs handle



Signed-off-by: Roman Kagan <rkagan virtuozzo com>
---
 v2v/v2v.ml | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index c28905d..23bd708 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -60,19 +60,9 @@ let rec main () =
   let overlays = create_overlays source.s_disks in
   let targets = init_targets overlays source output output_format in
 
-  (* Open the guestfs handle. *)
   message (f_"Opening the overlay");
-  let g = new G.guestfs () in
-  g#set_identifier "v2v";
-  if trace () then g#set_trace true;
-  if verbose () then g#set_verbose true;
-  g#set_network true;
-  List.iter (
-    fun ({ov_overlay_file = overlay_file}) ->
-      g#add_drive_opts overlay_file
-        ~format:"qcow2" ~cachemode:"unsafe" ~discard:"besteffort"
-        ~copyonread:true
-  ) overlays;
+  let g = open_guestfs () in
+  populate_overlays g overlays;
 
   g#launch ();
 
@@ -261,6 +251,24 @@ and init_targets overlays source output output_format =
 
   output#prepare_targets source targets
 
+and open_guestfs () =
+  (* Open the guestfs handle. *)
+  let g = new G.guestfs () in
+  g#set_identifier "v2v";
+  if trace () then g#set_trace true;
+  if verbose () then g#set_verbose true;
+  g#set_network true;
+  g
+
+and populate_overlays (g:G.guestfs) overlays =
+  (* Populate guestfs handle with qcow2 overlays. *)
+  List.iter (
+    fun ({ov_overlay_file = overlay_file}) ->
+      g#add_drive_opts overlay_file
+        ~format:"qcow2" ~cachemode:"unsafe" ~discard:"besteffort"
+        ~copyonread:true
+  ) overlays
+
 and inspect_source g root_choice =
   let roots = g#inspect_os () in
   let roots = Array.to_list roots in
-- 
2.4.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]