o ckF[tã@s~ddlZddlZddlmZmZddlmZmZddlm Z ddl Z Gdd„de ƒZ e dkr=e  dd ¡e ƒZe ¡dSdS) éN)Úget_instance_metadataÚget_instance_userdata)ÚConfigÚBotoConfigPath)Ú ScriptBasecsPeZdZdZ‡fdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z ‡Z S)Ú Bootstrapa\ The Bootstrap class is instantiated and run as part of the PyAMI instance initialization process. The methods in this class will be run from the rc.local script of the instance and will be run as the root user. The main purpose of this class is to make sure the boto distribution on the instance is the one required. cs d|_| ¡tt|ƒ ¡dS)Nz /mnt/pyami)Ú working_dirÚwrite_metadataÚsuperrÚ__init__©Úself©Ú __class__©ú6/usr/lib/python3/dist-packages/boto/pyami/bootstrap.pyr (szBootstrap.__init__cCsŒttj t¡dƒ}| d¡tƒ}|D] }| d|||f¡qtƒ}| d|¡| d¡| d|j¡|  ¡t ƒt _ t   ¡dS)NÚwz [Instance] z%s = %s z %s z[Pyami] zworking_dir = %s )ÚopenÚosÚpathÚ expanduserrÚwriterrrÚcloserÚbotoÚconfigÚ init_logging)r ÚfpÚ inst_dataÚkeyÚ user_datarrrr -s   zBootstrap.write_metadatacCs4tj d|j¡tj |j¡st |j¡dSdS)NzWorking directory: %s)rÚlogÚinforrrÚexistsÚmkdirr rrrÚcreate_working_dir>sÿzBootstrap.create_working_dirc CsHtj ddd¡}| d¡r5| d¡dkr | d¡\}}d|}nd}tj dd d ¡}| d ||f¡dS| d ¡r–tj dd d ¡}d}|dkrz|d8}z |jd|dd}Wntyu}ztj  d|¡t   d¡WYd}~nd}~ww|dksH| d¡dkr‰| d¡\}}nd}|jd||ddS| d¡| d|¡dS)NÚBotoÚ boto_updatezsvn:HEADÚsvnú:rz-r%sz-rHEADÚ boto_locationz/usr/local/botozsvn update %s %sÚgitz*/usr/share/python-support/python-boto/botoé ézgit pull)ÚcwdzOgit pull attempt failed with the following exception. Trying again in a bit. %séÚmasterzgit checkout %sz.rm /usr/local/lib/python2.5/site-packages/botozeasy_install %s) rrÚgetÚ startswithÚfindÚsplitÚrunÚ Exceptionr r!ÚtimeÚsleep)r ÚupdateÚmethodÚversionÚlocationÚnum_remaining_attemptsÚerrrÚ load_botoCs8   €þû zBootstrap.load_botocCsjz$ddlm}||ƒ}tj |j| d¡d¡}t|dƒ |  ¡¡W|St j   d|¡d}Y|S)Nr)Ú fetch_fileú/éÿÿÿÿrzProblem Retrieving file: %s) Ú boto.utilsr?rrÚjoinrr3rrÚreadrr Ú exception)r Ús3_filer?ÚfrrrrÚ fetch_s3_filebs ýzBootstrap.fetch_s3_filecCsjtj dd¡}|r1| d¡}|D]"}| ¡}| d¡r | |¡}|r0| d¡s0|jd|ddqdSdS) NÚPyamiÚpackagesú,zs3:z.pyzeasy_install -Z %sF)Ú exit_on_error) rrr0r3Ústripr1rHÚendswithr4)r Ú package_strrJÚpackagerrrÚ load_packagesms    €özBootstrap.load_packagescCs2| ¡| ¡| ¡| dtj d¡¡dS)NzBootstrap Completed for %sz instance-id)r$r>rQÚnotifyrrÚ get_instancer rrrÚmain{szBootstrap.main) Ú__name__Ú __module__Ú __qualname__Ú__doc__r r r$r>rHrQrTÚ __classcell__rrrrrs  rÚ__main__Ú bootstrapz/var/log/boto.log)rrrBrrÚboto.pyami.configrrÚboto.pyami.scriptbaserr6rrUÚset_file_loggerÚbsrTrrrrÚs d  û