/usr/lib/python3/dist-packages/cloudinit/sources/__pycache__
Edit: /usr/lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceWSL.cpython-310.pyc (11550B)
o
thC @ s d Z ddlZddlZddlZddlmZ ddlmZmZmZ ddl Z ddl
mZmZm
Z
ddlmZ ddlmZ ddlmZ eeZd Zd
ZdZdZd
ZdZdZdefddZdee fddZ defddZ!defddZ"dedee fddZ#dee fddZ$G dd dZ%d edee& fd!d"Z'dedede&fd#d$Z(ded%edeee% ee% f fd&d'Z)d(ee% d)ee% dee fd*d+Z*d,efd-d.Z+G d/d0 d0ej,Z-e-ej.ffgZ/d1d2 Z0dS )3z?Datasource to support the Windows Subsystem for Linux platform. N)PurePath)ListOptionalTuple)sourcessubputil)Distro)type_from_starts_with)Pathsz/usr/bin/wslpathziid-datasource-wsl%s.user-dataz
agent.yaml landscapeclientinstallation_request_idreturnc C s" t tddg\} }t| jS )zL
Returns the name of the current WSL instance as seen from outside.
z-am/)r WSLPATH_CMDr rstripname)
root_net_path_ r A/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceWSL.py
instance_name! s r c C sH d} d}g }t D ]}|d | kr!||d v r!||d q|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=drvfsfstypeopts
mountpoint)r mountsvaluesappend)FS_TYPEOPTIONS_CONTAINmountedmntr r r mounted_win_drives. s r% c C s` t } | s tdd}| D ]}|| }t|tjsq
td| t| S tdd| )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% IOErrorosaccessX_OKLOGdebugr join)r candidater$ cmdr r r cmd_executable> s r/ c C sV t } td| ddg\}}| }|stdttd|g\}}t| 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)r/ r as_posixr ProcessExecutionErrorr r )r. homer outr r r find_homeV s r4 user_homec C s2 t j| d}t j|std| dS t|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' pathr, isdirr* r+ r )r5 seed_dirr r r cloud_init_data_dirt s
r9 c C s6 t \}}}|r|n|}d| d||f d| dgS )z
Return a list of candidate file names that may contain user-data
in some supported format, ordered by precedence.
r z%s-%s.user-dataz%s-all.user-datazdefault.user-data)r get_linux_distro)r distribution_id
version_idversion_codenameversionr r r candidate_user_data_file_names s
r? c @ s0 e Zd ZdZdefddZdedefddZd S )
ConfigDataz~Models a piece of configuration data as a dict if possible, while
retaining its raw representation alongside its file pathr c C s
| j d uS N)config_dict)selfr r r is_cloud_config s
zConfigData.is_cloud_configr6 instance_idc C s t || _|| _d | _dt| jkrt | j| _| jrK|rM|tkrO| jt i t
d urQ| jt t
t|}||krSdt
| j | _d S d S d S d S d S d S )Nztext/cloud-configz#cloud-config
%s)r load_text_filerawr6 rB r
load_yamlDEFAULT_INSTANCE_IDgetLANDSCAPE_CFG_KEYLANDSCAPE_CLIENT_CFG_KEY
setdefaultLANDSCAPE_INSTALLATION_REQ_IDyamldumpstrip)rC r6 rE req_idr r r __init__ s6
zConfigData.__init__N) __name__
__module____qualname____doc__boolrD r strrS r r r r r@ s r@
metadata_pathc C s@ d}z
t jt | i d}W |S ty td| Y |S w )zO
Returns the relevant metadata loaded from the supplied metadata_path.
N)defaultz!No instance metadata found at %s.)r rH rF FileNotFoundErrorr* r+ )rZ metadatar r r _load_metadata s
r^ c
C s dt i}t| d }t| }d}||fD ]}|du rq|d| }t|}|dur1|}| } nq|s9td |r?d|vrPd| d| } t| 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 Nz%s.meta-datazCUnable to find meta-data file candidates. Using default instance-idzMetadata at z5 does not contain instance-id key. Instead received: )rI r9 r^ r0 r* r+ error
ValueError)
r5 r r] pro_diruser_dirfound_atdirr6 dtmsgr r r load_instance_metadata s4
rj rE c C s t | d }|du rdS ttj|tt }d}tj|r.t d|t | t
||}ttj|t}d}tj|rDt
||}||fS )zg
Read .ubuntupro user-data if present and return a tuple of agent and
landscape user-data.
r` N)NNzYLandscape configuration found: %s. Organization policy ignores any local user-data in %s.)r9 r r' r6 r, LANDSCAPE_DATA_FILEr isfiler* r+ r@ AGENT_DATA_FILE)r5 rE rd landscape_pathlandscape_data
agent_path
agent_datar r r load_ubuntu_pro_data s&