Current File : //lib/python2.7/site-packages/cloudinit/cmd/main.pyc
�
oB�]c@s�ddlZddlZddlZddlZddlZddlZddlmZej�ddlm	Z
ddlmZddlmZddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZmZmZmZddlmZddlmZddlmZdZdZ ied6ed6ed6Z!e
j"�Z#dd�Z$dd�Z&d�Z'd�Z(d�Z)d�Z*d.d �Z+e,dd!�Z-d"�Z.d#�Z/d$�Z0d%�Z1ddd&�Z2d'�Z3d(�Z4d)�Z5dd*�Z6e7d+kr�d,ej8krsd-ej8d,<ne6ej9�Z:e:r�ej;e:�q�ndS(/i����N(tpatcher(tlog(tnetinfo(tsignal_handler(tsources(tstages(t
url_helper(tutil(tversion(twarnings(t	reporting(tevents(tPER_INSTANCEt
PER_ALWAYStPER_ONCEtCLOUD_CONFIG(t
atomic_helper(tcc_set_hostname(t
dhclient_hooksOCloud-init v. {version} running '{action}' at {timestamp}. Up {uptime} seconds.scloud_%s_modulestinstancetalwaystoncetcCs||rtjjd|�ntjjdd�tjjd�tjdtj�tjjdd�tjjd�dS(Ns%s
t-i<s
tfile(tsyststderrtwritet	tracebackt	print_exc(tmsg((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyRCscCs<|st|�}ntjd|dtdtdt�|S(Ns%s
tconsoleRR(twelcome_formatRt	multi_logtFalsetTruetLOG(tactionR((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytwelcomeMs
c	Cs4tjdtj�dtj�dtj�d|�S(NRtuptimet	timestampR%(tWELCOME_MSG_TPLtformatRtversion_stringRR'ttime_rfc2822(R%((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyR Us
	cCsFg}|jrBx0|jD]"}|jtjj|j��qWn|S(N(tfilestappendtostpathtrealpathtname(targstfn_cfgstfh((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytextract_fns]s
	#cCs�t|}|j|�\}}t|�t|�}|dkrvd||f}tjjd|�tj|�gStjdt|�t|��|SdS(Nis)No '%s' modules to run under section '%s's%s
sRan %s modules with %s failures(tMOD_SECTION_TPLtrun_sectiontlenRRRR$tdebug(tmodstaction_nametsectiontfull_section_namet	which_rantfailuresttotal_attemptedR((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytrun_module_sectionjs


	cCs,|jd�r(tj|jd��ndS(NR
(tgetR
tupdate_configuration(tcfg((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytapply_reporting_cfgzsscloud-config-urlturlcCsTtj|�}x(|D] }||kr|||fSqWtd||f��dS(Ns!No keys (%s) found in string '%s'(Rtkeyval_str_to_dicttKeyError(tcmdlinetnamestdatatkey((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytparse_cmdline_urls
c
Cs|dkrtj�}nyt|�\}}Wntk
rNtjdfSX|jd�pj|jd�}|r�tj	j
|�r�|r�d||f}tj}|r�tj}q�nd||f}tj}||fSi|d6dd6d	d
6}|s|rtj}d|d<ntj}d
|d<d}	d}
y�t
j|�}|j�r�|j}	|jj|
�s�|dkr�tj}n	tj}|d||
ffSn|d||jffSWn't
jk
r�}|d||ffSXtj||	dd�tjd|||ffS(s�Write 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.
    s!No kernel command line url found.sfile://t/s_file '%s' existed, possibly from local stage download of command line url '%s'. Not re-writing.safile '%s' existed, possibly from previous boot download of command line url '%s'. Not re-writing.RGi
ttimeoutitretriesitsec_betweeng�������?s
#cloud-configscloud-config-urls&contents of '%s' did not start with %ss$url '%s' returned code %s. Ignoring.sretrieving url '%s' failed: %stmodei�s*wrote cloud-config data from %s='%s' to %sN(tNoneRtget_cmdlineRNRItloggingtDEBUGt
startswithR/R0texiststINFOtWARNRtread_file_or_urltoktcontentstcodetUrlErrort
write_file(
R0tnetworkRJtcmdline_nameRGt
path_is_localtmtleveltkwargsRLtheadertrespte((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytattempt_cmdline_url�sX

	
	
	
	
		cCstjtjg}|jr*tjg}ntdtjjdtd�d|j�g}|jsqt	|�}nt	d|�}t
jd|d|j�}|j
t|��d}d}y?|jtjdf�tj�tj|j|�\}}WnGtk
rCd	}tjt|�t|�|jtj|f�nX|jrgtjd
�tj�ntj|j�t|j�t |d|�x$|D]\}	}tj!|	|�q�Wy|j"�Wn!tk
r�tjtd�nX|j#}
|jrtj$ntj%}|tj%kr�d
}t&j'j(dt)j*��tjd�tjj|
j+d�d�g}
g}x0|
D](}tjj,|�r{|j|�q{q{W|r�tjd||�dgfStjd�n�d}tj-|jdt.�}|rtjd�d
}n:|
j/d�}tjj0|�rNtjd|�d
}n|j1�tj2tjj|
j+d�d��yU|j3d|�|tj%kr�|j4j5|kr�tjd||j4�dgfSWn�tj6k
r}|tj$krtjd�ntjtd�|j7sj|j8d|j�tjd|�|tj$krZdgfSddgfSq~tjd |�nXt9|�|j:�}tjd!||||j;��|tj$kr�t<|d"d#d$d�n|j8dt=|tj$k��|tj$krW|j4j5|kr>tjd%||j4�|j4gfStjd&||j4�n|j>�|j?�t<|d"d'd$d(�yJ|j@�jAd)|jBd*tCgd+tC�\}}|s�|jBtD�nWn.tk
r�tjtd,�|j4d,gfSXt|j�t
jE|t|�d|j�}yt|}|}tjF|j|�\}}||ksl||kr�tjGd-||�tj|j|�\}}nWn!tk
r�tjtd.�nXtj|j�|jH�tId/|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=%ststagetlocaltretry_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_FILESYSTEMtDEP_NETWORKRuRkR/R0tjoinRR RtInitRmtread_cfgR6RTR.RVRWRtclose_stdintfixup_outputREt	ExceptiontlogexcR$RR[R:tresetLoggingtsetupLoggingRFR&Rt
initializetpathstDSMODE_LOCALtDSMODE_NETWORKRRRRt
debug_infot	get_cpathtisfiletget_cfg_option_boolR"t
get_ipath_curRYtpurge_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_msgtinittoutfmtterrfmtRtlvltpath_helperRSRrt
stop_filestexisting_filestfntmcfgtmfiletiidtrant_resultsR;toutfmt_origterrfmt_orig((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyt	main_init�s�			


	



	
!
	


		
%!	
	
	
		

	

		

!	
"

cCsSd|krtjd�dS|d}|dkrDtjd�dSt|t�sgtjd|�dS|jd�}|dkr�tjd�dSt|t�s�tjd|�dS|jj	d�d	}|j
tj�r�|t
tj�}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
isinstancetdictR�RCtlistt
__module__t
rpartitionRXRt	DS_PREFIXR9R	tshow_warningtstr(RyREtdicfgR�tmodname((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyR��s8



	
	
cCs�|j}td||f�}tjdgd|j�}|jt|��y|jdd�WnHtj	k
r�d|}t
jt|�t
|�|js�|gSnXt|�tj|t|�d|j�}y.tjd�t
j�t
j|j|�Wn!tk
r(t
jtd�nX|jrLtjd	�tj�ntj|j�t|j�t|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~R6R�RR�RR�R$RR�R�R�R:RR�RER�RVR�R�RFR&RB(R<R3R2R�R�RR;((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytmain_modules�s8	
	
!


	


c
Cs|j}t|�}tjdgd|j�}|jt|��y|jdd�Wn;tj	k
r�t
jtd�t
d�|js�dSnXt|�tj|t|�d|j�}|j}|r�tjd|�n|j}|rtjd|�tj|�}ny.tjd	�t
j�t
j|jd�Wn!tk
rdt
jtd
�nX|jr�tjd�tj�ntj|j�t|j�t|d|�|j |||�\}}	|	r�t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~R6R�RR�RR�R$RR�R�R�tmodule_argsR:t	frequencytFREQ_SHORT_NAMESRCRR�RERTR�RVR�R�RFR&t
run_singleR�(
R2R3tmod_nameR�R�R;tmod_argstmod_freqR?R@((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytmain_singlesT		
	
!		


	


	cCs(|dkr!tjjd�}n|dkrBtjjd�}ntjj|d�}tjj|d�}tjj|d�}tjj|d�}tj||f�|j\}}	|dkr�|jr�d}
