diff options
author | Tim Small <tim@seoss.co.uk> | 2022-11-24 14:33:33 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-04-07 08:06:23 +0000 |
commit | bc737ad9966201b68f5e8d98521b4abb4add870d (patch) | |
tree | 72b0b22657dab8c64f1f99a74e98daf0440793a8 | |
parent | 8a9977bc1703fd61670249750227d803649c95a5 (diff) | |
download | vmdb2-bc737ad9966201b68f5e8d98521b4abb4add870d.tar.gz |
Use set_grub_default() for all grub defaults edits.
-rw-r--r-- | vmdb/plugins/grub_plugin.py | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/vmdb/plugins/grub_plugin.py b/vmdb/plugins/grub_plugin.py index cf40e2d..31b2016 100644 --- a/vmdb/plugins/grub_plugin.py +++ b/vmdb/plugins/grub_plugin.py @@ -363,20 +363,7 @@ class GrubStepRunner(vmdb.StepRunnerInterface): def set_grub_cmdline_config(self, chroot, kernel_params): param_string = " ".join(kernel_params) - - filename = self.chroot_path(chroot, "/etc/default/grub") - - with open(filename) as f: - text = f.read() - - lines = text.splitlines() - lines = [ - line for line in lines if not line.startswith("GRUB_CMDLINE_LINUX_DEFAULT") - ] - lines.append('GRUB_CMDLINE_LINUX_DEFAULT="{}"'.format(param_string)) - - with open(filename, "w") as f: - f.write("\n".join(lines) + "\n") + self.set_grub_default(chroot, "GRUB_CMDLINE_LINUX_DEFAULT", '"' + param_string + '"') def set_grub_default(self, chroot, param, value): filename = self.chroot_path(chroot, "/etc/default/grub") @@ -402,19 +389,12 @@ class GrubStepRunner(vmdb.StepRunnerInterface): f.write(newdefault) def add_grub_serial_console(self, chroot): - filename = self.chroot_path(chroot, "/etc/default/grub") - - with open(filename, "a") as f: - f.write("GRUB_TERMINAL=serial\n") - f.write( - 'GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 ' - '--word=8 --parity=no --stop=1"\n' - ) + self.set_grub_default(chroot, "GRUB_TERMINAL", "serial") + self.set_grub_default(chroot, "GRUB_SERIAL_COMMAND", '"serial ' + '--speed=115200 --unit=0 --word=8 --parity=no --stop=1"') def add_grub_crypto_disk(self, chroot): - filename = self.chroot_path(chroot, "/etc/default/grub") - with open(filename, "a") as f: - f.write("GRUB_ENABLE_CRYPTODISK=y\n") + self.set_grub_default(chroot, "GRUB_ENABLE_CRYPTODISK", "y") def set_grub_timeout(self, chroot, timeout): self.set_grub_default(chroot, "GRUB_TIMEOUT", timeout) |