%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/cloudinit/distros/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/cloudinit/distros/__pycache__/alpine.cpython-312.pyc

�

���fda����ddlZddlZddlZddlZddlmZddlmZmZmZddl	m
Z
mZmZm
Z
mZddlmZddlmZmZej(e�ZdZGd�d	e
j0�Zy)
�N)�datetime)�Any�Dict�Optional)�distros�helpers�	lifecycle�subp�util)�HostnameConf)�
PER_ALWAYS�PER_INSTANCEa7# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}

c�p��eZdZdZdZdZdZdZdeed�iZ	dZ
d	Zd
�Zd�Z
d0d
�Zdej fd�Zd�Zd�Zd�Zd0d�Zd�Zdedededefd�Zd�Zd1d�Zdd�d�Zed��Zd ef�fd!�Z�fd"�Z d#ef�fd$�Z!�fd%�Z"d0�fd&�	Z#d2d'�Z$e%d(��Z&e'dd)�d*ed+ed,efd-��Z(e%d.ed e)efd/��Z*�xZ+S)3�Distrozpy3-pipz/usr/share/bkeymaps/z&/etc/profile.d/50-cloud-init-locale.shz/etc/network/interfacesz/etc/shadow�eni)�eni_path�
eni_headerz
/var/lib/dhcpzdhclient\.leasesc��tjj||||�tj|�|_d|_d|_d|d<y)NzC.UTF-8�alpine�sshd�ssh_svcname)rr�__init__r�Runners�_runner�default_locale�osfamily)�self�name�cfg�pathss    �:/usr/lib/python3/dist-packages/cloudinit/distros/alpine.pyrzDistro.__init__.sE��������d�C��7����u�-���'��� ��
�#��M��c��|jS)zgThe default locale for Alpine Linux is different than
        cloud-init's DataSource default.
        )r�rs r!�
get_localezDistro.get_locale8s���"�"�"r"Nc��|s|j}|s|j}ddddd|zddg}tj|dj	|�d�y)	N�#z?# This file is created by cloud-init once per new instance bootzexport CHARSET=UTF-8zexport LANG=%szexport LC_COLLATE=C��
�)r�locale_conf_fnr�
write_file�join)r�locale�out_fn�liness    r!�apply_localezDistro.apply_locale>s^����(�(�F���(�(�F�
�M��"��v�%�!��
��	
�����	�	�%� 0�%�8r"�pkglistc�J�|j�|jd|��y)N�add)�pkgs)�update_package_sources�package_command)rr2s  r!�install_packageszDistro.install_packagesQs!���#�#�%����U���1r"c�<�d}	|j|�}|std�}|j|�tj|t|�d�y#t$r>tj|jdd�}|rnt
j
d�YyY��wxYw)N�create_hostname_fileTz8create_hostname_file is False; hostname file not createdr(r*)�_read_hostname_conf�IOErrorr�get_cfg_option_bool�_cfg�LOG�infor�set_hostnamer,�str)r�hostname�filename�confr:s     r!�_write_hostnamezDistro._write_hostnameUs�����	��+�+�H�5�D����#�D����(�#�����#�d�)�U�3���
	�#'�#;�#;��	�	�1�4�$� �$�����N����
	�s�A�AB�Bc�T�|j|j�}|j|fS�N)�_read_hostname�hostname_conf_fn)r�sys_hostnames  r!�_read_system_hostnamezDistro._read_system_hostnameks)���*�*�4�+@�+@�A���%�%�|�4�4r"c�b�ttj|��}|j�|SrH)rr�load_text_file�parse)rrDrEs   r!r;zDistro._read_hostname_confos%���D�/�/��9�:���
