HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/cloudinit/distros/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/distros/__pycache__/__init__.cpython-311.pyc
�

܍~c���
�.�ddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
mZddlmZddlmZddlmZmZmZmZmZmZmZddlmZmZddlmZdd	lm Z dd
l!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)d
Z*dgdgddgddgddgdgdggd�ddgd�	Z+ej,e-��Z.ej/d��Z0gd�Z1ej2ej3zdzZ4Gd�d ej5ej6�!��Z7d"e8d#e9fd$�Z:d"e8fd%�Z;dej<fd&�Z=d'�Z>d(e8d)ee7fd*�Z?	d/d-�Z@d.�ZAdS)0�N)�StringIO)�Any�Mapping�MutableMapping�Optional�Type)�importer)�log)�net�persistence�ssh_util�subp�
temp_utils�
type_utils�util)�LinuxNetworking�
Networking)�hosts)�+ALLOW_EC2_MIRRORS_ON_NON_AWS_INSTANCE_TYPES)�
activators�eni�
network_state�	renderers)�parse_net_config_data)�Renderer�all�alpine�arch�debian�ubuntu�freebsd�	dragonfly�gentoo�cos�netbsd�openbsd)�	almalinux�amazon�centos�
cloudlinux�	eurolinux�fedora�mariner�miraclelinux�	openEuler�openmandriva�photon�rhel�rocky�	virtuozzo�opensuse�sles)	rrrr!r#r%r&�redhat�susez#^[a-z][a-z]-(?:[a-z]+-)+[0-9][a-z]$)�chronyzsystemd-timesyncd�ntp�ntpdate�-c�d�eZdZUdZdZdZdZdZdZdZ	dgZ
iZee
ee
effed	<d
ZeZeeed<dd
dd�ZdZdZdZe
ed<d�Zdedd
fd�Zejd���Zd�Z e!de"ee#j$fd���Z%de&fd�Z'de&fd�Z(d�Z)dTd�Z*dTd �Z+dTd!�Z,d"�Z-ejdUd#���Z.ejd$���Z/d%�Z0dTd&�Z1dUd'�Z2dVd)�Z3dVd*�Z4d+�Z5dWde6fd,�Z7ejdTd-���Z8ejd.���Z9d/�Z:d0�Z;ejdTd1���Z<ejd2���Z=ejd3���Z>d4�Z?d5�Z@eAd6���ZBd7�ZCd8�ZDe!d9���ZEd:�ZFd;�ZGd<�ZHd=�ZId>�ZJd?�ZKd@�ZLdA�ZMdWdB�ZNdCeOdDe6fdE�ZPdXdG�ZQdTdH�ZRdTdI�ZSdJ�ZTdKe
de
fdL�ZUdM�ZVde
fdN�ZWdYdPeOdQe
dRe
fdS�ZXd
S)Z�Distrozpython3-pipz/usr/libz
/etc/hostsz"/etc/sudoers.d/90-cloud-init-usersz
/etc/hostnamez/usr/share/zoneinfoz	root:root�service�renderer_configsN�networking_clsz-Hz-Pz-r)�halt�poweroff�reboot�Fz/etc/resolv.conf�osfamilyc�b�||_||_||_|���|_dS�N)�_paths�_cfg�namerA�
networking)�selfrK�cfg�pathss    �</usr/lib/python3/dist-packages/cloudinit/distros/__init__.py�__init__zDistro.__init__is.�������	���	�&*�&9�&9�&;�&;������ci_pkl_version�returnc�f�d|jvs|jjs|���|_dSdS)z)Perform deserialization fixes for Distro.rLN)�__dict__rLrA)rMrSs  rP�	_unpicklezDistro._unpickleos:���t�}�,�,�D�O�4L�,�#�1�1�3�3�D�O�O�O�-�,rRc��t���rH��NotImplementedError)rM�pkglists  rP�install_packageszDistro.install_packages{���!�#�#�#rRc�0�td|jz���)�=Deprecated. Remove if/when arch and gentoo support renderers.zhLegacy function '_write_network' was called in distro '%s'.
_write_network_config needs implementation.
)rZrK)rM�settingss  rP�_write_networkzDistro._write_networks$��!�
<�>B�i�
H�
�
�	
rRc��tj|jdd��}	tj|���S#tj$rYdSwxYw)z=Return the configured network activator for this environment.)�networkrN��priority)r�get_cfg_by_pathrJr�select_activator�NoActivatorException)rMres  rP�network_activatorzDistro.network_activator�s^���'��I�0�$�
�
��	��.��A�A�A�A���.�	�	�	��4�4�	���s�2�A�Ac���tj|jdd��}tj|���\}}t
�d||��||j�|�����}|S)N)rcrrdz-Selected renderer '%s' from priority list: %s)�config)	rrfrJr�select�LOG�debugr@�get)rMrerK�
render_cls�renderers     rP�
_get_rendererzDistro._get_renderer�s���'��I�/��
�
��%�+�X�>�>�>���j��	�	�;�T�8�	
�	
�	
��:�T�%:�%>�%>�t�%D�%D�E�E�E���rRrqc�0�|�|��dSrH)�render_network_state)rMrrqs   rP�_write_network_statezDistro._write_network_state�s���%�%�m�4�4�4�4�4rRc���tj�|jt	|����}tj�|��st
d|�d|�����|S)NzInvalid timezone z, no file found at )�os�path�join�tz_zone_dir�str�isfile�IOError)rM�tz�tz_files   rP�
_find_tz_filezDistro._find_tz_file�s_���'�,�,�t�/��R���9�9���w�~�~�g�&�&�	��'�>@�b�b�'�'�J���
��rRc�8�|j�||��SrH)rJro)rM�opt_name�defaults   rP�
get_optionzDistro.get_option�s���y�}�}�X�w�/�/�/rRc��||j|<dSrH)rJ)rMr��values   rP�
set_optionzDistro.set_option�s��#��	�(���rRc��|�||��}|�||j��|�|��dSrH)�_select_hostname�_write_hostname�hostname_conf_fn�_apply_hostname)rM�hostname�fqdn�writeable_hostnames    rP�set_hostnamezDistro.set_hostname�sM��!�2�2�8�T�B�B�����/��1F�G�G�G����/�0�0�0�0�0rRc��t��S)z?Wrapper to report whether this distro uses systemd or sysvinit.)�uses_systemd�rMs rPr�zDistro.uses_systemd�s���~�~�rRc��t���rHrY)rM�command�args�pkgss    rP�package_commandzDistro.package_command�r]rRc��t���rHrYr�s rP�update_package_sourceszDistro.update_package_sources�r]rRc�D�tj��d}|dvrdS|S)N�)�i386�i486�i586�i686r�)rw�uname)rMrs  rP�get_primary_archzDistro.get_primary_arch�s'���x�z�z�!�}���3�3�3��6��rRc�z�|�dg��}|s|���}t||��S)N�package_mirrors)r�r��_get_arch_package_mirror_info)rMr�mirror_infos   rPr�z$Distro._get_arch_package_mirror_info�s?���o�o�&7��<�<���	+��(�(�*�*�D�,�[�$�?�?�?rRc�N�|�|��}t||���S)N)�data_sourcer�)r��_get_package_mirror_info)rMrr��	arch_infos    rP�get_package_mirror_infozDistro.get_package_mirror_info�s3���6�6�t�<�<�	�'�#��
�
�
�	
rRTc�^�|�|��}|r|�|��SdS)r_F)ra�_bring_up_interfaces)rMr`�bring_up�	dev_namess    rP�
apply_networkzDistro.apply_network�s:���'�'��1�1�	��	8��,�,�Y�7�7�7��urRc��|j}t�d|��d�d|zdg��}t	j|��}t
j||d���}|�||���S)r_ziapply_network_config is not currently implemented for distribution '%s'.  Attempting to use apply_network�
z-# Converted from network_config for distro %sz4# Implementation of _write_network_config is needed.T)�header�render_hwaddress�r�)	�	__class__rm�warningryrrr�network_state_to_enir�)rM�	netconfigr��distror��ns�contentss       rP�"_apply_network_from_network_configz)Distro._apply_network_from_network_config�s���������
F��	
�	
�	
�
���?�&�H�F�
�
�
���
0��
;�
;���+��v��
�
�
���!�!�(�X�!�>�>�>rRc�(�tj��SrH)r�generate_fallback_configr�s rPr�zDistro.generate_fallback_config�s���+�-�-�-rRc��	|���}n'#t$r|�||���cYSwxYwt||���}|�||��|rUt
�d��|j}|st
�d��dS|�	|��nt
�d��dS)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�)rqz/Bringing up newly configured network interfacesz>No network activator found, not bringing up network interfacesTz3Not bringing up newly configured network interfacesF)
rrrZr�rrurmrnrir��bring_up_all_interfaces)rMr�r�rqrris      rP�apply_network_configzDistro.apply_network_config�s��	��)�)�+�+�H�H��"�	�	�	��:�:��H�;���
�
�
�	����.�i�(�K�K�K�
��!�!�-��:�:�:��	M��I�I�G�H�H�H� $� 6��$�
����)�����t��5�5�m�D�D�D�D��I�I�K�L�L�L��us��!;�;c��t���rHrY)rM�locale�out_fns   rP�apply_localezDistro.apply_localer]rRc��t���rHrY)rMr~s  rP�set_timezonezDistro.set_timezone"r]rRc��dS)Nz	127.0.0.1�r�s rP�_get_localhost_ipzDistro._get_localhost_ip&s���{rRc��t���rHrYr�s rP�
get_localezDistro.get_locale)s��!�#�#�#rRc��t���rHrY)rM�filenamer�s   rP�_read_hostnamezDistro._read_hostname,r]rRc��t���rHrY)rMr�r�s   rPr�zDistro._write_hostname0r]rRc��t���rHrYr�s rP�_read_system_hostnamezDistro._read_system_hostname4r]rRc���t�d|��	tjd|g��dS#tj$rt	jtd|��YdSwxYw)Nz2Non-persistently setting the system hostname to %sr�z;Failed to non-persistently adjust the system hostname to %s)rmrnr�ProcessExecutionErrorr�logexc)rMr�s  rPr�zDistro._apply_hostname8s���
	�	�	�@�(�	
�	
�	
�	��I�z�8�,�-�-�-�-�-���)�	�	�	��K��M��
�
�
�
�
�
�	���s�5�*A#�"A#c�V�tj|jd|j��r|r|S|s|S|S)N�prefer_fqdn_over_hostname)r�get_cfg_option_boolrJ�prefer_fqdn)rMr�r�s   rPr�zDistro._select_hostnameIsI��
�$��	�6��8H�
�
�	��		��K��	��K��rRc��g}|D]M}|tvr"td�|�����|�t|���N|S)Nz&No distributions found for osfamily {})�
OSFAMILIES�
ValueError�format�extend)�family_list�distros�familys   rP�expand_osfamilyzDistro.expand_osfamilyWse����!�	/�	/�F��Z�'�'� �<�C�C�F�K�K����
�N�N�:�f�-�.�.�.�.��rRc���|}|�||��}|r5tj�|��r|�|��}nd}|���\}}g}|r||kr|�|��|r||kr||kr|�|��|r&|r$||krt�d||��dStd�|D����}t�
d|t|����|D]E}		|�||	���#t$rtjtd||	��Y�BwxYw||vr|�|��dSdS)Nz6%s differs from %s, assuming user maintained hostname.c��g|]}|�|��Sr�r�)�.0�fs  rP�
<listcomp>z*Distro.update_hostname.<locals>.<listcomp>�s��9�9�9�!�q�9�A�9�9�9rRz/Attempting to update hostname to %s in %s filesz!Failed to write hostname %s to %s)r�rwrx�existsr�r��appendrm�info�setrn�lenr�r}rr�r�)
rMr�r��prev_hostname_fn�applying_hostname�
prev_hostname�sys_fn�sys_hostname�update_files�fns
          rP�update_hostnamezDistro.update_hostnamebs���$���(�(��4�8�8���	!�����/?� @� @�	!� �/�/�0@�A�A�M�M� �M�"&�!;�!;�!=�!=������
�	2�
�� 9� 9���� 0�1�1�1��	(��M�)�)�l�h�.F�.F�����'�'�'�
�	�M�	�l�m�.K�.K��H�H�H� ��
�
�
�

�F�
�9�9�|�9�9�9�:�:���	�	�=������	
�	
�	
��	�	�B�
��$�$�X�r�2�2�2�2���
�
�
����<�h�������
�����\�!�!�� � �!2�3�3�3�3�3�"�!s�D1�1&E�Ec�6�d}tj�|j��r,t	jt
j|j����}n)t	jd��}t
jd���}|�	��}|�
|��}d}|s|�|||��d}n�d}|D]L}d}	g}
t|��dkr|d}	t|��dkr
|dd�}
|	�|	|kr||
vrd}�M|r�t|��}|�||g��|�|��|D]S}t|��dkr|�||d���2t|��dkr|j|g|�R��T|rpt!��}|r|�d	|z��|�d	|z��t
j|j|���d
���dSdS)N��added��baseFTrEr�z%s
i�)�mode)rwrxr��hosts_fnr�	HostsConfr�	load_file�make_headerr��	get_entry�	add_entryr��listr��del_entriesr�write�
write_file�getvalue)
rMr�r�r��eh�local_ip�	prev_info�need_change�entry�
entry_fqdn�
entry_aliases�new_entriesr�s
             rP�update_etc_hostszDistro.update_etc_hosts�s<����
�7�>�>�$�-�(�(�	4������
�!>�!>�?�?�B�B����$�$�B��%�7�3�3�3�F��)�)�+�+���L�L��*�*�	����	7��L�L��4��2�2�2��K�K��K�"�

,�

,��!�
� "�
��u�:�:��?�?�!&�q��J��u�:�:��?�?�$)�!�"�"�I�M��)�j�D�.@�.@��=�0�0�&+����	
7�"�9�o�o���"�"�D�(�#3�4�4�4����x�(�(�(�(�7�7�E��5�z�z�Q������X�u�Q�x�8�8�8�8��U���q���$���X�6��6�6�6�6���	L��z�z�H��
2����v��0�1�1�1��N�N�6�R�=�)�)�)��O�D�M�8�+<�+<�+>�+>�U�K�K�K�K�K�K�	L�	LrRc�P�|jstt��|_|jS)z7Allow distro to determine the preferred ntp client list)�_preferred_ntp_clientsr�PREFERRED_NTP_CLIENTSr�s rP�preferred_ntp_clientszDistro.preferred_ntp_clients�s*���*�	F�*.�/D�*E�*E�D�'��*�*rRc��t�)r_rY)rM�device_names  rP�_bring_up_interfacezDistro._bring_up_interface�s��!�!rRc�X�d}|D]}|�|��s|dz
}�|dkrdSdS)r_rrETF)r)rM�device_names�	am_failed�ds    rPr�zDistro._bring_up_interfaces�sI���	��	�	�A��+�+�A�.�.�
��Q��	����>�>��4��urRc�,�|�d��S)N�default_user)r�r�s rP�get_default_userzDistro.get_default_user�s�����~�.�.�.rRc�F�tj|��rt�d|��dSd|vr|�d��}nd}d|g}d|g}tj��r*|�d��|�d��ddd	d
ddd
dddd�
}dddd�}dg}|�d��}	|	r�t|	t��r|	�
d��}	t|	t��rt�d|��d�|	D��}	d�
|	��|d<|�d��}
|
r|	�|
��|rL|	rJ|	D]G}tj|��s1|�|��t�d||���Hd|���vrt|d��|d<t%|�����D]�\}}
||vrt|
rrt|
t��r]|�|||
g��||vr|�||dg���_|�|||
g���}||vr8|
r6|�||��|�||����|�d��s|�d ��r+|�d!��|�d!��n*|�d"��|�d"��t�d#|��	t+j||�$��dS#t,$r"}tjtd%|��|�d}~wwxYw)&z�
        Add a user to the system using standard GNU tools

        This should be overriden on distros where useradd is not desirable or
        not available.
        z!User %s already exists, skipping.N�
create_groupsT�useradd�--extrausersz	--commentz--homez--gidz--uidz--groupsz
--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�DEPRECATED: The user %s has a 'groups' config value of type dict which is deprecated and will be removed in a future version of cloud-init. Use a comma-delimited string or array instead: group1,group2.c�6�g|]}|�����Sr���strip)r��gs  rPr�z#Distro.add_user.<locals>.<listcomp>)s ��0�0�0�A�a�g�g�i�i�0�0�0rRr%z created group '%s' for user '%s'r&�REDACTED�no_create_homer.z-Mz-mzAdding user %s��	logstringzFailed to create user %s)r�is_userrmr��pop�system_is_snappyr�ro�
isinstancer{�split�dictr�ry�is_group�create_grouprn�keys�sorted�itemsr�r�	Exceptionr�)rMrK�kwargsr �useradd_cmd�log_useradd_cmd�useradd_opts�
useradd_flags�redact_optsr'r%�group�key�val�es               rP�add_userzDistro.add_user�s���<����	��H�H�8�$�?�?�?��F��f�$�$�"�J�J��7�7�M�M� �M� �$�'��$�d�+��� �"�"�	3����~�.�.�.��"�"�>�2�2�2�!��$�� �"��(�$�,�
�
��/� �*�
�
�
� �j�����H�%�%���	-��&�#�&�&�
+����c�*�*���&�$�'�'�
����?�����1�0��0�0�0�F� #�x�x��/�/�F�8��"�J�J��7�7�M��
-��
�
�m�,�,�,��	O�V�	O��
O�
O���}�U�+�+�O��%�%�e�,�,�,��I�I�@�%��N�N�N���F�K�K�M�M�!�!���u�
�.�.�F�5�M��v�|�|�~�~�.�.�
	;�
	;�H�C���l�"�"�s�"�z�#�s�/C�/C�"��"�"�L��$5�s�#;�<�<�<��+�%�%�#�*�*�L��,=�z�+J�K�K�K�K�#�*�*�L��,=�s�+C�D�D�D�D��
�%�%�#�%��"�"�=��#5�6�6�6��&�&�}�S�'9�:�:�:���:�:�&�'�'�	)�6�:�:�h�+?�+?�	)����t�$�$�$��"�"�4�(�(�(�(����t�$�$�$��"�"�4�(�(�(�	�	�	�"�D�)�)�)�	��I�k�_�=�=�=�=�=�=���	�	�	��K��7��>�>�>��G�����	���s�M4�4
N �>N�N c��|�d��}|�dd��}gd�}|r|�d��|�|��t�d|��	t	j||d���\}}t�d	||��tj|��}|�d
d��}	n/#t$r"}
tjtd|��|
�d}
~
wwxYw|	S)
zD
        Add a snappy user to the system using snappy tools
        �snapuser�knownF)�snapzcreate-userz--sudoerz--jsonz--knownzAdding snap user %sT)r8�capturez snap create-user returned: %s:%s�usernameNzFailed to create snap user %s)	ror�rmrnrr�	load_jsonrDr�)rMrKrErQrR�create_user_cmd�out�err�jobjrUrNs           rP�
add_snap_userzDistro.add_snap_user\s��
�:�:�j�)�)���
�
�7�E�*�*��G�G�G���	.��"�"�9�-�-�-����x�(�(�(�	�	�	�'��.�.�.�		����?�D����J�S�#�
�I�I�8�#�s�C�C�C��>�#�&�&�D��x�x�
�D�1�1�H�H���	�	�	��K��<�d�C�C�C��G�����	�����s�8A C�
D�#D�Dc���d|vr|j|fi|��S|j|fi|��d|vr$|dr|�||d��d|vr&|dr|�||dd���|�dd��r|�|��d|vrJ|dr|�||d��n%|ddurt�d	|��d
|vr�|d
}t|t��r|g}n6t|t��r!t|�����}|�^t|tttf��s+t�dt|����g}nt|��pg}t!jt|��|��d
|vr�|�dg��}|s#t�d||d
��nd|d
}t j}|�d|��}|�d|��}t!jt|��||���dS)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``
        * ``sudo``
        * ``ssh_authorized_keys``
        * ``ssh_redirect_user``
        rQ�plain_text_passwd�
hashed_passwdT)�hashed�lock_passwd�sudoFzxDEPRECATED: The user %s has a 'sudo' config value of 'false' which will be dropped after April 2027. Use 'null' instead.�ssh_authorized_keysNzZInvalid 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[rO�
set_passwdror`�write_sudo_rulesrmr�r<r{r>r�values�tupler��typer
�setup_user_keys�DISABLE_USER_OPTS�replace)rMrKrErA�
cloud_keys�
redirect_user�disable_options       rP�create_userzDistro.create_userws���*����%�4�%�d�5�5�f�5�5�5�	��
�d�%�%�f�%�%�%��&�(�(�V�4G�-H�(��O�O�D�&�)<�"=�>�>�>��f�$�$���)@�$��O�O�D�&��"9�$�O�G�G�G��:�:�m�T�*�*�	#����T�"�"�"��V����f�~�
��%�%�d�F�6�N�;�;�;�;����5�(�(����+��	���!�F�*�*��/�0�D��$��$�$�
+��v����D�$�'�'�
+��D�K�K�M�M�*�*����!�$���c�(:�;�;�	+��K�K�1��T�
�
�	����D�D��t�9�9�?��D��$�S��Y�Y��5�5�5��&�(�(����$;�R�@�@�J��
����L���.�/�	����!'�':� ;�
�!)�!;��!/�!7�!7���!O�!O��!/�!7�!7���!N�!N���(��
�O�O�T�>������trRc�>�dd|gdd|gf}	td�|D����}n3#t$r&}td|�dd�|D���d	���|�d
}~wwxYw	tj|��d
S#t$r"}tjtd|��|�d
}~wwxYw)zL
        Lock the password of a user, i.e., disable password logins
        r(z-l�usermodz--lockc3�NK�|] }tj|d���|V��!dS)rN)r�which)r��tools  rP�	<genexpr>z%Distro.lock_passwd.<locals>.<genexpr>�s5����J�J��d�j��a��6I�6I�J�t�J�J�J�J�J�JrRzUnable to lock user account 'z '. No tools available.   Tried: c��g|]
}|d��S)rr�)r��cs  rPr�z&Distro.lock_passwd.<locals>.<listcomp>�s��(B�(B�(B�!��1��(B�(B�(BrR�.Nz&Failed to disable password for user %s)�next�
StopIteration�RuntimeErrorrrDrr�rm)rMrK�
lock_tools�cmdrNs     rPr`zDistro.lock_passwd�s���
 ��t�,�y�(�D�.I�J�
�	��J�J�
�J�J�J�J�J�C�C���	�	�	��,�"&�$�$�(B�(B�z�(B�(B�(B�(B�(B�D����
�����	����
	��I�c�N�N�N�N�N���	�	�	��K��E�t�L�L�L��G�����	���s,�&�
A�!A�A�A0�0
B�:B�Bc��	tjdd|g��dS#t$r"}tjtd|��|�d}~wwxYw)Nr(z--expirezFailed to set 'expire' for %s)rrDrr�rm)rM�userrNs   rP�
expire_passwdzDistro.expire_passwd�s]��	��I�x��T�2�3�3�3�3�3���	�	�	��K��<�d�C�C�C��G�����	���s��
A�A�Ac���|�d|��}dg}|r|�d��	tj||d|z���n/#t$r"}tjt
d|��|�d}~wwxYwdS)N�:�chpasswd�-ezchpasswd for %sr7zFailed to set password for %sT)r�rrDrr�rm)rMr�r(r_�pass_stringrrNs       rPrfzDistro.set_passwd�s���!%���v�v�.���l���	�
�J�J�t����	��I�c�;�2C�d�2J�K�K�K�K�K���	�	�	��K��<�d�C�C�C��G�����	�����ts�>�
A*�A%�%A*�plist_inr_c��d�d�|D����dz}dg|rdgngz}tj||��dS)Nr�c3�JK�|]\}}d�||g��V��dS)r�N�ry)r�rK�passwords   rPrwz"Distro.chpasswd.<locals>.<genexpr>s7����K�K���h����4��*�+�+�K�K�K�K�K�KrRr�r�)ryr)rMr�r_�payloadrs     rPr�zDistro.chpasswd�sd���I�I�K�K�(�K�K�K�
�
��
�	��l��6�t�f�f�B�7���	�#�w�����rR�/etc/sudoersc��d}d}tj�|��rtj|��}d}d}|���D]�}|���}tjd|��}|s�.|�	d�����}|s�Xtj�
|��}||krd}n��|s�	|sIddtjd���d	|zdg}	d
�|	��}tj
||d��nFdtjd���d	|zdg}	d
�|	��}tj||��t�d||��n/#t"$r"}
tjtd
|��|
�d}
~
wwxYwtj|d��dS)Nr�FTz^[#|@]includedir\s+(.*)$rEz?# See sudoers(5) for more information on "#include" directives:r�r�z#includedir %sr�� zAdded '#includedir %s' to %szFailed to write %si�)rwrxr�rr��
splitlinesr3�re�searchrK�abspathrryr�append_filermrnr}r��
ensure_dir)rMrx�	sudo_base�sudoers_contents�base_exists�
found_include�line�
include_match�included_dir�linesrNs           rP�ensure_sudo_dirzDistro.ensure_sudo_dirs������
�7�>�>�)�$�$�	�#�~�i�8�8���K��
�$�/�/�1�1�	�	�D��:�:�<�<�D��I�&A�4�H�H�M� �
��(�.�.�q�1�1�7�7�9�9�L��
���7�?�?�<�8�8�L��t�#�#� $�
���$��	�
�"�B�5���(�g�6�6�6�(�D�1��
�E�(,�y�y��'7�'7�$��O�I�/?��G�G�G�G���(�g�6�6�6�(�D�1��	�E�(,�y�y��'7�'7�$��$�Y�0@�A�A�A��	�	�8�$�	�J�J�J�J���
�
�
���C�!5�y�A�A�A�������
����	
���e�$�$�$�$�$s�B-F�
F/�
F*�*F/c��|s|j}dd|zg}t|ttf��r |D]}|�|�d|�����nVt|t
��r|�|�d|����n&d}t
|tj|��z���d�	|��}|dz
}|�
tj�
|����tj�|��sptj��|g}	tj|d�	|��d��dS#t$$r"}	tjt(d|��|	�d}	~	wwxYw	tj||��dS#t$$r"}	tjt(d|��|	�d}	~	wwxYw)	Nr�z# User rules for %s� z1Can not create sudoers rule addition with type %rr�r�zFailed to write sudoers file %sz Failed to append sudoers file %s)�
ci_sudoers_fnr<rrir�r{�	TypeErrorr�obj_nameryr�rwrx�dirnamer�rrrr}r�rmr�)
rMr��rules�	sudo_filer��rule�msg�contentr�rNs
          rPrgzDistro.write_sudo_rules9s����	+��*�I�
�!�D�(�
���e�d�E�]�+�+�	@��
5�
5��������d�d�3�4�4�4�4�
5�
��s�
#�
#�	@��L�L�D�D�D�%�%�0�1�1�1�1�E�C��C�:�#6�u�#=�#=�>�?�?�?��)�)�E�"�"���4������R�W�_�_�Y�7�7�8�8�8��w�~�~�i�(�(�	�� �"�"���H�
���	�4�9�9�X�+>�+>��F�F�F�F�F���
�
�
���C�!B�I�N�N�N�������
����
�� ��G�4�4�4�4�4���
�
�
���C�!C�Y�O�O�O�������
���s0�$)E�
E;�E6�6E;�?F�
G� F=�=Gc�~�d|g}tj��r|�d��|sg}tj|��rt�d|��n\	t
j|��t�d|��n+#t$rtj	td|��YnwxYwt|��dkrk|D]j}tj|��st�d||���3t
jdd	d
||g��t�d||���idSdS)N�groupaddr"z(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.rsz-az-GzAdded user '%s' to group '%s')rr;r�r?rmr�rr�rDr�r�r9)rMrK�members�
group_add_cmd�members     rPr@zDistro.create_group^sx��#�T�*�
�� �"�"�	1�� � ��0�0�0��	��G��=����	D��K�K�B�D�I�I�I�I�
D��	�-�(�(�(����/��6�6�6�6���
D�
D�
D���C�!<�d�C�C�C�C�C�
D�����w�<�<�!���!�
H�
H���|�F�+�+���K�K�1���	�����	�9�d�D�$��?�@�@�@����8�&�$�G�G�G�G���
H�
Hs�"/B�%B:�9B:c���d|j|g}	|dkrdt|��z}n&#t$r}td|�d���|�d}~wwxYw||gz}|r|�|��|S)N�shutdown�nowz+%dz;power_state[delay] must be 'now' or '+m' (minutes). found 'z'.)�shutdown_options_map�intr�r�r�)rMr��delay�messager�rNr�s       rP�shutdown_commandzDistro.shutdown_command~s����t�8��>�?��	���~�~���E�
�
�*�����	�	�	��)�"'�%�%�*����
�����	����
�%�� ���	!��K�K�� � � ��s�*�
A
�A�A
�actionc	�*�|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
        �	systemctl�stop�start�enable�disable�restartzreload-or-restartzreload-or-try-restart�status)r�r�r�r�r��reloadz
try-reloadr�T)rT)�init_cmdr�rr)rMr�r?r��cmdsrs      rP�manage_servicezDistro.manage_service�s����=�������	�+��"9�"9�#�}�H���)�!�7�+�#�W�-�%�w�/�%�w�/�.��8�6��@�#�W�-�	�	�D�D�!�&�)�!�7�+�"�G�,�#�V�,�#�Y�/�"�I�.�&�	�2�"�H�-�	�	�D��8�n�n�t�D��L�1�1�1���y��d�+�+�+�+rRc�~�|���rtjdd||||g��dSt���)N�	localectlzset-x11-keymap)r�rrZ)rM�layout�model�variantres     rP�
set_keymapzDistro.set_keymap�sY�������	(��I��$�����
�	
�	
�	
�	
�	
�&�'�'�'rRc��tjd���}tj|d��s|Stj�|jdd��S)NT)�	needs_exe�noexecz
cloud-init�clouddir)r�get_tmp_ancestorr�
has_mount_optrwrxry�usr_lib_exec)rM�tmp_dirs  rP�get_tmp_exec_pathzDistro.get_tmp_exec_path�sJ���-��=�=�=���!�'�8�4�4�	��N��w�|�|�D�-�|�Z�H�H�HrRr�r�r��cwdc
�v�|rd|�d�nd}tjdd|d|dzd�|��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 && r��sur<z-czenv PATH=$PATH r�)rry)rMr�r�r�rE�	directorys      rP�do_aszDistro.do_as�sh��(+�2�O�#�O�O�O�O��	��y������-�-�����0A�0A�A�
�	
�	
��	
�	
�		
rRrH)NN)T)F)r�)r�)Y�__name__�
__module__�__qualname__�pip_package_namer�r�r�r�rz�
default_ownerr�r@rr{rr�__annotations__rrrArrr��_ci_pkl_versionr��resolve_conf_fnrQr�rW�abc�abstractmethodr\ra�propertyrr�NetworkActivatorrirrrrur�r�r�r�r�r�r�r�r�r�r�r�r��boolr�r�r�r�r�r�r�r�r�r��staticmethodr�r�rrrr�rrOr[rqr`r�rfrr�r�rgr@r�r�r�r�r�r�rRrPr>r>Ssf�������$���L��H�8�M�&��'�K��M��{�H�?A��g�c�>�#�s�(�#;�;�<�A�A�A�!��'6�N�D��$�6�6�6�%)�d�d�K�K���O��K�(�O��M�M�M�<�<�<�
4��
4��
4�
4�
4�
4�	��$�$���$�
�
�
���8�D��1L�,M�#N�����X��
�x�
�
�
�
�5�H�5�5�5�5����0�0�0�0�$�$�$�$�1�1�1�1�
���	��$�$�$���$�	��$�$���$����@�@�@�@�
�
�
�
�
�
�
�
�?�?�?�?�(.�.�.�#�#��#�#�#�#�J	��$�$�$���$�	��$�$���$����$�$�$�	��$�$�$���$�	��$�$���$�	��$�$���$����"�������\��?4�?4�?4�B)L�)L�)L�V�+�+��X�+�"�"�"����/�/�/�s�s�s�j���6Y�Y�Y�v���&�������$ �� �t� � � � �/%�/%�/%�/%�b#�#�#�#�JH�H�H�H�@���  ,�S� ,�3� ,� ,� ,� ,�D
(�
(�
(�I�3�I�I�I�I�
�
�T�
��
�3�
�
�
�
�
�
rRr>)�	metaclass�url�transformationsc�V�	tj�|��}n#t$rYdSwxYw|j}|�dS|D]}||��}|�|cS�|}|j�d�||j��}tj�|�|�����S)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 unparseable.
    Nz{}:{})�netloc)	�urllib�parse�urlsplitr�r��portr��
urlunsplit�_replace)r�r��parts�new_hostname�transformation�
new_netlocs      rP�&_apply_hostname_transformations_to_urlr��s���&���%�%�c�*�*���������t�t������>�L����t�)����%�~�l�3�3�����J�J�J� �
�J��z���^�^�J��
�;�;�
��<�"�"�5�>�>��>�#D�#D�E�E�Es�"�
0�0c�P��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.
    rzc�2�tj|��rdn|SrH)r�
is_ip_address�r�s rP�<lambda>z&_sanitize_mirror_url.<locals>.<lambda>0s���!2�8�!<�!<�J���(�rRc�R�|�d���d��S)N�idna�ascii)�encode�decoder�s rPr�z&_sanitize_mirror_url.<locals>.<lambda>3s ������0�0�7�7��@�@�rRc�F��d��fd�|D����S)Nr�c3�(�K�|]}|�vr|ndV��
dS�r<Nr�)r�ry�acceptable_charss  �rPrwz9_sanitize_mirror_url.<locals>.<lambda>.<locals>.<genexpr>5sC�����!
�!
�45��&�&�&�A�A�C�!
�!
�!
�!
�!
�!
rRr�)r�rs �rPr�z&_sanitize_mirror_url.<locals>.<lambda>5s;������!
�!
�!
�!
�9A�!
�!
�!
�
�
�rRc�f�d�d�|�d��D����S)Nrzc3�@K�|]}|�d��V��dSrr2)r��parts  rPrwz9_sanitize_mirror_url.<locals>.<lambda>.<locals>.<genexpr>9s=����"
�"
� $�D�J�J�s�O�O�"
�"
�"
�"
�"
�"
rR)ryr=r�s rPr�z&_sanitize_mirror_url.<locals>.<lambda>9s<�����"
�"
�(0���s�(;�(;�"
�"
�"
�
�
�rR)�LDH_ASCII_CHARSr�)r�r�rs  @rP�_sanitize_mirror_urlr	sZ���L'��,��	K�J�	A�@�	
�	
�	
�	
�	
�	
��O�"2�#��G�G�GrRc��|si}i}|rb|jr[|j|d<t�|j��r2|jdd�}tr	d|z|d<n|jdkrd|z|d<|r|jr
|j|d<i}|�di�����D]
\}}|||<�|�d	i�����D][\}}g}	|D]?}
	|
