name : debian.cpython-39.opt-1.pyc
a

'�Dgi*�@s�ddlZddlZddlmZddlmZmZmZddlm	Z	ddl
mZddlm
Z
ddlmZe�e�ZdZd	ZGd
d�dej�Zdd
d�Zedfdd�Zddd�Zddd�ZdS)�N)�List)�distros�subp�util)�Apt)�PackageManager)�HostnameConf)�CLOUDINIT_NETPLAN_FILEa8# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
z/etc/default/localecs�eZdZdZded�Zeded�ededd�d�Zd	Zd
Z	�fdd�Z
d
d�Zd(dd�Z�fdd�Z
dd�Zdd�Zdd�Zd)dd�Zdd�Zdd �Zd*d!d"�Zd#d$�Zeeeed%�d&d'�Z�ZS)+�Distroz
/etc/hostnamez'/etc/network/interfaces.d/50-cloud-init)�eni�netplanr)Zeni_pathZ
eni_headerrT)Znetplan_pathZnetplan_headerZpostcmdsz
/var/lib/dhcpzdhclient\.\w+\.leasescs@t��|||�d|_d|_d|_t�|j|�|_|jg|_	dS)NZdebianzC.UTF-8)
�super�__init__Zosfamily�default_locale�
system_localerZfrom_configZ_runner�aptZpackage_managers)�self�nameZcfg�paths��	__class__��</usr/lib/python3.9/site-packages/cloudinit/distros/debian.pyr7szDistro.__init__cCs |jst�|_|jr|jS|jS)z9Return the default locale if set, else use default locale)r�read_system_localer�rrrr�
get_localeBs�zDistro.get_localeN�LANGc	Cs�|st}|std��|��}tj�|�}|j}|rFt�dt|j	�nt�d|jt�|�
�|�
�kpn|pn|}|p||p||}|r�t||||jd�nt�d||j|�|r�t
||||jd�d|_dS)zeApply specified locale to system, regenerate if specified locale
        differs from system default.zFailed to provide locale value.zVSystem locale not found in %s. Assuming system locale is %s based on hardcoded defaultzSystem locale set to %s via %s)�keyname�install_functionz9System has '%s=%s' requested '%s', skipping regeneration.N)�LOCALE_CONF_FN�
ValueErrorr�os�path�existsr�LOG�debugr�lower�regenerate_localeZinstall_packages�update_locale_conf)	r�localeZout_fnrZ
distro_localeZconf_fn_existsZsys_locale_unsetZ
need_regenZ	need_confrrr�apply_localeMsZ�������zDistro.apply_localecst�t�j|i|��S�N)�_maybe_remove_legacy_eth0r
�_write_network_state)r�args�kwargsrrrr-�szDistro._write_network_statecCsxd}z|�|�}Wn8tyJt�|jdd�}|r6nt�d�YdSYn0|sXtd�}|�|�t�	|t
|�d�dS)N�create_hostname_fileTz8create_hostname_file is False; hostname file not created��)�_read_hostname_conf�IOErrorrZget_cfg_option_boolZ_cfgr$�inforZset_hostname�
write_file�str)r�hostname�filename�confr0rrr�_write_hostname�s"��
zDistro._write_hostnamecCs|�|j�}|j|fSr+)�_read_hostname�hostname_conf_fn)rZsys_hostnamerrr�_read_system_hostname�szDistro._read_system_hostnamecCstt�|��}|��|Sr+)rr�load_text_file�parse)rr9r:rrrr3�szDistro._read_hostname_confcCs8d}z|�|�}|j}Wnty*Yn0|s4|S|Sr+)r3r8r4)rr9�defaultr8r:rrrr<�s

zDistro._read_hostnamecCsdS)Nz	127.0.1.1rrrrr�_get_localhost_ip�szDistro._get_localhost_ipcCstj||�|�d�dS)N)�tzZtz_file)rZset_etc_timezoneZ
_find_tz_file)rrCrrr�set_timezone�szDistro.set_timezonecCs(|dkrtd|�d���|j�d�dS)NZupgradezUnable to handle z command)�RuntimeErrorrZrun_package_command)rZcommandr.Zpkgsrrr�package_command�szDistro.package_commandcCst��Sr+)rZget_dpkg_architecturerrrr�get_primary_arch�szDistro.get_primary_arch)�layout�model�variant�optionscCs^d�ddd|�d�d|�d�d|�d�d|�d�dd	dg	�}tjd
|ddd
�|�dd�dS)N�
z'# This file was generated by cloud-initr1z
XKBMODEL="�"zXKBLAYOUT="zXKBVARIANT="zXKBOPTIONS="zBACKSPACE="guess"z/etc/default/keyboardr2�w)r9Zcontent�modeZomodeZrestartz
console-setup)�joinrr6Zmanage_service)rrHrIrJrK�contentsrrr�
set_keymap�s&



��
�zDistro.set_keymap)Nr)N)NN)�__name__�
__module__�__qualname__r=r	Znetwork_conf_fn�NETWORK_FILE_HEADERZrenderer_configsZdhclient_lease_directoryZdhclient_lease_file_regexrrr*r-r;r>r3r<rBrDrFrGr7rR�
__classcell__rrrrr
!s6����

;

r
�"/etc/network/interfaces.d/eth0.cfgcCs�tj�|�sdSd}zPt�|�}ddg}dd�|��D�}||krVt�|�d|}n|d|}Wnty�|d	|}Yn0t�	|�dS)
aOUbuntu cloud images previously included a 'eth0.cfg' that had
    hard coded content.  That file would interfere with the rendered
    configuration if it was present.

    if the file does not exist do nothing.
    If the file exists:
      - with known content, remove it and warn
      - with unknown content, leave it and warn
    Nz(Dynamic networking config may not apply.z	auto eth0ziface eth0 inet dhcpcSsg|]}|�d�s|���qS)�#)�
startswith�strip)�.0�frrr�
<listcomp>�sz-_maybe_remove_legacy_eth0.<locals>.<listcomp>zremoved %s with known contentsz* '%s' exists with user configured content.z" %s exists, but could not be read.)
r!r"r#rr?�
splitlinesZdel_file�	Exceptionr$Zwarning)r"ZbmsgrQZknown_contents�lines�msgrrrr,�s 
�

r,rcCsDd}|std|��tj�|�r@t�|�}t�|�}|�|d�}|S)z.Read system default locale setting, if presentr1zInvalid path: %s)r r!r"r#rr?Zload_shell_content�get)�sys_pathrZsys_valZlocale_contentZsys_defaultsrrrr
s

rcCsHt�d|||�t�d�s$|dg�tjdd|d||fgdd�dS)	zUpdate system locale configz%Updating %s with locale setting %s=%sz
update-locale�localesz--locale-file=z%s=%sF�ZcaptureN)r$r%r�which�r)rdrrrrrr(s�


��r(cCsT|��dvrt�d||�dSt�d�s2|dg�t�d|�tjd|gdd�dS)	z�
    Run locale-gen for the provided locale and set the default
    system variable `keyname` appropriately in the provided `sys_path`.

    )�czc.utf-8�posixz$%s=%s does not require rengenerationNz
locale-genrezGenerating locales for %sFrf)r&r$r%rrgrhrrrr'+s

r')rX)rN)rN)Zloggingr!�typingrZ	cloudinitrrrZ(cloudinit.distros.package_management.aptrZ4cloudinit.distros.package_management.package_managerrZ"cloudinit.distros.parsers.hostnamerZcloudinit.net.netplanr	Z	getLoggerrSr$rVrr
r,rr(r'rrrr�<module>
s"
J
 �


© 2025 Cubjrnet7