o x[hk@sddlZddlmZmZddlmZddlmZddlmZm Z ddl m Z m Z e eZdeejfdd Zd edefd d Zd e jdefddZdefddZdS)N)datetimetimezone)Optional)version)handlersinstantiated_handler_registry)errorsidentityreturncCs tjd}t|tjsdS|S)z'Get instantiated KVP telemetry handler. telemetryN)rregistered_itemsget isinstancerHyperVKvpReportingHandler) kvp_handlerr=/usr/lib/python3/dist-packages/cloudinit/sources/azure/kvp.pyget_kvp_handlers  rreportcCs,t}|durtddS|d|dS)z/Report to host via PROVISIONING_REPORT KVP key.Nz.KVP handler not enabled, skipping host report.FPROVISIONING_REPORTT)rLOGdebug write_key)rrrrrreport_via_kvps   rerrorcCs t|S)N)ras_encoded_report)rrrrreport_failure_to_host&s rc Csxzt}Wnty}z d|}WYd}~nd}~wwtddtdtt j  d|g}t |S)Nzfailed to read vm id: zresult=successzagent=Cloud-Init/z timestamp=zvm_id=) r query_vm_id Exceptionr encode_reportrversion_stringrnowrutc isoformatr)vm_idid_errorrrrrreport_success_to_host*s   r&)loggingrrtypingr cloudinitrcloudinit.reportingrrcloudinit.sources.azurerr getLogger__name__rrrstrboolrReportableErrorrr&rrrrs