o
    fX                     @   s   d dl Z d dl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)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   st   zt  } W n ty } zd|} W Y d }~nd }~ww tddt  dt 	  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   utcnow	isoformatr   )vm_idid_errorr   r   r   r   report_success_to_host*   s   	r$   )loggingr   typingr   	cloudinitr   cloudinit.reportingr   r   cloudinit.sources.azurer   r   	getLogger__name__r   r   r   strboolr   ReportableErrorr   r$   r   r   r   r   <module>   s   
