[Libguestfs] [PATCH 4/4] convert_windows: split firstboot into steps

Roman Kagan rkagan at parallels.com
Fri Feb 27 12:20:18 UTC 2015


Instead of doing all firstboot actions in a single script, take the
advantage of the firstboot infrastructure and store and run unrelated
actions as individual steps.

This facilitates troubleshooting and fault recovery; besides it makes
adding more actions easier.

Signed-off-by: Roman Kagan <rkagan at parallels.com>
---
 v2v/convert_windows.ml | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index a3c7152..0cd818a 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -140,17 +140,10 @@ let convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
   (* Perform the conversion of the Windows guest. *)
 
   let rec configure_firstboot () =
-    let fb = Buffer.create 1024 in
-    bprintf fb "@echo off\n";
+    configure_rhev_apt ();
+    unconfigure_xenpv ()
 
-    configure_rhev_apt fb;
-    unconfigure_xenpv fb;
-
-    (* Write the completed script to the guest. *)
-    let firstboot_script = Buffer.contents fb in
-    Firstboot.add_firstboot_script g inspect.i_root "firstboot" firstboot_script
-
-  and configure_rhev_apt fb =
+  and configure_rhev_apt () =
     (* Configure RHEV-APT (the RHEV guest agent).  However if it doesn't
      * exist just warn about it and continue.
      *)
@@ -159,22 +152,30 @@ let convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
     | Some rhev_apt_exe ->
       g#upload rhev_apt_exe "/rhev-apt.exe"; (* XXX *)
 
-      bprintf fb "\
+      let fb_script = "\
+ at echo off
+
 echo installing rhev-apt
 \"\\rhev-apt.exe\" /S /v /qn
 
 echo starting rhev-apt
 net start rhev-apt
-"
+" in
+      Firstboot.add_firstboot_script g inspect.i_root
+        "configure rhev-apt" fb_script
 
-  and unconfigure_xenpv fb =
+  and unconfigure_xenpv () =
     match xenpv_uninst with
     | None -> () (* nothing to be uninstalled *)
     | Some uninst ->
-      bprintf fb "\
+      let fb_script = sprintf "\
+ at echo off
+
 echo uninstalling Xen PV driver
 \"%s\"
-" uninst
+" uninst in
+      Firstboot.add_firstboot_script g inspect.i_root
+        "uninstall Xen PV" fb_script
   in
 
   let rec update_system_hive root =
-- 
2.1.0




More information about the Libguestfs mailing list