�
���r"c�l�d}	|j|�}|j}|s|S|S#t$rY�wxYwrH)r;rCr<)rrD�defaultrCrEs     r!rIzDistro._read_hostnametsH����	��+�+�H�5�D��}�}�H���N����	�	��	�s�'�	3�3c��y)Nz	127.0.1.1�r$s r!�_get_localhost_ipzDistro._get_localhost_ips��r"�layout�model�variant�optionsc���|s"d}tj|�t|��tjj|j|�}tjj|�s%d|z}tj|�t|��|s"d}tj|�t|��tjj|d|z�}tjj|�s%d|z}tj|�t|��|rtjd�|rtjd�tjd||g�y)	NzKeyboard layout not specified.z,Keyboard layout directory %s does not exist.zKeyboard variant not specified.z
%s.bmap.gzz(Keyboard variant file %s does not exist.z+Keyboard model is ignored for Alpine Linux.z.Keyboard options are ignored for Alpine Linux.zsetup-keymap)r?�error�RuntimeError�os�pathr-�keymap_path�isdir�isfile�warningr
)rrUrVrWrX�msg�keymap_layout_path�keymap_variant_paths        r!�
set_keymapzDistro.set_keymap�s���2�C��I�I�c�N��s�#�#��W�W�\�\�$�*:�*:�F�C���w�w�}�}�/�0�>�$�%�
�
�I�I�c�N��s�#�#��3�C��I�I�c�N��s�#�#� �g�g�l�l���w� 6�
���w�w�~�~�1�2�:�%�&�
�
�I�I�c�N��s�#�#���K�K�E�F���K�K�H�I��	�	�>�6�7�3�4r"c�P�tj||j|���y)N)�tz�tz_file)r�set_etc_timezone�
_find_tz_file)rrgs  r!�set_timezonezDistro.set_timezone�s��� � �B��0B�0B�2�0F�Gr"c��|�g}dg}|jd�|r"t|t�r|j|�n#|r!t|t�r|j	|�|r|j|�|dk(r|j	ddg�tjd|�}|j	|�tj|d��y)	N�apkz--quiet�upgradez--update-cachez--availablez%s-%sF)�capture)�append�
isinstancerB�list�extendr�expand_package_listr
)r�command�argsr5�cmdr2s      r!r7zDistro.package_command�s����<��D��g���
�
�9���J�t�S�)��J�J�t��
�j��t�,��J�J�t����J�J�w���i���J�J�(�-�8�9��*�*�7�D�9���
�
�7��	
�	�	�#�u�%r"F)�forcec�|�|jjd|jdg|rt��yt��y)Nzupdate-sources�update)�freq)r�runr7r
r)rrxs  r!r6zDistro.update_package_sources�s>��������� � �
�J�$��		�	
�+7�		�	
r"c�D�|js	ddg|_|jS)z7Allow distro to determine the preferred ntp client list�chrony�ntp)�_preferred_ntp_clientsr$s r!�preferred_ntp_clientszDistro.preferred_ntp_clients�s&���*�*�+3�U�*;�D�'��*�*�*r"�returnc�R
��tj|�rtjd|�yd|vrtj	d�|d=tjd�rt�|� |fi|��S|jdd�}dd	g}d
ddd
dd�}ddi}|jd�}|r�t|t�r|jd�}n,t|t�rtj d|�d�dd��|D�cgc]}|j#���}}dj%|�|d<|jd�r|j'|d�|rG|rE|D]@}	tj(|	�r�|j+|	�tj-d|	|��Bd|vrt|d�|d<gdddd�}
t/|j1��D]�\}}||vr)|r't|t�r|j3|||g��3||
vr2|r0t|t�r |dk(r|jd�|
|<�c||
|<�i||vs�n|s�q|j'||���|jd�s|jd�r|j'd�|j'|�tj-d |�	tj
|�|
dD]1}tj-d"|�	tj
d#||g��3|
d%rt�|�q||
d%d�&�|
d'}|
d(}d}|j:}	tj<|�}d}|jA�D]}|jd*�}|d+|k(s�|}n|r�d,}d,d-<d,|d.<d,|d/<d0}|�RtCjD|�tCjDd1�z
jF}t|�|d2<|d,k7r|d3z}|d4z}|�||d5<|d,k7r|d3z}|d6z}|jI|d*j%|��}tj-d7||�	tjJ||d8d�9�ytj6td;||�ycc}w#t
j4$r}
tj	d!|�|
�d}
~
wwxYw#t
j4$r#}
tj6td$||�|
�d}
~
wwxYw#t>$r}
tj	d)|�|
�d}
~
wwxYw#tL$r"}
tj6td:|�|
�d}
~
wwxYw)<z�
        Add a user to the system using standard tools

        On Alpine this may use either 'useradd' or 'adduser' depending
        on whether the 'shadow' package is installed.

        Returns False if user already exists, otherwise True.
        z!User %s already exists, skipping.F�selinux_userz0Ignoring selinux_user parameter for Alpine Linux�useradd�
