404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@18.117.183.206: ~ $
3

\�mea;�@sJddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
ddlmZddlm
Z
ddlmZmZddlmZeje�ZGdd�de�ZGd	d
�d
ejd�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�Ze
eeeeefZe�Zej de�ej de�ej de�ej de�dS)�N)�datetime)�Event)�Union)�
url_helper�util)�DictRegistryc@seZdZdS)�ReportExceptionN)�__name__�
__module__�__qualname__�rr�/usr/lib/python3.6/handlers.pyrsrc@s&eZdZdZejdd��Zdd�ZdS)�ReportingHandlerz�Base class for report handlers.

    Implement :meth:`~publish_event` for controlling what
    the handler does with an event.
    cCsdS)zPublish an event.Nr)�self�eventrrr
�
publish_event"szReportingHandler.publish_eventcCsdS)z0Ensure ReportingHandler has published all eventsNr)rrrr
�flush&szReportingHandler.flushN)r	r
r�__doc__�abc�abstractmethodrrrrrr
rsr)�	metaclasscs*eZdZdZd�fdd�	Zdd�Z�ZS)�
LogHandlerzBPublishes events to the cloud-init log at the ``DEBUG`` log level.�DEBUGcsbtt|�j�t|t�rn>|}ytt|j��}Wn&tk
rVt	j
d|�tj}YnX||_dS)Nzinvalid level '%s', using WARN)
�superr�__init__�
isinstance�int�getattr�logging�upper�	Exception�LOG�warningZWARN�level)rr#Zinput_level)�	__class__rr
r-s
zLogHandler.__init__cCs2tjdjdd|j|jg��}|j|j|j��dS)N�.�	cloudinitZ	reporting)r�	getLogger�join�
event_type�name�logr#�	as_string)rrZloggerrrr
r:szLogHandler.publish_event)r)r	r
rrrr�
__classcell__rr)r$r
r*s
rc@seZdZdZdd�ZdS)�PrintHandlerzPrint the event as a string.cCst|j��dS)N)�printr,)rrrrr
rDszPrintHandler.publish_eventN)r	r
rrrrrrr
r.Asr.cs6eZdZd
�fdd�	Zdd�Zdd�Zdd	�Z�ZS)�WebHookHandlerNc	s�tt|�j�t||||g�r:tj||||d�}|j|_ntj|_||_||_||_	t
j�|_t
�|_tj�|_tj|jd�|_d|j_|jj�dS)N)�consumer_key�	token_key�token_secret�consumer_secret)�targetT)rr0r�anyrZOauthUrlHelper�readurl�endpoint�timeout�retriesrZfetch_ssl_details�ssl_detailsr�flush_requested�queue�Queue�	threading�Thread�process_requestsZevent_processor�daemon�start)	rr8r1r2r3r4r9r:Zoauth_helper)r$rr
rIs$



zWebHookHandler.__init__cCs�d}x�|jj�rJ|dkrJtjd�x"|jj�sD|jj�|jj�q$Wd}|jjdd�}zty2|j	|d|d|d|d|dd	d
�d}Wn<t
k
r�}z tjd|d|�|d7}WYdd}~XnXWd|jj�XqWdS)Nr�zNMultiple consecutive failures in WebHookHandler. Cancelling all queued events.T)�block���F)�datar9r:r;Zlog_req_respz0Failed posting event: %s. This was caused by: %s)r<Zis_setr!r"r=�emptyZ
get_nowait�	task_done�getr7r )rZconsecutive_failed�args�errr
rAjs4
zWebHookHandler.process_requestscCs@|j�}tjd|j|�|jj|jtj|�|j|j	|j
f�dS)NzQueuing POST to %s, data: %s)Zas_dictr!�debugr8r=�put�json�dumpsr9r:r;)rrZ
event_datarrr
r�szWebHookHandler.publish_eventcCs,|jj�tjd�|jj�|jj�dS)Nz(WebHookHandler flushing remaining events)r<�setr!rOr=r(�clear)rrrr
r�s


