%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core18/current/usr/lib/python3/dist-packages/cloudinit/cmd/__pycache__/
Upload File :
Create Path :
Current File : //snap/core18/current/usr/lib/python3/dist-packages/cloudinit/cmd/__pycache__/main.cpython-36.pyc

3

�Ad���@sNddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZe	j�ddl
mZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZmZmZm Z ddlm!Z!ddl"m#Z#ddlm$Z$ddl%m&Z&dZ'dZ(eeed�Z)ej*�Z+dIdd�Z,dJdd�Z-dd�Z.d d!�Z/ed"�d#d$�Z0d%d&�Z1dLd)d*�Z2dMee3e4fd,�d-d.�Z5d/d0�Z6d1d2�Z7d3d4�Z8d5d6�Z9d7d8�Z:d9d:�Z;dNd;d<�Z<ej=d=�d>d?�Z>d@dA�Z?dBdC�Z@dOdDdE�ZAeBdFk�rJdGejCk�r0dHejCdG<eAejD�ZEeE�rJejFeE�dS)P�N)�Tuple)�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_hook)�read_cfg_pathszOCloud-init v. {version} running '{action}' at {timestamp}. Up {uptime} seconds.zcloud_%s_modules)�instance�always�once�cCs^|rtjjd|�tjjdd�tjjd�tjtjd�tjjdd�tjjd�dS)Nz%s
�-�<�
)�file)�sys�stderr�write�	traceback�	print_exc)�msg�r'�4/usr/lib/python3/dist-packages/cloudinit/cmd/main.pyr%Lsr%cCs&|st|�}tjd|ddtd�|S)Nz%s
FT)Zconsoler"r)�welcome_formatrZ	multi_log�LOG)�actionr&r'r'r(�welcomeVsr,cCstjtj�tj�tj�|d�S)N)r
�uptimeZ	timestampr+)�WELCOME_MSG_TPL�formatr
�version_stringrr-Ztime_rfc2822)r+r'r'r(r)]s
r)cCs2g}|jr.x"|jD]}|jtjj|j��qW|S)N)�files�append�os�path�realpath�name)�argsZfn_cfgsZfhr'r'r(�extract_fnsfs
r8)�modscCsvt|}|j|�\}}t|�t|�}|dkrXd||f}tjjd|�tj|�gStjdt|�t|��|SdS)Nrz)No '%s' modules to run under section '%s'z%s
zRan %s modules with %s failures)�MOD_SECTION_TPLZrun_section�lenr!r"r#r*�debug)r9�action_nameZsectionZfull_section_name�	which_ran�failuresZtotal_attemptedr&r'r'r(�run_module_sectionss
r@cCs|jd�rtj|jd��dS)Nr)�getrZupdate_configuration)�cfgr'r'r(�apply_reporting_cfg�s
rC�cloud-config-url�urlcCs@tj|�}x |D]}||kr|||fSqWtd||f��dS)Nz!No keys (%s) found in string '%s')rZkeyval_str_to_dict�KeyError)�cmdline�names�data�keyr'r'r(�parse_cmdline_url�s


rKT)�returncCs |dkrtj�}yt|�\}}Wntk
r:tjdfSX|jd�pN|jd�}|r�tjj	|�r�|r�d||f}tj
}|r�tj}nd||f}tj}||fS|ddd	d
�}|s�|r�tj}d|d<ntj}d
|d<d}	d}
y�tj
f|�}d}|j��r�d	}
t|tj��rLy|t|jt|
�d��7}Wntk
�r8YnX|j|
��s^d}
n|jj|
��s^d}
|
�rz|dk�r�tjd�n0|dk�r�tj}ntj
}|d|�dt|
���fSn|d||jffS||j}	Wn0tjk
�r�}z|d||ffSd}~XnXtj||	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.�
�T)rEZtimeoutZretries�stream�Zsec_betweeng�������?s
#cloud-config�)Z
chunk_sizeFrEz�DEPRECATED: `url` kernel command line key is deprecated for providing cloud-config via URL. Please use `cloud-config-url` kernel command line parameter insteadzcloud-config-urlz
contents of 'z' did not start with z$url '%s' returned code %s. Ignoring.zretrieving url '%s' failed: %si�)�modez*wrote cloud-config data from %s='%s' to %s)rZget_cmdlinerKrF�logging�DEBUG�
startswithr3r4�exists�INFO�WARNrZread_file_or_url�ok�
isinstanceZUrlResponse�nextZiter_contentr;�
StopIteration�contentsr*�warning�str�codeZUrlError�
write_file)r4�networkrGZcmdline_namerEZ
path_is_local�m�level�kwargsrI�headerZrespZsniffed_contentZis_cloud_cfg�er'r'r(�attempt_cmdline_url�sv





ricCs�dtjjtjjf}tjj|jjd�d�}tjj	|�rlt
|�j�}||kr�tj
d�|jd�tj||�n*tjj	|jjd��r�tjd�tj||�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�minorr3r4�join�paths�	get_cpathrW�open�readr*r<�purge_cacherrb�
get_ipath_cur�info)�initZcurrent_python_versionZpython_version_pathZcached_python_versionr'r'r(�$purge_cache_on_python_version_change�s

rvcCstj|jd�rdS|jS)NZdisable_network_activationF)r�get_cfg_option_boolrB�local)rur7r'r'r(�_should_bring_up_interfacessryc-Cs�tjtjg}|jrtjg}ttjjdtd�|jd�g}|jsJt	|�}nt	d|�}t
j||jd�}|j
t|��d}d}y.|jtjdf�tj�tj|j|�\}}Wn<tk
r�d}tjt|�t|�|jtj|f�YnX|j�rtjd�tj�tj|j�t|j�t||d	�x|D]\}	}tj |	|��q*Wy|j!�Wn"tk
�rrtjtd
�YnX|j"}
t#|�|j�r�tj$ntj%}|tj%k�r�d}t&j'j(dt)j*��nZd
}tj+|jdd�}
|
�r�tjd�d}n(|
j,d�}tjj-|��rtjd|�d}|j.�t/||�}yB|j0|d�|tj%k�r`|j1j2|k�r`tjd||j1�dgfSWn�tj3k
�r�|tj$k�r�tjd�ntjtd�|j4�s�|j5|d�tjd|�|tj$k�r�dgfSddgfSntjd|�YnXt6|�|j7�}tjd||||j8��|tj$k�r,t9|ddd�|j5|d�|tj$k�r||j1j2|k�rltjd||j1�|j1gfStjd ||j1�|j:�|j;�t9|d!d"d�y2|j<�j=d#|j>t?gt?d$�\}}|�s�|j>t@�Wn*tk
�r�tjtd%�|j1d%gfSXtjj-|j"j,d&���r"tA|jddd'd(�n
tjd)�t|j�tB|t|�|jd*�}yR|}|}tjC|j|�\}}||k�sz||k�r�tjDd+||�tj|j|�\}}Wn"tk
�r�tjtd,�YnXtj|j�|jE�tF|j1|jd-�|j1tG|||�fS).Nz%s.dz91_kernel_cmdline_url.cfg)r4rcz%s-local)�ds_deps�reporterzClosing stdin.z#Failed to setup output redirection!z@Logging being reset, this logger may no longer be active shortly)r&z0Failed to initialize, likely bad things to come!�trustz%s
ZcheckZmanual_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=%srxrc)�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)r7ZfreqzConsuming user data failed!Zuserdata_rawT)�config�strictZlog_detailsZlog_deprecationsz2Skipping user-data validation. No user-data found.)r{z#Stdout, stderr changing to (%s, %s)z'Failed to re-adjust output redirection!)�
datasourcerB)Hr	ZDEP_FILESYSTEMZDEP_NETWORKrxrir3r4rmrr)r
�Initr{�read_cfgr8r2rTrUr�close_stdin�fixup_outputrB�	Exception�logexcr*r%rYr<�resetLogging�setupLoggingrCr,rZ
initializernrvZDSMODE_LOCALZDSMODE_NETWORKr!r"r#rZ
debug_inforwrsrWrrry�fetchr�Zdsmode�DataSourceNotFoundException�forceZapply_network_config�_maybe_persist_instance_dataZ
instancifyZis_new_instance�_maybe_set_hostnameZsetup_datasource�update�cloudifyZrunr�rrrrZget_output_cfgr_Zactivate_datasource�di_report_warnr@)r6r7ZdepsZ
early_logs�w_msgruZoutfmtZerrfmtr&ZlvlZpath_helperrSr}ZmcfgZmfileZbring_up_interfacesZiidZranZ_resultsr9Zoutfmt_origZerrfmt_origr'r'r(�	main_init#s










r�cCs�d|krtjd�dS|d}|dkr4tjd�dSt|t�sNtjd|�dS|jd�}|dkrntjd�dSt|t�s�tjd|�dS|jjd�d	}|j	t
j�r�|tt
j�d�}ntjd
||�||kr�tjd|||�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�.rOz1Datasource '%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<r[�dictr_rA�list�
__module__�
rpartitionrVr	Z	DS_PREFIXr;rZshow_warningr`)r�rBZdicfgr��modnamer'r'r(r�sB





r�cCs.|j}td||f�}tjg|jd�}|jt|��y|jdd�Wn>tj	k
r�d|}t
jt|�t
|�|js~|gSYnXt|�t|t|�|jd�}y$tjd�t
j�t
j|j|�Wn tk
r�t
jtd�YnX|j�rtjd	�tj�tj|j�t|j�t||d
�t|||�S)Nz%s:%s)rzr{r|)r}zGCan not apply stage %s, no datasource found! Likely bad things to come!)r{z
Closing stdinz#Failed to setup output redirection!z@Logging being reset, this logger may no longer be active shortly)r&)rSr)r
r�r{r�r8r�r	r�rr�r*r%r�r�rr<r�r�rBr�rTr�r�rCr,r@)r=r7r6r�rur&r9r'r'r(�main_modules4s:

r�c
Cs�|j}t|�}tjg|jd�}|jt|��y|jdd�Wn4tj	k
rpt
jtd�t
d�|jsldSYnXt|�t|t|�|jd�}|j}|r�tjd|�|j}|r�tjd|�tj|�}y$tjd	�t
j�t
j|jd�Wn"tk
�r
t
jtd
�YnX|j�r&tjd�tj�tj|j�t|j�t||d�|j|||�\}}	|	�rptj d
|�dS|�s�tj d|�dSdSdS)N)rzr{r|)r}z;Failed to fetch your datasource, likely bad things to come!rQ)r{zUsing passed in arguments %szUsing passed in frequency %sz
Closing stdinz#Failed to setup output redirection!z@Logging being reset, this logger may no longer be active shortly)r&zRan %s but it failed!zDid not run %s, does it exist?r)!r6r)r
r�r{r�r8r�r	r�rr�r*r%r�r�r�module_argsr<Z	frequency�FREQ_SHORT_NAMESrAr�r�rBr�rTr�r�rCr,Z
run_singler_)
r6r7�mod_namer�rur9Zmod_argsZmod_freqr>r?r'r'r(�main_singleksV	



r�cCs|dkrt�}|jd�}|dkr,tjjd�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}tj||f�|j\}	}
|dkr�|j	r�d}q�d}n |dkr�d|j
}ntd	|��d}||kr�td
j|���d}
|dk�rxL||||fD]}tj
|�q�Wn,ytjtj|��}
Wntk
�r*YnXgddd�}|
dk�rVdii}
d|
dd<x,|D]$}||
dk�r\|j�|
d|<�q\W|
d}||d<tj�||d<tj||
�tjtjj||�|dd�yR|
||�}|dk�r|\}}|dk	�rt|�|d<n|}dd�|D�||d<WnPtk
�rl}z2tjtd|�td|�t|�g||d<WYdd}~XnXtj�||d<d|d<tj||
�|dk�rg}x2|D]*}||d�r�|j||jdg���q�Wtj|d|d|d�i�tjtjj||�|dd�t||d�S)NrIz/run/cloud-initzstatus.jsonzresult.jsonru�
init-local�modulesz
modules-%szunknown name: %s�modules-init�modules-config�
modules-finalz'Invalid cloud init mode specified '{0}')�errors�start�finished�v1r�r~r�T)r�cSsg|]}t|��qSr')r`)�.0rhr'r'r(�
<listcomp>sz"status_wrapper.<locals>.<listcomp>r�zfailed stage %szfailed run of stage %sr�)r�r�)rur�r�r�r�)rur�)rror3r4�normpathrmrZensure_dirsr+rxrS�
ValueErrorr/Zdel_file�json�loadsZ	load_filer��copy�timerZ
write_jsonZsym_link�relpathr`r�r*r%�extendrAr;)r6r7Zdata_dZlink_drnZstatus_pathZstatus_linkZresult_pathZresult_link�_name�functorrSZmodes�status�fZ
nullstatusrdr�Zretr�r�rhr'r'r(�status_wrapper�s�







$

r�)rucCs6|jr2|jr2|jjd�}tjj|�s2|jjdd�dS)zCWrite instance-data.json file if absent and datasource is restored.Z
instance_dataF)Zwrite_cacheN)r�Zds_restoredrnZget_runpathr3r4rWZpersist_instance_data)ruZinstance_data_filer'r'r(r�%sr�cCsz|j�}tj|j|dd�\}}}|rvytjd|j|td�Wn8tjk
rt}ztjd||t	|��WYdd}~XnXdS)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_fqdnrBrZhandler*ZSetHostnameErrorr<r`)rur~rZcloudZhostnameZ_fqdn�_rhr'r'r(r�-sr�cCs tjjdjttj��d�dS)Nr)r!�stdoutr#rm�sortedr
ZFEATURES)r6r7r'r'r(�
main_featuresDsr�c#Csv|s
tj}tj|jd�d�}|jddddtj�dd�|jd	d
ddd
tjd�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,dcd.�|j	d&tfd%�|jd/d0d!�}|jd1d2d*d3dd4�|jd5d*d6dttj��d7�|jd8dd9dd4�|jd:d;d<d=d>�|j	d/tfd%�|jd?d@d!�}|jtjtjd!�}tj|�|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'j(�t)j*�|ddk�r�t+}d}d} |dk�r�|j,�r�de\}}!ndf\}}!nZ|d&k�r�d[|j-d\|j-}}!n8|d/k�rd]|j.d^|j.}}!|j/} n|}d_|}!d} t0j1||!| d`�|_2|j2�$t3j4t5j&da|d|||fdb�}"WdQRXt6j7�|"S)gNr)�progz	--versionz-vr
z	%(prog)s z'Show program's version number and exit.)r+r
�helpz--filez-fr2r1z(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�Truz2Initialize 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��final)r+r�r��choicesZsinglezRun a single module.z--namez-nzModule name to run.)r+r��requiredz--frequencyzModule frequency for this run.)r+r�r�r�z--reportzEnable reporting.r��*Zargumentz0Any additional arguments to pass to this module.)�nargs�metavarr�Zqueryz;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)r7�
init-local�searching for local datasources�init-network�!searching for network datasourcesz
modules-%szrunning modules for %sz	single/%szrunning single module %szrunning 'cloud-init %s')Zreporting_enabledzcloud-init mode '%s')Zlogfuncr&Z
get_uptime�funcr7)rur�r�)r�ru)r�r�)r�r�)8r!�argv�argparse�ArgumentParser�pop�add_argumentr
r0ZFileTypeZ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<rTZsetupBasicLoggingrZattach_handlersr�rxrSr6ZreportrZReportEventStackr{rZlog_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�r7r6r�ZrnameZ	report_onZrdescZretvalr'r'r(�mainHs@

























r��__main__ZTZz:/etc/localtime)r)N�rDrE)r�)TN)NN)N)Gr�r�r3r!r�r$ZtypingrZ	cloudinitrZcloudinit.config.modulesrZ
patch_loggingr�rrrTrrr	r
rrr
rrZcloudinit.reportingrZcloudinit.settingsrrrrrZcloudinit.configrrZcloudinit.cmd.develrr.r:r�Z	getLoggerr*r%r,r)r8r@rCrK�intr`rirvryr�r�r�r�r�r�r�r�r�r��__name__�environr�Zreturn_value�exitr'r'r'r(�<module>sx


	

l`27G
s





Zerion Mini Shell 1.0