|z}n#t$rY�wxYwt|��}|�|	�
|���@||	��}|r|||<�\t�d
|��|S)N�availability_zoner���z%s�
ec2_region�ec2�region�failsafer�zfiltered distro mirror info: %s)
r�
_EC2_AZ_RE�matchr�
platform_typerrorC�KeyErrorr	r�rmrn)r�r��
mirror_filter�substr
�resultsrK�mirror�
searchlist�mirrors�tmpl�founds            rPr�r�As��������E��8�{�4�8�%0�%B��!�"����K�9�:�:�	8�$�6�q��t�<�J�:�
8�&*�Z�&7��l�#�#��*�e�3�3�&*�Z�&7��l�#��-�{�)�-�%�,��h���G�%�/�/�*�b�9�9�?�?�A�A�����v����
�
�)�o�o�h��;�;�A�A�C�C�"�"���z����	'�	'�D�
��������
�
�
���
����*�&�1�1�F��!����v�&�&�&���
�g�&�&���	"�!�G�D�M���I�I�/��9�9�9��Ns�'C-�-
C:�9C:c�Z�d}|D]%}|�d��}||vr|cSd|vr|}�&|S)N�archesr�)ro)r�rr��itemrs     rPr�r�tsO���G��������(�#�#���6�>�>��K�K�K������G���NrRrKrTc���tj|dtgdg��\}}|std|�d|�d����tj|d��}t|d��}|S)Nr�r>z!No distribution found for distro z (searched �)r)r	�find_moduler��ImportError�
import_module�getattr)rK�locs�looked_locs�mod�clss     rP�fetchr*�sy�� �,�T�B��>�H�:�N�N��D�+��
��k��t�t�[�[�[�
"�
�
�	
��
 ��a��
)�
)�C�
�#�x�
 �
 �C��JrR�
/etc/timezone�/etc/localtimec�~�tj|t|�����dz��|r�|r�tj�|��}|stj�|��s,|rtj|��t	j	||��ntj
||��dS)Nr�)rrr{�rstriprwrx�islinkr��del_file�symlink�copy)r~r�tz_conf�tz_localr/s     rP�set_etc_timezoner5�s���	�O�G�S��W�W�^�^�-�-��4�5�5�5��)�G�)������)�)���	)������1�1�	)��
(��
�h�'�'�'��J�w��)�)�)�)��I�g�x�(�(�(�
�FrRc��	tjd��}tj|j��S#t
$rYdSwxYw)Nz/run/systemd/systemF)rw�lstat�stat�S_ISDIR�st_moderD)�ress rPr�r��sK����h�,�-�-���|�C�K�(�(�(�������u�u����s�,/�
=�=)Nr+r,)Br�rwr�r8�string�urllib.parser��ior�typingrrrrr�	cloudinitr	r
�loggingrrr
rrrr�cloudinit.distros.networkingrr�cloudinit.distros.parsersr�cloudinit.featuresr�
cloudinit.netrrrr�cloudinit.net.network_stater�cloudinit.net.rendererr�ALL_DISTROSr��	getLoggerr�rm�compilerr�
ascii_letters�digitsr�CloudInitPickleMixin�ABCMetar>r{rr�r	�search_for_mirrorr�r�r*r5r�r�rRrP�<module>rPs9���
�
�
�	�	�	�	�	�	�	�	�����
�
�
�
�����������?�?�?�?�?�?�?�?�?�?�?�?�?�?�������$�$�$�$�$�$�������������������E�D�D�D�D�D�D�D�+�+�+�+�+�+�J�J�J�J�J�J�C�C�C�C�C�C�C�C�C�C�C�C�=�=�=�=�=�=�+�+�+�+�+�+����j�
�H���"��;�'�����j��{���� �� �1��
�6�g���!�!���R�Z�=�
>�
>�
�J�I�I���&���6��<��E
�E
�E
�E
�E
�[�
-���E
�E
�E
�E
�P(F��(F�d�(F�(F�(F�(F�V8H�c�8H�8H�8H�8H�x"��1G�0�0�0�0�f	�	�	�	��	��V��	�	�	�	�9I�����"����rR