summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2023-10-21 13:33:37 -0500
committerJohn Estabrook <jestabro@vyos.io>2023-12-16 20:37:10 -0600
commitbb1c98ae64667fdc4fba7a316671d16964fb024f (patch)
tree43ce153d3d211d973034e806b331ac7309517d87 /src/op_mode
parent06832e3cc962eb4f94afe5319e7416d68756dba9 (diff)
downloadvyos-1x-bb1c98ae64667fdc4fba7a316671d16964fb024f.tar.gz
vyos-1x-bb1c98ae64667fdc4fba7a316671d16964fb024f.zip
image: T4516: support for interoperability of legacy/new image tools
This commit allows management of system images with either new or legacy tools: 'add/delete/rename system image' and 'set default' are translated appropriately on booting between images with the old and new tools. Consequently, the warning of the initial commit of T4516 is dropped. (cherry picked from commit 96b65e90fbfa1fe63d97929ac86fc910abb0caa9)
Diffstat (limited to 'src/op_mode')
-rwxr-xr-xsrc/op_mode/image_info.py7
-rwxr-xr-xsrc/op_mode/image_installer.py17
-rwxr-xr-xsrc/op_mode/image_manager.py7
3 files changed, 19 insertions, 12 deletions
diff --git a/src/op_mode/image_info.py b/src/op_mode/image_info.py
index 14dca7476..791001e00 100755
--- a/src/op_mode/image_info.py
+++ b/src/op_mode/image_info.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright 2022 VyOS maintainers and contributors <maintainers@vyos.io>
+# Copyright 2023 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This file is part of VyOS.
#
@@ -91,10 +91,7 @@ def show_images_summary(raw: bool) -> Union[image.BootDetails, str]:
def show_images_details(raw: bool) -> Union[list[image.ImageDetails], str]:
- images: list[str] = grub.version_list()
- images_details: list[image.ImageDetails] = list()
- for image_name in images:
- images_details.append(image.get_details(image_name))
+ images_details = image.get_images_details()
if raw:
return images_details
diff --git a/src/op_mode/image_installer.py b/src/op_mode/image_installer.py
index 12d32968c..2d998f5e1 100755
--- a/src/op_mode/image_installer.py
+++ b/src/op_mode/image_installer.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright 2022 VyOS maintainers and contributors <maintainers@vyos.io>
+# Copyright 2023 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This file is part of VyOS.
#
@@ -28,7 +28,7 @@ from psutil import disk_partitions
from vyos.configtree import ConfigTree
from vyos.remote import download
-from vyos.system import disk, grub, image
+from vyos.system import disk, grub, image, compat, SYSTEM_CFG_VER
from vyos.template import render
from vyos.utils.io import ask_input, ask_yes_no
from vyos.utils.file import chmod_2775
@@ -462,6 +462,7 @@ def install_image() -> None:
exit(1)
+@compat.grub_cfg_update
def add_image(image_path: str) -> None:
"""Add a new image
@@ -488,10 +489,16 @@ def add_image(image_path: str) -> None:
Path(DIR_ROOTFS_SRC).mkdir(mode=0o755, parents=True)
disk.partition_mount(f'{DIR_ISO_MOUNT}/live/filesystem.squashfs',
DIR_ROOTFS_SRC, 'squashfs')
- version_file: str = Path(
- f'{DIR_ROOTFS_SRC}/opt/vyatta/etc/version').read_text()
+
+ cfg_ver: str = image.get_image_tools_version(DIR_ROOTFS_SRC)
+ version_name: str = image.get_image_version(DIR_ROOTFS_SRC)
+
disk.partition_umount(f'{DIR_ISO_MOUNT}/live/filesystem.squashfs')
- version_name: str = version_file.lstrip('Version: ').strip()
+
+ if cfg_ver < SYSTEM_CFG_VER:
+ raise compat.DowngradingImageTools(
+ f'Adding image would downgrade image tools to v.{cfg_ver}; disallowed')
+
image_name: str = ask_input(MSG_INPUT_IMAGE_NAME, version_name)
set_as_default: bool = ask_yes_no(MSG_INPUT_IMAGE_DEFAULT, default=True)
diff --git a/src/op_mode/image_manager.py b/src/op_mode/image_manager.py
index 76fc4367f..725c40613 100755
--- a/src/op_mode/image_manager.py
+++ b/src/op_mode/image_manager.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright 2022 VyOS maintainers and contributors <maintainers@vyos.io>
+# Copyright 2023 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This file is part of VyOS.
#
@@ -22,10 +22,11 @@ from pathlib import Path
from shutil import rmtree
from sys import exit
-from vyos.system import disk, grub, image
+from vyos.system import disk, grub, image, compat
from vyos.utils.io import ask_yes_no
+@compat.grub_cfg_update
def delete_image(image_name: str) -> None:
"""Remove installed image files and boot entry
@@ -57,6 +58,7 @@ def delete_image(image_name: str) -> None:
exit(f'Unable to remove the image "{image_name}": {err}')
+@compat.grub_cfg_update
def set_image(image_name: str) -> None:
"""Set default boot image
@@ -86,6 +88,7 @@ def set_image(image_name: str) -> None:
exit(f'Unable to set default image "{image_name}": {err}')
+@compat.grub_cfg_update
def rename_image(name_old: str, name_new: str) -> None:
"""Rename installed image