403Webshell
Server IP : 3.96.16.70  /  Your IP : 216.73.216.15
Web Server : Apache
System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64
User : ec2-user ( 1000)
PHP Version : 8.4.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3.9/site-packages/cloudinit/cmd/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3.9/site-packages/cloudinit/cmd/__pycache__/main.cpython-39.pyc
a

ꬊhD��@s ddlZddlZddlZddlZddlZddlZddlmZddlm	Z	e�
�ddlmZddlm
ZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZmZmZmZddlmZddl m!Z!ddlm"Z"dZ#dZ$eeed�Z%e�&�Z'dDdd�Z(dEdd�Z)dd�Z*dd�Z+e	d �d!d"�Z,d#d$�Z-dFd&d'�Z.dGd)d*�Z/d+d,�Z0d-d.�Z1d/d0�Z2d1d2�Z3d3d4�Z4d5d6�Z5dHd7d8�Z6d9d:�Z7d;d<�Z8d=d>�Z9dId?d@�Z:e;dAk�rdBej<v�rdCej<dB<e:ej=�Z>e>�re�?e>�dS)J�N)�patcher)�Modules)�validate_cloudconfig_schema)�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%�6/usr/lib/python3.9/site-packages/cloudinit/cmd/main.pyr"Jsr"cCs&|st|�}tjd|ddtd�|S)NrFT)Zconsolerr)�welcome_formatrZ	multi_log�LOG)�actionr$r%r%r&�welcomeTsr*cCstjt��t��t��|d�S)N)r�uptimeZ	timestampr))�WELCOME_MSG_TPL�formatr�version_stringrr+Ztime_rfc2822�r)r%r%r&r'[s�r'cCs.g}|jr*|jD]}|�tj�|j��q|S)N)�files�append�os�path�realpath�name)�argsZfn_cfgsZfhr%r%r&�extract_fnsds

r7)�modscCsvt|}|�|�\}}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�lenrrr r(�debug)r8�action_nameZsectionZfull_section_name�	which_ran�failuresZtotal_attemptedr$r%r%r&�run_module_sectionqs�
�r?cCs|�d�rt�|�d��dS)Nr)�getrZupdate_configuration)�cfgr%r%r&�apply_reporting_cfg�s
rB��cloud-config-url�urlcCs@t�|�}|D]}||vr|||fSqtd||f��dS)Nz!No keys (%s) found in string '%s')rZkeyval_str_to_dict�KeyError)�cmdline�names�data�keyr%r%r&�parse_cmdline_url�s

rKTc

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.�
�)rEZtimeoutZretries�Zsec_betweeng�������?s
#cloud-configrDz&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)rZget_cmdlinerKrF�logging�DEBUG�
startswithr2r3�exists�INFO�WARNr
Zread_file_or_url�ok�contents�codeZUrlError�
write_file)
r3�networkrGZcmdline_namerEZ
path_is_local�m�level�kwargsrI�headerZresp�er%r%r&�attempt_cmdline_url�sh����



��
&��racCs�dtjjtjjf}tj�|j�d�d�}tj�	|�rlt
|���}||kr�t�
d�|�d�t�||�n*tj�	|j�d��r�t�d�t�||�dS)	z�Purge 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.%drIzpython-versionz-Python version change detected. Purging cacheTZobj_pklzMWriting python-version file. Cache compatibility status is currently unknown.N)r�version_info�major�minorr2r3�join�pathsZ	get_cpathrT�open�readr(r;�purge_cacherrZ�
get_ipath_cur�info)�initZcurrent_python_versionZpython_version_pathZcached_python_versionr%r%r&�$purge_cache_on_python_version_change�s$��

