%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

�

���f��
�8�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l2m3Z3m4Z4m5Z5dd
l6m7Z7ddl8m9Z9ddl:m;Z;dZ<dgdgdgddgddgddgdgdggd�gd�dgdd gd!�Z=ej|e?�Z@ej�d"�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)�
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.r0r1�redhatrCrDrEz#^[a-z][a-z]-(?:[a-z]+-)+[0-9][a-z]$)�chronyzsystemd-timesyncd�ntp�ntpdate�-c��eZdZy)�PackageInstallerErrorN)�__name__�
__module__�__qualname__���</usr/lib/python3/dist-packages/cloudinit/distros/__init__.pyrMrM�s��rRrMc
�`�eZdZUdZdZdZdZdZdZdZ	dZ
d	d
gZdZdZ
d
gZiZeeeeeffed<dZeZeeed<dddd�Zej8Zeeed<dZdZ 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#�Z/e0de1jdfd$��Z3e0de#ee4jjfd%��Z6e0de7fd&��Z8d'e7fd(�Z9d)�Z:dxd*�Z;dxd+�Z<dxd,�Z=e>d-��Z?e@j�dyd.��ZBdd/�d0�ZCd1�ZDdxd2�ZEdyd3�ZFd4�ZGdzdeHfd5�ZIe@j�dxd6��ZJe@j�d7��ZKd8�ZLd9�ZMe@j�dxd:��ZNe@j�d;��ZOe@j�d<��ZPd=�ZQd>�ZRe>d?��ZSd@�ZTdA�ZUe0dB��ZVdC�ZWdeHfdD�ZXdE�ZYdeHfdF�ZZdG�Z[dH�Z\dIefdJ�Z]dK�Z^dzdL�Z_dMe`dNeHfdO�ZadP�ZbdxdQ�Zcd{dR�ZddxdS�ZedxdT�ZfegdU��ZhegdxdV��ZiegddW�dXed
edYefdZ��Zjd[ed\ed]ed^efd_�Zkdefd`�Zld|dae`dbedcefdd�Zme>deedfedgedhediede`fdj��Zne0dk��Zoeoj�dl��Zoe>dme&de#e&fdn��Zqe>dme&de#e&fdo��Zre>dme&dpe&de#e&fdq��Zse>dreddfds��Zte>dtede#efdu��Zue>dvedevfdw��Zwy)}�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�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�namerX�
networkingr!�ALL_DHCP_CLIENTS�dhcp_client_priority�iproute2�Iproute2r\r�Runners�_runner�package_managers�_dhcp_client�_fallback_interface�is_linux)�selfrd�cfg�pathss    rS�__init__zDistro.__init__�sq�������	���	�&*�&9�&9�&;���$(�$9�$9��!��(�(������u�-���68��� ���#'�� ���
rR�ci_pkl_version�returnc���d|jvs|jjs|j�|_t|d�sd|_t|d�sd|_t|d�sd|_yy)z)Perform deserialization fixes for Distro.rermNrnroT)�__dict__rerX�hasattrrmrnro)rprts  rS�	_unpicklezDistro._unpickle�sg���t�}�}�,�D�O�O�4L�4L�#�1�1�3�D�O��t�^�,� $�D���t�2�3�'+�D�$��t�Z�(� �D�M�)rRc��t|t�r|St|ttf�rt	|�dk(rt|�Std��)N�z?Invalid 'packages' yaml specification. Check schema definition.)�
isinstance�str�list�tuple�len�
ValueError)rp�entrys  rS�_validate_entryzDistro._validate_entry�sF���e�S�!��L�
���e�}�
-��5�z�Q���U�|�#��
'�
�	
rR�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)rpr��packages_by_manager�generic_packagesr��package_manager�package_list�
definitions        rS�_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�rl�get�	__class__�difference_update�	availabler��debugrd�update�install_packages�infor��from_configrkrcrM)
rpr��
error_messager�r��total_failed�manager�manager_packages�to_try�failed�manager_type�packages�ps
             rSr�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
        )�networkrgz.Using configured dhcp client priority list: %sz4Configured dhcp client %s is not supported, skippingzDHCP client selected: %szDHCP client not found: %s)
rmrgr�get_cfg_by_pathrcr�r�r!rf�client_name�append�warning�NoDHCPLeaseMissingDhclientError)rprg�config_priority�
found_clients�client_configured�client_class�clients       rS�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��tj|jdd�}	tj|��S#tj
$rYywxYw)z=Return the configured network activator for this environment.)r�r N��priority)rr�rcr �select_activator�NoActivatorException)rpr�s  rS�network_activatorzDistro.network_activator_sN���'�'��I�I�0�$�
��	��.�.��A�A���.�.�	��	�s�9�A�Ac���tj|jdd�}tj|��\}}t
j
d||�||jj|���}|S)N)r�r"r�z-Selected renderer '%s' from priority list: %s)�config)	rr�rcr"�selectr�r�rWr�)rpr�rd�
render_cls�renderers     rS�network_rendererzDistro.network_rendererjsj���'�'��I�I�/��
��%�+�+�X�>���j��	�	�;�T�8�	
��T�%:�%:�%>�%>�t�%D�E���rRr�c�&�|j|�y�N)�render_network_state)rp�
network_stater�s   rS�_write_network_statezDistro._write_network_statews���%�%�m�4rRc���tjj|jt	|��}tjj|�st
d|�d|����|S)NzInvalid timezone z, no file found at )�os�path�join�tz_zone_dirr}�isfile�IOError)rp�tz�tz_files   rS�
_find_tz_filezDistro._find_tz_filezsL���'�'�,�,�t�/�/��R��9���w�w�~�~�g�&��>@�'�J��
��rRc�:�|jj||�Sr�)rcr�)rp�opt_name�defaults   rS�
get_optionzDistro.get_option�s���y�y�}�}�X�w�/�/rRc�"�||j|<yr�)rc)rpr��values   rS�
set_optionzDistro.set_option�s��#��	�	�(�rRc��|j||�}|j||j�|j|�yr�)�_select_hostname�_write_hostname�hostname_conf_fn�_apply_hostname)rp�hostname�fqdn�writeable_hostnames    rS�set_hostnamezDistro.set_hostname�s;��!�2�2�8�T�B�����/��1F�1F�G����/�0rRc��t�S)z?Wrapper to report whether this distro uses systemd or sysvinit.)�uses_systemdrQrRrSr�zDistro.uses_systemd�s���~�rRc��t��r���NotImplementedError)rp�command�args�pkgss    rS�package_commandzDistro.package_command�s
��
"�#�#rR��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)rlr�r�r�rd�update_package_sources�	Exceptionr�)rpr�r��es    rSr�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)rpr)s  rS�get_primary_archzDistro.get_primary_arch�s"���x�x�z�!�}���3�3���rRc�b�|jdg�}|s|j�}t||�S)N�package_mirrors)r�r��_get_arch_package_mirror_info)rpr)�mirror_infos   rSr�z$Distro._get_arch_package_mirror_info�s1���o�o�&7��<����(�(�*�D�,�[�$�?�?rRc�>�|j|�}t||��S)N)�data_sourcer�)r��_get_package_mirror_info)rpr)r��	arch_infos    rS�get_package_mirror_infozDistro.get_package_mirror_info�s&���6�6�t�<�	�'�#��
�	
rRc�*�tj�Sr�)r�generate_fallback_config�rps rSr�zDistro.generate_fallback_config�s���+�+�-�-rRc��|j}t||��}|j||�|rKtj	d�|j
}|stj
d�y|j|�ytj	d�y)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��bring_up_all_interfaces)rp�	netconfig�bring_upr�r�r�s      rS�apply_network_configzDistro.apply_network_config�s����(�(��-�i�(�K�
��!�!�-��:���I�I�G�H� $� 6� 6��$����)����5�5�m�D��
�I�I�K�L�rRc��t��r�r�)rp�locale�out_fns   rS�apply_localezDistro.apply_locale����!�#�#rRc��t��r�r�)rpr�s  rS�set_timezonezDistro.set_timezone�r
rRc��y)Nz	127.0.0.1rQrs rS�_get_localhost_ipzDistro._get_localhost_ip�s��rRc��t��r�r�rs rS�
get_localezDistro.get_locale�s��!�#�#rRc��t��r�r�)rp�filenamer�s   rS�_read_hostnamezDistro._read_hostname�r
rRc��t��r�r�)rpr�rs   rSr�zDistro._write_hostname�r
rRc��t��r�r�rs rS�_read_system_hostnamezDistro._read_system_hostname�r
rRc���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)rpr�s  rSr�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_boolrc�prefer_fqdn)rpr�r�s   rSr�zDistro._select_hostnames;��
�$�$��	�	�6��8H�8H�
���K���K��rRc��g}|D]<}|tvrtdj|���|jt|��>|S)Nz&No distributions found for osfamily {})�
OSFAMILIESr��format�extend)�family_list�distros�familys   rS�expand_osfamilyzDistro.expand_osfamilysS����!�	/�F��Z�'� �<�C�C�F�K���
�N�N�:�f�-�.�	/��rRc��|}|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�)rpr�r��prev_hostname_fn�applying_hostname�
prev_hostname�sys_fn�sys_hostname�update_files�f�fns           rS�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)
rpr�r��header�eh�local_ip�	prev_info�need_changer��
entry_fqdn�
entry_aliases�new_entries�contentss
             rS�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�rRc�Z�|jstt�|_|jS)z7Allow distro to determine the preferred ntp client list)�_preferred_ntp_clientsr~�PREFERRED_NTP_CLIENTSrs rS�preferred_ntp_clientszDistro.preferred_ntp_clients�s'���*�*�*.�/D�*E�D�'��*�*�*rRc�$�|jd�S)N�default_user)r�rs rS�get_default_userzDistro.get_default_user�s�����~�.�.rRc�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_messagerZz created group '%s' for user '%s'r[�REDACTED�no_create_homercz-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)rprd�kwargsrT�useradd_cmd�log_useradd_cmd�useradd_opts�
useradd_flags�redact_optsr\�grZ�group�key�valr�s                rS�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)rl�capturez snap create-user returned: %s:%s�usernameNzFailed to create snap user %s)	r�r�r�r�rr�	load_jsonr�r)rprdrwr�r��create_user_cmd�out�err�jobjr�r�s           rS�
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)rro�shadow_extrausers_fn�	shadow_fnr��#shadow_empty_locked_passwd_patternsr r�r�r'r:�re�findall�	MULTILINEr�r�)rpr��shadow_files�pattern�shadow_empty_passwd_re�shadow_file�shadow_contents       rS�$_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}|r1|s>d|vrd}tj	d	|�|j|�}nd|vrd}d}|dsd}|j
d
d�r|j|�n^|s|r+|rtjd||�|j|�n/|rtj	d|�ntj	d
|�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	dt+|��g}nt)|�xsg}t-j.t)|�|�d|vr�|j
dg�}	|	stj	d||d�y|d}
t,j0}|j3d|
�}|j3d|�}t-j.t)|	�||��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]z5'passwd' in user-data is ignored for existing user %s�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.rf�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�r�r�r�r��
unlock_passwd�write_doas_rules�write_sudo_rulesrrqr|r}r�r~�valuesrr��typer�setup_user_keys�DISABLE_USER_OPTS�replace)rprdrw�pre_existing_user�has_existing_password�ud_blank_password_specified�ud_password_specified�password_keyru�
cloud_keys�
redirect_user�disable_options            rS�create_userzDistro.create_userLsY��,���%�4�%�%�d�5�f�5�5�!.��
�
�d� =�f� =�=�� %��&+�#� %�����&�(�$(�!�.�L��)�*�����f�-@�&A�B�.2�+��f�$�$(�!�*�L��o�&�����f�_�&=�d��K�.2�+��(��v�%�#+�L��K�K�"����=�=�d�C�)�%��6�!�(,�%�'���h�'�26�/�
�:�:�m�T�*����T�"�
"�&;�+��	�	�)�� �	�
���t�$�
�
�K�K�)��
�
�K�K�8��	
��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�>��rRc�<�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  rS�	<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�)rprd�
lock_tools�cmdr��cs      rSr�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�Brdc��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  rSr�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-drWz''c3�RK�|]}tj|d�s�|���!y�wr�r�r�s  rSr�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�)	rprd�unlock_toolsr�r�r��_r��passwd_set_toolss	         rSr�zDistro.unlock_passwd	sz��
"�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�)rp�userr�s   rS�
expire_passwdzDistro.expire_passwd5s@��	��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)�datarlzFailed to set password for %sT)r�rr�rrr�)rpr�r]r��pass_stringr�r�s       rSr�zDistro.set_passwd<so��!%�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�rd�passwords   rSr�z"Distro.chpasswd.<locals>.<genexpr>Ss"����K���h����4��*�+�K�s� "r�r�)r�)r�r)rpr�r��payloadr�s     rSr�zDistro.chpasswdPsG���I�I�K�(�K�
��
�	��l��t�f�B�7���	�	�#�G�$rRc�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~)rpr��rule�rule_pattern�valid_matchs     rS�is_doas_rule_validzDistro.is_doas_rule_valid]s���
�	�	�	�	�A�4��	
��i�i��d�3����I�I�3�[�5F�5F�q�5I�
�� � ��#�t�+��	�	�C�D���	�	�D��%�%�a�(����I�I�G�H�rRc���|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!r2z# cloud-init User rules for %s�%sr�� r6zFailed to write doas file %sz Failed to append to doas file %s)�doas_fnr�r�r�r�r�r�r�r'rr;r@r�rr:�append_file)
rpr��rules�	doas_filer��msg�lines�contentrJr�s
          rSr�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)Nr2Fz/usr/etc/sudoersTz^[#|@]includedir\s+(.*)$r]z?# See sudoers(5) for more information on "#include" directives:r3r4z#includedir %szUsing content from '%s'r�r�zAdded '#includedir %s' to %szFailed to write %si�)r�r�r'rr:�
splitlinesrrr�r�r~�abspathr;r�r�r�r@r�r�r�r�
ensure_dir)rpr��	sudo_base�sudoers_contents�base_exists�system_sudo_base�
found_include�line�
include_match�included_dirr�r�s            rS�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)	Nr2z# 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~rr�r}�	TypeErrorr�obj_namer�rr�r��dirnamer'rr;r@r�rr�r:r�)
rpr�r��	sudo_filer�r�r�r�rJr�s
          rSr�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�groupaddrVz(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')rror�rsr�r�rr�r�rr�rm)rprd�members�
group_add_cmd�members     rSrtzDistro.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�)�clsr7�delay�messager�r�r�s       rS�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)�init_cmdr�r)rr�rr�s    rS�reload_initzDistro.reload_init1sB���<�<��������!8��_�-�C��9�9�S�$�C�8�8�"9rRr��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
�}t|�t||�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)rr�r~r)rrrVr�rr�cmdsr�s        rS�manage_servicezDistro.manage_service<s����<�<��������!8�#�}�H���)�!�7�+�#�W�-�%�w�/�%�w�/�.��8�6��@�#�W�-�	�D�!�&�)�!�7�+�"�G�,�#�V�,�#�Y�/�"�I�.�&�	�2�"�H�-�	�D��8�n�t�D��L�1�1���y�y��d��4�4rR�layout�model�variantr�c�n�|j�rtjdd||||g�yt��)N�	localectlzset-x11-keymap)r�rr�)rpr*r+r,r�s     rS�
set_keymapzDistro.set_keymapas<�������I�I��$�����
�	
�&�'�'rRc��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)rp�tmp_dirs  rS�get_tmp_exec_pathzDistro.get_tmp_exec_pathpsD���-�-��=���!�!�'�8�4��N��w�w�|�|�D�-�-�|�Z�H�HrRr�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 && r2�surKz-czenv PATH=$PATH r)rr�)rpr�r�r9rw�	directorys      rS�do_aszDistro.do_asvsX��(+�c�#��d�O��	��y�y������-�-�����0A�A�
�	
��	
�		
rRr��
lease_file�pid_file�	interface�config_filec	�2�|ddd|d|ddg	|rd||gzS|gzS)Nz-1z-vz-lfz-pfz-sfz	/bin/truez-cfrQ)r�r>r?r@rAs     rS�build_dhclient_cmdzDistro.build_dhclient_cmd�sS��
���������

�1<�e�[�)�
,�
N�
	N�CL��
N�
	NrRc��|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.)rnr�find_fallback_nicr�r�rdrs rS�fallback_interfacezDistro.fallback_interface�sN���#�#�+�'*�'<�'<�'>�D�$��+�+����F��I�I���'�'�'rRc��||_yr�)rn)rpr�s  rSrFzDistro.fallback_interface�s
��#(�� rR�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]�rU�_get_proc_stat_by_indexrr�rr�r��rH�matchs  rS�
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||��%)rJ�Nz&/proc/%s/stat has an invalid pgid [%s]rKrMs  rS�
get_proc_pgidzDistro.get_proc_pgid�rPrQ�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:rrr�r�r�r�rr~r��
IndexError)rHrUr�rNr�s     rSrLzDistro._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)rYr�s  rS�eject_mediazDistro.eject_media�s_�����:�:�g���F�#�C�
�Z�Z�,�
-�'��&�A�C��,�,�%�5�G��
�
	
�	�	�#�rR�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�)r`rbs  rS�get_mapped_devicezDistro.get_mapped_device�sC���7�7�#�#�H�-�����z�*��I�I�6��(�
��O�rR�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�rb�basenamer'r�r�rrr:�rstripr	)
re�rpath�bname�syspath�ptpath�ptnum�rsyspath�disksyspath�
diskmajmin�diskdevpaths
          rS�device_part_infozDistro.device_part_infos ����� � ��)����� � ��'��'�%�/���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�!�!rRr�)NN)F)z/etc/sudoers)r2)xrNrOrP�pip_package_namer6r8r�rr�r�r�r�r��
