o ckF[t@s~ddlZddlZddlmZmZddlmZmZddlm Z ddl Z Gddde Z e dkr=e dd e ZedSdS) N)get_instance_metadataget_instance_userdata)ConfigBotoConfigPath) ScriptBasecsPeZdZdZfddZddZddZdd Zd d Zd d Z ddZ 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_dirwrite_metadatasuperr__init__self __class__6/usr/lib/python3/dist-packages/boto/pyami/bootstrap.pyr (szBootstrap.__init__cCsttjtd}|dt}|D] }|d|||fqt}|d||d|d|j| t t _ t dS)Nwz [Instance] z%s = %s z %s z[Pyami] zworking_dir = %s )openospath expanduserrwriterrrcloserbotoconfig init_logging)r fp inst_datakey user_datarrrr -s   zBootstrap.write_metadatacCs4tjd|jtj|jst|jdSdS)NzWorking directory: %s)rloginforrrexistsmkdirr rrrcreate_working_dir>szBootstrap.create_working_dirc CsHtjddd}|dr5|ddkr |d\}}d|}nd}tjdd d }|d ||fdS|d rtjdd d }d}|dkrz|d8}z |jd|dd}Wntyu}ztj d|t dWYd}~nd}~ww|dksH|ddkr|d\}}nd}|jd||ddS|d|d|dS)NBoto boto_updatezsvn:HEADsvn:rz-r%sz-rHEAD boto_locationz/usr/local/botozsvn update %s %sgitz*/usr/share/python-support/python-boto/boto zgit pull)cwdzOgit pull attempt failed with the following exception. Trying again in a bit. %smasterzgit checkout %sz.rm /usr/local/lib/python2.5/site-packages/botozeasy_install %s) rrget startswithfindsplitrun Exceptionr r!timesleep)r updatemethodversionlocationnum_remaining_attemptserrr load_botoCs8    zBootstrap.load_botocCsjz$ddlm}||}tj|j|dd}t|d| W|St j d|d}Y|S)Nr) fetch_file/rzProblem Retrieving file: %s) boto.utilsr?rrjoinrr3rrreadrr exception)r s3_filer?frrrr fetch_s3_filebs zBootstrap.fetch_s3_filecCsjtjdd}|r1|d}|D]"}|}|dr ||}|r0|ds0|jd|ddqdSdS) NPyamipackages,zs3:z.pyzeasy_install -Z %sF) exit_on_error) rrr0r3stripr1rHendswithr4)r package_strrJpackagerrr load_packagesms    zBootstrap.load_packagescCs2||||dtjddS)NzBootstrap Completed for %sz instance-id)r$r>rQnotifyrr get_instancer rrrmain{szBootstrap.main) __name__ __module__ __qualname____doc__r r r$r>rHrQrT __classcell__rrrrrs  r__main__ bootstrapz/var/log/boto.log)rrrBrrboto.pyami.configrrboto.pyami.scriptbaserr6rrUset_file_loggerbsrTrrrrs d