�rmcCst�|jd�rdS|jS)NZdisable_network_activationF)r�get_cfg_option_boolrA�local)rlr6r%r%r&�_should_bring_up_interfacessrpcCs�tjtjg}|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"}
t#|�|j�r�tj$ntj%}|tj%k�r�d}t&j'�(dt)�*��nZd
}t�+|jdd�}
|
�r�t�d�d}n(|
�,d�}tj�-|��rt�d|�d}|�.�t/||�}zD|j0|d�|tj%k�rX|j1j2|k�rXt�d||j1�dgfWSWn�tj3�y�|tj$k�r�t�d�nt�td�|j4�s�|j5|d�t�d|�|tj$k�r�dgfYSddgfYSnt�d|�Yn0t6|�|�7�}t�d||||�8��|tj$k�r*t9|ddd�|j5|d�|tj$k�rz|j1j2|k�rjt�d||j1�|j1gfSt�d ||j1�|�:�|�;�t9|d!d"d�z2|�<�j=d#|j>t?gt?d$�\}}|�s�|�>t@�Wn,t�y�t�td%�|j1d%gfYS0tj�-|j"�,d&���r tA|jddd'�n
t�d(�t|j�tB|t|�|jd)�}zR|}|}t�C|j|�\}}||k�sx||k�r�t�Dd*||�t�|j|�\}}Wn t�y�t�td+�Yn0t�|j�|�E�tF|j1|jd,�|j1tG|||�fS)-Nz%s.dz91_kernel_cmdline_url.cfg)r3r[z%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!�trustrZcheckZmanual_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=%sror[)�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)r6ZfreqzConsuming user data failed!Zuserdata_raw)�config�strictZlog_detailsz2Skipping user-data validation. No user-data found.�rrz#Stdout, stderr changing to (%s, %s)z'Failed to re-adjust output redirection!)�
datasourcerA)HrZDEP_FILESYSTEMZDEP_NETWORKrorar2r3rerr'r	�Initrr�read_cfgr7r1rQrRr�close_stdin�fixup_outputrA�	Exception�logexcr(r"rVr;�resetLogging�setupLoggingrBr*rZ
initializerfrmZDSMODE_LOCALZDSMODE_NETWORKrrr rZ
debug_infornrjrTrirp�fetchr~Zdsmode�DataSourceNotFoundException�forceZapply_network_config�_maybe_persist_instance_dataZ
instancifyZis_new_instance�_maybe_set_hostnameZsetup_datasource�update�cloudify�runrzrrrrZget_output_cfg�warningZactivate_datasource�di_report_warnr?)r5r6ZdepsZ
early_logs�w_msgrlZoutfmtZerrfmtr$ZlvlZpath_helperrPrwZmcfgZmfileZbring_up_interfacesZiidZranZ_resultsr8Zoutfmt_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�.rNz1Datasource '%s' came from unexpected module '%s'.z:used datasource '%s' from '%s' was in di_report's list: %sZdsid_missing_source)�source�dslist)r(r;�
isinstance�dictr�r@�list�
__module__�
rpartitionrSrZ	DS_PREFIXr:r
Zshow_warning�str)r~rAZdicfgr��modnamer%r%r&r��sH





���r�cCs,|j}td||f�}tjg|jd�}|�t|��z|jdd�Wn@tj	y�d|}t
�t|�t
|�|js�|gYSYn0t|�t|t|�|jd�}z$t�d�t
��t
�|j|�Wnty�t
�td�Yn0|jr�t�d	�t��t�|j�t|j�t||d
�t|||�S)Nz%s:%srqrurvzGCan not apply stage %s, no datasource found! Likely bad things to come!r}�
Closing stdinrsrtr#)rPr'r	rrrr�r7r�rr�rr�r(r"r�r�rr;r�r�rAr�rQr�r�rBr*r?)r<r6r5r�rlr$r8r%r%r&�main_moduless@��
�
r�c
Cs�|j}t|�}tjg|jd�}|�t|��z|jdd�Wn4tj	ypt
�td�t
d�|jslYdSYn0t|�t|t|�|jd�}|j}|r�t�d|�|j}|r�t�d|�t�|�}z$t�d	�t
��t
�|jd�Wn t�yt
�td
�Yn0|j�r$t�d�t��t�|j�t|j�t||d�|�|||�\}}	|	�rnt� d
|�dS|�s�t� d|�dSdSdS)Nrqrurvz;Failed to fetch your datasource, likely bad things to come!rOr}zUsing passed in arguments %szUsing passed in frequency %sr�rsrtr#zRan %s but it failed!zDid not run %s, does it exist?r)!r5r'r	rrrr�r7r�rr�rr�r(r"r�r�r�module_argsr;Z	frequency�FREQ_SHORT_NAMESr@r�r�rAr�rQr�r�rBr*Z
run_singler�)
r5r6Zmod_namer�rlr8Zmod_argsZmod_freqr=r>r%r%r&�main_singleQs\	��

