File manager - Edit - /usr/lib/python3/dist-packages/cloudinit/sources/helpers/__pycache__/azure.cpython-310.pyc
Back
o o@�d�� � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl m Z d dlmZ d dlm Z d dlmZmZ d dlmZmZmZmZmZmZ d dlmZ d dlmZ d d lmZmZmZmZm Z m!Z! d d l"m#Z# d dl$m%Z% er~d dl&m'Z' e�(e)�Z*d Z+dZ,dZ-dZ.dZ/dZ0dZ1e#j2dddd�Z3ed�Z4dede4f dede4f fdd�Z5e5dd� �Z6e5d d!� �Z7dd"�d#e8de#j9fd$d%�Z:d&d'� Z;e5e%d( fd)d*��Z<e5d+d,� �Z=e d-d.� �Z>d/d0� Z?e5dd1d2d3�d4e8d5e@d6eeA d7eBd8eBdejCfd9d:��ZDd;e8d<e8d=e8deAfd>d?�ZEG d@dA� dA�ZFG dBdC� dCeG�ZHG dDdE� dE�ZIG dFdG� dG�ZJG dHdI� dI�ZKG dJdK� dK�ZLe5 d]dLe8dMeee8 dNee8 fdOdP��ZMe5dLe8dQdRfdSdT��ZNdUdV� ZOG dWdX� dXeG�ZPG dYdZ� dZeG�ZQG d[d\� d\�ZRdS )^� N)�contextmanager)�datetime)�ENOENT)�sleep�time)� TYPE_CHECKING�Callable�List�Optional�TypeVar�Union)�ElementTree)�escape)�distros�subp� temp_utils� url_helper�util�version)�events)�CFG_BUILTIN)�errorsz 168.63.129.16�boot-telemetryzsystem-info� diagnostic� compressedi � z'/run/cloud-init/log_pushed_to_kvp_indexzazure-dsz initialize reporter for azure dsT)�name�description�reporting_enabled�T�func.�returnc s � fdd�}|S )Nc sF t j� j� jtd�� � | i |��W d � S 1 sw Y d S )N�r r �parent)r �ReportEventStack�__name__�azure_ds_reporter)�args�kwargs�r � �A/usr/lib/python3/dist-packages/cloudinit/sources/helpers/azure.py�impl5 s �$�z)azure_ds_telemetry_reporter.<locals>.implr) )r r+ r) r( r* �azure_ds_telemetry_reporter4 s r, c C s� t �� std��t�d� z tt� �tt�� � } W n t y+ } ztd�|�d}~ww z*t j g d�dd�\}}d}|rGd|v rG|�d�d }|sMtd ��| t|�d }W n& t jyj } ztd| �|�d}~w t y| } ztd | �|�d}~ww z*t j g d�dd�\}}d}|r�d|v r�|�d�d }|s�td��| t|�d }W n& t jy� } ztd| �|�d}~w t y� } ztd| �|�d}~ww t �tddt�| ��� d t�|��� d t�|��� d f t j�}t �|� |S )z[Report timestamps related to kernel initialization and systemd activation of cloud-initz1distro not using systemd, skipping boot telemetryzCollecting boot telemetryz*Failed to determine kernel start timestampN)� systemctl�show�-p�UserspaceTimestampMonotonicT)�capture�=� z8Failed to parse UserspaceTimestampMonotonic from systemdi@B z-Failed to get UserspaceTimestampMonotonic: %sz<Failed to parse UserspaceTimestampMonotonic from systemd: %s)r- r. zcloud-init-localr/ �InactiveExitTimestampMonotonicz;Failed to parse InactiveExitTimestampMonotonic from systemdz0Failed to get InactiveExitTimestampMonotonic: %sz?Failed to parse InactiveExitTimestampMonotonic from systemd: %sr z5kernel_start=%s user_start=%s cloudinit_activation=%s�Z)r �uses_systemd�RuntimeError�LOG�debug�floatr r �uptime� ValueErrorr �split�ProcessExecutionErrorr �ReportingEvent�BOOT_EVENT_TYPEr �utcfromtimestamp� isoformat�DEFAULT_EVENT_ORIGIN�report_event)�kernel_start�e�out�_�tsm� user_start�cloudinit_activation�evtr) r) r* �get_boot_telemetry@ s� �� ��������� � ������������ rM c C sb t �� } t�tddt�� | d | d | d d | d d | d d | d f tj�}t�|� |S ) z%Collect and report system informationzsystem informationztcloudinit_version=%s, kernel_version=%s, variant=%s, distro_name=%s, distro_version=%s, flavor=%s, python_version=%s�release�variant�distr r3 � �python) r �system_infor r? �SYSTEMINFO_EVENT_TYPEr �version_stringrC rD )�inforL r) r) r* �get_system_info� s$ ��� rW ��logger_func�msgc C s6 t |�r|| � t�td| tj�}tj|dhd� |S )zReport a diagnostic eventzdiagnostic message�log��excluded_handler_types)�callabler r? �DIAGNOSTIC_EVENT_TYPErC rD )rZ rY rL r) r) r* �report_diagnostic_event� s �r` c C sN t �t�|��}d|�d�d�}t�t| t� |�tj �}tj|h d�d� |S )zReport a compressed eventzgz+b64�ascii)�encoding�data> r[ �print�webhookr\ )�base64�encodebytes�zlib�compress�decoder r? �COMPRESSED_EVENT_TYPE�json�dumpsrC rD )� event_name� event_content�compressed_data� event_datarL r) r) r* �report_compressed_event� s ���rr �def_log_filec C sV t � }t�d� zNt| d��?}|�dtj� t|�� t |�}t d�|�� | |�tjd� |�|tj� t d|�� � t�tt|�� �� W d � n1 sPw Y W n tys } zt dt|� tjd� W Y d}~nd}~ww t�d � ztjd gddd �\}}t d |� W dS ty� } zt dt|� tjd� W Y d}~dS d}~ww )az Push a portion of cloud-init.log file or the whole file to KVP based on the file size. The first time this function is called after VM boot, It will push the last n bytes of the log file such that n < MAX_LOG_TO_KVP_LENGTH If called again on the same boot, it continues from where it left off. In addition to cloud-init.log, dmesg log will also be collected.z"Dumping cloud-init.log file to KVP�rbr zMDumping last {0} bytes of cloud-init.log file to KVP starting from index: {1}rX zcloud-init.logNz#Exception when dumping log file: %szDumping dmesg log to KVP�dmesgFT)rj r1 z$Exception when dumping dmesg log: %s)�%get_last_log_byte_pushed_to_kvp_indexr8 r9 �open�seek�os�SEEK_END�max�tell�MAX_LOG_TO_KVP_LENGTHr` �format�SEEK_SETrr �readr � write_file�LOG_PUSHED_TO_KVP_INDEX_FILE�str� Exception�repr�warningr )� file_name�start_index�f� seek_index�exrG rH r) r) r* �push_log_to_kvp� sD ��� ��� ���r� c C s zt td��} t| �� �W d � W S 1 sw Y W dS tyI } z|jtkr>tdt|� t j d� W Y d }~dS W Y d }~dS d }~w tyf } ztdt|� t j d� W Y d }~dS d }~w ty� } ztdt|� t j d� W Y d }~dS d }~ww )N�rz0Reading LOG_PUSHED_TO_KVP_INDEX_FILE failed: %s.rX z2Invalid value in LOG_PUSHED_TO_KVP_INDEX_FILE: %s.z2Failed to get the last log byte pushed to KVP: %s.r ) rw r� �intr� �IOError�errnor r` r� r8 r� r<