HEX
Server: nginx/1.24.0
System: Linux webserver 6.8.0-87-generic #88-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 09:28:41 UTC 2025 x86_64
User: wpuser (1002)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/cmd/__pycache__/main.cpython-312.pyc
�

쑛h�����ddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZddlm
Z
mZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZmZddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/e0Z1dZ2dZ3e,e-e.d�Z4ddddd �Z5ejle7�Z8Gd!�d"ejr�Z:dCd#�Z;dDd$�Z<d%�Z=ej|d&�e8j~fd'e
e0gdffd(��Z@d)�ZAd*e$fd+�ZBd,�ZCdEd-�ZDdFd.e	eEe0ffd/�ZFd0�ZGd1�ZHd2eee0eIfd.e	eJe1ffd3�ZKd4eej�d.e	eJe1ffd5�ZMd6�ZNd7�ZOd8�ZPd9�ZQd:�ZRd;ej�fd<�ZTd=�ZUd>�ZVdDd?�ZWd@�ZXdA�ZYe7dBk(r#ej�eWej���yy)G�N)�Optional�Tuple�Callable�Union)�features�netinfo)�signal_handler)�sources)�socket)�stages)�
url_helper)�util)�performance)�version)�warnings)�	reporting)�
atomic_helper)�	lifecycle)�handlers)�log_util�loggers)�read_cfg_paths)�cc_set_hostname)�Modules)�validate_cloudconfig_schema)�log_with_downgradable_level)�events)�PER_INSTANCE�
PER_ALWAYS�PER_ONCE�CLOUD_CONFIGzOCloud-init v. {version} running '{action}' at {timestamp}. Up {uptime} seconds.zcloud_%s_modules)�instance�always�oncezLocal Stagez
Network StagezConfig StagezFinal Stage)�
init-local�init�modules-config�
modules-finalc�&��eZdZd�fd�	Zd�Z�xZS)�SubcommandAwareArgumentParserc�2��||_t�|�	||�S)z>Override parse_args to store raw arguments for error handling.)�	_raw_args�super�
parse_args)�self�args�	namespace�	__class__s   ��4/usr/lib/python3/dist-packages/cloudinit/cmd/main.pyr.z(SubcommandAwareArgumentParser.parse_argsSs�������w�!�$�	�2�2�c��td|�d�tj��t|d�stjdd|_d}|j
r:|j
D]+}||jjdjvs�)|}n|rG|jjdj|}|jtj��n |jtj��tjd�y)	z=Override error method to show subcommand usage if applicable.zerror: �
��filer,�Nr�)�print�sys�stderr�hasattr�argvr,�_subparsers�_group_actions�choices�
print_help�exit)r/�message�
subcommand�arg�	subparsers     r3�errorz#SubcommandAwareArgumentParser.errorXs���
���y��#�#�*�*�5��t�[�)� �X�X�a�b�\�D�N��
��>�>��~�~�
���$�*�*�9�9�!�<�D�D�D�!$�J��
���(�(�7�7��:�B�B�:�N�I�� � ��Z�Z�
!�
�
�O�O����O�,�����r4)NN)�__name__�
__module__�__qualname__r.rI�
__classcell__)r2s@r3r*r*Rs
���3�
r4r*c��|r"tjjd|z�tjjd�tjjd�tjtj��tjjd�tjjd�y)N�%s
z<------------------------------------------------------------r6r7)r<r=�write�	traceback�	print_exc��msgs r3rRrRtsu��
��
�
����3��(��J�J���X���J�J���T��
���S�Z�Z�(��J�J���X���J�J���T�r4c�`�|st|�}tjd|zddt��|S)NrOFT)�consoler=�log)�welcome_formatr�	multi_log�LOG)�actionrTs  r3�welcomer\~s,����V�$�����v��~�u�T�s�K��Jr4c��tjtj�t	j
�t	j�|��S)N)r�uptime�	timestampr[)�WELCOME_MSG_TPL�formatr�version_stringrr^�time_rfc2822�r[s r3rXrX�s>���!�!��&�&�(��{�{�}��#�#�%��	"��r4�
Closing stdin�loggerc�d�tjtjj	��sk|d�ttj�5}tj|j	�tjj	��ddd�y|d�y#1swYyxYw)zj
    reopen stdin as /dev/null to ensure no side effects

    logger: a function for logging messages
    reNz"Not closing stdin, stdin is a tty.)�os�isattyr<�stdin�fileno�open�devnull�dup2)rf�fps  r3�close_stdinrp�sy���9�9�S�Y�Y�%�%�'�(����
�"�*�*�
�	5���G�G�B�I�I�K����!1�!1�!3�4�	5�	5�	�3�4�	5�	5�s
�AB&�&B/c��g}|jrI|jD]:}|jtjj	|j
���<|S�N)�files�appendrh�path�realpath�name)r0�fn_cfgs�fhs   r3�extract_fnsrz�sK���G��z�z��*�*�	6�B�
�N�N�2�7�7�+�+�B�G�G�4�5�	6��Nr4�modsc�N�t|z}|j|�\}}t|�t|�z}|dk(rBd|�d|�d�}tjjd|z�tj|�gStjdt|�t|��|S)NrzNo 'z ' modules to run under section '�'rOzRan %s modules with %s failures)�MOD_SECTION_TPL�run_section�lenr<r=rPrZ�debug)r{�action_name�section�full_section_name�	which_ran�failures�total_attemptedrTs        r3�run_module_sectionr��s���'�7�3�� �,�,�->�?��Y���)�n�s�8�}�4�O��!����
��	�
�
����3��(��	�	�#���	��	�	�-�s�9�~�s�8�}�	
��r4c�p�|jd�r%tj|jd��yy)Nr)�getr�update_configuration)�cfgs r3�apply_reporting_cfgr��s*��
�w�w�{���&�&�s�w�w�{�';�<�r4c�x�tj|�}|D]}||vs�|||fcStd|�d|�d���)Nz	No keys (z) found in string 'r})r�keyval_str_to_dict�KeyError)�cmdline�names�data�keys    r3�parse_cmdline_urlr��sH���"�"�7�+�D��"���$�;���S�	�>�!�"��'�5�I�
J�Jr4�returnc��|�tj�}	t|�\}}|j
d�}|rmtjj|�rN|r/d|�d|�d�}tj}|rtj
}||fSd|�d|�d�}tj}||fS|dd	d
d�}|s|rtj}d|d
<ntj
}d|d
<d}	d}
	tjd%i|��}d}|j�r�d
}
t|tj �r<	|t#|j%t'|
����z
}|j
|
�s d}
n|j*j
|
�sd}
|
r|dk(rgt-j.dddd
��S|dk(rtj}ntj}|d|�dt1|
���fS|d|�d|j2�d�fS||j*z}	tj6||	d �!�tjd"|�d#|�d$|��fS#t$rtj
dfcYSwxYw#t($rY��wxYw#tj4$r}|d|�d|��fcYd}~Sd}~wwxYw)&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://�/zfile 'zC' existed, possibly from local stage download of command line url 'z'. Not re-writing.zE' existed, possibly from previous boot download of command line url '�
r:T)�url�timeout�retries�streamr9�sec_betweeng�������?s
#cloud-configr4)�
chunk_sizeFr�z!The kernel command line key `url`z22.3zD Please use `cloud-config-url` kernel command line parameter instead��
deprecated�deprecated_version�
extra_message�skip_log�cloud-config-urlz
contents of 'z' did not start with zurl 'z' returned code z. Ignoring.zretrieving url 'z
' failed: i�)�modezwrote cloud-config data from z='z' to �)r�get_cmdliner�r��logging�DEBUG�
startswithrhru�exists�INFO�WARNr
�read_file_or_url�ok�
isinstance�UrlResponse�next�iter_contentr��
StopIteration�contentsr�	deprecate�str�code�UrlError�
write_file)ru�networkr��cmdline_namer��
path_is_local�m�level�kwargsr��header�resp�sniffed_content�is_cloud_cfg�es               r3�attempt_cmdline_urlr��s���&���"�"�$��D�-�g�6���c��N�N�#3�4�M��������-��AE�c�K�
��L�L�E���
�
���q�z���AE�c�K�
��L�L�E��q�z���R�A��
F�F��-����� !��}���
�
�� #��}���D�
�F�*D��*�*�4�V�4�����7�7�9��L��$�
� 6� 6�7��#�t��)�)�S��[�)�A�(��O�
'�1�1�&�9�#(�L��]�]�-�-�f�5�$����5�(�$�.�.�#F�+1�'@�!%��� �#5�5�#�L�L�E�#�L�L�E��#�C�5�(=�c�&�k�]�K����:=�t�y�y�I��
�����.��
	�O�O�D�$�U�+������d�	$����]�D��
�
�B�C�C�D��V%�����>���D��3��B�C�C��D�sg�H-�!AI�%'I�AI�8I�I�+I�-I�
I�	I�I�I�I�J�1	J�:J�Jc��dtjjtjjfz}tj
j
|jjd�d�}tj
j|�rXtj|�}||k7r=tjd�|jd�tj||�yytj
j|jj!d��rtj#d�tj||�y)	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.%dr�zpython-versionz-Python version change detected. Purging cacheT�obj_pklzMWriting python-version file. Cache compatibility status is currently unknown.N)r<�version_info�major�minorrhru�join�paths�	get_cpathr�r�load_text_filerZr��purge_cacher��
get_ipath_cur�info)r&�current_python_version�python_version_path�cached_python_versions    r3�$purge_cache_on_python_version_changer�7s��%�����������(����'�'�,�,��
�
���V�$�&6���
�w�w�~�~�)�*� $� 3� 3�4G� H��!�$:�:��I�I�E�F����T�"��O�O�/�1G�H�;�
�7�7�>�>�$�*�*�2�2�9�=�>��H�H�C�
�	
���+�-C�Dr4c�^�tj|jd�ry|jS)N�disable_network_activationF)r�get_cfg_option_boolr��local)r&r0s  r3�_should_bring_up_interfacesr�Us&��������*F�G���z�z�>�r4�
raw_configc�@�|sytj|j�dd�dk7ry	tj|�}t|t�sy
d|vrG|dD]?}|jd�xsi}|jd
d�}|s�-|jd�r�?y|jd�ry|jdi�jd�ry|jd�ryy#t
$r-}t
tdtjd|f��Yd}~y	d}~wwxYw)a�Determine if our cloud-config requires us to wait

    User data requires us to wait during cloud-init network phase if:
    - We have user data that is anything other than cloud-config
      - This can likely be further optimized in the future to include
        other user data types
    - cloud-config contains:
      - bootcmd
      - random_seed command
      - mounts
      - write_files with source
    )Fzno configuration foundN�*ztext/cloud-config)Tz non-cloud-config user data foundz24.4z'Unexpected failure parsing userdata: %s)rfr�requested_levelrTr0)Tz!failed to parse user data as yaml)Tz(parsed config not in cloud-config format�write_files�source�uri�)r�zfile:)Tz!write_files with source uri found�bootcmd)Tz
bootcmd found�random_seed�command)Tzrandom_seed command found�mounts)Tzmounts found)Fz8cloud-config does not contain network requiring elements)r�type_from_starts_with�strip�yaml�	safe_load�	ExceptionrrZr��WARNINGr��dictr�r�)r��parsed_yamlr��item�source_dict�
source_uris      r3�_should_wait_via_user_datar�[s"���.�	�&�&�z�'7�'7�'9�#�2�'>�?��	�8�
9��n�n�Z�0���k�4�(�?���#��
�.�	A�D��(�(�8�,�2��K�$�����3�J��:�#8�#8��#H�@�		A�
���y�!�$����}�b�)�-�-�i�8�0����x� �#�L��5�9�#���#�O�O�9���	
�9��9�s�C'�'	D�0#D�D�
datasourcec��|syt|j��\}}|rd|�d�fSt|j��\}}|rd|�d�fSt|j��\}}|rd|�d�fSdd|�d|�d	|��fS)
z�Determine if we should wait on network connectivity for cloud-init.

    We need to wait during the cloud-init network phase if:
    - We have no datasource
    - We have user data that may require network access
    )Tzno datasource foundTz
 in user dataz in vendor dataz in vendor data2Fzuser data: z, vendor data: z, vendor data2: )r��get_userdata_raw�get_vendordata_raw�get_vendordata2_raw)r��user_should_wait�user_reason�vendor_should_wait�
vendor_reason�vendor2_should_wait�vendor2_reasons       r3�_should_wait_on_networkr�s����*�$>��#�#�%�%�!��k����}�M�2�2�2�(B��%�%�'�)�%��
���
��o�6�6�6�*D��&�&�(�+�'������'�'7�8�8�8�	��+��'�)�?�+�+�,�
.��r4c����tjtjg}|jrtjg}t	t
jjdtzd�|j��g�|jrdnd}t|�}tj||j��}|jt|��d}d}	|js2t!�fd��t#j$|j&|�\}}n#t#j(|j&|�\}}|j8r)t.j9d	�t;j<�|js4t;j>|j&�tA|j&�tC||�
�t.jEdtjF�|��D]\}	}t.jI|	|��	|jK�|jL}
tO|�|jrtjPntjR}|tjRk(r�tTjVrgt
jjY|jLj[d
��s/t.j9d�|j\j_�d}t`jbjedtgjh�z�n�d}t#jj|j&dd�}
|
rt.j9d�d}nH|
jmd�}t
jjY|�rt.j9d|�d}|jo�tq||�}	|js|��|tjRk(r>|jtjv|k7r%t.j9d||jt�dgfSt|�|j��}t.j9d||||j���|tjPk(rt�|d d!�"�|j}|��|tjPk(r�tTjVrvt�|jt�\}}|rt.j9d#|�nEt.j9d$|�t#j�|jLj[d
�d%�|jtjv|k7r/t.j9d&||jt�|jtgfSt.j9d'||jt�|j��|j��t�|d(d)�"�	|j��j�d*|j�t�gt��+�\}}|s|j�t��|jLjmd-�}t
jjY|�rXtj�|�j�d.k7r6t�t�j�t#j�|��ddd/�0�nt.j9d1�tA|j&�t�|t|�|j�2�}	|}|}t#j(|j&|�\}}||k7s||k7r:t.j�d3||�t#j$|j&|�\}}t;j>|j&�|j��t�|jt|j&�5�|jtt�|||�fS#t*$rLd}t#j,t.|�t1|��j3t4j6|f�Y���wxYw#t*$rt#j,t.d�Y��/wxYw#tjx$r�|tjPk(rt.j9d�nt#j,t.d�|jzsH|j}|��t.j9d|�|tjPk(rdgfcYSddgfcYSt.j9d|�Y���wxYw#t*$r,t#j,t.d,�|jtd,gfcYSwxYw#t*$rt#j,t.d4�Y��wxYw)6Nz%s.dz91_kernel_cmdline_url.cfg)rur�r%r&��ds_deps�reporterc�F���jtj|f�Srr)rtr�r�)rT�
early_logss �r3�<lambda>zmain_init.<locals>.<lambda>�s���J�$5�$5�w�}�}�c�6J�$K�r4�#Failed to setup output redirection!�@Logging being reset, this logger may no longer be active shortlyrS�!PID [%s] started cloud-init '%s'.z0Failed to initialize, likely bad things to come!z
.skip-networkz4Will wait for network connectivity before continuing�trustrO�check�manual_cache_cleanFz"manual cache clean set from config�manual_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!)�bring_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=%sr�r�)�stage�retry_stagezTNetwork connectivity determined necessary for cloud-init's network stage. Reason: %szVNetwork connectivity determined unnecessary for cloud-init's network stage. Reason: %sr�z.[%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)r0�freqzConsuming user data failed!�cloud_configrT)�config�strict�log_details�log_deprecationsz2Skipping user-data validation. No user-data found.�rz#Stdout, stderr changing to (%s, %s)z'Failed to re-adjust output redirection!)r�r�)Wr
�DEP_FILESYSTEM�DEP_NETWORKr�r�rhrur�r!rXr�Initr�read_cfgrz�skip_log_setuprpr�fixup_outputr��get_output_cfgr��logexcrZrRrtr�r�r�r�
reset_logging�
setup_loggingr�r\r��getppidrW�
initializer�r��DSMODE_LOCAL�DSMODE_NETWORKr�MANUAL_NETWORK_WAITr��get_runpath�distro�wait_for_networkr<r=rPr�
debug_infor�r�r�r��fetchr��dsmode�DataSourceNotFoundException�force�apply_network_config�_maybe_persist_instance_data�
instancify�is_new_instance�_maybe_set_hostnamerr��setup_datasource�update�cloudify�runrrr�stat�st_sizerr�r�r�r�warning�activate_datasource�di_report_warnr�)rwr0�deps�bootstage_name�w_msgr&�outfmt�errfmtrT�lvl�path_helperr�r�mcfg�mfile�bring_up_interfaces�iid�should_wait�reason�ran�_results�cloud_cfg_pathr{�outfmt_orig�errfmt_origrs                         @r3�	main_initrS�sw����"�"�G�$7�$7�8�D��z�z��&�&�'��	��������%�'B���
�
�N�		
��J�,&*�Z�Z�\�V�N��>�*�E��;�;�t�d�m�m�<�D��M�M�+�d�#�$�
�F�
�F�
/��"�"��K�L�!�.�.�t�x�x��>�N�F�F�!�0�0����4�@�N�F�F��z�z��	�	�N�	
�	����������d�h�h�'��D�H�H�%�
�D�e���H�H�
0�"�*�*�,��O�����S�����S���M������*�*�K�(��.�#'�:�:�7���7�3I�3I�D��w�%�%�%��'�'�������J�J�"�"�?�3�1
�
�I�I�L�M��K�K�(�(�*����
�
����7�#5�#5�#7�8�9����'�'����2F��N����I�I�:�;��H��-�-�.C�D�E��w�w�~�~�e�$��	�	�D�e�L�"������6�d�D�A����
�
�H�
�%��7�)�)�)�d�o�o�.D�.D��.L��I�I�;�����
�
�"�:��.!��&�
�/�/�
�C��I�I�?����������w�#�#�#�	�D��Y�G����':��;��w�#�#�#��'�'�"9�$�/�/�"J��K����	�	�=����	�	�=���
����
�
� 6� 6�� G��L��?�?�!�!�T�)��I�I�@�����
�
�O�O�R�(�(��I�I�H�����
�	�����K�K�M���J�<L�M�B��-�-�/�-�-��������	.�
���h��
���j�)��Z�Z�-�-�n�=�N�	�w�w�~�~�n�%�"�'�'�.�*A�*I�*I�Q�*N�#��>�>�$�"5�"5�n�"E�F���!�		
�	�	�	�F�G�����!��4��T�*�T�]�]�C�D�D������.�.�t�x�x��>�����&� �K�6�$9��K�K�=�v�v�N�#�0�0����4�@��V�V����$�(�(�#�	�����d�o�o�4�8�8�<�
�O�O�/��d�D�A�B�B��Y�/�3�����C����#�����7�<�<��-�.�	/��8�M����C�K�L�M��T�.�.���7�'�'�'��I�I�1�2��K�K��O�
��z�z��%�%�/B�%�C��I�I�7��>��w�+�+�+��b�z�!��>�?�@�@��I�I�D�d�
�%��@�B����C�6�7����"?�!@�A�A�B��8�D����C�B�C�D�sl�A!_�`�;A"a�Ad�2A+e�A`�`�#a�a�B!d�+d�2d�d�2e�e�#e.�-e.c��d|vrtjd�y|d}|�tjd�yt|t�stj	d|�y|jd�}|�tj	d�yt|t�stj	d|�y|jjd�d	}|jtj�r|ttj�d}ntj	d
||�||vrtjd|||�ytjd||t|��
�y)N�	di_reportzno di_report found in config.zdi_report was None.z%di_report config not a dictionary: %s�datasource_listz(no 'datasource_list' found in di_report.z(di_report/datasource_list not a list: %s�.r:z1Datasource '%s' came from unexpected module '%s'.z:used datasource '%s' from '%s' was in di_report's list: %s�dsid_missing_source)r��dslist)rZr�r�r�r>r��listrK�
rpartitionr�r
�	DS_PREFIXr�r�show_warningr�)r�r��dicfgrY�modnames     r3r@r@�s7���#���	�	�1�2�����E��}�	�	�	�'�(���e�T�"����;�U�C��
�Y�Y�(�
)�F�
�~����>�?��
���
%����>��G���#�#�.�.�s�3�A�6�G����'�+�+�,��#�g�/�/�0�2�3�����?���	
��&���	�	�H����		
�	�����s�7�3�v�;�r4c�H�|j}|�d|��}t|�}tjg|j��}|jt
|��	|jd��t|�t!|t
|�|j��}	|j"s*t%�tj&|j(|�|j,r)tj-d�t/j0�|j"s4t/j2|j(�t5|j(�t7||�	�tj9d
t;j<�|�|dk(rt?j@dd
d��tC|||�S#tj$r?d|z}tjt|�t|�|js|gcYSY���wxYw#t*$rtjtd�Y��PwxYw)N�:rrrzGCan not apply stage %s, no datasource found! Likely bad things to come!rrr	rSr
r&z
`--mode init`�24.1�Use `cloud-init init` instead.)r�r�r�)"r�rXrrrrrzr/r
r1rr#rZrRr2r4rr rpr!r�r�r�rr$r%r�r\r�rhr&rr�r�)r�r0rwrBrCr&rTr{s        r3�main_modulesrd�s����9�9�D�!,�T�2�N��>�*�E��;�;�r�D�M�M�:�D��M�M�+�d�#�$���
�
�G�
�$�!��&��4��T�*�T�]�]�C�D�@��"�"��M����d�h�h��-��z�z��	�	�N�	
�	����������d�h�h�'��D�H�H�%��D�e���H�H�
0�"�*�*�,��O��v�~����&�%�:�	
��d�D�$�/�/��U�.�.�	�
� $�
%�	�	
���C����#���z�z��7�N��	��$�@����C�>�?�@�s%�F%�6G:�%AG7�6G7�:#H!� H!c��|j}t|�}tjg|j��}|jt
|��	|jd��t|�t!|t
|�|j��}|j"}|rtj%d|�|j&}|r+tj%d|�t(j+|�}	t-�tj.|j0d�|j$r)tj%d
�t5j6�t5j8|j0�t;|j0�t=||��|j?|||�\}}	|	rtjAd|�y|stjAd
|�yy#tj$r7tjtd�td�|jsYyY���wxYw#t2$rtjtd	�Y��2wxYw)Nrrrz;Failed to fetch your datasource, likely bad things to come!r9rzUsing passed in arguments %szUsing passed in frequency %srr	rSzRan %s but it failed!zDid not run %s, does it exist?r)!rwrXrrrrrzr/r
r1rr#rZrRr2r4r�module_argsr��	frequency�FREQ_SHORT_NAMESr�rpr!r�r�rr$r%r�r\�
run_singler>)
rwr0�mod_namerCr&r{�mod_args�mod_freqr�r�s
          r3�main_singlerm&s����y�y�H��4� �E��;�;�r�D�M�M�:�D��M�M�+�d�#�$�
��
�
�G�
�$�!��&��4��T�*�T�]�]�C�D����H���	�	�0�(�;��~�~�H���	�	�0�(�;�#�'�'��1��@��
����$�(�(�D�)��z�z��	�	�N�	
�	�������$�(�(�#�����!��D�e��!�O�O�H�h��I��Y������+�X�6��
����4�h�?����e�.�.��	
����N�	
�	�I�	
��z�z�����4�@����C�>�?�@�s%�G�0*H&�AH#�"H#�&#I
�I
c
��t�}|jd�}tjj	|j
�}tjj
|d�}tjj
|d�}tjj
|d�}tjj
|d�}tj�}	tj||f�|j\}
}|dk(r|jrd}n&d}n#|dk(rd|jz}ntd|z��|tvrtd	j!|���giddd
�}
dd|
j#�|
j#�|
j#�|
j#�d�i}|dk(r!||||fD]}tj$|��n)	t'j(tj*|��}||dvr|
j#�|d|<|d}||d
<||dr%||dst.j1dt|�t3tj4��||d<t7t9d�|	j:��}|j=�}t?j@||�tjBtjjE||�|d��	|||�}|dvr|\}}|�tG|�|d<n|}||djI|D�cgc]
}tG|���c}�t3tj4��||d<d|d
<|j=�}|jU�|jW�D];}||vr'tYt[||||z��||d|<�.||||d|<�=t?j@||�|dk(r�g}|jW�D]O}t]||t^�s�||jad�s�,|jI||jadg���Qt?j@|d|d|d�i�tjBtjjE||�|d��tc||d�S#t,$rY���wxYwcc}w#t,$rO}t.jKd|�tMd|z�||djOtG|��Yd}~���d}~wtP$ri}|jRrRt.jKd|�tMd|z�||djOdtG|jR��d��Yd}~��Rd}~wwxYw#t3tj4��||d<d|d
<|j=�}|jU�|jW�D];}||vr'tYt[||||z��||d|<�.||||d|<�=t?j@||�wxYw)Nr�zstatus.jsonzresult.jsonr&r%�modules�
modules-%szunknown name: %sz'Invalid cloud init mode specified '{0}')�errors�recoverable_errors�start�finished�v1)r�r&r%r'r(rrsrtz=Unexpected start time found for %s. Was this stage restarted?c�6�t|tj�Srr)r�r�LogExporter)�hs r3rz status_wrapper.<locals>.<lambda>�s��j��G�$7�$7�8�r4T)r2)r&r%r�rqzfailed stage %szfailed run of stage %sz	sys.exit(z) calledrrr()r�rq)2rr�rhru�normpath�run_dirr�r��	getLoggerr�ensure_dirsr[r�r��
ValueError�
STAGE_NAMEra�copy�del_file�json�loadsr�r�rZr>�floatr^r��filterr�export_logsr�
write_json�sym_link�relpathr��extend�	exceptionrRrt�
SystemExitr��
clean_logs�keysrZ�setr�r�r�r�)rwr0r��data_d�link_d�status_path�status_link�result_path�result_link�root_logger�_name�functorr��
nullstatus�status�fru�handler�preexisting_recoverable_errors�retr�rqr��new_recoverable_errorsr�r�s                          r3�status_wrapperr�ls����E�
�_�_�V�
$�F�
�W�W�
�
�e�m�m�
,�F��'�'�,�,�v�}�5�K��'�'�,�,�v�}�5�K��'�'�,�,�v�}�5�K��'�'�,�,�v�}�5�K��#�#�%�K������	
���{�{��U�G��v�~��:�:��D��D�	
��	��d�i�i�'���+�d�2�3�3��:���5�<�<�T�B�
�	
�
� ���	�J�	
���O�O�%�$�/�/�+�(�o�o�/�'�_�_�.�
��F��|���{�K��E�	�A��M�M�!��	�	��Z�Z�� 3� 3�K� @�A�F��6�$�<��'�_�_�.��t��T��	���B��B�w�K�	�$�x����D��*�!5����K��t��	
�
�d�k�k�m�,�B�t�H�W����8�+�:N�:N�	
��G�
&-�%8�%8�%:�"����[�&�1��M�M�
������V�,�k���16��d�D�!���)�)�#&� �Z���%�#&�z�?��<� ��F�
�4����!�!�6�":�a�3�q�6�":�;�( %�T�[�[�]�3��4������7��")�!4�!4�!6������)�.�.�0�	�C��4�4�6:��6�s�;�0��5�6��7��4��-�.�s�3�7M��7��4��-�.�s�3�	�	� � ��f�5����������	7�A��"�Q�%��&�2�a�5�9�9�X�+>��
�
�b��e�i�i��"�5�6�	7�	� � ��
�"�\�"2�f�E�F�	
�	
�
�
��G�G�O�O�K��0�+�T�	
��r�$�x��!�"�"��A�	��	��N#;���*��
�
�'��.��*�T�1�2�
�4����!�!�#�a�&�)�)���	I�
�6�6�
�M�M�+�T�2��.��5�6��t�H�X��%�%�	�#�a�f�f�+��h�&G�H���	I�� %�T�[�[�]�3��4������7��")�!4�!4�!6������)�.�.�0�	�C��4�4�6:��6�s�;�0��5�6��7��4��-�.�s�3�7M��7��4��-�.�s�3�	�	� � ��f�5�sc�(R4�':S	�!S�3S	�4	S�S�S	�		V�AT�V�V�(AV�V�V�V�B.Yr&c���|jre|jrX|jjd�}tj
j
|�s|jjd��yyyy)zCWrite instance-data.json file if absent and datasource is restored.�
instance_dataF)�write_cacheN)r��ds_restoredr�r+rhrur��persist_instance_data)r&�instance_data_files  r3r4r4sX�����4�+�+�!�Z�Z�3�3�O�D���w�w�~�~�0�1��O�O�1�1�e�1�D�2�,�r4c	�>�|j�}tj|j|d��\}}}|r$	t	j
d|j|d�yy#tj$r+}tjd||t|��Yd}~yd}~wwxYw)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)�
metadata_only�set_hostnameNzGFailed setting hostname in %s stage. Will retry in %s stage. Error: %s.)
r:r�get_hostname_fqdnr�r�handle�SetHostnameErrorrZr�r�)r&rr�cloud�hostname�_fqdn�_r�s        r3r7r7s���
�M�M�O�E��1�1����%�t���X�u�a��		��"�"�>�4�8�8�U�D�I����/�/�	��I�I�1����A��
�
��	�s�"A�B�1!B�Bc��tjjdjt	t
j��dz�y)Nr6)r<�stdoutrPr��sortedr�FEATURES)rwr0s  r3�
main_featuresr�&s-���J�J���T�Y�Y�v�g�&6�&6�7�8�4�?�@r4c
�V	�tj�|stj}t	|jd���}|j
ddddtj�zd��|j
d	d
ddd
��|j
ddddd
��|j
ddddd
��|jd��|jdd��}|jdd��}|j
dddd d
��|j
d!d"d#d$d%tjd&��'�|jdtf�(�|jd)d*��}tj d+d,d-d.�/�j"}|j
d0d1d2d3|��d4d5�6�|j
d!d"d#d$d%tjd&��'�|jd)t$f�(�|jd7d8��}|j
d9d:d2d;d.�<�|j
d=d2d>d
t't(j+���?�|j
d@ddAd
�<�|j
dBdCdDdE�F�|j
d!d"d#d$d%tjd&��'�|jd7t,f�(�|jdGdH��}|jdIdJ��}|jdIt.f�(�|jdKdL��}	|jdMdN��}
|jdOdP��}|jdQdR��}|jdSdT��}
|jdUdV��}|�rt1dW�|D�d�}|dKk(rddXlm}||	�n�|dMk(rddXlm}||
�n�|dOk(r&ddYlm}m}||�Z�|jdO|f�(�n�|dQk(r%dd[lm}m}||�|jdQ|f�(�n�|dGk(r%dd\l m}m!}||�|jd]|f�(�ne|dUk(r%dd^l"m}m#}||�|jdU|f�(�n;|dSk(r6dd_l$m}m%}||
�|
jdS|f�(�n|jMd`�|jO|�a�}tQ|dbd
�|jRstU||�StS|�S)cNr)�progz	--versionz-vrz	%(prog)s z'Show program's version number and exit.)r[r�helpz--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).r2)r[r��destr�z--all-stages�
all_stageszsRun cloud-init's stages under a single process using a syncronization protocol. This is not intended for CLI usage.)r�r[r�r�r�SubcommandsrF)�titler�r&z2Initialize cloud-init and perform initial modules.)r��--localz-lz+Start in local mode (default: %(default)s).z--filez-frtrsz(Use additional yaml configuration files.�rb)r[r�r��typerdroz1Activate modules using a given configuration key.z`init`rbrcTr�z--modez-m�storez9Module configuration name to use (default: %(default)s). r)r&r�final)r[r�r�rB�singlezRun a single module.z--namez-nzModule name to run.)r[r��requiredz--frequencyzModule frequency for this run.)r[r�r�rBz--reportzEnable reporting.rf�*�argumentz0Any additional arguments to pass to this module.)�nargs�metavarr��queryz;Query standardized instance metadata from the command line.rzList defined features.�analyzez-Devel tool: Analyze cloud-init logs and data.�develzRun development tools.zcollect-logsz*Collect and tar all cloud-init debug info.�cleanz3Remove logs and artifacts so cloud-init can re-run.r�z/Report cloud-init status or wait on completion.�schemaz-Validate cloud-config files using jsonschema.c3�DK�|]}|jd�r�|���y�w)�-N)r�)�.0�posargs  r3�	<genexpr>zmain.<locals>.<genexpr>�s����J��6�3D�3D�S�3I�V�J�s� � )�
get_parser)r��handle_collect_logs_args)�parser)r��handle_clean_args)r��handle_args�render)r��handle_schema_args)r��handle_status_argsza subcommand is required�r0r )+r�configure_root_loggerr<r?r*�pop�add_argumentrrb�set_defaults�add_subparsers�
add_parser�argparse�FileTyperSrr�rErdrZrhr�rmr�r��cloudinit.analyzer��cloudinit.cmd.devel.parser�cloudinit.cmd.devel.logsr��cloudinit.cmd.cleanr��cloudinit.cmd.queryr��cloudinit.config.schemar��cloudinit.cmd.statusr�rIr.�setattrr��sub_main)�	sysv_argsr��
subparsers�parser_init�
parser_mod�
extra_help�
parser_single�parser_query�parser_features�parser_analyze�parser_devel�parser_collect_logs�parser_clean�
parser_status�
parser_schemarF�analyze_parser�devel_parser�logs_parserr��clean_parserr��query_parser�handle_query_args�
schema_parserr��
status_parserr�r0s                             r3�mainr*s����!�!�#���H�H�	�
*�	�
�
�a�0@�
A�F��������w�5�5�7�8�
6���������
I���������
-����	�����
��
K���	������&��&�&�]��&�N�J��'�'��I�(��K�������
:����������
�
7�
�
�
�t�
$�
�����V�Y�$7��8��&�&��K�'��J��$�$��!�6��	�
�g����������|�
��+��
�������
�
7�
�
�
�t�
$�
�����I�|�#<��=��)�)��-�*��M�������
"���������
-���%�*�*�,�-��������
 ��	��������
?�	��������
�
7�
�
�
�t�
$�
�����x��&=��>��(�(��
J�)��L�
!�+�+��1�,��O�� � ��]�(C� �D��*�*��G�+��N��(�(��.�)��L�%�/�/��I�0����(�(��K�)��L��)�)��H�*��M��)�)��F�*��M���J�)�J��
�
���"�F�
�>�*�
�7�
"�M�
��&�
�>�
)�
�

�2�3��,�,�&�(@�A�
-�
��7�
"�
�

��&��%�%�g�7H�-I�%�J�
�7�
"�
�

��&��%�%�h�8I�-J�%�K�
�8�
#�
�

�-�(��&�&�x�9K�.L�&�M�
�8�
#�
�

�-�(��&�&�x�9K�.L�&�M����/�0����)��,�D��D�"�E�*��?�?���f�%�%��f��r4c���tjd�tjdddd�}tjd�|d�5|jddg�	�}d
|_t||�|_ddd�|d�5|jdg�	�}d|_t||�|_ddd�|d�5|jd
dg�	�}d|_t||�|_ddd�|d�5|jd
dg�	�}d|_t||�|_ddd�|jrLd}|jrd|j��}tjd|�d��tjd�ytjd�tjd�y#1swY��CxYw#1swY��xYw#1swY��xYw#1swY��xYw)z>Run all stages in a single process using an ordering protocol.z*Running cloud-init in single process mode.r�r�rr�zREADY=1r&r�r�FNTroz
--mode=configz--mode=finalz%a stage of cloud-init exited non-zerozfirst exception received: zSTATUS=Completed with failure, z2. Run 'cloud-init status --long' for more details.z
STOPPING=1r9zSTATUS=Completed)rZr�r�
SocketSync�	sd_notifyr.r r��systemd_exit_code�experienced_any_error�first_exception)r��syncr0rEs    r3r�r�s����H�H�
9�:����W�i��7�C�D����Y��	
�g��8�� � �v�y�&9� �:��#���!)�$��!7���8�
�i��8�� � �v�h� �/��"���!)�$��!7���8�
�h��8�� � �y�/�&B� �C��"���!)�$��!7���8�
�g��8�� � �y�.�&A� �B��"���!)�$��!7���8��!�!�9�����2�4�3G�3G�2H�I�G����-�g�Y�7)�
)�	
�	����&�����+�,�����&�[8�8��8�8��8�8��8�8�s0�-F9�,G�-G�-G�9G�G�G�G(c�H�	|j\}}dvr@tj|jrtjntj�n |jrtj�tj�d|k(sd|k(rd|jk7rt }d}d}|dk(r|j"rd\}}ncd\}}n]|dk(rd	|jzd
|jz}}n9|dk(r+d|j$zd
|j$z}}|j&}n	|}d|z}d}t)j*|||��|_|j,5t/j0d|�d��5||�}ddd�ddd�t3j4�d|k(rd|jk(rt7�}S#t$rH|j�tjjd�tjd�Y���wxYw#1swY��xYw#1swY��xYw)NzO
No Subcommand specified. Please specify a subcommand in addition to the optionr9)r&ror&roT)r%zsearching for local datasources)zinit-networkz!searching for network datasourcesrpzrunning modules for %sr�z	single/%szrunning single module %szrunning 'cloud-init %s'F)�reporting_enabledzcloud-init stage: 'r})r[�AttributeError�print_usager<r=rPrDr�setup_basic_loggingr�r�r�r�r	�attach_handlersr�r�r�rw�reportr�ReportEventStackrr�Timedr�flush_eventsr�)r0r�rwr��rname�	report_on�rdesc�retvals        r3r�r�Ws��
��+�+���w��&�&��#�#�!�Z�Z�G�M�M�W�_�_�	
�
����#�#�%��"�"�$�
��~�)�t�+��$�)�)�0C� ���E��I��v�~��:�:�L�L�E�5��L�E�5�
��	��4�9�9�$�$�t�y�y�0���
��	��$�)�)�#�&����2����K�K�	���)�D�0���	��+�+�
�u�	��D�M�
���)�
�
�
�!4�U�G�1�=�
>�	)��T�4�(�F�	)�)������D��V�t�y�y�0��V����M��K�������
�
���
&�	
�	�����
��x	)�	)��)�)�s6�F8�H�)
H�3H�8A
H	�H	�H	�H�H!�__main__)r�rr))r�r�)TN)\r�r�rhr<rQr�r��typingrrrr�	cloudinitrrr	r
rrr
rrrrrrrr�
cloudinit.logrr�cloudinit.cmd.develr�cloudinit.configr�cloudinit.config.modulesrr�r�cloudinit.lifecycler�cloudinit.reportingr�cloudinit.settingsrrr r!r��Reasonr`r~rhr~r{rJrZ�ArgumentParserr*rRr\rX�timedr�rprzr�r�r��intr�r�r��bytes�boolr��
DataSourcerrSr@rdrmr�rr4r7r�rr�r�rDr?r�r4r3�<module>r*s+����	�
����3�3�'�$���� ��!����#���+�.�,�,�?�;�&���

��(��%��
����� ��$�"�	�
��g����!���H�$;�$;��D�������?�#�03�	�	�5��#����-�5�$�5�
��W��&=�
K�j�U�3��8�_�j�ZE�<�8M���s�E�z�*�+�8M�
�4��<��8M�v"���+�+�,�"�
�4��<��"�JuC�p/�d>0�BC�LX#�vE�v�{�{�E��.A�o�d8'�vK�\�z���C�H�H�T�#�(�(�^��r4