default_ownerrrWr	r}r
r�__annotations__rMrrXrrrrhrir\r#�_ci_pkl_versionr�resolve_conf_fnr_rr`rsrryr��PackageListr
rrrr�r��propertyr!�
DhcpClientr�r �NetworkActivatorr�r%r�r�r�r�r�r��staticmethodr��abc�abstractmethodr�r�r�r�r�r��boolrr	rrrrr�rr�r�r%r0rKrOrRr�r�r�r�r�r�r�r�r~r�r�r�rr�rt�classmethodrrr)r/r8r=rCrF�setterrOrTrLr_rdrrurQrRrSrUrU�s\��$���L��H��G�8�M�&���I�7��+:�<L�*M�'�'�K��M��{�H�?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��8�D��1L�1L�,M�#N�����
�(�
��
�5�H�5��0�$�1�
����	���$��$�/4�
��@�
�.����8	���$��$�	���$��$��$�	���$��$�	���$��$�	���$��$��"�����?4�B)L�V�+��+�/�w�$�w�r�6 �� �Dh�T�&*�#�*�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����"�!"�#�!"�%�!"��!"rRrU)�	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      rS�&_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 rS�<lambda>z&_sanitize_mirror_url.<locals>.<lambda>s���!2�!2�8�!<���(�rRc�B�|jd�jd�S)N�idna�ascii)�encode�decoder�s rSr�z&_sanitize_mirror_url.<locals>.<lambda>�s������0�7�7��@�rRc�8��dj�fd�|D��S)Nr2c3�.�K�|]}|�vr|nd���y�w�rKNrQ)r�r��acceptable_charss  �rSr�z9_sanitize_mirror_url.<locals>.<lambda>.<locals>.<genexpr>�s#�����!
�45��&�&�A�C�/�!
�s�r�)r�r�s �rSr�z&_sanitize_mirror_url.<locals>.<lambda>�s������!
�9A�!
�
�rRc�P�djd�|jd�D��S)Nr�c3�>K�|]}|jd����y�wr�)rr)r��parts  rSr�z9_sanitize_mirror_url.<locals>.<lambda>.<locals>.<genexpr>�s����"
� $�D�J�J�s�O�"
�s�)r�rpr�s rSr�z&_sanitize_mirror_url.<locals>.<lambda>�s%�����"
�(0���s�(;�"
�
�rR)�LDH_ASCII_CHARSr�)r�r�r�s  @rS�_sanitize_mirror_urlr�Us=���L'��,��	K�	A�	
�	
��O�"2�#��G�GrRc��|si}i}|ro|jrc|j|d<tj|j�r5|jdd}tr	d|z|d<n|jdk(rd|z|d<|r|j
r|j
|d<i}|j
di�j�D]
\}}|||<�|j
d	i�j�D]C\}}g}	|D]'}
	|
