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/sources/__pycache__/DataSourceWSL.cpython-312.pyc
�

쑛h�C�	��dZddlZddlZddlZddlmZddlmZmZmZddl	Z	ddl
mZmZm
Z
ddlmZddlmZddlmZej(e�Zd	Zd
ZdZdZd
ZdZdZdefd�Zdeefd�Z defd�Z!defd�Z"dedeefd�Z#deefd�Z$Gd�d�Z%dedee&fd�Z'dedede&fd�Z(dededeee%ee%ffd�Z)d ee%d!ee%deefd"�Z*d#efd$�Z+Gd%�d&ejX�Z-e-ej\ffgZ/d'�Z0y)(z?Datasource to support the Windows Subsystem for Linux platform.�N)�PurePath)�List�Optional�Tuple)�sources�subp�util)�Distro)�type_from_starts_with)�Pathsz/usr/bin/wslpathziid-datasource-wsl�%s.user-dataz
agent.yaml�	landscape�client�installation_request_id�returnc��tjtddg�\}}t|j��jS)zL
    Returns the name of the current WSL instance as seen from outside.
    z-am�/)r�WSLPATH_CMDr�rstrip�name)�
root_net_path�_s  �A/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceWSL.py�
instance_namer!s8���y�y�+�u�c�!:�;��M�1��M�(�(�*�+�0�0�0�c��d}d}g}tj�j�D]'}|d|k(s�||dvs�|j|d��)|S)z�
    Return a list of mount points of the Windows drives inside the current
    WSL instance, if drives are mounted, or an empty list otherwise
    �9pzaname=drvfs�fstype�opts�
