
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\me                 @   s   d dl Z d dlZd dlZd dlmZmZ e jeZG dd de	Z
G dd dZG dd dZG d	d
 d
eZG dd deZdS )    N)subputilc               @   s   e Zd ZdS )CustomScriptNotFoundN)__name__
__module____qualname__ r   r   */usr/lib/python3.6/config_custom_script.pyr      s   r   c               @   s*   e Zd ZdZdZejjeeZdZ	dZ
dS )CustomScriptConstantz/root/.customizationzcustomize.shz)/.guest-customization-post-reboot-pendingzpost-customize-guest.shN)r   r   r   CUSTOM_TMP_DIRZCUSTOM_SCRIPT_NAMEospathjoinCUSTOM_SCRIPTPOST_CUSTOM_PENDING_MARKERPOST_CUSTOM_SCRIPT_NAMEr   r   r   r	   r
      s
   r
   c               @   s   e Zd Zdd Zdd ZdS )RunCustomScriptc             C   s    || _ || _tjj||| _d S )N)
scriptname	directoryr   r   r   
scriptpath)selfr   r   r   r   r	   __init__!   s    zRunCustomScript.__init__c             C   sp   t jj| jstd| j tjtj t	j
dtj tj| jtj tjtjjdd}tjtj|dd d S )Nz3Script %s not found!! Cannot execute custom script!zCopying custom script to %s id  )mode)r   r   existsr   r   r   Z
ensure_dirr
   r   LOGdebugr   copyZ	load_filereplaceZ
write_file)r   Zcontentr   r   r	   prepare_script&   s    

zRunCustomScript.prepare_scriptN)r   r   r   r   r    r   r   r   r	   r       s   r   c               @   s   e Zd Zdd ZdS )PreCustomScriptc             C   s&   t jd | j  tjtjdg dS )z7Executing custom script with precustomization argument.z"Executing pre-customization scriptZprecustomizationN)r   r   r    r   r
   r   )r   r   r   r	   execute>   s    
zPreCustomScript.executeN)r   r   r   r"   r   r   r   r	   r!   =   s   r!   c                   s$   e Zd Z fddZdd Z  ZS )PostCustomScriptc                s.   t t| j|| || _tjj|tj| _	d S )N)
superr#   r   ccScriptsDirr   r   r   r
   r   ccScriptPath)r   r   r   r%   )	__class__r   r	   r   F   s    zPostCustomScript.__init__c             C   sn   | j   tjd| j tjtjj| j	t
j| j tj| j}tj| j|jtjB  tjd tjt
j dS )z
        This method copy the post customize run script to
        cc_scripts_per_instance directory and let this
        module to run post custom script.
        z'Copying post customize run script to %sz*Creating post customization pending markerN)r    r   r   r&   r   r   r   r   r   r   r
   r   statchmodst_modeS_IEXECinfoZensure_filer   )r   str   r   r	   r"   M   s    

zPostCustomScript.execute)r   r   r   r   r"   __classcell__r   r   )r'   r	   r#   E   s   r#   )Zloggingr   r(   Z	cloudinitr   r   Z	getLoggerr   r   	Exceptionr   r
   r   r!   r#   r   r   r   r	   <module>   s   
