HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/1784574/root/usr/lib/python3/dist-packages/cloudinit/cmd/__pycache__/
Upload File :
Current File : //proc/1784574/root/usr/lib/python3/dist-packages/cloudinit/cmd/__pycache__/query.cpython-311.pyc
�

܍~c�(����dZddlZddlZddlZddlmZddlmZmZddl	m
Z
mZddlm
Z
mZmZddlmZdZeje��Zdd	�Zd
�Zdefd�Zd
edededefd�Zd�Zd�Zedkre��dSdS)aTQuery standardized instance metadata provided to machine, returning a JSON
structure.

Some instance-data values may be binary on some platforms, such as userdata and
vendordata. Attempt to decompress and decode UTF-8 any binary values.

Any binary values in the instance metadata will be base64-encoded and prefixed
with "ci-b64:" in the output. userdata and, where applicable, vendordata may
be provided to the machine gzip-compressed (and therefore as binary data).
query will attempt to decompress these to a string before emitting the JSON
output; if this fails, they are treated as binary.
�N)�EACCES)�log�util)�addLogHandlerCLI�read_cfg_paths)�convert_jinja_instance_data�get_jinja_variable_alias�render_jinja_payload)�REDACT_SENSITIVE_VALUE�queryc	�Z�|s tjtt���}|�ddddd���|�dd	t
d
t
���d�������|�d
dddd���|�ddt
d���|�ddt
d���|�dt
dd���|�dddddd���|�dd t
d!d"�#��|S)$a#Build or extend an arg parser for query utility.

    @param parser: Optional existing ArgumentParser instance representing the
        query subcommand which will be extended to support the args of
        this utility.

    @returns: ArgumentParser with proper argument configuration.
    )�prog�descriptionz-dz--debug�
store_trueFz+Add verbose messages during template render)�action�default�helpz-iz--instance-dataz,Path to instance-data.json file. Default is �
instance_data)�typerz-lz--list-keyszBList query keys available at the provided instance-data <varname>.z-uz--user-datazHPath to user-data file. Default is /var/lib/cloud/instance/user-data.txtz-vz
--vendor-datazLPath to vendor-data file. Default is /var/lib/cloud/instance/vendor-data.txt�varname�?z�A dot-delimited specific variable to query from instance-data. For example: v1.local_hostname. If the value is not JSON serializable, it will be base64-encoded and will contain the prefix "ci-b64:". )r�nargsrz-az--all�dump_allz Dump all available instance-data)rr�destrz-fz--format�formatz�Optionally specify a custom output format string. Any instance-data variable can be specified between double-curly braces. For example -f "{{ v2.cloud_name }}")rrr)�argparse�ArgumentParser�NAME�__doc__�add_argument�strr�get_runpath��parsers �5/usr/lib/python3/dist-packages/cloudinit/cmd/query.py�
get_parserr&$s����I��(�d��H�H�H��
�������
:����������
�
?����+�+�O�<�<�
?�
?������������
�
�	�	�	������
�
5����������
�
7���������
��
3��
�
�
��������
�
/�
���������
�
�
<�
�
�
�
��M�c��tj|d���}	|�d��S#t$rtj|dd���cYSwxYw)z�Attempt to return a string of user-data from ud_file_path

    Attempt to decode or decompress if needed.
    If unable to decode the content, raw bytes will be returned.

    @returns: String of uncompressed userdata if possible, otherwise bytes.
    F)�decodezutf-8T)�quietr))r�	load_filer)�UnicodeDecodeError�decomp_gzip)�ud_file_path�bdatas  r%�
load_userdatar0|sm��
�N�<��6�6�6�E�A��|�|�G�$�$�$���A�A�A����U�4�@�@�@�@�@�@�A���s�-�!A�A�returnc��tj��}t��}|r|}ns|�d��}|dkrV|�d��}tj�|��r|}n!t�d||��|}n|}|r|}n%tj�|j	d��}|r|}	n%tj�|j	d��}		tj|��}
na#ttf$rM}|jtkrt�d|��nt�d|���d	}~wwxYwtj|
��}|dkr!d
t$�d|��|d<d
t$�d|	��|d
<n$t'|��|d<t'|	��|d
<|S)a�Return a dict of merged instance-data, vendordata and userdata.

    The dict will contain supplemental userdata and vendordata keys sourced
    from default user-data and vendor-data files.

    Non-root users will have redacted INSTANCE_JSON_FILE content and redacted
    vendordata and userdata values.

    :raise: IOError/OSError on absence of instance-data.json file or invalid
        access perms.
    rr�instance_data_sensitivez4Missing root-readable %s. Using redacted %s instead.z