mountpoint)r	�mounts�values�append)�FS_TYPE�OPTIONS_CONTAIN�mounted�mnts    r�mounted_win_drivesr(.s`��
�G�#�O��G��{�{�}�#�#�%�.���x�=�G�#��3�v�;�(F��N�N�3�|�,�-�.��Nrc��t�}|std��d}|D]N}||z}tj|tj�s�-t
j
d|�t|�cStddj|�z��)z?
    Returns the Linux path to the Windows host's cmd.exe.
    zWindows drives are not mounted.z%s/Windows/System32/cmd.exezFound cmd.exe at <%s>z,Couldn't find cmd.exe in any mount point: %sz, )	r(�IOError�os�access�X_OK�LOG�debugr�join)r!�	candidater'�cmds    r�cmd_executabler3>s���
 �
!�F���7�8�8�.�I�����#�o���y�y��b�g�g�&���	�	�)�3�/���}��
��6����6�9J�J��rc�(�t�}tjd|j�ddg�\}}|j�}|stjd��tjt
d|g�\}}t
|j��S)z�
    Finds the user's home directory path as a WSL path.

    raises: IOError when no mountpoint with cmd.exe is found
               ProcessExecutionError when either cmd.exe is unable to retrieve
               the user's home directory
    z/initz/Czecho %USERPROFILE%z4No output from cmd.exe to show the user profile dir.z-au)r3r�as_posixr�ProcessExecutionErrorrr)r2�homer�outs    r�	find_homer9Vs����
�C��i�i��#�,�,�.�$�8L�M�N�G�D�!��;�;�=�D���(�(�B�
�	
��Y�Y��U�D�1�
2�F�C���C�J�J�L�!�!r�	user_homec���tjj|d�}tjj|�stjd|�yt
|�S)z�
    Returns the Windows user profile .cloud-init directory translated as a
    Linux path accessible inside the current WSL instance, or None if not
    found.
    z.cloud-initz*cloud-init user data dir %s doesn't exist.N)r+�pathr0�isdirr.r/r)r:�seed_dirs  r�cloud_init_data_dirr?tsE���w�w�|�|�I�}�5�H�
�7�7�=�=��"��	�	�>��I���H��rc�b�tj�\}}}|r|n|}d|z|�d|�d�d|zdgS)z
    Return a list of candidate file names that may contain user-data
    in some supported format, ordered by precedence.
    r
�-z
.user-dataz%s-all.user-datazdefault.user-data)r	�get_linux_distro)r�distribution_id�
version_id�version_codename�versions     r�candidate_user_data_file_namesrG�sK��
59�4I�4I�4K�1�O�Z�!1�&�j�,<�G�	��&�,�g�6��_�,��	�	rc�,�eZdZdZdefd�Zdedefd�Zy)�
ConfigDataz~Models a piece of configuration data as a dict if possible, while
    retaining its raw representation alongside its file pathrc��|jduS�N)�config_dict)�selfs r�is_cloud_configzConfigData.is_cloud_config�s�����t�+�+rr<�instance_idc�<�tj|�|_||_d|_dt|j�k(r$tj|j�|_|jr�|r�|tk7r�|jjti�jt�	�j|jttjt|�}||k(r6dtj|j�j�z|_yyyyyy)Nztext/cloud-configz#cloud-config
%s)r	�load_text_file�rawr<rLr�	load_yaml�DEFAULT_INSTANCE_ID�get�LANDSCAPE_CFG_KEY�LANDSCAPE_CLIENT_CFG_KEY�
setdefault�LANDSCAPE_INSTALLATION_REQ_ID�yaml�dump�strip)rMr<rO�req_ids    r�__init__zConfigData.__init__�s���+�+�D�1���"��	�+/����"7����"A�A�#�~�~�d�h�h�7�D��
�����2�2�� � �$�$�%6��;�?�?�(�����%�%�&7�8�(���j�6��D�
���$�'�$�)�)�D�4D�4D�*E�*K�*K�*M�M���%��3��
rN)	�__name__�
__module__�__qualname__�__doc__�boolrNr�strr^�rrrIrI�s'��@�,��,��X��C�rrI�
metadata_pathc��d}	tjtj|�i��}|S#t$rtjd|�Y|SwxYw)zO
    Returns the relevant metadata loaded from the supplied metadata_path.
    N)�defaultz!No instance metadata found at %s.)r	rSrQ�FileNotFoundErrorr.r/)rf�metadatas  r�_load_metadatark�s]���H�
��>�>����
�.��
���O��
�
��	�	�/��	
�
�O�

�s�*0�A�Arc�@�dti}t|dz�}t|�}d}||fD].}|��|d|zz}t|�}|��|}|j�}n|stjd�|rd|vr(d|�d|��}	tj
|	�t|	��|S)z�
    Returns the relevant metadata loaded from either the Ubuntu Pro dir
    or the user cloud-int dir based on the instance name
    �instance-id�
.ubuntupro�z%s.meta-datazCUnable to find meta-data file candidates. Using default instance-idzMetadata at z5 does not contain instance-id key. Instead received: )rTr?rkr5r.r/�error�
ValueError)
r:rrj�pro_dir�user_dir�found_at�dirr<�dt�msgs
          r�load_instance_metadatarx�s���
�2�3�H�!�)�l�":�;�G�"�9�-�H��H���"����;���n�}�4�5��
�D�
!��
�>��H��}�}��H�����	�	�
)�	
�
�}�H�4��8�*�%"�"*��
-�	�	�	�	�#����o���OrrOc���t|dz�}|�yttjj	|t
t
�z��}d}tjj|�r,tjd|t|��t||�}ttjj	|t��}d}tjj|�rt||�}||fS)zg
    Read .ubuntupro user-data if present and return a tuple of agent and
    landscape user-data.
    rnN)NNzYLandscape configuration found: %s. Organization policy ignores any local user-data in %s.)r?rr+r<r0�LANDSCAPE_DATA_FILEr�isfiler.r/rI�AGENT_DATA_FILE)r:rOrr�landscape_path�landscape_data�
agent_path�
agent_datas       r�load_ubuntu_pro_datar��s���"�)�l�":�;�G�����
�����W�1�M�O�C�D��N��N�	�w�w�~�~�n�%��	�	�
1���	�*�		
�$�N�K�@���"�'�'�,�,�w��@�A�J��J�	�w�w�~�~�j�!��
�K�8�
��~�%�%rr��	user_datac�2�|�|js|�|jsy|jS|�|js|�|jsy|jSt|j�|j�g�sNtj	d�d|j
j
��d|j
j
��d�Si}d}g}t|jt�r>|j}|jdi�jdi�jdd�}t|jt�r�|rtj	d	�|j}|D]}||vr|j|�||||<�!|r$tj	d
j|��|rB|jdi�jd�r!tj	d|�||ddd<dtj|�j�zS)
aMerge agent.yaml data provided by Ubuntu Pro for WSL
    and user data provided either by Landscape or the local user,
    according to the UP4W specific rules.

    When merging is not possible, provide #include directive to allow
    cloud-init to merge separate parts.
    NzaUnable to merge {agent_data.path} and {user_data.path}. Providing as separate user-data #include.z	#include
�
rorr�tagsz.Merging both user_data and agent.yaml configs.z% agent.yaml overrides config keys: , zFLandscape client conf updated with user-data landscape.client.tags: %sz@#cloud-config
# WSL datasouce Merged agent.yaml and user_data
%s)rR�allrNr.r/r<r5�
isinstancerL�dictrUr#r0rZr[r\)r�r��merged�	user_tags�overridden_keys�agent�keys       r�merge_agent_landscape_datar�s���	��J�N�N���y�}�}���}�}��	��9�=�=���
�����~�~���
�*�*�,�i�.G�.G�.I�J�K��	�	�
8�	
�

�O�O�$�$�&��N�N�#�#�%�
�	
��F��I�(*�O��)�'�'��.��&�&���J�J�{�B�'�+�+�H�b�9�=�=�f�b�I�	��*�(�(�$�/���I�I�F�G��&�&���	%�C��f�}��&�&�s�+���*�F�3�K�	%���I�I����o�.�
�����K��4�8�8��B��I�I�-��
�
5>�F�;���)�&�1�	M�
�)�)�F�
�
!�
!�
#�	$�r�fieldc���	d|jdd�z}tjddg�\}}||vS#tj$r+}tj	d||j
�Yd}~yd}~wwxYw)	z�Checks if the landscape-config binary supports the intended
    configuration field, returning False if not or if attempting
    to run that binary fails.
    z--rrAzlandscape-configz--helpz4Unable to verify if landscape-client supports %s: %sNF)�replacerr6r.�warning�reason)r��flagr8r�errs     r�landscape_supports_fieldr�fst��

��e�m�m�C��-�-�����.��9�:���Q��s�{����%�%�����B���J�J�	
�
��
�s�25�A3�!A.�.A3c�V��eZdZdZd
dedef�fd�
Zdedefd�Zde	fd�Z
de	fd	�Z�xZS)�
DataSourceWSL�WSL�distro�pathsc�8��t�|�||||�d|_y)Nro)�superr^r)rM�sys_cfgr�r��ud_proc�	__class__s     �rr^zDataSourceWSL.__init__~s���
����&�%��9���rr>rc��tj|�D�cic]'}|jj�|j��)}}|std|z��t
|j�D�cgc]}|j���}}|D]$}||j�vs�t||�cStd|z��cc}wcc}w)z�
        Finds the most precendent of the candidate files that may contain
        user-data, if any, or None otherwise.
        z%s directory is emptyz6%s doesn't contain any of the expected user-data files)
r+�scandirr�casefoldr<r*rGr�keysr)rMr>�ef�existing_files�f�folded_names�filenames       r�find_user_data_filez!DataSourceWSL.find_user_data_file�s���35�*�*�X�2F�
�,.�B�G�G�������'�
��
���1�H�<�=�=�4�D�4F�4F�G�
��
�J�J�L�
��
�%�	:�H��>�.�.�0�0���x� 8�9�9�	:��D�x�O�
�	
��
��
s�,B=�-Cc��|j�}|sy	t�}t|t��}||j	d�k(S#t
tf$r)}tjdt|��Yd}~yd}~wwxYw)NFrmz2Unable to check_instance_id from metadata file: %s)
�get_instance_idr9rxrrUr*rqr.r�rd)rMr��currentr7rjr�s      r�check_instance_idzDataSourceWSL.check_instance_id�sv���&�&�(����
	��;�D�-�d�M�O�D�H��h�l�l�=�9�9�9����$�	��K�K�D��C��
���	�s�1A�A?�A:�:A?c�t�tjt�stj	dt�yt�|_	t
�}t|�}d}d}	t||j
�|_
|jd}|jjdk(r t!t"�sd}t%||�\}}	|�|�t'|j)|�d�}t-||g�syt/||�|_y	#t$r }tj	d|�Yd}~yd}~wwxYw#ttf$r)}tjdt|��Yd}~yd}~wwxYw#ttf$r?}|rtj*ntj}|d|t|��Yd}~��d}~wwxYw)
Nz5No WSL command %s found. Cannot detect WSL datasourceFz#Unable to detect WSL datasource: %szUnable to load metadata: %srm�ubunturoz+Unable to load any user-data file in %s: %sT)r�whichrr.r/rr9r*r?rxrjrqrprdr�rr�rYr�rIr��info�anyr��userdata_raw)	rMr:�er>r�r�r��iid�logs	         r�	_get_datazDataSourceWSL._get_data�s����z�z�+�&��I�I�G��
��*�_���	�!��I�
'�y�1��+/�
�*.�	�	�2��4�-�-��D�M��m�m�M�*���;�;���x�'�+�,I�J���$8��C�$H�!�J�	�
	�� �X�%9�&�t�'?�'?��'I�2�N�	��I�z�*�+��6�z�9�M�����[�	��I�I�;�Q�?���	���G�$�	��I�I�3�S��X�>���	��&�G�$�	�(�#�(�(�c�i�i�C��=���C��
�
��	�sH�
D�D.�E)�	D+�D&�&D+�.E&�=E!�!E&�)F7�85F2�2F7rK)
r_r`ra�dsnamer
rr^rr�rcr�r��
__classcell__)r�s@rr�r�{sF���
�F� �� �u� �
�H�
��
�<�D��&8�4�8rr�c�6�tj|t�SrK)r�list_from_depends�datasources)�dependss r�get_datasource_listr��s���$�$�W�k�:�:r)1rb�loggingr+�typing�pathlibrrrrrZ�	cloudinitrrr	�cloudinit.distrosr
�cloudinit.handlersr�cloudinit.helpersr�	getLoggerr_r.rrTrzr|rVrWrYrdrr(r3r9r?rGrIr�rkrxr�r�r��
DataSourcer��DEP_FILESYSTEMr�r�rerr�<module>r�s���F��	�
��(�(��)�)�$�4�#��g����!�� ��*��$������#�� 9��
1�s�
1�
�D��I�
� ���0"�8�"�<�8����0B���T�#�Y��(!�!�H�(��x��~��$"�h�"�s�"�t�"�J&��&�&)�&�
�8�J���*�!5�5�6�&�@R���$�R�19�*�1E�R�
�c�]�R�j�C��*p�G�&�&�p�j�W�+�+�-�.���;r