܍~cddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z e j ddl mZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZmZmZm Z ddlm!Z!ddl"m#Z#ddlm$Z$ddl%m&Z&dZ'dZ(eeedZ)ej*Z+d5dZ,d6dZ-dZ.dZ/de fdZ0d Z1d7d"Z2d8d$ee3e4ffd%Z5d&Z6d'Z7d(Z8d)Z9d*Z:d+Z;d9d,Zd/Z?d0Z@d6d1ZAeBd2kr7d3ejCvr d4ejCd3<eAejDZEeErejFeEdSdSdS):N)Tuple)patcher)Modules)validate_cloudconfig_schema)log)netinfo)signal_handler)sources)stages) url_helper)util)version)warnings) reporting)events) PER_INSTANCE PER_ALWAYSPER_ONCE CLOUD_CONFIG) atomic_helper)cc_set_hostname) dhclient_hook)read_cfg_pathszOCloud-init v. {version} running '{action}' at {timestamp}. Up {uptime} seconds.zcloud_%s_modules)instancealwaysoncec|r"tjd|ztjdtjdtjtjtjdtjddS)N%s z<------------------------------------------------------------ )file)sysstderrwrite traceback print_excmsgs 4/usr/lib/python3/dist-packages/cloudinit/cmd/main.pyr&r&Ls ) 3(((JXJT SZ((((JXJTch|st|}tjd|zddt|S)NrFT)consoler#r)welcome_formatr multi_logLOG)actionr(s r)welcomer1Vs9 %V$$N6S>53GGGG Jr*cttjt jt j|S)N)ruptime timestampr0)WELCOME_MSG_TPLformatrversion_stringr r3 time_rfc2822r0s r)r-r-]sC  ! !&(({}}#%% "  r*cg}|jrA|jD]9}|tj|j:|SN)filesappendospathrealpathname)argsfn_cfgsfhs r) extract_fnsrEfsRG z6* 6 6B NN27++BG44 5 5 5 5 Nr*modsct|z}||\}}t|t|z}|dkrGd|d|d}tjd|zt |gSt dt|t||S)NrzNo 'z ' modules to run under section ''rzRan %s modules with %s failures)MOD_SECTION_TPL run_sectionlenr"r#r$r/debug)rF action_namesectionfull_section_name which_ranfailurestotal_attemptedr(s r)run_module_sectionrSss'73 ,,->??Y)nns8}}4O! KK     3((( #  -s9~~s8}}   r*c|dr)tj|ddSdS)Nr)getrupdate_configuration)cfgs r)apply_reporting_cfgrXsC ww{=&sww{';';<<<<<==r*cloud-config-urlurlctj|}|D]}||vr |||fcStd|d|d)Nz No keys (z) found in string 'rH)r keyval_str_to_dictKeyError)cmdlinenamesdatakeys r)parse_cmdline_urlrcs`  "7 + +D"" $;;S > ! ! !  ('''555I J JJr*Treturnc|tj} t|\}}n#t$rtjdfcYSwxYw|dp|d}|r^tj |r?|r$d|d|d}tj }|r tj}nd|d|d}tj }||fS|d d d d }|s|rtj }d |d<ntj}d|d<d} d} tj d#i|} d} | rd } t| tjr] | t#| t'| z } n#t($rYnwxYw| | sd} n| j| sd} | r!|dkrt,dnF|dkr tj }n tj }|d|dt1| fS|d|d| jdfS| | jz} n&#tj$r}|d|d|fcYd}~Sd}~wwxYwtj|| dtj d |d!|d"|fS)$aWrite data from url referenced in command line to path. path: a file to write content to if downloaded. network: should network access be assumed. cmdline: the cmdline to parse for cloud-config-url. This is used in MAAS datasource, in "ephemeral" (read-only root) environment where the instance netboots to iscsi ro root. and the entity that controls the pxe config has to configure the maas datasource. An attempt is made on network urls even in local datasource for case of network set up in initramfs. Return value is a tuple of a logger function (logging.DEBUG) and a message indicating what happened. Nz!No kernel command line url found.zfile:///zfile 'zC' existed, possibly from local stage download of command line url 'z'. Not re-writing.zE' existed, possibly from previous boot download of command line url ' T)r[timeoutretriesstream sec_betweeng?s #cloud-configr*) chunk_sizeFr[zDEPRECATED: `url` kernel command line key is deprecated for providing cloud-config via URL. Please use `cloud-config-url` kernel command line parameter insteadrZz contents of 'z' did not start with zurl 'z' returned code z . Ignoring.zretrieving url 'z ' failed: i)modezwrote cloud-config data from z='z' to )r get_cmdlinercr^loggingDEBUG startswithr>r?existsINFOWARNr read_file_or_urlok isinstance UrlResponsenext iter_contentrK StopIterationcontentsr/warningstrcodeUrlError write_file)r?networkr_ cmdline_namer[ path_is_localmlevelkwargsraheaderrespsniffed_content is_cloud_cfges r)attempt_cmdline_urlrsz&"$$D-g66 cc DDD BCCCCDNN9--D1D1DM--  ! !AEcccK LE &  !AEcccK LEqzRA F FF$-$  !}  #} D F)D*44V44 7799" L$ 677 %#t))S[[)AA((OO%D&11&99)#(L]--f55 %$  5((KK- #555#LEE#LEKCKKc&kkKK :=##tyyyI .  DDD333BCCCCCCCD OD$U++++ <<dd $ s_*AAAH5 3E=<H5= F H5 F  BH5H5* H55I I IIcdtjjtjjfz}tj|jdd}tj |rot| }||krFt d|dtj||dSdStj |jdrtdtj||dS) zPurge the cache if python version changed on us. There could be changes not represented in our cache (obj.pkl) after we upgrade to a new version of python, so at that point clear the cache z%d.%drazpython-versionz-Python version change detected. Purging cacheTobj_pklzMWriting python-version file. Cache compatibility status is currently unknown.N)r" version_infomajorminorr>r?joinpaths get_cpathruopenreadr/rL purge_cacher r get_ipath_curinfo)initcurrent_python_versionpython_version_pathcached_python_versions r)$purge_cache_on_python_version_changers@ %  (',, V$$&6 w~~)**E $%8 9 9 > > @ @ !$: : : IIE F F F   T " " " O/1G H H H H H ; : 7>>$*229== > >  HHC    +-CDDDDDr*cJtj|jdrdS|j S)Ndisable_network_activationF)r get_cfg_option_boolrWlocal)rrBs r)_should_bring_up_interfacesrs) *FGGuz>r*ctjtjg}|jr tjg}t t jdtzd|j g}|jst|}ntd|z}tj ||j }| t|d}d} |t jdft%jt%j|j|\}}n\#t,$rOd}t%jt0|t3||t j|fYnwxYw|jr-t0dt!jt!j|jt=|jt?|| |D] \} }t0 | |! |!n*#t,$rt%jt0d YnwxYw|j"} tG||jr tj$n tj%} | tj%kr6d } tLj'(d tSj*znd } t%j+|jdd} | rt0dd } nQ| ,d}t j-|rt0d|d } |.t_||} |0| | tj%kr5|j1j2| kr%t0d| |j1dgfSn#tj3$r| tj$krt0dnt%jt0d|j4sN|5|t0d| | tj$krdgfcYSddgfcYSt0d| YnwxYwtm||7}t0d| |||8| tj$krts|dd|5|| tj$kr[|j1j2| kr*t0d| |j1|j1gfSt0d | |j1|:|;ts|d!d" |<=d#|j>t~gt~$\}}|s|>tn4#t,$r't%jt0d%|j1d%gfcYSwxYwt j-|j",d&rt|jddd'(nt0d)t=|jt|t||j *} |}|}t%jC|j|\}}||ks||kr9t0Dd+||t%j|j|\}}n*#t,$rt%jt0d,YnwxYwt!j|j|Et|j1|j-|j1t|||fS).Nz%s.dz91_kernel_cmdline_url.cfg)r?rz%s-localds_depsreporterzClosing stdin.#Failed to setup output redirection!@Logging being reset, this logger may no longer be active shortlyr'z0Failed to initialize, likely bad things to come!trustrcheckmanual_cache_cleanFz"manual cache clean set from configmanual_clean_markerz(manual cache clean found from marker: %sexistingz)[%s] Exiting. datasource %s in local modezNo local datasource foundz8No instance datasource found! Likely bad things to come!)bring_upz[%s] Exiting without datasourcezNo instance datasource found.z2[%s] barreling on in force mode without datasourcez5[%s] %s will now be targeting instance id: %s. new=%srr)stage retry_stagez.[%s] Exiting. datasource %s not in local mode.z6[%s] %s is in local mode, will apply init modules now.zinit-netzmodules:config consume_data)rBfreqzConsuming user data failed! userdata_rawT)configstrict log_detailslog_deprecationsz2Skipping user-data validation. No user-data found.rz#Stdout, stderr changing to (%s, %s)z'Failed to re-adjust output redirection!) datasourcerW)Hr DEP_FILESYSTEM DEP_NETWORKrrr>r?rrr-r Initrread_cfgrEr=rrrsr close_stdin fixup_outputrW Exceptionlogexcr/r&rwrL resetLogging setupLoggingrXr1r initializerr DSMODE_LOCALDSMODE_NETWORKr"r#r$r debug_inforrrurrfetchrdsmodeDataSourceNotFoundExceptionforceapply_network_config_maybe_persist_instance_data instancifyis_new_instance_maybe_set_hostnamesetup_datasourceupdatecloudifyrunrrrrrget_output_cfgractivate_datasourcedi_report_warnrS)rArBdeps early_logsw_msgroutfmterrfmtr(lvl path_helperrormcfgmfilebring_up_interfacesiidran_resultsrF outfmt_orig errfmt_origs r) main_initr#s>  "G$7 8D z(&' %'B N    J, :4t$$zT233 ;tdm < < > >w+++bz!!!>?@@@@ IIDd     %,!&&& //  CII?      w### DYGGGG':;;; w### ? !T ) ) II@    OR( ( IIH    KKMMMJ>??H#8!       FGGG!!! 4T**T] C C CDD  .tx>> & K6$9$9 KK=vv N N N#04@@ VV DDD CBCCCCCD """ do48<<<< O/dDAA BBslAD((AFFH//$IIAO""B R)R) R)(R)AX88.Y)(Y)A&]66$^^cJd|vrtddS|d}|tddSt|tstd|dS|d}|tddSt|t std|dS|jdd }| tj r"|ttj d}ntd ||||vrtd |||dStjd ||t| dS)N di_reportzno di_report found in config.zdi_report was None.z%di_report config not a dictionary: %sdatasource_listz(no 'datasource_list' found in di_report.z(di_report/datasource_list not a list: %s.rhz1Datasource '%s' came from unexpected module '%s'.z:used datasource '%s' from '%s' was in di_report's list: %sdsid_missing_source)sourcedslist)r/rLrzdictrrUlist __module__ rpartitionrtr DS_PREFIXrKr show_warningr)rrWdicfgrmodnames r)rrs# 1222  E } '((( eT " " ;UCCC YY( ) )F ~ >???  % % >GGG#..s33A6G'+,, #g/00223 ?     & H        s73v;;r*c|j}t|d|}tjg|j}|t | |dnO#tj $r=d|z}tj t|t||js|gcYSYnwxYwt|t!|t ||j} tdtjtj|j|n*#t*$rtj tdYnwxYw|jr-td t-jt-j|jt3|jt5|| t7|||S) N:rrrzGCan not apply stage %s, no datasource found! Likely bad things to come!r Closing stdinrrr')ror-r rrrrErr rr rr/r&rrrrLrrrWrrrrrrXr1rS)rMrBrArrr(rFs r) main_modulesr4s 9D kkk448 9 9E ;rDM : : :DMM+d##$$$  G $$$$  .     $ %  C#z 7NNN   !&&& 4T**T] C C CD@ /"""  $(D)))) @@@ C>?????@ z N     """!!! De dD$ / //s&A11AB=<B=4AD<<$E#"E#c|j}t|}tjg|j}|t | |dnH#tj $r6tj tdtd|jsYdSYnwxYwt|t!|t ||j}|j}|rtd||j}|r5td|t(|} td tjtj|jdn*#t2$rtj td YnwxYw|jr-td t5jt5j|jt;|jt=|| ||||\}} | rt d |dS|st d|dSdS)Nrrrz;Failed to fetch your datasource, likely bad things to come!rlrzUsing passed in arguments %szUsing passed in frequency %srrrr'zRan %s but it failed!zDid not run %s, does it exist?r)!rAr-r rrrrErr rr rr/r&rrr module_argsrL frequencyFREQ_SHORT_NAMESrUrrrWrrrrrrXr1 run_singler) rArBmod_namerrrFmod_argsmod_freqrPrQs r) main_singler ksyH 4 E ;rDM : : :DMM+d##$$$  G $$$$  .    N     I   z 11   !&&& 4T**T] C C CDH< 0(;;;~H2 0(;;;#''11@ /"""  $(D)))) @@@ C>?????@ z N     """!!! De!OOHhIIY +X666q  4h???qqs%A,,?B10B1 AF$F98F9c|#t}|d}|tjd}tj|d}tj|d}tj|d}tj|d}t j||f|j\} } |dkr |j rd} n&d} n#|dkr d|j z} ntd |zd } | | vr"td | d} | dkr||||fD]}t j |n8 tjt j|} n#t"$rYnwxYwgddd }| d ii} d| d d<| D])}|| d vr|| d |<*| d }| |d<t'j|| d<t)j|| t jtj|||d | ||}| dvr|\}}|t1||d<n|}d|D|| d<n]#t"$rP}t jt4d| t7d| zt1|g|| d<Yd}~nd}~wwxYwt'j|| d<d|d<t)j|| | dkrg}| D]?}||dr/|||dg@t)j|d |d|dit jtj|||dt=|| dS)Nraz/run/cloud-initz status.jsonz result.jsonr init-localmodules modules-%szunknown name: %s)rr z modules-initzmodules-config modules-finalz'Invalid cloud init mode specified '{0}')errorsstartfinishedv1rrrT)r)rr c,g|]}t|Srp)r).0rs r) z"status_wrapper..s555c!ff555r*rzfailed stage %szfailed run of stage %srr)rr)rrr>r?normpathrr ensure_dirsr0rro ValueErrorr6del_filejsonloads load_filercopytimer write_jsonsym_linkrelpathrrr/r&extendrUrK)rArBdata_dlink_dr status_path status_link result_path result_link_namefunctorromodesstatusf nullstatusrrretrrrs r)status_wrapperr0sm ~  (( ~!!"344',,v}55K',,v}55K',,v}55K',,v}55K   {UG v~~ : DDDD   di'+d2333 E 5 5 < r?rupersist_instance_data)rinstance_data_files r)rr%s E4+E!Z33ODDw~~011 E O 1 1e 1 D D D D DEEEE E Er*c J|}tj|j|d\}}}|rl t jd|j|t ddS#tj$r5}t d||t|Yd}~dSd}~wwxYwdS)zCall set-hostname if metadata, vendordata or userdata provides it. @param stage: String representing current stage in which we are running. @param retry_stage: String represented logs upon error setting hostname. T) metadata_onlyz set-hostnameNzGFailed setting hostname in %s stage. Will retry in %s stage. Error: %s.) rr get_hostname_fqdnrWrhandler/SetHostnameErrorrLr)rrrcloudhostname_fqdn_rs r)rr-s MMOOE1 %tXua    ">48UC N N N N N/    II1A             s"AB +*BB ctjdt t jdzdS)Nr )r"stdoutr$rsortedrFEATURES)rArBs r) main_featuresrEDs:JTYYvg&677884?@@@@@r*c  |s tj}tj|d}|ddddt jzd|d d d d d tjd|ddddd|ddddd| d| dd}d|_ | dd !}|d"d#dd$d| dtf%| d&d'!}|d(d)d*d+d,d-.| d&tf%| d/d0!}|d1d2d*d3d4|d5d*d6dtt 7|d8dd9d4|d:d;d| d/t$f%| d?d@!}| t&jt&j!}t'j|| dAdB!}| dAt.f%| dCdD!} | dEdF!} | dGdH!} | dIdJ!} | dKdL!} | dMdN!}|r2|d}|dCkrddOlm}|| n|dEkrddOlm}|| n|dGkr,ddPlm}m}|| | dG|f%n|dIkr,ddQlm}m}|| | dI|f%n|d?kr,ddRlm}m}||| dS|f%nc|dMkr,ddTl m}m!}||| dM|f%n1|dKkr+ddUl"m}m#}|| | dK|f%|$|V}|j%\}}|j&rtOj(tSj*|dWvrtV}d}d} |dkr|j,rdX\}}!nLdY\}}!nF|d&krdZ|j-zd[|j-z}!}n+|d/krd\|j.zd]|j.z}!}|j/} n |}d^|z}!d} taj1||!| _|_2|j25tgj4tjj&d`|zd|||fa}"dddn #1swxYwYtmj7|"S)bNr)progz --versionz-vrz %(prog)s z'Show program's version number and exit.)r0rhelpz--filez-fr=r<z(Use additional yaml configuration files.rb)r0destrHtypez--debugz-d store_truez:Show additional pre-action logging (default: %(default)s).F)r0rHdefaultz--forcezDForce running even if no datasource is found (use at your own risk).r)r0rHrJrMr Subcommands subcommand)titlerJTrz2Initialize cloud-init and perform initial modules.)rHz--localz-lz+Start in local mode (default: %(default)s).r9r z1Activate modules using a given configuration key.z--modez-mstorez8Module configuration name to use (default: %(default)s).r)rrfinal)r0rHrMchoicessinglezRun a single module.z--namez-nzModule name to run.)r0rHrequiredz --frequencyzModule frequency for this run.)r0rHrUrSz--reportzEnable reporting.r*argumentz0Any additional arguments to pass to this module.)nargsmetavarrHqueryz;Query standardized instance metadata from the command line.featureszList defined features.analyzez-Devel tool: Analyze cloud-init logs and data.develzRun development tools.z collect-logsz*Collect and tar all cloud-init debug info.cleanz3Remove logs and artifacts so cloud-init can re-run.r,z/Report cloud-init status or wait on completion.schemaz-Validate cloud-config files using jsonschema.) get_parser)r`handle_collect_logs_args)r`handle_clean_args)r` handle_argsrender)r`handle_schema_args)r`handle_status_args)rB)r r)r zsearching for local datasources)z init-networkz!searching for network datasourcesr zrunning modules for %sz single/%szrunning single module %szrunning 'cloud-init %s')reporting_enabledzcloud-init mode '%s')logfuncr( get_uptimefuncrB)8r"argvargparseArgumentParserpop add_argumentrr7FileType set_defaultsadd_subparsersrU add_parserrrrrkeysr rNAME__doc__r`rEcloudinit.analyze.__main__cloudinit.cmd.devel.parsercloudinit.cmd.devel.logsracloudinit.cmd.cleanrbcloudinit.cmd.queryrccloudinit.config.schemarecloudinit.cmd.statusrf parse_argsr0rLrrsetupBasicLoggingr attach_handlersr0rrorAreportrReportEventStackrr log_timer/r flush_events)# sysv_argsparser subparsers parser_init parser_mod parser_single parser_queryparser_dhclientparser_featuresparser_analyze parser_develparser_collect_logs parser_clean parser_status parser_schemarOanalyze_parser devel_parser logs_parserra clean_parserrb query_parserhandle_query_args schema_parserre status_parserrfrBrAr*rname report_onrdescretvals# r)mainrHs H  $)--*:*: ; ; ;F  w5778 6     7  t $ $    I   -    &&&&&]&NNJJ''I(K  : VY$7888&&K'J  G+ I|#<===))-*M  "  -%**,,--     ?  x&=>>>(( J)L !++!6,O_--- ++1,O  ](C DDD**G+N((.)L%//I0((K)L))H*M))F*M6Nq\  " " O O O O O O N> * * * * 7 " " M M M M M M L & & & & > ) )         K+ , , ,  , ,&(@A -    7 " "         L & & &  % %g7H-I % J J J J 7 " "         L & & &  % %h8I-J % K K K K 8 # #         M- ( ( (  & &x9K.L & M M M M 8 # #         M- ( ( (  & &x9K.L & M M M   )  , ,DkOT7 z$!###"$$$ """  EI v~~ : LLE55LE55    49 $ $ty 0    $) # & 2K )D0 + u DM   I&-                    Ms<)V11V58V5__main__TZz:/etc/localtime)rr;)rY)TN)NN)Grlrr>r"rr%typingr cloudinitrcloudinit.config.modulesr patch_loggingr|rrrrrr r r r r rrrcloudinit.reportingrcloudinit.settingsrrrrrcloudinit.configrrcloudinit.cmd.develrr5rIr getLoggerr/r&r1r-rErSrXrcintrrrrrrrr r0rrrrEr__name__environrk return_valueexitrpr*r)rs$ ,,,,,,??????$$$$$$$$$$$$ &&&&&&OOOOOOOOOOOO######,,,,,,######...... ( %   g    W&=== KKKKiiU38_iiiiXEEE< \C\C\C~///d404040nDDDNp#p#p#p#fEv{EEEE.AAA~~~~B z 2:, 44>>L r*