summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2025-10-03 12:21:05 +0100
committerDaniil Baturin <daniil@baturin.org>2025-10-03 12:21:05 +0100
commit38567e4f7747d0d97ff5685f6da2c1edd78920af (patch)
tree4e8317c6697c65889216fb8af6171f10218cfb09 /python
parentec939ce053e748c984faa98e22913b4421b674ac (diff)
downloadvyos-1x-38567e4f7747d0d97ff5685f6da2c1edd78920af.tar.gz
vyos-1x-38567e4f7747d0d97ff5685f6da2c1edd78920af.zip
vyos.utils.network: T7898: check if system UUID is available
before trying to use it for host identity generation
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/network.py19
1 files changed, 16 insertions, 3 deletions
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 "<uuid>:<hostname>", 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:
"""