create_groupsT�adduserz-Dz-gz-hz-Gz-s�-u)�gecos�homedir�
primary_group�shell�uid�systemz-S�groups�,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�N)r��
expiredate�inactive�passwd�no_create_homez-HzAdding user %szFailed to create user %szAdding user to group %s�addgroupz!Failed to add user %s to group %sr�)�hashedr�r��&Failed to read %s file, file not found�:rr(���zpassword agingz
1970-01-01�z & zacct expiration date�zinactivity periodzUpdating %s for user %s�w��omode�
preserve_mode�Failed to update %s filezFailed to update %s for user %s)'r�is_userr?r@rar
�which�super�add_user�pop�getrqrB�split�dictr	�	deprecate�stripr-rp�is_group�create_group�debug�sorted�itemsrs�ProcessExecutionError�logexc�
set_passwd�	shadow_fnrN�FileNotFoundError�
splitlinesr�
fromisoformat�days�replacer,r<)rr�kwargsr��adduser_cmd�adduser_opts�
adduser_flagsr��g�group�unsupported_busybox_values�key�val�e�
addn_groupr�r��shadow_contents�shadow_file�
original_line�line�new_line_parts�update_typer��	__class__s                        �r!r�zDistro.add_user�s�����<�<����H�H�8�$�?���V�#��K�K�J�K��~�&��:�:�i� ��7�#�D�3�F�3�3��
�
�?�D�9�
� �$�'����!���
��"�4�(�
����H�%����&�#�&����c�*���F�D�)��#�#�!*�4�&�1#� #�'-�#4�	�*0�0�A�a�g�g�i�0�F�0� #�x�x��/�F�8���z�z�/�*��
�
�f�_�5�6��V��
O���}�}�U�+��%�%�e�,��I�I�@�%��N�
O��F�?���u�
�.�F�5�M�����	6
�"��v�|�|�~�.�	7�H�C���l�"�s�z�#�s�/C��"�"�L��$5�s�#;�<��1�1���s�C�(��(�?�69�i�i��n�.�s�3�69�.�s�3��
�%�#��"�"�=��#5�6�	7�&�:�:�&�'�6�:�:�h�+?����t�$�	���4� �	�	�	�"�D�)�	��I�I�k�"�5��
�
	�J�
�I�I�/��<�
��	�	�:�t�Z�8�9�
	�&�h�/�
�G���0��:�4�
�
�&0��=�
�-�j�9�����n�n��	�"�1�1�+�>�O��
�#�.�.�0�	�D�!�Z�Z��_�N��a� �D�(� $�
��		���K�!#�N�1�� "�N�1�� "�N�1��*�K��%��*�*�:�6��,�,�\�:�;��$��%(��I��q�!��"�$�"-��"5�K�)�,B�B���#�$,��q�!��"�$�"-��"5�K�)�,?�?��.�5�5��s�x�x��7��O�
�I�I�/��d�C�
�������4���
�K�K��6��T�
�
��C1��l�)�)�	��K�K�2�D�9��G��	���-�-�
�����<�d�J�����	
��F!�	��K�K�@�+�N��G��	��b�
����C�!;�[�I����
�sf�6Q!�(Q&�R�)S�*S;�&R�9R�R�S�,S
�
S�	S8�S3�3S8�;	T&�T!�!T&c�r��tjjd�rdtjd�vrt�|�|�Sdd|g}	t
j|ddg��\}}tjd|�ry	y#tj$r"}tjtd
|�|�d}~wwxYw)zL
        Lock the password of a user, i.e., disable password logins
        �/usr/bin/passwd�bbsuidr�z-lr���rcszis already lockedTz&Failed to disable password for user %sN)
