3 \meX@sddlZddlmZddlmZddlmZddlmZmZddl m Z m Z ej e Zeejddd Zeed d d Ze jed ddZedddZdS)N)datetime)Optional)version)handlersinstantiated_handler_registry)errorsidentity)returncCs tjjd}t|tjsdS|S)z'Get instantiated KVP telemetry handler.Z telemetryN)rZregistered_itemsget isinstancerHyperVKvpReportingHandler) kvp_handlerr/usr/lib/python3.6/kvp.pyget_kvp_handlers  r)reportr cCs,t}|dkrtjddS|jd|dS)z/Report to host via PROVISIONING_REPORT KVP key.Nz.KVP handler not enabled, skipping host report.FZPROVISIONING_REPORTT)rLOGdebugZ write_key)rr rrrreport_via_kvps   r)errorr cCs t|jS)N)rZas_encoded_report)rrrrreport_failure_to_host&srcCsry tj}Wn,tk r8}zd|}WYdd}~XnXtjddtjdtjj d|g}t |S)Nzfailed to read vm id: zresult=successzagent=Cloud-Init/z timestamp=zvm_id=) rZ query_vm_id ExceptionrZ encode_reportrZversion_stringrZutcnowZ isoformatr)Zvm_idZid_errorrrrrreport_success_to_host*s  r)ZloggingrZtypingrZ cloudinitrZcloudinit.reportingrrZcloudinit.sources.azurerrZ getLogger__name__rr rstrboolrZReportableErrorrrrrrrs