3 \me @sddlZddlZddlZddlmZmZejeZGddde Z GdddZ GdddZ Gd d d e Z Gd d d e ZdS) N)subputilc@s eZdZdS)CustomScriptNotFoundN)__name__ __module__ __qualname__rr*/usr/lib/python3.6/config_custom_script.pyrsrc@s*eZdZdZdZejjeeZdZ dZ dS)CustomScriptConstantz/root/.customizationz customize.shz)/.guest-customization-post-reboot-pendingzpost-customize-guest.shN) rrrCUSTOM_TMP_DIRZCUSTOM_SCRIPT_NAMEospathjoin CUSTOM_SCRIPTPOST_CUSTOM_PENDING_MARKERPOST_CUSTOM_SCRIPT_NAMErrrr r s r c@seZdZddZddZdS)RunCustomScriptcCs ||_||_tjj|||_dS)N) scriptname directoryr r r scriptpath)selfrrrrr __init__!szRunCustomScript.__init__cCsptjj|jstd|jtjtjt j dtj tj |jtj tj tj jdd}tjtj |dddS)Nz3Script %s not found!! Cannot execute custom script!zCopying custom script to %s id)mode)r r existsrrrZ ensure_dirr r LOGdebugrcopyZ load_filereplaceZ write_file)rZcontentrrr prepare_script&s    zRunCustomScript.prepare_scriptN)rrrrr rrrr r src@seZdZddZdS)PreCustomScriptcCs&tjd|jtjtjdgdS)z7Executing custom script with precustomization argument.z"Executing pre-customization scriptZprecustomizationN)rrr rr r)rrrr execute>s zPreCustomScript.executeN)rrrr"rrrr r!=sr!cs$eZdZfddZddZZS)PostCustomScriptcs.tt|j||||_tjj|tj|_ dS)N) superr#r ccScriptsDirr r rr r ccScriptPath)rrrr%) __class__rr rFszPostCustomScript.__init__cCsn|jtjd|jtjtjj|j t j |jtj |j}tj |j|jt jBtjdtjt jdS)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 rrr&rrr r rrr rstatchmodst_modeS_IEXECinfoZ ensure_filer)rstrrr r"Ms   zPostCustomScript.execute)rrrrr" __classcell__rr)r'r r#Es r#)Zloggingr r(Z cloudinitrrZ getLoggerrr Exceptionrr rr!r#rrrr s