�
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.jsonrl�
init-local�modules�
modules-%szunknown name: %s)rlr�zmodules-initzmodules-config�
modules-finalz'Invalid cloud init mode specified '{0}')�errors�start�finished�v1r~rxr�T)r�)rlr�cSsg|]}t|��qSr%)r�)�.0r`r%r%r&�
<listcomp>��z"status_wrapper.<locals>.<listcomp>r�zfailed stage %szfailed run of stage %sr�r�)r~r�)r2r3�normpathrerZensure_dirsr)rorP�
ValueErrorr-Zdel_file�json�loadsZ	load_filer��copy�timerZ
write_jsonZsym_link�relpathr�r�r(r"�extendr@r:)r5r6Zdata_dZlink_dZstatus_pathZstatus_link�result_pathZresult_link�_name�functorrPZmodes�status�fZ
nullstatusr\r��retr~r�r`r%r%r&�status_wrapper�s���
��
�


(
��r�cCs4|jr0tj�|jjtj�}tj�|�s0|j	�
�dS)zCWrite instance-data.json file if absent and datasource is restored.N)Zds_restoredr2r3rerfZrun_dirrZINSTANCE_JSON_FILErTr~Zpersist_instance_data)rlZinstance_data_filer%r%r&r�
s
�r�c
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�rZget_hostname_fqdnrArZhandler(ZSetHostnameErrorr;r�)rlrxryZcloud�hostnameZ_fqdnr`r%r%r&r�s�
�r�cCs tj�d�ttj��d�dS)Nr)r�stdoutr re�sortedrZFEATURES)r5r6r%r%r&�
main_features+sr�c#	Cs�|s
tj}tj|�d�d�}|jddddt��dd�|jd	d
ddd
t�d�d�|jdddddd�|jdddddd�|j	dd�|j
ddd�}d|_|jdd d!�}|jd"d#dd$dd�|j	dt
fd%�|jd&d'd!�}|jd(d)d*d+d,d-d.�|j	d&tfd%�|jd/d0d!�}|jd1d2d*d3dd4�|jd5d*d6dtt���d7�|jd8dd9dd4�|jd:d;d<d=d>�|j	d/tfd%�|jd?d@d!�}|jtjtjd!�}t�|�|jdAdBd!�}|j	dAtfd%�|jdCdDd!�}	|jdEdFd!�}
|jdGdHd!�}|jdIdJd!�}|jdKdLd!�}
|jdMdNd!�}|�rd|d}|dCk�r@ddOlm}||	��n$|dEk�rbddOlm}||
��n|dGk�r�ddPlm}m}||�|j	dG|fd%�n�|dIk�r�ddQlm}m}||�|j	dI|fd%�n�|d?k�r�ddRlm}m}||�|j	dS|fd%�nf|dMk�r2ddTl m}m!}||�|j	dM|fd%�n2|dKk�rdddUl"m}m#}||
�|
j	dK|fd%�|j$|dV�}|j%\}}|j&�r�t'�(�t)�*�|dWv�r�t+}d}d} |dk�r�|j,�r�dX\}}!ndY\}}!nZ|d&k�r�dZ|j-d[|j-}}!n8|d/k�rd\|j.d]|j.}}!|j/} n|}d^|}!d} t0j1||!| d_�|_2|j2�:t3j4t5j&d`|d|||fda�}"t6�7�|"Wd�S1�s�0YdS)bNr)�progz	--versionz-vrz	%(prog)s z'Show program's version number and exit.)r)r�helpz--filez-fr1r0z(Use additional yaml configuration files.�rb)r)�destr��typez--debugz-d�
store_truez:Show additional pre-action logging (default: %(default)s).F)r)r��defaultz--forcezDForce running even if no datasource is found (use at your own risk).r�)r)r�r�r�r}ZSubcommands�
subcommand)�titler�Trlz2Initialize cloud-init and perform initial modules.)r�z--localz-lz+Start in local mode (default: %(default)s).r/r�z1Activate modules using a given configuration key.z--modez-mZstorez8Module configuration name to use (default: %(default)s).r{)rlr{�final)r)r�r��choicesZsinglezRun a single module.z--namez-nzmodule name to run)r)r��requiredz--frequencyzSet module frequency.)r)r�r�r�z--reportzEnable reporting.r��*Zargumentz0Any additional arguments to pass to this module.)�nargs�metavarr��queryz;Query standardized instance metadata from the command line.ZfeatureszList defined features.Zanalyzez-Devel tool: Analyze cloud-init logs and data.ZdevelzRun development tools.zcollect-logsz*Collect and tar all cloud-init debug info.Zcleanz3Remove logs and artifacts so cloud-init can re-run.r�z/Report cloud-init status or wait on completion.Zschemaz-Validate cloud-config files using jsonschema.)�
get_parser)r��handle_collect_logs_args)r��handle_clean_args)r��handle_argsZrender)r��handle_schema_args)r��handle_status_args)r6)r�rl)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�funcr6)8r�argv�argparse�ArgumentParser�pop�add_argumentrr.ZFileTypeZset_defaultsZadd_subparsersr�Z
add_parserr�r�r�r��keysr�r�NAME�__doc__r�r�Zcloudinit.analyze.__main__Zcloudinit.cmd.devel.parserZcloudinit.cmd.devel.logsr�Zcloudinit.cmd.cleanr�Zcloudinit.cmd.queryr��cloudinit.config.schemar�Zcloudinit.cmd.statusr��
parse_argsr)r;rQZsetupBasicLoggingrZattach_handlersr�rorPr5�reportrZReportEventStackrrrZlog_timer(rZflush_events)#Z	sysv_args�parserZ
subparsersZparser_initZ
parser_modZ
parser_singleZparser_queryZparser_dhclientZparser_featuresZparser_analyzeZparser_develZparser_collect_logsZparser_cleanZ
parser_statusZ
parser_schemar�Zanalyze_parserZdevel_parserZlogs_parserr�Zclean_parserr�Zquery_parserZhandle_query_argsZ
schema_parserr�Z
status_parserr�r6r5r�ZrnameZ	report_onZrdescZretvalr%r%r&�main/st
������	����
�����
�������


�









�
���r��__main__ZTZz:/etc/localtime)r)N)rC)TN)NN)N)@r�r�r2rr�r!Z	cloudinitrZcloudinit.config.modulesrZ
patch_loggingr�rrrQrrrr	r
rrr
rZcloudinit.reportingrZcloudinit.settingsrrrrrZcloudinit.configrrr,r9r�Z	getLoggerr(r"r*r'r7r?rBrKrarmrpr�r�r�r�r�r�r�r�r��__name__�environr�Zreturn_value�exitr%r%r%r&�<module>sx��


	


W]27G
r






Youez - 2016 - github.com/yon3zu
LinuXploit