3 \¼me¨ ã@s®ddlZddlZddlZddlZddlmZddlmZddlm Z ej e ƒZ e e dœdd„Ze e dœdd „Zed œd d „Ze d œd d„Ze d œdd„ZGdd„dejƒZdS)éN)ÚOptional)Údmi)Úreport_diagnostic_event)Ú system_uuidÚreturnc CsPytj|ƒ}Wn.tk r<d|›}t|tjd‚YnXttj|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)rZ original_uuidÚmsg©rú/usr/lib/python3.6/identity.pyÚbyte_swap_system_uuids rcCstƒrt|ƒS|S)z!Determine VM ID from system uuid.)Ú is_vm_gen1r)rrrrÚconvert_system_uuid_to_vm_id)sr)rcCs$tjjdƒrdStjjdƒr dSdS)zZDetermine if VM is gen1 or gen2. Gen2 guests use UEFI while gen1 is legacy BIOS. z/sys/firmware/efiFz/dev/efiT)ÚosÚpathÚexistsrrrrr1s   rcCs2tjdƒ}|dkrtdƒ‚|jƒ}tjd|ƒ|S)z Query system uuid in lower-case.z system-uuidNzfailed to read system-uuidzRead product uuid: %s)rÚ read_dmi_dataÚ RuntimeErrorÚlowerr Údebug)rrrrÚquery_system_uuidAs   rcCstƒ}t|ƒS)zQuery VM ID from system.)rr)rrrrÚ query_vm_idMsrc@s&eZdZdZeeddœdd„ƒZdS)ÚChassisAssetTagz 7783-7084-3265-9085-8269-3286-77)rc CsZtjdƒ}y ||ƒ}Wn&tk r<td|tjddSXtd||jftjd|S)zŽCheck platform environment to report if this datasource may run. :returns: ChassisAssetTag if matching tag found, else None. zchassis-asset-tagzNon-Azure chassis asset tag: %r)rNz Azure chassis asset tag: %r (%s))rrr rr rÚname)ÚclsZ asset_tagÚtagrrrÚ query_systemVs     zChassisAssetTag.query_systemN)Ú__name__Ú __module__Ú __qualname__Z AZURE_CLOUDÚ classmethodrr!rrrrrSsr)ÚenumZloggingrr ZtypingrZ cloudinitrZcloudinit.sources.helpers.azurerZ getLoggerr"r r rrÚboolrrrÚEnumrrrrrÚs