
    x[h"                         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e	      Z
 G d d      Z G d d      Z G d	 d
e      Z G d de      Zy)    N)subputilc                       e Zd Zy)CustomScriptNotFoundN)__name__
__module____qualname__     [/usr/lib/python3/dist-packages/cloudinit/sources/helpers/vmware/imc/config_custom_script.pyr   r      s    r   r   c                   T    e Zd ZdZdZej                  j                  ee      ZdZ	dZ
y)CustomScriptConstantz/root/.customizationzcustomize.shz)/.guest-customization-post-reboot-pendingzpost-customize-guest.shN)r   r   r	   CUSTOM_TMP_DIRCUSTOM_SCRIPT_NAMEospathjoinCUSTOM_SCRIPTPOST_CUSTOM_PENDING_MARKERPOST_CUSTOM_SCRIPT_NAMEr
   r   r   r   r      s0    +N (GGLL1CDM!L7r   r   c                       e Zd Zd Zd Zy)RunCustomScriptc                 j    || _         || _        t        j                  j	                  ||      | _        y N)
scriptname	directoryr   r   r   
scriptpath)selfr   r   s      r   __init__zRunCustomScript.__init__!   s&    $"'',,y*=r   c                 "   t         j                  j                  | j                        st	        d| j                  z        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       y )Nz3Script %s not found!! Cannot execute custom script!zCopying custom script to %s id  )mode)r   r   existsr   r   r   
ensure_dirr   r   LOGdebugr   copyload_text_filereplace
write_file)r   contents     r   prepare_scriptzRunCustomScript.prepare_script&   s    ww~~doo.&E//" 
 	,;;<		)+?+M+M	
 			$//#7#E#EF %% ..

'$
 	 	 ..e	
r   N)r   r   r	   r   r-   r
   r   r   r   r       s    >

r   r   c                       e Zd Zd Zy)PreCustomScriptc                     t         j                  d       | j                          t        j                  t        j
                  dg       y)z7Executing custom script with precustomization argument.z"Executing pre-customization scriptprecustomizationN)r&   r'   r-   r   r   r   )r   s    r   executezPreCustomScript.execute>   s4    		67		'557IJKr   N)r   r   r	   r2   r
   r   r   r/   r/   =   s    Lr   r/   c                   $     e Zd Z fdZd Z xZS )PostCustomScriptc                     t         t        |   ||       || _        t        j
                  j                  |t        j                        | _	        y r   )
superr4   r   ccScriptsDirr   r   r   r   r   ccScriptPath)r   r   r   r7   	__class__s       r   r   zPostCustomScript.__init__F   s>    .z9E(GGLL.FF
r   c                 4   | j                          t        j                  d| j                         t	        j
                  t        j                  j                  | j                  t        j                        | j                         t        j                  | j                        }t        j                  | j                  |j                  t        j                  z         t        j!                  d       t	        j"                  t        j$                         y)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'   r8   r   r(   r   r   r   r   r   r   statchmodst_modeS_IEXECinfoensure_filer   )r   sts     r   r2   zPostCustomScript.executeM   s     			;T=N=NO		GGLL 4 L L 		
 WWT&&'
""BJJ$=>=>-HHIr   )r   r   r	   r   r2   __classcell__)r9   s   @r   r4   r4   E   s    
Jr   r4   )loggingr   r;   	cloudinitr   r   	getLoggerr   r&   	Exceptionr   r   r   r/   r4   r
   r   r   <module>rG      sa     	   g!	9 	8 8
 
:Lo LJ Jr   