jbc@sddlZddlZddlZddlZddlmZddlmZm Z m Z m Z ddl m Z ddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd l mZdd l mZddl mZddl mZddl m Z ddl m!Z"ddl m#Z#ddl$m%Z%ddl&m'Z'ddl m(Z(ddl m)Z)ddl m*Z*e"j+e,Z-e.Z/dZ0de1fdYZ2de1fdYZ3dZ4dZ5dZ6d Z7dS(!iN(tcPickle(t FREQUENCIESt CLOUD_CONFIGt PER_INSTANCEtRUN_CLOUD_CONFIG(thandlers(tBootHookPartHandler(tCloudConfigPartHandler(tJinjaTemplatePartHandler(tShellScriptPartHandler(tUpstartJobPartHandler(t EventType(tNetworkConfigSource(tcloud(tconfig(tdistros(thelpers(timporter(tlog(tnet(tcmdline(tevents(tsources(t type_utils(tutiltNO_PREVIOUS_INSTANCE_IDtInitcBseZd)d)dZedZedZedZdZ edZ dZ edZ dZ d Zd)d Zd Zd Zd ZdZdZdZdZd)dZdZdZdZddZdZdZdZdZdZ dZ!dZ"d)dZ#d Z$d!Z%d)d"Z&e'd#Z(e'd$Z)e'd%Z*d&Z+d'Z,d(Z-RS(*cCs|dk r||_ntjtjg|_d|_d|_d|_t|_ t |_ d|_ |dkrt jdddddt }n||_dS(Ntnames init-reportert descriptions init-desctreporting_enabled(tNonetds_depsRtDEP_FILESYSTEMt DEP_NETWORKt_cfgt_pathst_distrotNULL_DATA_SOURCEt datasourcetFalset ds_restoredt _previous_iidRtReportEventStacktreporter(tselfRR+((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt__init__1s            cCs:d|_d|_d|_|r6t|_t|_ndS(N(RR"R#R$R%R&R'R((R,treset_ds((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_resetEs     cCs|js|jd}|jdd}tj|}tjd|||||j|_|jt k r|j|j_ |j |j_ qn|jS(NtsystemtdistrotubuntusUsing distro class %s( R$t _extract_cfgtpopRtfetchtLOGtdebugtpathsR&R%R1tcfgtsys_cfg(R,t system_configt distro_namet distro_cls((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR1Ns cCs |jdS(Nt restricted(R3(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR9_scCs|jtj|j}|dkr;|jddnH|dkr_tj|di}n$|dkrtj|di}nt|t si}n|S(NR>t system_infoR0R8(R?(R?spaths( tread_cfgtcopytdeepcopyR"R4RRtget_cfg_by_patht isinstancetdict(R,t restrictiontocfg((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR3cs     cCs:|js3|jd}tj||j|_n|jS(NR8(R#R3RtPathsR&(R,t path_info((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR8rs c Cs|jj}|tjj|dtjj|ddtjj|ddtjj|ddtjj|ddtjj|dtjj|dtjj|dtjj|d tjj|d g }|S( Ntscriptss per-instancesper-oncesper-boottvendortseedt instancesRtsemtdata(R8t cloud_dirtostpathtjoin(R,tc_dirt initial_dirs((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_initial_subdirsys cCsS|jjg}|r+|j|jjnx|D]}tj|q2Wt|S(N(R8t boot_finishedtappendt instance_linkRtdel_filetlen(R,trm_instance_lnktrm_listtf((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt purge_caches  cCs|jdS(N(t_initialize_filesystem(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt initializesc Cstj|jtj|jd}tj|jd}|rtj|d||jjd}|swi}nt|t s|g}nd}xZ|D]R}tj |\}}ytj |||dSWqt k r}|}qXqWtjd|dj||ndS(Nt def_log_filetdef_log_file_modetmodetsyslog_fix_permss,Failed changing perms on '%s'. tried: %s. %st,(Rt ensure_dirsRVtget_cfg_option_strR9tget_cfg_option_intt ensure_filetgetRDtlistRtextract_usergroupt chownbynametOSErrorR6twarningRS( R,tlog_filet log_file_modetpermsterrortpermtutgte((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR`s(    cCs(|jdkr$|j||_ndS(N(R"Rt _read_cfg(R,t extra_fns((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR@sc CsFtji|j}tjd|d|jd|dt}|jS(NR8R&tadditional_fnstbase_cfg(RRHR&t ConfigMergertfetch_base_configR9(R,Rzt no_cfg_pathstmerger((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyRys   cCst|jjdS(Ntobj_pkl(t _pkl_loadR8t get_ipath_cur(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_restore_from_cachescCso|jtkrtStj|jdtrStj|jjdddddnt |j|jjdS(Ntmanual_cache_cleantmanual_clean_markertomodetwtcontenttR( R&R%R'Rtget_cfg_option_boolR9t write_fileR8Rt _pkl_store(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_write_to_cachescCsv|jjdpg}x9dtjtgD]"}||kr.|j|q.q.W|jjdpig}||fS(Ntdatasource_pkg_listRtdatasource_list(R9RkRtobj_nameRRX(R,tpkg_listtntcfg_list((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_get_datasourcess  cCs|d krtd|n|j}|s5d S|jjd}tjj|rqtj |j }nd}||j kr|d|fS|dkr|d|fSt |dr|j |jr|d |fSdd |fSdS( Ntcheckttrusts!Unexpected value for existing: %ssno cache foundt instance_ids&restored from cache with run check: %ssrestored from cache: %stcheck_instance_idsrestored from checked cache: %sscache invalid in datasource: %s(RR(Nsno cache found(t ValueErrorRRR8t get_runpathRQRRtexistsRt load_filetstriptget_instance_idthasattrRR9(R,texistingtdst run_iid_fntrun_iid((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_restore_from_checked_caches"   c Cs|jtk r|jStjdddd|d|jD}|j|\}}||_t||_t j |jWdQX|st j |j j|j\}}tj|j|j|j tj|j|||j\}}t jd||n||_|j|S(NRs check-cacheRs"attempting to read from cache [%s]tparentsLoaded datasource %s - %s(R&R%RR*R+RRtboolR(R6R7RRZR8RYRRt find_sourceR9R1RARBRtinfoR/(R,RtmyrepRtdescRRtdsname((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_get_data_sources.      cCs dddgS(NRRJRN((R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_get_instance_subdirsscCs+|jj|}|s'tdn|S(NsCNo instance directory is available. Has a datasource been fetched??(R8t get_ipatht RuntimeError(R,tsubnamet instance_dir((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt _get_ipathsc Cs|j}tj|jjtj||jjg}x0|jD]"}|jtj j ||qHWtj ||jj d}dt j|j|jf}d}tj j |d}ytj|j}Wntk rnX|s|}ntj|d|tjtj j |dd||jj}tj j |d} |j} tj| d|tj|jjdd|tjtj j |dd| |j|j|S( NROs%s: %sR&s%s sprevious-datasources instance-idRsprevious-instance-id(RRRZR8RYtsym_linkRRXRQRRRSRgt get_cpathRRR&RRRt ExceptionRRt previous_iidRRR/( R,tidirtdir_listtdtdpRt previous_dstds_fntiidtiid_fnR((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_reflect_cur_instances<           cCs|jdk r|jS|jjd}tjj|d}ytj|j |_Wnt k rut |_nXt j d|j|jS(NROs instance-idsprevious iid found to be %s(R)RR8RRQRRRSRRRRRR6R7(R,RR((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyRLs  cCs1|j}|tkp*||jjk}|S(N(RRR&R(R,tprevioustret((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pytis_new_instanceZs  RcCs|jd|S(NR(R(R,R((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR5`scCs |jS(N(R(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt instancifycscCs:tj|j|j|j|jtj|jd|jS(NR+( R tCloudR&R8R9R1RtRunnersR+(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pytcloudifyfs  cCs|j|jdS(N(t_store_userdatat_store_vendordata(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pytupdatems cCs]tjddd|j<|jdkr:tdn|jjd|jWdQXdS(Nssetup-datasourcessetting up datasourceRs!Datasource is None, cannot setup.R(RR*R+R&RRtsetupR(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pytsetup_datasourceqs   c Csptjddd|jO|jdkr:tdn|jjd|jd|j|j WdQXdS(Nsactivate-datasourcesactivating datasourceRs$Datasource is None, cannot activate.R9R( RR*R+R&RRtactivateR9RR(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pytactivate_datasourceys   cCs|jj}|dkr$d}ntj|jd|d|jj}|dkrdd}ntj|jdt|ddS(NRt userdata_rawituserdata(R&tget_userdata_rawRRRRt get_userdatatstr(R,traw_udt processed_ud((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyRs    cCs|jj}|dkr$d}ntj|jd|dt|jj}|dkrjd}ntj|jdt|ddS(NRtvendordata_rawit vendordata(R&tget_vendordata_rawRRRRRtget_vendordata(R,traw_vdt processed_vd((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyRs    cCs|dkri}n|ji|jd6|jd6t|}t|}||t|t|g}|ji||gd6|jt ||S(NR8R&t sub_handlers( RRR8R&RR RR RXR(R,toptstcloudconfig_handlertshellscript_handlert def_handlers((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_default_handlerss       cCs |jS(N(R(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_default_userdata_handlersscCs|jdidd6dd6S(NRtvendor_scriptst script_pathtvendor_cloud_configtcloud_config_path(R(R,((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_default_vendordata_handlerss  c sT|d krg}n|jjd}|jdx?|gD]1}|rC|tjkrCtjjd|qCqCWfd}tj||x?|D]7}j |dt } | rt j d| |qqW|j fd} fd} fd} z| | |Wd | Xd S( sb Generalized handlers suitable for use with either vendordata or userdata Rics| stjj| rdStj|}x|jD]\}}ytj|dgddg\}}|stj d|||w:ntj |d}t j |}j |}|rtjd|||nWq:tk rtjtd|q:Xq:WdS(NRt list_typest handle_partsJCould not find a valid user-data handler named %s in file %s (searched %s)is(Added custom handler for %s [%s] from %ss"Failed to register handler from %s(RQRRtisdirRt find_modulestitemsRt find_moduleR6Rpt import_moduleRt fixup_handlertregisterR7Rtlogexc(RRtpotential_handlerstfnametmod_nametmod_locst looked_locstmodttypes(t c_handlers(s4/usr/lib/python2.7/site-packages/cloudinit/stages.pytregister_handlers_in_dirs(     t overwrites$Added default handler for %s from %scsYxRjD]D\}}|jkr.q ntj|jj|q WdS(N(Rt initializedRt call_beginRX(t_ctypeR(RROt frequency(s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt init_handlerss csMid6d6d6d6dd6|d6}tjtjd|dS(NRt handlerdirRORit handlercounttexcluded(Rtwalktwalker_callback(Rt part_data(RROtdata_msgRR(s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt walk_handlerss csx}jD]o\}}|jkr.q njj|ytj|Wq tk r{tjtd|q Xq WdS(NsFailed to finalize handler: %s( RRtremoveRtcall_endRRRR6(RR(RROR(s4/usr/lib/python2.7/site-packages/cloudinit/stages.pytfinalize_handlerss N(RR8RRtsysRRtinsertRtContentHandlersRR'R6R7R( R,Rtc_handlers_listRRtcdirRRRRRRR ((RRORRRs4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt _do_handlerss,        cCstjddd|j:tj|jdtrD|j|n tj dWdQXtjddd|j|j |WdQX|j dS(Nsconsume-user-datasreading and applying user-dataRtallow_userdatas,allow_userdata = False: discarding user-datasconsume-vendor-datas reading and applying vendor-data( RR*R+RRR9tTruet_consume_userdataR6R7t_consume_vendordataR/(R,R((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt consume_data#s    c Cs |jjs tjddStjd|jd|jdgd|jdt}|jj di}t |t sitd 6}tj d |n|j d }|j d d}tj|stjd dStjd ||jj}|j}|j|||d|dS(sH Consume the vendordata and run the part handlers on it sno vendordata from datasourceNR8R&R{R|tinclude_vendort vendor_datatenableds/invalid 'vendor_data' setting. resetting to: %stdisabled_handlerss#vendordata consumption is disabled.s2vendor data will be consumed. disabled_handlers=%sR(R&RR6R7RR}R#R9R'RkRDRERpRRtis_trueRRR(R,Rt _cc_mergertvdcfgRt no_handlerstvendor_data_msgR((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR>s0          cCs5|jjt}|j}|j|||dS(s@ Consume the userdata and run the part handlers N(R&RRRR(R,Rt user_data_msgR((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyRks cCstjj|jjdd}tjj|r=d|fSitjt j6tj t j 6dt j 6|j jdt j6}|jrt|jdr|jj|t j             cCsNy$tjd||jj|Wn#tk rI}tjd|nXdS(Ns applying net config names for %ssFailed to rename devices: %s(R6R7R1tapply_network_config_namesRRp(R,tnetcfgRx((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_apply_netcfg_namess cCs=|j\}}|dkr2tjd|dS|jtk r|js|jjtj gstj dtj |j |dS|j\}}qnt j ||j |tjd|||y|jj|d|SWnKt jk r}tjd|dStk r8tjd|jdSXdS(Ns network config is disabled by %ss]No network config applied. Neither a new instance nor datasource network update on '%s' events5Applying network configuration from %s bringup=%s: %stbring_ups@Unable to render networking. Network config is likely broken: %ss_distro '%s' does not implement apply_network_config. networking may not be configured properly.(R1RR6RR&R%Rtupdate_metadataR tBOOTR7R4Rtwait_for_physdevsR1tapply_network_configtRendererNotFoundErrorRttNotImplementedErrorRp(R,R5R3tsrcRx((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR9s6            N(.t__name__t __module__RR-R'R/tpropertyR1R9R3R8RVR_RaR`R@RyRRRRRRRRRRR5RRRRRRRRRRRRRRRR1R4R9(((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR0sP            0           j  -  ' tModulescBsYeZdddZedZdZdZdZdddZ dZ RS(cCsU||_||_d|_|dkrHtjdddddt}n||_dS(NRsmodule-reporterRs module-descR(tinitt cfg_filesRt _cached_cfgRR*R'R+(R,RARBR+((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR-s       c Csg|jdkrWtjd|jjd|jjd|jd|jj}|j|_nt j |jS(NR8R&R{R|( RCRRR}RAR8R&RBR9RARB(R,R((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR9s  cCsg}||jkr|S|jj|}|s5|Sx|D]}|sNq<nt|tjr}|ji|jd6q<t|tr i}t|dkr|dj|dg}tj|}|s\q n|r|tkrtjd||d}ntj|dt j tgdg\}} |stjd|| q ntj tj |d} |j | |||gq W|S( NRRDREs6Config specified module %s has an unknown frequency %sRthandles,Could not find module named %s (searched %s)i(RkRtform_module_nameRR6RpRRRRRt fixup_moduleRRX( R,traw_modst mostly_modstraw_modtraw_nameRDtrun_argsRRRR((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt_fixup_moduless*     '  c Csy|jj}g}g}xQ|D]I\}}}}y|sI|j}n|tkr^t}ntjd|||||j|tj|g} |j |d|} d| |f} t j d| d| d|j } | L|j | |j| d|\} }| rd| | _n d | | _WdQXWq"tk rj}tjtd |||j ||fq"Xq"W||fS( Ns(Running module %s (%s) with frequency %ss config-%ssrunning %s with frequency %sRRRRDs%s ran successfullys%s previously ransRunning module %s (%s) failed(RARRRRR6R7R9RRXRR*R+trunROtmessageRRR(R,RStcctfailurest which_ranRRRDREt func_argstrun_nameRRtrant_rRx((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt _run_modules3s8         cCs@i|d6|d6|d6}|g}|j|}|j|S(NRRERD(RWRa(R,RRERDt mod_to_beRRRS((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt run_single_s  cCsk|j|}|j|}|jjj}g}g}|jjdg}g}ttj g} x|D]\} } } } t| j}|j tj j | j |r|| kr||kr| |kr|j| qmn|j| qn|j| | | | gqmW|r<tjddj||n|r^tjddj|n|j|S(Ntunverified_modulessSkipping modules '%s' because they are not verified on distro '%s'. To run anyway, add them to 'unverified_modules' in config.Rfs running unverified_modules: '%s's, (RNRWRAR1RR9RktsetRt ALL_DISTROSRtDistrotexpand_osfamilyt osfamiliesRXR6RRSRa(R,t section_nameRRRStd_nametskippedtforcedt overriddent active_modst all_distrosRRt_freqt_argstworked_distros((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyt run_sectionks2    N( R=R>RR-R?R9RNRWRaRcRt(((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR@s  /  , cCs tjtS(N(Rt read_confR(((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pytread_runtime_configscCs7tjtjtjtttjgdtS(Ntreverse(Rt mergemanydicttget_builtin_cfgtread_conf_with_confdRRvtread_conf_from_cmdlineR(((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyR~s   cCsytj|}Wn%tk r:tjtd|tSXy tj||ddddWn%tk rtjtd|tSXtS(NsFailed pickling datasource %sRtwbRdis Failed pickling datasource to %s( tpickletdumpsRRRR6R'RR(tobjRt pk_contents((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyRs   cCsd}ytj|dt}Wn;tk r\}tjj|r]tj d||q]nX|sgdSyt j |SWn%tk rtj td|dSXdS(Ntdecodesfailed loading pickle in %s: %ss#Failed loading pickled blob from %s( RRRR'RRQRRtisfileR6RpR}tloadsR(Rtpickle_contentsRx((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pyRs (8RARQR RFt six.movesRR}tcloudinit.settingsRRRRt cloudinitRtcloudinit.handlers.boot_hookRtcloudinit.handlers.cloud_configRt!cloudinit.handlers.jinja_templateRtcloudinit.handlers.shell_scriptR tcloudinit.handlers.upstart_jobR tcloudinit.eventR tcloudinit.sourcesR R RRRRRtloggingRt cloudinit.netRtcloudinit.reportingRRRRt getLoggerR=R6RR%RtobjectRR@RvR~RR(((s4/usr/lib/python2.7/site-packages/cloudinit/stages.pytsH    "