3 \¼me¨ ã @ s® d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm Z ej eƒZe e dœdd„Ze e dœdd „Zed œdd„Ze d œd d„Ze d œdd„ZG dd„ de jƒZdS )é N)ÚOptional)Údmi)Úreport_diagnostic_event)Úsystem_uuidÚreturnc C sP yt j| ƒ}W n. tk r< d| ›}t|tjd ‚ Y nX tt j|jdƒS )aà Byte swap system uuid. Azure always uses little-endian for the first three fields in the uuid. This behavior was made strict in SMBIOS 2.6+, but Linux and dmidecode follow RFC 4122 and assume big-endian for earlier SMBIOS versions. Azure's gen1 VMs use SMBIOS 2.3 which requires byte swapping to match compute.vmId presented by IMDS. Azure's gen2 VMs use SMBIOS 3.1 which does not require byte swapping. :raises ValueError: if UUID is invalid. zFailed to parse system uuid: )Úlogger_func)Úbytes)ÚuuidZUUIDÚ ValueErrorr ÚLOGÚerrorÚstrZbytes_le)r Z original_uuidÚmsg© r ú/usr/lib/python3.6/identity.pyÚbyte_swap_system_uuid s r c C s t ƒ rt| ƒS | S )z!Determine VM ID from system uuid.)Ú is_vm_gen1r )r r r r Úconvert_system_uuid_to_vm_id) s r )r c C s$ t jjdƒrdS t jjdƒr dS dS )zZDetermine if VM is gen1 or gen2. Gen2 guests use UEFI while gen1 is legacy BIOS. z/sys/firmware/efiFz/dev/efiT)ÚosÚpathÚexistsr r r r r 1 s r c C s2 t jdƒ} | dkrtdƒ‚| jƒ } tjd| ƒ | S )z Query system uuid in lower-case.zsystem-uuidNzfailed to read system-uuidzRead product uuid: %s)r Ú read_dmi_dataÚRuntimeErrorÚlowerr Údebug)r r r r Úquery_system_uuidA s r c C s t ƒ } t| ƒS )zQuery VM ID from system.)r r )r r r r Úquery_vm_idM s r c @ s&