mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
virtinst: mv *inject.py into single installerinject.py
Share the mapping logic between them
This commit is contained in:
parent
ae5e9d9a2c
commit
20bb798a5f
@ -1,54 +0,0 @@
|
||||
#
|
||||
# Copyright 2019 Red Hat, Inc.
|
||||
#
|
||||
# This work is licensed under the GNU GPLv2 or later.
|
||||
# See the COPYING file in the top-level directory.
|
||||
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
def _run_iso_commands(iso, tempdir):
|
||||
cmd = ["mkisofs",
|
||||
"-o", iso,
|
||||
"-J",
|
||||
"-input-charset", "utf8",
|
||||
"-rational-rock",
|
||||
tempdir]
|
||||
logging.debug("Running mkisofs: %s", cmd)
|
||||
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
||||
logging.debug("cmd output: %s", output)
|
||||
|
||||
|
||||
def perform_cdrom_injections(injections, scratchdir):
|
||||
"""
|
||||
Insert files into the root directory of a floppy
|
||||
"""
|
||||
if not injections:
|
||||
return
|
||||
|
||||
fileobj = tempfile.NamedTemporaryFile(
|
||||
dir=scratchdir, prefix="virtinst-unattended-iso", delete=False)
|
||||
iso = fileobj.name
|
||||
|
||||
tempdir = tempfile.mkdtemp(dir=scratchdir)
|
||||
try:
|
||||
os.chmod(tempdir, 0o775)
|
||||
|
||||
for filename in injections:
|
||||
if type(filename) is tuple:
|
||||
filename, dst = filename
|
||||
else:
|
||||
dst = os.path.basename(filename)
|
||||
|
||||
logging.debug("Injecting src=%s dst=%s", filename, dst)
|
||||
shutil.copy(filename, os.path.join(tempdir, dst))
|
||||
|
||||
_run_iso_commands(iso, tempdir)
|
||||
finally:
|
||||
shutil.rmtree(tempdir)
|
||||
|
||||
return iso
|
@ -15,7 +15,7 @@ from .devices import DeviceDisk
|
||||
from .domain import DomainOs
|
||||
from .osdict import OSDB
|
||||
from .installertreemedia import InstallerTreeMedia
|
||||
from .cdrominject import perform_cdrom_injections
|
||||
from .installerinject import perform_cdrom_injections
|
||||
|
||||
|
||||
class Installer(object):
|
||||
|
@ -11,7 +11,7 @@ import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
def _run_inject_commands(initrd, tempdir):
|
||||
def _run_initrd_commands(initrd, tempdir):
|
||||
logging.debug("Appending to the initrd.")
|
||||
|
||||
find_proc = subprocess.Popen(['find', '.', '-print0'],
|
||||
@ -43,10 +43,19 @@ def _run_inject_commands(initrd, tempdir):
|
||||
logging.debug("gzip stderr=%s", gziperr)
|
||||
|
||||
|
||||
def perform_initrd_injections(initrd, injections, scratchdir):
|
||||
"""
|
||||
Insert files into the root directory of the initial ram disk
|
||||
"""
|
||||
def _run_iso_commands(iso, tempdir):
|
||||
cmd = ["mkisofs",
|
||||
"-o", iso,
|
||||
"-J",
|
||||
"-input-charset", "utf8",
|
||||
"-rational-rock",
|
||||
tempdir]
|
||||
logging.debug("Running mkisofs: %s", cmd)
|
||||
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
|
||||
logging.debug("cmd output: %s", output)
|
||||
|
||||
|
||||
def _perform_generic_injections(injections, scratchdir, media, cb):
|
||||
if not injections:
|
||||
return
|
||||
|
||||
@ -60,9 +69,36 @@ def perform_initrd_injections(initrd, injections, scratchdir):
|
||||
else:
|
||||
dst = os.path.basename(filename)
|
||||
|
||||
logging.debug("Injecting src=%s dst=%s", filename, dst)
|
||||
logging.debug("Injecting src=%s dst=%s into media=%s",
|
||||
filename, dst, media)
|
||||
shutil.copy(filename, os.path.join(tempdir, dst))
|
||||
|
||||
_run_inject_commands(initrd, tempdir)
|
||||
return cb(media, tempdir)
|
||||
finally:
|
||||
shutil.rmtree(tempdir)
|
||||
|
||||
|
||||
def perform_initrd_injections(initrd, injections, scratchdir):
|
||||
"""
|
||||
Insert files into the root directory of the initial ram disk
|
||||
"""
|
||||
_perform_generic_injections(injections, scratchdir, initrd,
|
||||
_run_initrd_commands)
|
||||
|
||||
|
||||
def perform_cdrom_injections(injections, scratchdir):
|
||||
"""
|
||||
Insert files into the root directory of a generated cdrom
|
||||
"""
|
||||
fileobj = tempfile.NamedTemporaryFile(
|
||||
dir=scratchdir, prefix="virtinst-unattended-iso", delete=False)
|
||||
iso = fileobj.name
|
||||
|
||||
try:
|
||||
_perform_generic_injections(injections, scratchdir, iso,
|
||||
_run_iso_commands)
|
||||
except Exception:
|
||||
os.unlink(iso)
|
||||
raise
|
||||
|
||||
return iso
|
@ -12,7 +12,7 @@ from . import unattended
|
||||
from . import urldetect
|
||||
from . import urlfetcher
|
||||
from .devices import DeviceDisk
|
||||
from .initrdinject import perform_initrd_injections
|
||||
from .installerinject import perform_initrd_injections
|
||||
from .kernelupload import upload_kernel_initrd
|
||||
from .osdict import OSDB
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user