Retrieves the machine ID from the host system.
()
| 6 | from shared_lib.logger import log |
| 7 | |
| 8 | |
| 9 | def get_machine_id() -> str: |
| 10 | """Retrieves the machine ID from the host system.""" |
| 11 | paths = ["/host/etc/machine-id", "/etc/machine-id"] |
| 12 | for path in paths: |
| 13 | if os.path.exists(path): |
| 14 | with open(path, "r", encoding="utf-8") as f: |
| 15 | machine_id = f.read().strip() |
| 16 | log.debug( |
| 17 | "Machine ID retrieved", |
| 18 | hypothesisId="SYS", |
| 19 | path=path, |
| 20 | id=machine_id, |
| 21 | ) |
| 22 | return machine_id |
| 23 | log.debug("Failed to retrieve machine ID", hypothesisId="SYS", checked_paths=paths) |
| 24 | raise RuntimeError("Failed to retrieve machine ID: No valid machine-id file found.") |
| 25 | |
| 26 |