o .&a@snddlZddlZddlZdZGdddZGdddeZGdddeZGd d d eZGd d d eZdS) Nzcodedeploy.onpremises.ymlc@s0eZdZdZddZddZddZdd Zd S) SystemzgOnly Ubuntu Server, Red Hat Enterprise Linux Server and Windows Server operating systems are supported.cCs |j|_|jjd|jd|_dS)Ns3) region_name)session create_clientregionrselfparamsr J/usr/lib/python3/dist-packages/awscli/customizations/codedeploy/systems.py__init__s  zSystem.__init__cCtd)Nvalidate_administratorNotImplementedErrorr r r r r"zSystem.validate_administratorcCr)Ninstallrrr r r r%rzSystem.installcCr)N uninstallrrr r r r(rzSystem.uninstallN)__name__ __module__ __qualname__UNSUPPORTED_SYSTEM_MSGr rrrr r r r rs rc@sDeZdZdZdZdeeZdZddZddZ d d Z d d Z d S)Windowsz C:\ProgramData\Amazon\CodeDeployzconf.onpremises.ymlz{0}\{1}zcodedeploy-agent.msicCstjjs tddS)Nz.You must run this command as an Administrator.)ctypeswindllshell32 IsUserAnAdmin RuntimeErrorrr r r r2s zWindows.validate_administratorcCsd|vr|j|_tjgdtjtjd}|\}}d}|jdkr,||vr,td||j j |j |j d}t |jd}||d Wdn1sPwYtjd |jd d d gddtgdtjgdtjtjd}|\}}d|vrtddS)N installerpowershell.exe-Commandz Stop-Service-Namecodedeployagentstdoutstderr;Cannot find any service with service name 'codedeployagent'r,Failed to stop the AWS CodeDeploy Agent: {0}BucketKeywbBodyz.\{0}z/quietz/lz".\codedeploy-agent-install-log.txtT)shell)r"r#zRestart-Servicer$r%)r"r#z Get-Servicer$r%Runningz:The AWS CodeDeploy Agent did not start after installation.)r INSTALLER subprocessPopenPIPE communicate returncoderformatr get_objectbucketkeyopenwriteread check_call)r r processoutputerror not_foundresponsefr r r r8sJ   zWindows.installcCsXtjgdtjtjd}|\}}d}|jdkr|dS||vr*td|dS)Nr!r&r)rr*)r3r4r5r6r7 _remove_agentrr8)r r r@rArBrCr r r ros   zWindows.uninstallcCs@tjgdtjtjd}|\}}|jdkrtd|dS)N)wmicproductwherezname="CodeDeploy Host Agent"callrz/nointeractiver&rz1Failed to uninstall the AWS CodeDeploy Agent: {0})r3r4r5r6r7rr8)r r@rArBr r r rFs zWindows._remove_agentN) rrr CONFIG_DIR CONFIG_FILEr8 CONFIG_PATHr2rrrrFr r r r r,s 7 rc@sTeZdZdZeZdeeZdZddZ ddZ dd Z d d Z d d Z ddZdS)Linuxz/etc/codedeploy-agent/confz{0}/{1}rcCstdkr tddS)Nrz"You must run this command as sudo.)osgeteuidrrr r r rs zLinux.validate_administratorcCsd|vr|j|_|||||jj|j|jd}t|jd}| |d Wdn1s6wYt ddd |jg|j}tj}|j|d<|j|d <|j|d <|jdurj|j|d <t j d |jd g|d dS)Nr r+r.r/chmodz+xz./{0} AWS_REGIONAWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_SESSION_TOKENauto)env)r r2_update_system _stop_agentrr9r:r;r<r=r>r3r?r8rget_credentialsrOenvironcopyr access_key secret_keytoken)r r rDrE credentials environmentr r r rs,          z Linux.installcCs&||}|jdkr||dSdS)Nr)rYr7rF)r r r@r r r rs  zLinux.uninstallcCr)N preinstallrrr r r rXrzLinux._update_systemcCr)N remove_agentrrr r r rFrzLinux._remove_agentcCsJtjgdtjtjd}|\}}|jdkr#|j|vr#td||S)N)servicecodedeploy-agentstopr&rr*)r3r4r5r6r7 not_found_msgrr8)r r r@rArBr r r rYs zLinux._stop_agentN)rrrrKDEFAULT_CONFIG_FILErLr8rMr2rrrrXrFrYr r r r rNs  rNc@$eZdZddZddZddZdS)UbuntucCs tgdtgddS)N)apt-get-yupdate)rkrlrzruby2.0r3r?rr r r rXszUbuntu._update_systemcCtgddS)N)dpkgz-rrernrr r r rFzUbuntu._remove_agentcCd|_t||S)Nz&codedeploy-agent: unrecognized servicergrNrYrr r r rY zUbuntu._stop_agentNrrrrXrFrYr r r r rjs rjc@ri)RHELcCro)N)yumrlrrubyrnrr r r rXrqzRHEL._update_systemcCro)N)rwrleraserernrr r r rFrqzRHEL._remove_agentcCrr)Nzs k>