�
�f� � �� � d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm Z ej e� Zde
de
fd�Zde
de
fd�Zdefd �Zde
fd
�Zde
fd�Z G d� d
e j( � Zy)� N)�Optional)�dmi)�report_diagnostic_event�system_uuid�returnc �� � t j | � }t
t j |j �� � S # t $ r" d| ��}t |t j
�� � w xY w)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)�uuid�UUID�
ValueErrorr �LOG�error�str�bytes_le)r �
original_uuid�msgs �B/usr/lib/python3/dist-packages/cloudinit/sources/azure/identity.py�byte_swap_system_uuidr s_ � ��� � �+�.�
� �t�y�y�}�5�5�6�7�7�� � �-�k�_�=�������;�
��s �A � +A+c �0 � t � rt | � S | S )z!Determine VM ID from system uuid.)�
is_vm_gen1r �r s r �convert_system_uuid_to_vm_idr ) s � ��|�$�[�1�1��� c � � t j j d� ryt j j d� ryy)zZDetermine if VM is gen1 or gen2.
Gen2 guests use UEFI while gen1 is legacy BIOS.
z/sys/firmware/efiFz/dev/efiT)�os�path�exists� r r r r 1 s0 � �
�w�w�~�~�)�*��
�w�w�~�~�j�!��r c � � t j d� } | �t d� �| j � } t j d| � | S )z Query system uuid in lower-case.zsystem-uuidzfailed to read system-uuidzRead product uuid: %s)r �
read_dmi_data�RuntimeError�lowerr �debugr s r �query_system_uuidr& |