
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\me                 @   sP   d dl Z d dlZd dlmZmZmZ d dlmZ e je	Z
G dd dejZdS )    N)handlerssubputil)
PER_ALWAYSc               @   s*   e Zd ZdgZdd Zdd Zdd ZdS )	BootHookPartHandlerz#cloud-boothookc             K   s2   t jj| t |jd| _d | _|r.|j | _d S )NZ	boothooks)r   Handler__init__r   Z	get_ipathboothook_dirinstance_idZget_instance_id)selfpathsZ
datasourceZ_kwargs r   /usr/lib/python3.6/boot_hook.pyr      s
    zBootHookPartHandler.__init__c             C   sJ   t j|}tjj| j|}t jt j|| jd d}t j	||j
 d |S )Nr   )prefixi  )r   Zclean_filenameospathjoinr	   Zstrip_prefix_suffixZdos2unixprefixesZ
write_filelstrip)r   payloadfilenamefilepathcontentsr   r   r   _write_part    s    
zBootHookPartHandler._write_partc             C   s   |t jkrd S | j||}yBtjj }| jd k	r>t| j|d< tj	d t
j
|g|dd W nD t
jk
r   tjtd| Y n" tk
r   tjtd| Y nX d S )NZINSTANCE_IDzExecuting boothookF)envZcapturez#Boothooks script %s execution errorz'Boothooks unknown error when running %s)r   ZCONTENT_SIGNALSr   r   environcopyr
   strLOGdebugr   ZProcessExecutionErrorr   Zlogexc	Exception)r   dataZctyper   r   Z	frequencyr   r   r   r   r   handle_part)   s    



zBootHookPartHandler.handle_partN)__name__
__module____qualname__r   r   r   r"   r   r   r   r   r      s   	r   )Zloggingr   Z	cloudinitr   r   r   Zcloudinit.settingsr   Z	getLoggerr#   r   r   r   r   r   r   r   <module>   s
   
