From 38567e4f7747d0d97ff5685f6da2c1edd78920af Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Fri, 3 Oct 2025 12:21:05 +0100 Subject: vyos.utils.network: T7898: check if system UUID is available before trying to use it for host identity generation --- python/vyos/utils/network.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py index e6b838cdc..54dc0b2d9 100644 --- a/python/vyos/utils/network.py +++ b/python/vyos/utils/network.py @@ -55,7 +55,8 @@ def get_host_identity() -> str: Build a stable host identity string for deterministic MAC generation. Combines: - • The system's HardwareUUID (from /sys/class/dmi/id/product_uuid) + • The system's hardware UUID (from /sys/class/dmi/id/product_uuid), + if available • The system hostname Both are normalized (lowercase, dashes removed in UUID) and joined with a colon. @@ -64,9 +65,21 @@ def get_host_identity() -> str: str: A string ":", used as part of the host-specific seed when generating deterministic MAC addresses. """ - uuid = cmd(f"cat /sys/class/dmi/id/product_uuid").strip().replace("-", "").lower() + import os.path + + uuid_file = '/sys/class/dmi/id/product_uuid' + + if os.path.exists(uuid_file): + uuid = cmd(f"sudo cat {uuid_file}").strip().replace("-", "").lower() + else: + uuid = None + host = cmd("hostname").strip().lower() - return f"{uuid}:{host}" + + if uuid is not None: + return f"{uuid}:{host}" + else: + return host def gen_mac(name: str, addr: str, ident: str) -> str: """ -- cgit v1.2.3