unattended: Share more script generation bits
- Break out the installer* unattended prep to its own function - Move logging into common unattended call - Use libosinfo APIs to generate script str, then we write it - Move commandline lookup to installertreemedia - Rename path->scriptpath for clarity
This commit is contained in:
parent
08baf0ee5f
commit
3495a8f1f9
|
@ -219,6 +219,19 @@ class Installer(object):
|
|||
# Internal API overrides #
|
||||
##########################
|
||||
|
||||
def _prepare_unattended_data(self, guest):
|
||||
osguess = OSDB.guess_os_by_iso(self.cdrom)
|
||||
osmedia = OsMedia(osguess[1])
|
||||
script = unattended.prepare_install_script(
|
||||
guest, self._unattended_data, self.cdrom, osmedia)
|
||||
scriptpath = unattended.generate_install_script(guest, script)
|
||||
|
||||
iso = perform_cdrom_injections([scriptpath],
|
||||
guest.conn.get_app_cache_dir())
|
||||
self._add_unattended_install_cdrom_device(guest, iso)
|
||||
|
||||
self._unattended_files.extend([scriptpath, iso])
|
||||
|
||||
def _prepare(self, guest, meter):
|
||||
if self._treemedia:
|
||||
k, i, a = self._treemedia.prepare(guest, meter)
|
||||
|
@ -227,20 +240,7 @@ class Installer(object):
|
|||
if a and "VIRTINST_INITRD_TEST" not in os.environ:
|
||||
self.extra_args.append(a)
|
||||
elif self._unattended_data:
|
||||
osguess = OSDB.guess_os_by_iso(self.cdrom)
|
||||
osmedia = OsMedia(osguess[1])
|
||||
script = unattended.prepare_install_script(
|
||||
guest, self._unattended_data, self.cdrom, osmedia)
|
||||
path, _ = unattended.generate_install_script(guest, script)
|
||||
logging.debug("Generated unattended script: %s", path)
|
||||
logging.debug("Generated script contents:\n%s",
|
||||
open(path).read())
|
||||
|
||||
iso = perform_cdrom_injections([path],
|
||||
guest.conn.get_app_cache_dir())
|
||||
self._add_unattended_install_cdrom_device(guest, iso)
|
||||
|
||||
self._unattended_files.extend([path, iso])
|
||||
self._prepare_unattended_data(guest)
|
||||
|
||||
def _cleanup(self, guest):
|
||||
if self._treemedia:
|
||||
|
|
|
@ -207,26 +207,25 @@ class InstallerTreeMedia(object):
|
|||
def set_unattended_data(self, unattended_data):
|
||||
self._unattended_data = unattended_data
|
||||
|
||||
def _prepare_unattended_data(self, guest, cache):
|
||||
location = self.location if self._media_type == MEDIA_URL else None
|
||||
script = unattended.prepare_install_script(
|
||||
guest, self._unattended_data, location, cache.os_media)
|
||||
scriptpath = unattended.generate_install_script(guest, script)
|
||||
unattended_cmdline = script.generate_cmdline()
|
||||
logging.debug("Generated unattended cmdline: %s", unattended_cmdline)
|
||||
|
||||
self.initrd_injections.append(scriptpath)
|
||||
self._tmpfiles.append(scriptpath)
|
||||
return unattended_cmdline
|
||||
|
||||
def prepare(self, guest, meter):
|
||||
unattended_cmdline = None
|
||||
fetcher = self._get_fetcher(guest, meter)
|
||||
cache = self._get_cached_data(guest, fetcher)
|
||||
|
||||
unattended_cmdline = None
|
||||
if self._unattended_data:
|
||||
location = self.location if self._media_type == MEDIA_URL else None
|
||||
script = unattended.prepare_install_script(
|
||||
guest, self._unattended_data, location, cache.os_media)
|
||||
path, unattended_cmdline = unattended.generate_install_script(
|
||||
guest, script)
|
||||
|
||||
logging.debug("Generated unattended cmdline: %s",
|
||||
unattended_cmdline)
|
||||
logging.debug("Generated unattended script: %s", path)
|
||||
logging.debug("Generated script contents:\n%s",
|
||||
open(path).read())
|
||||
|
||||
self.initrd_injections.append(path)
|
||||
self._tmpfiles.append(path)
|
||||
unattended_cmdline = self._prepare_unattended_data(guest, cache)
|
||||
|
||||
k, i, a = self._prepare_kernel_url(guest, fetcher)
|
||||
|
||||
|
|
|
@ -217,9 +217,8 @@ class OSInstallScript:
|
|||
def set_config(self, config):
|
||||
self._config = config
|
||||
|
||||
def generate_output(self, output_dir):
|
||||
self._script.generate_output(
|
||||
self._osobj.get_handle(), self._config, output_dir)
|
||||
def generate(self):
|
||||
return self._script.generate(self._osobj.get_handle(), self._config)
|
||||
|
||||
def generate_cmdline(self):
|
||||
return self._script.generate_command_line(
|
||||
|
@ -265,8 +264,11 @@ def generate_install_script(guest, script):
|
|||
if not os.path.exists(scratch):
|
||||
os.makedirs(scratch, 0o751)
|
||||
|
||||
script.generate_output(Gio.File.new_for_path(scratch))
|
||||
path = os.path.join(scratch, script.get_expected_filename())
|
||||
cmdline = script.generate_cmdline()
|
||||
content = script.generate()
|
||||
scriptpath = os.path.join(scratch, script.get_expected_filename())
|
||||
open(scriptpath, "w").write(content)
|
||||
|
||||
return path, cmdline
|
||||
logging.debug("Generated unattended script: %s", scriptpath)
|
||||
logging.debug("Generated script contents:\n%s", content)
|
||||
|
||||
return scriptpath
|
||||
|
|
Loading…
Reference in New Issue