diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/system/image.py | 17 | ||||
| -rw-r--r-- | python/vyos/utils/kernel.py | 7 |
2 files changed, 14 insertions, 10 deletions
diff --git a/python/vyos/system/image.py b/python/vyos/system/image.py index ed8a96fbb..02f2303b2 100644 --- a/python/vyos/system/image.py +++ b/python/vyos/system/image.py @@ -22,6 +22,7 @@ from json import loads from vyos.defaults import directories from vyos.system import disk, grub +from vyos.utils.kernel import get_kernel_boot_arg # Define variables GRUB_DIR_MAIN: str = '/boot/grub' @@ -29,8 +30,12 @@ GRUB_DIR_VYOS: str = f'{GRUB_DIR_MAIN}/grub.cfg.d' CFG_VYOS_VARS: str = f'{GRUB_DIR_VYOS}/20-vyos-defaults-autoload.cfg' GRUB_DIR_VYOS_VERS: str = f'{GRUB_DIR_VYOS}/vyos-versions' # prepare regexes -REGEX_KERNEL_CMDLINE: str = r'^BOOT_IMAGE=/(?P<boot_type>boot|live)/((?P<image_version>.+)/)?vmlinuz.*$' -REGEX_SYSTEM_CFG_VER: str = r'(\r\n|\r|\n)SYSTEM_CFG_VER\s*=\s*(?P<cfg_ver>\d+)(\r\n|\r|\n)' +REGEX_KERNEL_CMDLINE: str = ( + r'^/(?P<boot_type>boot|live)/((?P<image_version>.+)/)?vmlinuz.*$' +) +REGEX_SYSTEM_CFG_VER: str = ( + r'(\r\n|\r|\n)SYSTEM_CFG_VER\s*=\s*(?P<cfg_ver>\d+)(\r\n|\r|\n)' +) # structures definitions @@ -197,8 +202,8 @@ def get_running_image() -> str: """ running_image: str = '' regex_filter = re_compile(REGEX_KERNEL_CMDLINE) - cmdline: str = Path('/proc/cmdline').read_text() - running_image_result = regex_filter.match(cmdline) + cmdline_arg: str = get_kernel_boot_arg('BOOT_IMAGE') or '' + running_image_result = regex_filter.match(cmdline_arg) if running_image_result: running_image: str = running_image_result.groupdict().get( 'image_version', '') @@ -259,8 +264,8 @@ def is_live_boot() -> bool: bool: True if the system currently booted in live mode """ regex_filter = re_compile(REGEX_KERNEL_CMDLINE) - cmdline: str = Path('/proc/cmdline').read_text() - running_image_result = regex_filter.match(cmdline) + cmdline_arg: str = get_kernel_boot_arg('BOOT_IMAGE') or '' + running_image_result = regex_filter.match(cmdline_arg) if running_image_result: boot_type: str = running_image_result.groupdict().get('boot_type', '') if boot_type == 'boot': diff --git a/python/vyos/utils/kernel.py b/python/vyos/utils/kernel.py index 69574cefc..72c7413cf 100644 --- a/python/vyos/utils/kernel.py +++ b/python/vyos/utils/kernel.py @@ -165,14 +165,13 @@ def get_kernel_serial_console() -> Tuple[Optional[str], Optional[str], Optional[ command line which was used during system boot. """ import re - from vyos.utils.file import read_file cmdline_console_re = re.compile( - r'(?:^|\s)console=(?P<console_type>tty(?:S|AMA))(?P<console_num>\d+),(?P<console_speed>\d+)(?=\s|$)' + r'(?P<console_type>tty(?:S|AMA))(?P<console_num>\d+),(?P<console_speed>\d+)' ) - kernel_cmdline = read_file('/proc/cmdline') - if m := cmdline_console_re.search(kernel_cmdline): + console_value = get_kernel_boot_arg('console') or '' + if m := cmdline_console_re.search(console_value): return ( m.group('console_type'), m.group('console_num'), |
