o
    x[hk  ã                   @   s¦   d dl Z d dlmZmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZ e  e¡Zdeej fdd	„Zd
edefdd„Zdejdefdd„Zdefdd„ZdS )é    N)ÚdatetimeÚtimezone)ÚOptional)Úversion)ÚhandlersÚinstantiated_handler_registry)ÚerrorsÚidentityÚreturnc                  C   s    t j d¡} t| tjƒsdS | S )z'Get instantiated KVP telemetry handler.Ú	telemetryN)r   Úregistered_itemsÚgetÚ
isinstancer   ÚHyperVKvpReportingHandler)Úkvp_handler© r   ú=/usr/lib/python3/dist-packages/cloudinit/sources/azure/kvp.pyÚget_kvp_handler   s   ÿr   Úreportc                 C   s,   t ƒ }|du rt d¡ dS | d| ¡ dS )z/Report to host via PROVISIONING_REPORT KVP key.Nz.KVP handler not enabled, skipping host report.FÚPROVISIONING_REPORTT)r   ÚLOGÚdebugÚ	write_key)r   r   r   r   r   Úreport_via_kvp   s   
r   Úerrorc                 C   s   t |  ¡ ƒS )N)r   Úas_encoded_report)r   r   r   r   Úreport_failure_to_host&   s   r   c               
   C   sx   zt  ¡ } W n ty } zd|›�} W Y d }~nd }~ww t ddt ¡ › �dt t	j
¡ ¡ › �d| › �g¡}t|ƒS )Nzfailed to read vm id: zresult=successzagent=Cloud-Init/z
timestamp=zvm_id=)r	   Úquery_vm_idÚ	Exceptionr   Úencode_reportr   Úversion_stringr   Únowr   ÚutcÚ	isoformatr   )Úvm_idÚid_errorr   r   r   r   Úreport_success_to_host*   s   €ÿüÿ	r&   )Úloggingr   r   Útypingr   Ú	cloudinitr   Úcloudinit.reportingr   r   Úcloudinit.sources.azurer   r	   Ú	getLoggerÚ__name__r   r   r   ÚstrÚboolr   ÚReportableErrorr   r&   r   r   r   r   Ú<module>   s   