zWebHookHandler.flush)NNNNNN)r	r
rrrArrr-rr)r$r
r0Hs&r0cs�eZdZdZdZdZdZeeZdZdZ	dZ
dZd+ZdZ
dZe
d
f�fdd�	Zedd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zeed
d �d!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Z�ZS),�HyperVKvpReportingHandlera,
    Reports events to a Hyper-V host using Key-Value-Pair exchange protocol
    and can be used to obtain high level diagnostic information from the host.

    To use this facility, the KVP user-space daemon (hv_kvp_daemon) has to be
    running. It reads the kvp_file when the host requests the guest to
    enumerate the KVP's.

    This reporter collates all events for a module (origin|name) in a single
    json string in the dictionary.

    For more information, see
    https://technet.microsoft.com/en-us/library/dn798287.aspx#Linux%20guests
    iiiZ
CLOUD_INIT�msg�resultZmsg_i�,�:z/var/lib/hyperv/.kvp_pool_1FNcsrtt|�j�||_tj|j�||_tj�|_|j	�|_
dj|j|j
�|_
tj|jd�|_d|j_|jj�dS)Nz{0}|{1})r5T)rrUr�_kvp_file_path�_truncate_guest_pool_file�_event_typesr=r>�q�_get_incarnation_noZincarnation_no�format�EVENT_PREFIX�event_key_prefixr?r@�_publish_event_routineZpublish_threadrBrC)rZ
kvp_file_pathZevent_types)r$rr
r�s

z"HyperVKvpReportingHandler.__init__cCs�|jr
dStj�ttj��}zby*tjj|�|krHt|d��WdQRXWn2t	t
fk
r|}ztjd|�WYdd}~XnXWdd|_XdS)a
        Truncate the pool file if it has not been truncated since boot.
        This should be done exactly once for the file indicated by
        KVP_POOL_FILE_GUEST constant above. This method takes a filename
        so that we can use an arbitrary file during unit testing.
        Since KVP is a best-effort telemetry channel we only attempt to
        truncate the file once and only if the file has not been modified
        since boot. Additional truncation can lead to loss of existing
        KVPs.
        N�wz$failed to truncate kvp pool file, %sT)
�_already_truncated_pool_file�time�floatr�uptime�os�path�getmtime�open�OSError�IOErrorr!r")�clsZkvp_fileZ	boot_timerNrrr
r[�s"z3HyperVKvpReportingHandler._truncate_guest_pool_filecCsBtj�}yttj�t|��Stk
r<tjd|�dSXdS)z�
        use the time passed as the incarnation number.
        the incarnation number is the number which are used to
        distinguish the old data stored in kvp and the new data.
        z"uptime '%s' not in correct format.rN)rrgrrerf�
