a 'Dg @sddlZddlZddlZddlZddlmZddlmZddlm Z e e Z e e dddZe e ddd Zed d d Ze d d dZe d ddZGdddejZdS)N)Optional)dmi)report_diagnostic_event) system_uuidreturncCsNzt|}Wn,ty:d|}t|tjdYn0ttj|jdS)aByte 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: Z logger_func)bytes)uuidZUUID ValueErrorrLOGerrorstrZbytes_le)rZ original_uuidmsgrD/usr/lib/python3.9/site-packages/cloudinit/sources/azure/identity.pybyte_swap_system_uuids  rcCstrt|S|S)z!Determine VM ID from system uuid.) is_vm_gen1rrrrrconvert_system_uuid_to_vm_id)srrcCs$tjdrdStjdr dSdS)zZDetermine if VM is gen1 or gen2. Gen2 guests use UEFI while gen1 is legacy BIOS. z/sys/firmware/efiFz/dev/efiT)ospathexistsrrrrr1s   rcCs2td}|durtd|}td||S)z Query system uuid in lower-case.z system-uuidNzfailed to read system-uuidzRead product uuid: %s)r read_dmi_data RuntimeErrorlowerr debugrrrrquery_system_uuidAs   rcCst}t|S)zQuery VM ID from system.)rrrrrr query_vm_idMsrc@s&eZdZdZeeddddZdS)ChassisAssetTagz 7783-7084-3265-9085-8269-3286-77rcCsZtd}z ||}Wn&ty<td|tjdYdS0td||jftjd|S)zCheck platform environment to report if this datasource may run. :returns: ChassisAssetTag if matching tag found, else None. zchassis-asset-tagzNon-Azure chassis asset tag: %rrNz Azure chassis asset tag: %r (%s))rrr rr rname)clsZ asset_tagtagrrr query_systemVs    zChassisAssetTag.query_systemN)__name__ __module__ __qualname__Z AZURE_CLOUD classmethodrr#rrrrrSsr)enumZloggingrr typingrZ cloudinitrZcloudinit.sources.helpers.azurerZ getLoggerr$r r rrboolrrrEnumrrrrrs