oB]c@sddlZddlZddlZddlZddlZddlZddlmZejddlm Z ddlm Z ddlm Z ddlm Z ddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZmZmZmZddlmZddlmZddlmZdZdZ ied6ed6ed6Z!e j"Z#ddZ$ddZ&dZ'dZ(dZ)dZ*d.d Z+e,dd!Z-d"Z.d#Z/d$Z0d%Z1ddd&Z2d'Z3d(Z4d)Z5dd*Z6e7d+krd,ej8krsd-ej8d,tjd%| |j4|j4gfStjd&| |j4n|j>|j?t<|d"d'd$d(yJ|j@jAd)|jBd*tCgd+tC\}}|s|jBtDnWn.tk rtjtd,|j4d,gfSXt|jt jE|t|d|j }yt|}|}tjF|j|\}}||ksl||krtjGd-||tj|j|\}}nWn!tk rtjtd.nXtj|j|jHtId/|j4d0|j|j4tJ|||fS(1NR0s%s.ds91_kernel_cmdline_url.cfgRbs%s-localtds_depstreportersClosing stdin.s#Failed to setup output redirection!s@Logging being reset, this logger may no longer be active shortlyRs0Failed to initialize, likely bad things to come!ttrusts%s sjChecking to see if files that we need already exist from a previous run that would allow us to stop early.RLsno-nets"[%s] Exiting. stop file %s existedsQExecution continuing, no previous run detected that would allow us to stop early.tchecktmanual_cache_cleans"manual cache clean set from configtmanual_clean_markers(manual cache clean found from marker: %stexistings)[%s] Exiting. datasource %s in local modesNo local datasource founds8No instance datasource found! Likely bad things to come!tbring_ups[%s] Exiting without datasourcesNo instance datasource found.s2[%s] barreling on in force mode without datasources5[%s] %s will now be targeting instance id: %s. new=%ststagetlocalt retry_stages.[%s] Exiting. datasource %s not in local mode.s6[%s] %s is in local mode, will apply init modules now.sinit-netsmodules:configt consume_dataR3tfreqsConsuming user data failed!s#Stdout, stderr changing to (%s, %s)s'Failed to re-adjust output redirection!t datasourceRE(KRtDEP_FILESYSTEMt DEP_NETWORKRuRkR/R0tjoinRR RtInitRmtread_cfgR6RTR.RVRWRt close_stdint fixup_outputREt ExceptiontlogexcR$RR[R:t resetLoggingt setupLoggingRFR&Rt initializetpathst DSMODE_LOCALtDSMODE_NETWORKRRRRt debug_infot get_cpathtisfiletget_cfg_option_boolR"t get_ipath_curRYt purge_cachetdel_filetfetchRytdsmodetDataSourceNotFoundExceptiontforcetapply_network_configt_maybe_persist_instance_datat instancifytis_new_instancet_maybe_set_hostnametbooltsetup_datasourcetupdatetcloudifytrunRwR R tModulestget_output_cfgtwarningtactivate_datasourcetdi_report_warnRB(R2R3tdepst early_logstw_msgtinittoutfmtterrfmtRtlvlt path_helperRSRrt stop_filestexisting_filestfntmcfgtmfiletiidtrant_resultsR;t outfmt_origt errfmt_orig((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyt main_inits             !        %!                   !  "  cCsSd|krtjddS|d}|dkrDtjddSt|tsgtjd|dS|jd}|dkrtjddSt|tstjd|dS|jj dd }|j t j r|t t j }ntjd ||||kr-tjd |||dStjd |d |dt|dS(Nt di_reportsno di_report found in config.sdi_report was None.s%di_report config not a dictionary: %stdatasource_lists(no 'datasource_list' found in di_report.s(di_report/datasource_list not a list: %st.is1Datasource '%s' came from unexpected module '%s'.s:used datasource '%s' from '%s' was in di_report's list: %stdsid_missing_sourcetsourcetdslist(R$R:RTt isinstancetdictRRCtlistt __module__t rpartitionRXRt DS_PREFIXR9R t show_warningtstr(RyREtdicfgRtmodname((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyRs8            cCs|j}td||f}tjdgd|j}|jt|y|jddWnHtj k rd|}t j t |t ||js|gSnXt|tj|t|d|j}y.t jdt jt j|j|Wn!tk r(t j t dnX|jrLt jd tjntj|jt|jt|d |t|||S( Ns%s:%sRlRmRrRnsGCan not apply stage %s, no datasource found! Likely bad things to come!s Closing stdins#Failed to setup output redirection!s@Logging being reset, this logger may no longer be active shortlyR(RSR RR}RmR~R6RRRRRR$RRRRR:RRRERRVRRRFR&RB(R<R3R2RRRR;((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyt main_moduless8     !       c Cs |j}t|}tjdgd|j}|jt|y|jddWn;tj k rt j t dt d|jsdSnXt|tj|t|d|j}|j}|rt jd|n|j}|rt jd|tj|}ny.t jd t jt j|jdWn!tk rdt j t d nX|jrt jd tjntj|jt|jt|d ||j |||\}} | rt j!d |dS|st j!d|dSdSdS(NRlRmRrRns;Failed to fetch your datasource, likely bad things to come!isUsing passed in arguments %ssUsing passed in frequency %ss Closing stdins#Failed to setup output redirection!s@Logging being reset, this logger may no longer be active shortlyRsRan %s but it failed!sDid not run %s, does it exist?i("R2R RR}RmR~R6RRRRRR$RRRRt module_argsR:t frequencytFREQ_SHORT_NAMESRCRRRERTRRVRRRFR&t run_singleR( R2R3tmod_nameRRR;tmod_argstmod_freqR?R@((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyt main_singlesT     !          cCs(|dkr!tjjd}n|dkrBtjjd}ntjj|d}tjj|d}tjj|d}tjj|d}tj||f|j\}} |dkr|jrd} q d} n,|dkrd|j } nt d |d} | | kr5t d j | nd} | dkrtxZ||||fD]} tj | qZWn0yt jtj|} Wntk rnXigd6dd6dd6}| dkriid6} d| dddd?}|j dd>tf|jd@ddA} |jdBddC} |jdDddE} |jdFddG} |jdHddI} |r|dd@kradJdKlm}|| q|ddBkrdJdKlm}|| q|ddDkrdJdLlm}m}|| | j ddD|fq|ddFkr dJdMlm}m}|| | j ddF|fq|dd<kridJdNl m}m!}|||j ddO|fq|ddHkrdJdPl"m}m#}|| | j ddH|fqn|j$dQ|}|j%\}}|j&rt'j(nt)j*|dbkr t+}nd}t }|dkrJ|j,r;dc\}}qdd\}}ns|d#krtdV|j-dW|j-}}nI|d,krdX|j.dY|j.}}|j/}n|}dZ|}t}t0j1||d[||_2|j2Jt3j4d\t5j&d]d^|d_t d`|dQ||f}t6j7|SWdQXdS(eNtprogiis --versions-vR%Rs %(prog)s s--files-fR.tdestR-thelps*additional yaml configuration files to usettypetrbs--debugs-dt store_trues9show additional pre-action logging (default: %(default)s)tdefaults--forcesCforce running even if no datasource is found (use at your own risk)RRmttitlet Subcommandst subcommandRs3initializes cloud-init and performs initial moduless--locals-ls*start in local mode (default: %(default)s)Rs1activates modules using a given configuration keys--modes-mtstores7module configuration name to use (default: %(default)s)tconfigtchoicestfinaltsinglesrun a single module s--names-nsmodule name to runtrequireds --frequencysfrequency of the modules--reportsenable reportingRtnargst*tmetavartarguments/any additional arguments to pass to this moduletquerys;Query standardized instance metadata from the command line.tfeaturesslist defined featurestanalyzes,Devel tool: Analyze cloud-init logs and datatdevelsRun development toolss collect-logss)Collect and tar all cloud-init debug infotcleans3Remove logs and artifacts so cloud-init can re-run.Rs/Report cloud-init status or wait on completion.i(t get_parser(Rthandle_collect_logs_args(Rthandle_clean_args(Rt handle_argstrender(Rthandle_status_argsR3s init-localssearching for local datasourcess init-networks!searching for network datasourcess modules-%ssrunning modules for %ss single/%ssrunning single module %ssrunning 'cloud-init %s'treporting_enabledtlogfuncRscloud-init mode '%s't get_uptimetfunc(sinitsconfigsfinal(smodulessinit(s init-localssearching for local datasources(s init-networks!searching for network datasources(8RtargvtargparsetArgumentParsert add_argumentRR+tFileTypeR"t set_defaultsRTtadd_subparsersR#R t add_parserRRRRtkeysRRtNAMEt__doc__RRtcloudinit.analyze.__main__tcloudinit.cmd.devel.parsertcloudinit.cmd.devel.logsRtcloudinit.cmd.cleanRtcloudinit.cmd.queryRtcloudinit.cmd.statusRt parse_argsR%R:RVtsetupBasicLoggingRtattach_handlersRRuRSR2treportR tReportEventStackRmRtlog_timeR$R t flush_events(t sysv_argstparsert subparserst parser_initt parser_modt parser_singlet parser_querytparser_dhclienttparser_featurestparser_analyzet parser_develtparser_collect_logst parser_cleant parser_statustanalyze_parsert devel_parsert logs_parserRt clean_parserRt query_parserthandle_query_argst status_parserRR3R2Rtrnamet report_ontrdesctretval((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytmains                                       t__main__tTZs:/etc/localtime(scloud-config-urlsurl(<R"RR/RRRt cloudinitRtpatchRRVRRRRRRRR R tcloudinit.reportingR tcloudinit.settingsR R RRRtcloudinit.configRRR)R7Rt getLoggerR$RRTR&R R6RBRFRNR#RkRRRRRRRRRRt__name__tenvironR!t return_valuetexit(((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytsh       "       N * 4 Fd