user-data.txtzvendor-data.txtz$No read permission on '%s'. Try sudozMissing instance-data file: %sN�<z> file:�userdata�
vendordata)�os�getuidrr"�path�exists�LOG�warning�join�
instance_linkrr+�IOError�OSError�errnor�error�	load_jsonrr0)r�	user_data�vendor_data�uid�paths�instance_data_fn�redacted_data_fn�sensitive_data_fn�user_data_fn�vendor_data_fn�
instance_json�es            r%�_read_instance_datarO�s���
�)�+�+�C����E��0�(��� �,�,�_�=�=���!�8�8� %� 1� 1�2K� L� L���w�~�~�/�0�0�
4�#4� � ����J�%�$����
$4� � �/���J� ����w�|�|�E�$7��I�I���N�$�������e�&9�;L�M�M�����'7�8�8�
�
���W������7�f����I�I�<�>N�O�O�O�O��I�I�6�8H�I�I�I�
����������N�=�1�1�M�
�a�x�x�x�"�"�"��L�%
�
�j�!�!�

#�"�"��N�'
�
�l�#�#�
%2�,�$?�$?�
�j�!�&3�N�&C�&C�
�l�#��s�/D�E"�AE�E"�jinja_vars_without_aliases�jinja_vars_with_aliasesr�	list_keysc�j�d}|}|�d��D]�}	||}nQ#t$rD}|rd�||���}nd�|��}t|��|�d}~wwxYw||vr	||}n"|D]}	t	|	��|kr
||	}n� |r|dz
}||z
}��|S)a�Return the value of the dot-delimited varname path in instance-data

    Split a dot-delimited jinja variable name path into components, walk the
    path components into the instance_data and look up a matching jinja
    variable name or cloud-init's underscore-delimited key aliases.

    :raises: ValueError when varname represents an invalid key name or path or
        if list-keys is provided by varname isn't a dict object.
    ��.z*instance-data '{key_path}' has no '{leaf}')�leaf�key_pathz Undefined instance-data key '{}'N)�split�KeyErrorr�
ValueErrorr	)
rPrQrrR�walked_key_path�response�
key_path_partrN�msg�keys
          r%�(_find_instance_data_leaf_by_varname_pathr`�s���O�)�H� ���s�+�+�)�)�
�	)�'>�m�&L�#�#���	)�	)�	)��
I�B�I�I�&��J�����9�?�?��H�H���S�/�/�q�(�����	)�����H�$�$��
�.�H�H��
�
��+�C�0�0�M�A�A�'��}�H��E�B��	#��s�"�O��=�(����Os�&�
A4�?A/�/A4c��tt|jrtjntj��t
|j|j|j	|j
g��s<t�d��t���
��dS	t|j|j|j��}n#t$t&f$rYdSwxYw|j	rLd�	|j	���}t)|d||jrdnd���}|rt+|��d	SdSt-|��}|jrit-|d�
��}	t/|||j|j���}n9#t0t2f$r%}t�|��Yd}~dSd}~wwxYw|jrkt5|t6��s"t�d
|j��dSd�t;|�������}t5|t>��stAj!|��}t+|��d	S)z3Handle calls to 'cloud-init query' as a subcommand.zDExpected one of the options: --all, --format, --list-keys or varname�z## template: jinja
{fmt})�fmtzquery commandlineTF)�payload�
payload_fnr�debugr)�include_key_aliases)rPrQrrRNz+--list-keys provided but '%s' is not a dict�
)"rr;rfr�DEBUG�WARNING�anyrRrrrrBr&�
print_helprOrrDrEr?r@r
�printrr`rYrZ�
isinstance�dictr=�sorted�keysr!r�
json_dumps)�name�argsrrd�rendered_payloadr\rQrNs        r%�handle_argsrv�sm���S�t�z�B�#�)�)�s�{�C�C�C������d�k�4�=�I�J�J���	�	�
&�	
�	
�	
�	�����!�!�!��q��+������0@�
�
�
�
��
�W������q�q������{��-�4�4���4�E�E��/��*�'��*�/�$�$�%�	
�
�
���	��"�#�#�#��1��q�+�=�9�9�H��|�
�"=��t�#
�#
�#
��		�?�+3�(?����.�	���H�H���*�%�	�	�	��I�I�a�L�L�L��1�1�1�1�1�����	�����~�6��(�D�)�)�	��I�I�=�t�|�
�
�
��1��9�9�V�H�M�M�O�O�4�4�5�5���h��$�$�-��?�8�,�,��	�(�O�O�O��1s*� B8�8C
�C
�E)�)F�:F�Fc��t��}tjtt|�������dS)z,Tool to query specific instance-data values.N)r&�sys�exitrvr�
parse_argsr#s r%�mainr{4s7��
�\�\�F��H�[��v�0�0�2�2�
3�
3�4�4�4�4�4r'�__main__)N)rrr7rxrAr�	cloudinitrr�cloudinit.cmd.develrr�!cloudinit.handlers.jinja_templaterr	r
�cloudinit.sourcesrr�	getLoggerr;r&r0rorOr!�boolr`rvr{�__name__�r'r%�<module>r�s���
������	�	�	�	�
�
�
�
���������������@�@�@�@�@�@�@�@�����������
5�4�4�4�4�4����c�m�D����U�U�U�U�pA�A�A�>�$�>�>�>�>�B(� $�(�!�(��(��	(�(�(�(�V:
�:
�:
�z5�5�5��z����D�F�F�F�F�F��r'