ValueErrorr!r")rZ
uptime_strrrr
r^�sz-HyperVKvpReportingHandler._get_incarnation_noc
cs~t|jd��h}tj|tj�|j|�|j|j�}x.t|�|jkr`|j	|�}|V|j|j�}q4Wtj|tj
�WdQRXdS)z-iterate the kvp file from the current offset.�rbN)rkrZ�fcntl�flock�LOCK_EX�seek�read�HV_KVP_RECORD_SIZE�len�_decode_kvp_item�LOCK_UN)r�offset�f�record_dataZkvp_itemrrr
�
_iterate_kvps�s

z'HyperVKvpReportingHandler._iterate_kvpscCsdj|j|j|jtj��S)z�
        the event key format is:
        CLOUD_INIT|<incarnation number>|<event_type>|<event_name>|<uuid>
        [|subevent_index]
        z{0}|{1}|{2}|{3})r_rar)r*�uuidZuuid4)rrrrr
�
_event_keysz$HyperVKvpReportingHandler._event_keycCs*tjd|j|jf|jd�|jd��}|S)Nz%ds%dszutf-8)�struct�pack�HV_KVP_EXCHANGE_MAX_KEY_SIZE�HV_KVP_EXCHANGE_MAX_VALUE_SIZE�encode)r�key�valuerIrrr
�_encode_kvp_itemsz*HyperVKvpReportingHandler._encode_kvp_itemcCsdt|�}||jkr$tdj||j���|d|j�jd�jd�}||j|j�jd�jd�}||d�S)Nz$record_data len not correct {0} {1}.rzutf-8�)r�r�)rwrvrr_r��decode�strip)rr|Zrecord_data_len�k�vrrr
rx!s
z*HyperVKvpReportingHandler._decode_kvp_itemc
CsXt|jd��B}tj|tj�x|D]}|j|�q"W|j�tj|tj�WdQRXdS)NZab)rkrZrqrrrs�writerry)rr|r{rIrrr
�_append_kvp_item8s
z*HyperVKvpReportingHandler._append_kvp_itemcCs�||j=tj|�}|dt|�d�}d}g}d|jd}x�|||j<d||j<tj||jd�}|jt|�d}	|j|dj|j|d|	�d	��}
d
j||�}|j	|j
||
��|d7}||	d�}t|�dkr>Pq>W|S)NrFr�"z":""�)�
separators�z"{key}":"{desc}")r�Zdescz{}|{})�MSG_KEYrQrRrw�DESC_IDX_KEY�JSON_SEPARATORS�HV_KVP_AZURE_MAX_VALUE_SIZE�replacer_�appendr�)rr��	meta_data�descriptionZdes_in_json�iZresult_arrayZmessage_place_holderZdata_without_descZ
room_for_descr�Zsubkeyrrr
�_break_down@s.


z%HyperVKvpReportingHandler._break_down)r�r��returncCsht|�|jkr |d|jd�}|j||�g}y|j|�Wn&ttfk
rbtjd||�YnXdS)zJWrite KVP key-value.

        Values will be truncated as needed.
        rrFzfailed posting kvp=%s value=%sN)rwr�r�r�rlrmr!r")rr�r�rIrrr
�	write_key^sz#HyperVKvpReportingHandler.write_keycCs�|j|�}|j|jtj|j�j�dd�}t||j�rB|j	||j<|j
||j<tj
||jd�}t|�|jkr||j|||j
�S|j||�}|gSdS)z�
        encode the event into kvp data bytes.
        if the event content reaches the maximum length of kvp value.
        then it would be cut to multiple slices.
        �Z)r*�typeZts)r�N)rr*r)rZutcfromtimestampZ	timestampZ	isoformat�hasattr�
RESULT_KEYrWr�r�rQrRr�rwr�r�r�)rrr�r�r�rIrrr
�
_encode_eventms
z'HyperVKvpReportingHandler._encode_eventcCs�x�d}y�|jjdd�}|d7}g}xP|dk	rr||j|�7}y|jjdd�}|d7}Wq$tjk
rnd}Yq$Xq$WzFy|j|�Wn2ttfk
r�}ztj	d|�WYdd}~XnXWdxt
|�D]}|jj�q�WXWqtk
r�dSXqWdS)NrT)rErFFz failed posting events to kvp, %s)
r]rLr�r=ZEmptyr�rlrmr!r"�rangerK�EOFError)rZitems_from_queuerZencoded_datarN�_rrr
rb�s*
"z0HyperVKvpReportingHandler._publish_event_routinecCs$|js|j|jkr |jj|�dS)N)r\r)r]rP)rrrrr
r�sz'HyperVKvpReportingHandler.publish_eventcCstjd�|jj�dS)Nz0HyperVReportingHandler flushing remaining events)r!rOr]r()rrrr
r�s
zHyperVKvpReportingHandler.flush)rXrY) r	r
rrr�r�r�rvr`r�r�r�r�ZKVP_POOL_FILE_GUESTrdr�classmethodr[r^r}rr�rxr�r��strr�r�rbrrr-rr)r$r
rU�s4

rUr+r/ZwebhookZhyperv)!rrqrQrrhr=r�r?rer~rrZtypingrr&rrZcloudinit.registryrr'r	r!r r�ABCMetarrr.r0rUZHandlerTypeZavailable_handlersZ
register_itemrrrr
�<module>sD
`

Filemanager

Name Type Size Permission Actions
__init__.cpython-36.opt-1.pyc File 1.3 KB 0644
__init__.cpython-36.pyc File 1.3 KB 0644
events.cpython-36.opt-1.pyc File 8.45 KB 0644
events.cpython-36.pyc File 8.45 KB 0644
handlers.cpython-36.opt-1.pyc File 12.11 KB 0644
handlers.cpython-36.pyc File 12.11 KB 0644