HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/cmd/__pycache__/main.cpython-39.pyc
a

��`���@s�ddlZddlZddlZddlZddlZddlZddlmZe��ddlm	Z
ddlmZddlmZddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZmZmZmZddlmZddlmZddlmZdZdZ eeed�Z!e
�"�Z#d=dd�Z$d>dd�Z%dd�Z&dd�Z'dd�Z(d d!�Z)d?d#d$�Z*d@d&d'�Z+d(d)�Z,d*d+�Z-d,d-�Z.d.d/�Z/dAd0d1�Z0d2d3�Z1d4d5�Z2d6d7�Z3dBd8d9�Z4e5d:k�r�d;ej6v�r�d<ej6d;<e4ej7�Z8e8�r�e�9e8�dS)C�N)�patcher)�log)�netinfo)�signal_handler)�sources)�stages)�
url_helper)�util)�version)�warnings)�	reporting)�events)�PER_INSTANCE�
PER_ALWAYS�PER_ONCE�CLOUD_CONFIG)�
atomic_helper)�cc_set_hostname)�
dhclient_hookzOCloud-init v. {version} running '{action}' at {timestamp}. Up {uptime} seconds.zcloud_%s_modules)�instance�always�once�cCsV|rtj�d|�tj�d�tj�d�tjtjd�tj�d�tj�d�dS)N�%s
z<------------------------------------------------------------�
)�file)�sys�stderr�write�	traceback�	print_exc��msg�r#�4/usr/lib/python3/dist-packages/cloudinit/cmd/main.pyr Csr cCs&|st|�}tjd|ddtd�|S)NrFT)Zconsolerr)�welcome_formatr	Z	multi_log�LOG)�actionr"r#r#r$�welcomeMs
�r(cCstjt��t��t��|d�S)N)r
�uptimeZ	timestampr')�WELCOME_MSG_TPL�formatr
�version_stringr	r)Ztime_rfc2822�r'r#r#r$r%Us�r%cCs.g}|jr*|jD]}|�tj�|j��q|S)N)�files�append�os�path�realpath�name)�argsZfn_cfgsZfhr#r#r$�extract_fns]s

r5cCsvt|}|�|�\}}t|�t|�}|dkrXd||f}tj�d|�t�|�gSt�dt|�t|��|SdS)Nrz)No '%s' modules to run under section '%s'rzRan %s modules with %s failures)�MOD_SECTION_TPLZrun_section�lenrrrr&�debug)�mods�action_name�sectionZfull_section_name�	which_ran�failuresZtotal_attemptedr"r#r#r$�run_module_sectionjs�
�r>cCs|�d�rt�|�d��dS)Nr)�getrZupdate_configuration)�cfgr#r#r$�apply_reporting_cfgzs
rA��cloud-config-url�urlcCs@t�|�}|D]}||vr|||fSqtd||f��dS)Nz!No keys (%s) found in string '%s')r	Zkeyval_str_to_dict�KeyError)�cmdline�names�data�keyr#r#r$�parse_cmdline_urls
�rJTc

Cs�|durt��}zt|�\}}Wnty<tjdfYS0|�d�pP|�d�}|r�tj�	|�r�|r�d||f}tj
}|r�tj}nd||f}tj}||fS|ddd	�}|s�|r�tj}d
|d<ntj}d|d<d}	d
}
zrtj
fi|��}|���r4|j}	|j�|
��sH|dk�rtj}ntj
}|d||
ffWSn|d||jffWSWn8tj�y�}z|d||ffWYd}~Sd}~00tj||	dd�tj
d|||ffS)a�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.
    Nz!No kernel command line url found.zfile://�/z_file '%s' existed, possibly from local stage download of command line url '%s'. Not re-writing.zafile '%s' existed, possibly from previous boot download of command line url '%s'. Not re-writing.�
�)rD�timeoutZretries�Zsec_betweeng�������?s
#cloud-configrCz&contents of '%s' did not start with %sz$url '%s' returned code %s. Ignoring.zretrieving url '%s' failed: %si�)�modez*wrote cloud-config data from %s='%s' to %s)r	Zget_cmdlinerJrE�logging�DEBUG�
startswithr0r1�exists�INFO�WARNrZread_file_or_url�ok�contents�codeZUrlErrorZ
write_file)
r1�networkrFZcmdline_namerDZ
path_is_local�m�level�kwargsrH�headerZresp�er#r#r$�attempt_cmdline_url�sd��



��
&��r`cCsFtjtjg}|jrtjg}ttj�dtd�|jd�g}|jsJt	|�}nt	d|�}t
j||jd�}|�
t|��d}d}z.|�tjdf�t��t�|j|�\}}Wn:ty�d}t�t|�t|�|�tj|f�Yn0|jr�t�d�t��t�|j�t|j�t||d	�|D]\}	}t� |	|��q$z|�!�Wn t�yht�td
�Yn0|j"}
|j�r~tj#ntj$}|tj$k�rd}t%j&�'dt(�)��t�d
�tj�|
�*d�d�g}
g}|
D]}tj�+|��r�|�|��q�|�rt�d||�dgfSt�d�ntd}t�,|jdd�}|�rBt�d�d}n(|
�-d�}tj�.|��rjt�d|�d}|�/�t�0tj�|
�*d�d��zD|j1|d�|tj$k�r�|j2j3|k�r�t�d||j2�dgfWSWn�tj4�yb|tj#k�r�t�d�nt�td�|j5�sR|j6|jd�t�d|�|tj#k�rBdgfYSddgfYSnt�d|�Yn0t7|�|�8�}t�d ||||�9��|tj#k�r�t:|d!d"d#�|j6t;|tj#k�d�|tj#k�r�|j2j3|k�r�t�d$||j2�|j2gfSt�d%||j2�|�<�|�=�t:|d&d'd#�z2|�>�j?d(|j@tAgtAd)�\}}|�sL|�@tB�Wn,t�yzt�td*�|j2d*gfYS0t|j�t
jC|t|�|jd+�}zR|}|}t�D|j|�\}}||k�s�||k�r�t�Ed,||�t�|j|�\}}Wn t�yt�td-�Yn0t�|j�|�F�tG|j2|jd.�|j2tH|||�fS)/Nz%s.dz91_kernel_cmdline_url.cfg)r1rZz%s-local�Zds_deps�reporterzClosing 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!�trustrzjChecking to see if files that we need already exist from a previous run that would allow us to stop early.rHzno-netz"[%s] Exiting. stop file %s existedzQExecution continuing, no previous run detected that would allow us to stop early.�checkZmanual_cache_cleanFz"manual cache clean set from configZmanual_clean_markerz(manual cache clean found from marker: %s��existingz)[%s] Exiting. datasource %s in local modezNo local datasource foundz8No instance datasource found! Likely bad things to come!)Zbring_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=%s�localrZ)�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)r4�freqzConsuming user data failed!�rbz#Stdout, stderr changing to (%s, %s)z'Failed to re-adjust output redirection!)�
datasourcer@)IrZDEP_FILESYSTEMZDEP_NETWORKrir`r0r1�joinrr%r�Initrb�read_cfgr5r/rQrRr	�close_stdin�fixup_outputr@�	Exception�logexcr&r rVr8�resetLogging�setupLoggingrAr(rZ
initialize�pathsZDSMODE_LOCALZDSMODE_NETWORKrrrrZ
debug_infoZ	get_cpath�isfileZget_cfg_option_boolZ
get_ipath_currTZpurge_cache�del_file�fetchroZdsmode�DataSourceNotFoundException�forceZapply_network_config�_maybe_persist_instance_dataZ
instancifyZis_new_instance�_maybe_set_hostname�boolZsetup_datasource�update�cloudify�runrlrr�ModulesZget_output_cfg�warningZactivate_datasource�di_report_warnr>)r3r4�depsZ
early_logs�w_msg�initZoutfmtZerrfmtr"ZlvlZpath_helperrPrhZ
stop_filesZexisting_files�fnZmcfgZmfileZiidZranZ_resultsr9Zoutfmt_origZerrfmt_origr#r#r$�	main_init�s��



��

��
��
�
�

�r�cCs�d|vrt�d�dS|d}|dur4t�d�dSt|t�sNt�d|�dS|�d�}|durnt�d�dSt|t�s�t�d|�dS|j�d�d	}|�	t
j�r�|tt
j�d�}nt�d
||�||vr�t�d|||�dSt
jd||t|�d
�dS)NZ	di_reportzno di_report found in config.zdi_report was None.z%di_report config not a dictionary: %sZdatasource_listz(no 'datasource_list' found in di_report.z(di_report/datasource_list not a list: %s�.rMz1Datasource '%s' came from unexpected module '%s'.z:used datasource '%s' from '%s' was in di_report's list: %sZdsid_missing_source)�source�dslist)r&r8�
isinstance�dictr�r?�list�
__module__�
rpartitionrSrZ	DS_PREFIXr7rZshow_warning�str)ror@Zdicfgr��modnamer#r#r$r��s>





���r�cCs0|j}td||f�}tjg|jd�}|�t|��z|jdd�Wn@tj	y�d|}t
�t|�t
|�|js�|gYSYn0t|�tj|t|�|jd�}z$t�d�t
��t
�|j|�Wnty�t
�td�Yn0|j�rt�d	�t��t�|j�t|j�t||d
�t|||�S)Nz%s:%srarergzGCan not apply stage %s, no datasource found! Likely bad things to come!rn�
Closing stdinrcrdr!)rPr%rrqrbrrr5r|rr}r	rvr&r r~rr�r8rsrtr@rurQrwrxrAr(r>)r:r4r3r�r�r"r9r#r#r$�main_modules�s:�


r�c
Cs�|j}t|�}tjg|jd�}|�t|��z|jdd�Wn4tj	ypt
�td�t
d�|jslYdSYn0t|�tj|t|�|jd�}|j}|r�t�d|�|j}|r�t�d|�t�|�}z$t�d	�t
��t
�|jd�Wn t�y
t
�td
�Yn0|j�r&t�d�t��t�|j�t|j�t||d�|�|||�\}}	|	�rpt� d
|�dS|�s�t� d|�dSdSdS)Nrarergz;Failed to fetch your datasource, likely bad things to come!rOrnzUsing passed in arguments %szUsing passed in frequency %sr�rcrdr!zRan %s but it failed!zDid not run %s, does it exist?r)!r3r%rrqrbrrr5r|rr}r	rvr&r r~rr��module_argsr8Z	frequency�FREQ_SHORT_NAMESr?rsrtr@rurQrwrxrAr(Z
run_singler�)
r3r4Zmod_namer�r�r9Zmod_argsZmod_freqr<r=r#r#r$�main_singlesV	



�r�c
Cs|durtj�d�}|dur(tj�d�}tj�|d�}tj�|d�}tj�|d�}tj�|d�}t�||f�|j\}}	|dkr�|jr�d}
q�d}
n |dkr�d|j}
nt	d	|��d
}|
|vr�t	d�
|
���d}|
dkr�||||fD]}
t�|
�q�n*zt�
t�|��}Wnt�yYn0gddd�}|du�rJd
ii}d|d
d<|D]$}||d
v�rN|��|d
|<�qN|d
}|
|d<t��||
d<t�||�tjtj�||�|dd�zR|	||�}|
dv�r�|\}}|du�r�t|�|d<n|}dd�|D�||
d<WnRt�y^}z8t�td|
�td|
�t|�g||
d<WYd}~n
d}~00t��||
d<d|d<t�||�|
dk�r�g}|D]*}||d�r�|�||�dg���q�t�|d
|d|d�i�tjtj�||�|dd�t||
d�S)Nz/var/lib/cloud/dataz/run/cloud-initzstatus.jsonzresult.jsonr��
init-local�modules�
modules-%szunknown name: %s)r�r�zmodules-initzmodules-config�
modules-finalz'Invalid cloud init mode specified '{0}')�errors�start�finished�v1rorjr�T)r~)r�r�cSsg|]}t|��qSr#)r�)�.0r_r#r#r$�
<listcomp>��z"status_wrapper.<locals>.<listcomp>r�zfailed stage %szfailed run of stage %sr�r�)ror�)r0r1�normpathrpr	Zensure_dirsr'rirP�
ValueErrorr+r{�json�loadsZ	load_fileru�copy�timerZ
write_jsonZsym_link�relpathr�rvr&r �extendr?r7)r3r4Zdata_dZlink_dZstatus_pathZstatus_link�result_pathZresult_link�_name�functorrP�modes�status�fZ
nullstatusr[r�Zretror�r_r#r#r$�status_wrapperMs�
��
�


(

���r�cCs4|jr0tj�|jjtj�}tj�|�s0|j	�
�dS)zCWrite instance-data.json file if absent and datasource is restored.N)Zds_restoredr0r1rpryZrun_dirrZINSTANCE_JSON_FILErTroZpersist_instance_data)r�Zinstance_data_filer#r#r$r�s
�rc
Csz|��}tj|j|dd�\}}|rvzt�d|j|td�Wn:tjyt}z t�d||t	|��WYd}~n
d}~00dS)z�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)Z
metadata_onlyzset-hostnameNzGFailed setting hostname in %s stage. Will retry in %s stage. Error: %s.)
r�r	Zget_hostname_fqdnr@rZhandler&ZSetHostnameErrorr8r�)r�rjrkZcloud�hostnameZ_fqdnr_r#r#r$r��s�

�r�cCs tj�d�ttj��d�dS)Nr)r�stdoutrrp�sortedr
ZFEATURES)r3r4r#r#r$�
main_features�sr�c	Csd|s
tj}tj|dd�}|dd�}|jddddt��d�|jd	d
ddd
t�d�d�|jdddddd�|jdddddd�|jdd�|j	ddd�}d|_
|jdd d!�}|jd"d#dd$dd�|jdtfd%�|jd&d'd!�}|jd(d)d*d+d,d-d.�|jd&t
fd%�|jd/d0d!�}|jd1d2d*d3dd4�|jd5d*d6dtt���d7�|jd8dd9dd4�|jd:d;d<d=d>�|jd/tfd%�|jd?d@d!�}|jtjtjd!�}t�|�|jdAdBd!�}|jdAtfd%�|jdCdDd!�}	|jdEdFd!�}
|jdGdHd!�}|jdIdJd!�}|jdKdLd!�}
|�r8|ddCk�r6ddMlm}||	��n|ddEk�rZddMlm}||
�n�|ddGk�r�ddNlm}m}||�|jdG|fd%�n�|ddIk�r�ddOlm}m}||�|jdI|fd%�nn|dd?k�rddPlm}m}||�|jdQ|fd%�n6|ddKk�r8ddRlm}m }||
�|
jdK|fd%�|j!|dS�}|j"\}}|j#�r^t$�%�t&�'�|dTv�rtt(}d}d}|dk�r�|j)�r�dU\}}ndV\}}nZ|d&k�r�dW|j*dX|j*}}n8|d/k�r�dY|j+dZ|j+}}|j,}n|}d[|}d}t-j.|||d\�|_/|j/�:t0j1t2j#d]|d|||fd^�}t3�4�|Wd�S1�sV0YdS)_Nr)ZprogrOz	--versionz-vr
z	%(prog)s )r'r
z--filez-fr/r.z*additional yaml configuration files to use�rb)r'�dest�help�typez--debugz-dZ
store_truez9show additional pre-action logging (default: %(default)s)F)r'r��defaultz--forcezCforce running even if no datasource is found (use at your own risk)r~)r'r�r�r�rnZSubcommandsZ
subcommand)�titler�Tr�z3initializes cloud-init and performs initial modules)r�z--localz-lz*start in local mode (default: %(default)s)r-r�z1activates modules using a given configuration keyz--modez-m�storez7module configuration name to use (default: %(default)s)�config)r�r��final)r'r�r��choicesZsinglezrun a single module z--namez-nzmodule name to run)r'r��requiredz--frequencyzfrequency of the module)r'r�r�r�z--reportzenable reportingr��*Zargumentz/any additional arguments to pass to this module)�nargs�metavarr��queryz;Query standardized instance metadata from the command line.Zfeatureszlist defined featuresZanalyzez,Devel tool: Analyze cloud-init logs and dataZdevelzRun development toolszcollect-logsz)Collect and tar all cloud-init debug infoZcleanz3Remove logs and artifacts so cloud-init can re-run.r�z/Report cloud-init status or wait on completion.)�
get_parser)r��handle_collect_logs_args)r��handle_clean_args)r��handle_argsZrender)r��handle_status_args)r4)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')Zreporting_enabledzcloud-init mode '%s')Zlogfuncr"Z
get_uptime�funcr4)5r�argv�argparse�ArgumentParser�add_argumentr
r,ZFileTypeZset_defaultsZadd_subparsersr�Z
add_parserr�r�r�r��keysr�rZNAME�__doc__r�r�Zcloudinit.analyze.__main__Zcloudinit.cmd.devel.parserZcloudinit.cmd.devel.logsr�Zcloudinit.cmd.cleanr�Zcloudinit.cmd.queryr�Zcloudinit.cmd.statusr��
parse_argsr'r8rQZsetupBasicLoggingrZattach_handlersr�rirPr3Zreportr
ZReportEventStackrbr	Zlog_timer&rZflush_events)Z	sysv_args�parserZ
subparsersZparser_initZ
parser_modZ
parser_singleZparser_queryZparser_dhclientZparser_featuresZparser_analyzeZparser_develZparser_collect_logsZparser_cleanZ
parser_statusZanalyze_parserZdevel_parserZlogs_parserr�Zclean_parserr�Zquery_parserZhandle_query_argsZ
status_parserr�r4r3r�ZrnameZ	report_onZrdescZretvalr#r#r$�main�s6

�
�
���
��
��
�
�����
������
����





�
��

�r��__main__ZTZz:/etc/localtime)r)N)rB)TN)NN)N):r�r�r0rr�rZ	cloudinitrZpatchrrQrrrrrr	r
rrZcloudinit.reportingr
Zcloudinit.settingsrrrrrZcloudinit.configrrr*r6r�Z	getLoggerr&r r(r%r5r>rArJr`r�r�r�r�r�rr�r�r��__name__�environr�Zreturn_value�exitr#r#r#r$�<module>sl�




	
NT*4F
d	
3