|z}t|�}|��|	j|��)||	�}|s�?|||<�Etjd
|�|S#t$rY�_wxYw)N�availability_zoner���r��
ec2_region�ec2�region�failsafer�zfiltered distro mirror info: %s)
r��
_EC2_AZ_RErNr�
platform_typer�r�r�r�r�r�r�r�)r�r��
mirror_filter�substr��resultsrd�mirror�
searchlist�mirrors�tmpl�founds            rSr�r��s������E��{�4�4�%0�%B�%B��!�"����K�9�9�:�$�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�2E�	E�
Ec�X�d}|D]"}|jd�}||vr|cSd|vs�!|}�$|S)N�archesr�)r�)r�r)r��itemr�s     rSr�r��sD���G�������(�#���6�>��K�����G���NrRrdruc��tj|dtgdg�\}}|std|�d|�d���tj|d�}t|d�}|S)Nr2rUz!No distribution found for distro z (searched rgr)r�find_modulerN�ImportError�
import_module�getattr)rd�locs�looked_locs�modrs     rS�fetchr��sb�� �,�,�T�B��>�H�:�N��D�+����[�
"�
�	
��
 �
 ��a��
)�C�
�#�x�
 �C��JrRc�t�tj|t|�j�dz�|r�|r�tj
j
|�}|stj
j|�s.|rtj|�t	j||�ytj||�y)Nr�)rr@r}rkr�r��islinkr'�del_file�symlink�copy)r�r��tz_conf�tz_localr�s     rS�set_etc_timezoner��s���	�O�O�G�S��W�^�^�-��4�5��G�������)���������1���
�
�h�'��J�J�w��)��
�I�I�g�x�(�
rRc��	tjd�}tj|j�S#t
$rYywxYw)Nz/run/systemd/systemF)r��lstat�stat�S_ISDIR�st_moder�)�ress rSr�r��s;����h�h�,�-���|�|�C�K�K�(�(������s�36�	A�A)Nz
/etc/timezonez/etc/localtime)Wr��loggingr�r�r��string�urllib.parser��collectionsr�
contextlibr�ior�typingrrrr	r
rrr
rr�cloudinit.net.netops.iproute2r�netopsrh�	cloudinitrrrrrrrrr�cloudinit.distros.networkingrr�4cloudinit.distros.package_management.package_managerr�*cloudinit.distros.package_management.utilsr�cloudinit.distros.parsersr�cloudinit.featuresr�
cloudinit.netr r!r"�cloudinit.net.netopsr#�cloudinit.net.network_stater$�cloudinit.net.rendererr%�ALL_DISTROSr�	getLoggerrNr��compiler�rN�
ascii_letters�digitsr�r}r{r�rM�CloudInitPickleMixin�ABCMetarUr~r�r��search_for_mirrorr�r�r�r�r�rQrRrS�<module>r�s�����	�	��
��#������1�0����E�O�M�+�J�5�5�'�=�+����j�
�H�
�H���"��;�'�����j��{�� 	
���!�;�/�I%�
�N�g����!���R�Z�Z�=�
>�
�J���&�&����6��<�����I���M���c��O���s�D��I�~�	����s�D��I�w�&�	'�(�	*���	�I�	�c"�[�
-�
-����c"�L-(F��(F�d�(F�V8H�c�8H�x"��1G�1G�0�f	�	��	��V��	�9I��"rR

Zerion Mini Shell 1.0