r\r]�islink�readlinkr��lock_passwdr
�re�searchr�rr�r?)rrrw�_out�errr�r�s      �r!r�zDistro.lock_passwd�s�����w�w�~�~��
�
�R�[�[�):�;�
;��7�&�t�,�,���t�$��	��)�)�C�a��V�4�K�T�3��y�y�-�s�3��4���)�)�	��K�K��E�t�L��G��	���
2B�B6�B1�1B6rc�r��tjjd�rdtjd�vrt�|�|�Sdd|g}	t
j|ddg��\}}tjd|�ry	y#tj$r"}tjtd
|�|�d}~wwxYw)zM
        Unlock the password of a user, i.e., enable password logins
        r�r�r�r�rr�r�zis already unlockedTz%Failed to unlock password for user %sN)
r\r]r�r�r��
unlock_passwdr
r�r�r�rr�r?)rrrw�_r�r�r�s      �r!r�zDistro.unlock_passwd�s�����w�w�~�~��
�
�R�[�[�):�;�
;��7�(��.�.���t�$��	��Y�Y�s��A��/�F�A�s��y�y�/��5��6���)�)�	��K�K��D�d�K��G��	�r�c�B��tjjd�rdtjd�vrt�|�|�Sd}|j}	tj|�}d}|j�D]5}|jd�}|d|k(s�tjd|�|}n|rwddk7rXd|d<|j|dj!|�d	�}tjd
|�	tj"||dd�
�ytjd|�ytj&td|�y#t$r}tjd|�|�d}~wwxYw#t$$r"}tj&td|�|�d}~wwxYw)Nr�r�r�r�rz'Found /etc/shadow line matching user %s��0r�zExpiring password for user %sr�Tr�r�z'Password for user %s is already expiredzFailed to set 'expire' for %s)r\r]r�r�r��
expire_passwdr�rrNr�r?rar�r�r�r�r-r,r<r�)	r�userr�r�r�r�r�r�r�s	        �r!r�zDistro.expire_passwd�s�����w�w�~�~��
�
�R�[�[�):�;�
;��7�(��.�.����n�n��	�"�1�1�+�>�O��
�#�.�.�0�	�D�!�Z�Z��_�N��a� �D�(��	�	�C�T�J� $�
��	��
�a� �C�'�%(��q�!�"1�"9�"9�!�3�8�8�N�#;�Q�#���	�	�9�4�@�	��O�O�#�'�!�&*�	��	�	�C�T�J��K�K��<�d�C��Q!�	��K�K�@�+�N��G��	��D���K�K��%?��M��G���s0�E
�=E3�
	E0�E+�+E0�3	F�<F�Fc�\��tjd�rt�|�
||�Sd|g}|sg}t	j
|�rtjd|�n,	tj|�tjd|�t|�dkDrd|D]^}t	j|�stjd||��0tjd||g�tjd||��`yy#tj$rt	jtd|�Y��wxYw)	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.zAdded user '%s' to group '%s')
r
r�r�r�rr�r?rar@r�r��lenr�)rr�members�
group_add_cmd�memberr�s     �r!r�zDistro.create_groups
����:�:�j�!��7�'��g�6�6�#�T�*�
���G��=�=����K�K�B�D�I�
D��	�	�-�(����/��6�
�w�<�!��!�
H���|�|�F�+��K�K�1���	���	�	�:�v�t�4�5����8�&�$�G�
H���	�-�-�
D����C�!<�d�C�
D�s�+C:�:.D+�*D+c��|dg}|dk(r|dgz
}|S	|jtt|�dz��|S#t$r}t	d|�d��|�d}~wwxYw)Nz-d�nowr��<z;power_state[delay] must be 'now' or '+m' (minutes). found 'z'.)rprB�int�
ValueError�	TypeError)r�mode�delay�messagerur�s      r!�shutdown_commandzDistro.shutdown_command@sz����,���E�>���u��G���
����s�3�u�:��?�3�4����
�
��&+�.�����
�s�&;�	A�A�Ac��y)z1
        Alpine uses OpenRC, not systemd
        FrSrSr"r!�uses_systemdzDistro.uses_systemdZs��
r"r��action�service�
extra_argsc
�T�ddg}ddg}t|�|dgzt|�|dgzt|�d|gzt|�d|gzt|�|dgzt|�|dgzt|�|dgzt|�|d	gzd
�}t||�}tj|d|��S)
a<
        Perform the requested action on a service. This handles OpenRC
        specific implementation details.

        OpenRC has two distinct commands relating to services,
        'rc-service' and 'rc-update' and the order of their argument
        lists differ.
        May raise ProcessExecutionError
        z
rc-servicez	--nocolorz	rc-update�stop�start�delr4�restart�status)r�r��disable�enabler��reloadz
try-reloadrT)ror�)rrr
)	rr�r�r�r��init_cmd�
update_cmd�cmdsrws	         r!�manage_servicezDistro.manage_serviceas���!�+�.��!�;�/�
���N�g�v�%6�6��(�^�w��&8�8��J�'�5�'�*:�:��:�&�%��)9�9��H�~��)�(<�<��8�n���';�;��x�.�G�Y�+?�?��8�n���':�:�	
���4��<� ���y�y��d��4�4r"�blockdevc���tjj|�}|jd��r�tjtj
|�j�}tjtj
|�j�}tjd�5}|D�]}|jjd�s� tj|j�}tj|j�s�_tjtj
|j�j�|k(s��tjtj
|j�j�|k(s��tjj|j�}nddd�|jd�rtjd||�|Sy#1swY�4xYw)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/mapperz/dev/zdm-Nz/dev/dm-z$%s is a mapped device pointing to %s)r\r]�realpath�
startswith�major�stat�st_rdev�minor�scandirr�lstat�S_ISBLK�st_moder?r�)rr
rr�it�deventry�ress       r!�get_mapped_devicezDistro.get_mapped_device}sb���7�7�#�#�H�-�����}�-��H�H�R�W�W�X�.�6�6�7�E��H�H�R�W�W�X�.�6�6�7�E����G�$�
&�� "�&�H��}�}�/�/��6� �h�h�x�}�}�5���<�<����4� "���������)?�)G�)G� H�#(�!)�$&�H�H�R�W�W�X�]�]�-C�-K�-K�$L�#(�%)�,.�7�7�+;�+;�H�M�M�+J�� %�&�
&����z�*��I�I�6��(�
��O��'
&�
&�s$�+"G,�>G,�
?G,�
?G,�
,G,�,G5rH)NN)�poweroffr�N),�__name__�
__module__�__qualname__�pip_package_namer^r+�network_conf_fnr��NETWORK_FILE_HEADER�renderer_configs�dhclient_lease_directory�dhclient_lease_file_regexrr%r1r�PackageListr8rFrLr;rIrTrBrerkr7r6�propertyr��boolr�r�r�r�r�r��staticmethodr��classmethodrrr�
__classcell__)r�s@r!rr s_��� ��(�K�=�N�/�O��I�
�O�;N�O���
 /�� 3��$�#�9�&2��(;�(;�2�4�,5��
	�� 5�� 5�S� 5�3� 5�� 5�DH�&�2/4�
��+��+�X�$�X�t�8�#��<7D�r!H�F�4�����?C�5��5�$'�5�69�5��5�6�(�C�(�H�S�M�(��(r"r)�loggingr\r�r
r�typingrrr�	cloudinitrrr	r
r�"cloudinit.distros.parsers.hostnamer�cloudinit.settingsr
r�	getLoggerrr?rrrSr"r!�<module>r.sT���	�	���&�&�=�=�;�7��g����!����F
�W�^�^�F
r"

Zerion Mini Shell 1.0