[virt-tools-list] [virt-install PATCH v2 09/14] unattended: Add helper method to generate the install script

Fabiano Fidêncio fidencio at redhat.com
Fri Feb 22 08:40:16 UTC 2019


generate_install_script() is a helper that will do all the needed
plumbing related to create, populating and generating the install script
and its config.

The method returns the path to the generated install script and the
kernel command line to be used with it.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 virtinst/unattended.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/virtinst/unattended.py b/virtinst/unattended.py
index 01f6f5a2..9550beef 100644
--- a/virtinst/unattended.py
+++ b/virtinst/unattended.py
@@ -6,8 +6,40 @@
 # This work is licensed under the GNU GPLv2 or later.
 # See the COPYING file in the top-level directory.
 
+import os
+
+from . import util
+
+import gi
+from gi.repository import Gio as gio
+
 
 class UnattendedData():
     profile = None
     admin_password = None
     user_password = None
+
+
+def generate_install_script(guest, unattended_data):
+    script = guest.osinfo.get_install_script(unattended_data.profile)
+
+    # For all tree based installations we're going to perform initrd injection
+    # and install the systems via network.
+    guest.osinfo.set_install_script_preferred_injection_method(
+            script, "initrd")
+    guest.osinfo.set_install_script_installation_source(script, "network")
+
+    config = guest.osinfo.get_install_script_config(
+            script, unattended_data, guest.os.arch, guest.name)
+
+    scratch = os.path.join(util.get_cache_dir(), "unattended")
+    if not os.path.exists(scratch):
+        os.makedirs(stratch, 0o751)
+
+    guest.osinfo.generate_install_script_output(script, config,
+            gio.File.new_for_path(scratch))
+
+    path = os.path.join(scratch, script.get_expected_filename())
+    cmdline = guest.osinfo.generate_install_script_cmdline(script, config)
+
+    return path, cmdline
-- 
2.20.1




More information about the virt-tools-list mailing list