qd}
n,|dkr�d|j	}
nt
d	|��d}|
|kr5t
d
j|
���nd}|
dkrtxZ||||fD]}
tj|
�qZWn0yt
jtj|��}Wntk
r�nXigd6dd6dd6}|dkr�iid6}d|dd<nx5|D]-}||dkr�|j�|d|<q�q�W|d}|
|d<tj�||
d<tj||�tjtjj||�|dt�yz|	||�}|
dkr�|\}}|dk	r�t|�|d<q�n|}g|D]}t|�^q�||
d<WnKtk
rE}tjtd|
�td|
�t|�g||
d<nXtj�||
d<d|d<tj||�|
dkrg}x<|D]4}||dr�|j||jdg��q�q�Wtj|ii|dd6|d6d6�tjtjj||�|dt�nt||
d�S(Ns/var/lib/cloud/datas/run/cloud-initsstatus.jsonsresult.jsonR�s
init-localtmoduless
modules-%ssunknown name: %ssmodules-initsmodules-configs
modules-finals'Invalid cloud init mode specified '{0}'terrorststarttfinishedtv1RyRtR�sfailed stage %ssfailed run of stage %s(sinits
init-localsmodules-initsmodules-configs
modules-final(sinits
init-local(RTR/R0tnormpathR|Rtensure_dirsR%RuRSt
ValueErrorR*R�tjsontloadst	load_fileR�tcopyttimeRt
write_jsontsym_linktrelpathR#R�R�R$RtextendRCR9(R2R3tdata_dtlink_dtstatus_pathtstatus_linktresult_pathtresult_linkt_nametfunctorRStmodeststatustft
nullstatusReR�tretRyR�Rj((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytstatus_wrapperMs�			





+

$
cCsP|jrLtjj|jjtj�}tjj|�sL|j	j
�qLndS(sCWrite instance-data.json file if absent and datasource is restored.N(tds_restoredR/R0R|R�trun_dirRtINSTANCE_JSON_FILERYRytpersist_instance_data(R�tinstance_data_file((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyR��s
		cCs�|j�}tj|j|dt�\}}|r�y tjd|j|td�Wq�tj	k
r�}tj
d||t|��q�XndS(s�Call 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_onlysset-hostnamesGFailed setting hostname in %s stage. Will retry in %s stage. Error: %s.N(R�Rtget_hostname_fqdnRER#RthandleR$RTtSetHostnameErrorR:R�(R�RtRvtcloudthostnamet_fqdnRj((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyR��s cCs*tjjdjttj��d�dS(Ns
(RtstdoutRR|tsortedRtFEATURES(R2R3((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyt
main_features�scCs1|stj}ntjd|d�}|d}|jddddddtj��|jd	d
dddd
dddtjd��|jdddddddt�|jddddddddt�|j	dd�|jdddd�}t|_
|jddd�}|jd d!dddd"dt�|j	ddtf�|jd#dd$�}|jd%d&dd'dd(dd)d*da�|j	dd#tf�|jd,dd-�}|jd.d/dd'dd0d1t�|jd2dd'dd3d1td*ttj���|jd4dddd5d1t�|jd6d7d8d9d:dd;�|j	dd,tf�|jd<dd=�}|jtjdtj�}tj|�|jd>dd?�}|j	dd>tf�|jd@ddA�}	|jdBddC�}
|jdDddE�}|jdFddG�}|jdHddI�}
|r�|dd@kradJdKlm}||	�q�|ddBkr�dJdKlm}||
�q�|ddDkr�dJdLlm}m}||�|j	ddD|f�q�|ddFkr dJdMlm}m}||�|j	ddF|f�q�|dd<kridJdNl m}m!}||�|j	ddO|f�q�|ddHkr�dJdPl"m}m#}||
�|
j	ddH|f�q�n|j$dQ|�}|j%\}}|j&r�t'j(�nt)j*�|dbkrt+}nd}t}|dkrJ|j,r;dc\}}q�dd\}}ns|d#krtdV|j-dW|j-}}nI|d,kr�dX|j.dY|j.}}|j/}n|}dZ|}t}t0j1||d[|�|_2|j2�Jt3j4d\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)R�RmttitletSubcommandst
subcommandR�s3initializes cloud-init and performs initial moduless--locals-ls*start in local mode (default: %(default)s)R�s1activates 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 reportingR�tnargst*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.R�s/Report cloud-init status or wait on completion.i����(t
get_parser(Rthandle_collect_logs_args(Rthandle_clean_args(Rthandle_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_parserR�R�R�R�tkeysR�RtNAMEt__doc__RR�tcloudinit.analyze.__main__tcloudinit.cmd.devel.parsertcloudinit.cmd.devel.logsRtcloudinit.cmd.cleanRtcloudinit.cmd.queryRtcloudinit.cmd.statusRt
parse_argsR%R:RVtsetupBasicLoggingRtattach_handlersR�RuRSR2treportRtReportEventStackRmRtlog_timeR$R
tflush_events(t	sysv_argstparsert
subparserstparser_initt
parser_modt
parser_singletparser_querytparser_dhclienttparser_featurestparser_analyzetparser_develtparser_collect_logstparser_cleant
parser_statustanalyze_parsertdevel_parsertlogs_parserRtclean_parserRtquery_parserthandle_query_argst
status_parserRR3R2R�trnamet	report_ontrdesctretval((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pytmain�s�
					
	


	
	
	
		

		



	
t__main__tTZs:/etc/localtime(scloud-config-urlsurl(<R"R�R/RR�Rt	cloudinitRtpatchRRVRRRRRRRR	R
tcloudinit.reportingRtcloudinit.settingsRR
RRRtcloudinit.configRRR)R7R�t	getLoggerR$RRTR&R R6RBRFRNR#RkR�R�R�R�R�R�R�R�RRt__name__tenvironR!treturn_valuetexit(((s6/usr/lib/python2.7/site-packages/cloudinit/cmd/main.pyt<module>sh
"

		
			N	�	*	4	Fd				