summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2025-10-03 15:31:26 +0100
committerGitHub <noreply@github.com>2025-10-03 15:31:26 +0100
commit714248a44dff73ecf6e51a905e1837a67b784aa5 (patch)
tree49edfd6ec34b7a711544a9a7a1fe1675b31dc778 /python
parentb4c1af24982094c194e0f9cf539bcc2087969081 (diff)
parent38567e4f7747d0d97ff5685f6da2c1edd78920af (diff)
downloadvyos-1x-714248a44dff73ecf6e51a905e1837a67b784aa5.tar.gz
vyos-1x-714248a44dff73ecf6e51a905e1837a67b784aa5.zip
Merge pull request #4774 from dmbaturin/T7898-no-container-mac-system-uuid
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:
"""