%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_growpart.cpython-312.pyc

�

���f�I�
�r�UdZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
ddlmZddlmZmZddlmZmZmZmZddlmZdd	lmZdd
lmZddlmZm Z ddl!m"Z"d
Z#e"Z$dege$gd�Z%ee&d<ddgdd�Z'ed�Z(Gd�d�Z)ejTe+�Z,Gd�de-�Z.Gd�de
�Z/Gd�de/�Z0Gd�de/�Z1Gd �d!e/�Z2d"e3d#e d$e4d%e/fd&�Z5d%ee6fd'�Z7d%ee6fd(�Z8d)�Z9d%e:fd*�Z;d+�Z<d%ee3e3ffd,�Z=d-�Z>d.e/d#e fd/�Z?d0e3d1ed2ed3e4d%df
d4�Z@d5e0fd6e1fd7e2ffZAy)8zGrowpart: Grow partitions�N)�ABC�abstractmethod)�suppress)�Path)�Optional�Tuple)�	lifecycle�subp�
temp_utils�util)�Cloud)�Config)�
MetaSchema)�ALL_DISTROS�Distro)�
PER_ALWAYS��cc_growpart)�id�distros�	frequency�activate_by_schema_keys�meta�auto�/F)�mode�devices�ignore_growroot_disabledz/cc_growpart_keydatac��eZdZdZdZdZdZy)�RESIZE�SKIPPED�CHANGED�NOCHANGE�FAILEDN)�__name__�
__module__�__qualname__r!r"r#r$���>/usr/lib/python3/dist-packages/cloudinit/config/cc_growpart.pyr r 1s���G��G��H�
�Fr)r c��eZdZy)�ResizeFailedExceptionN)r%r&r'r(r)r*r,r,;s��r)r,c�B�eZdZdefd�Zededefd��Zed��Z	y)�Resizer�distroc��||_y�N)�_distro)�selfr/s  r*�__init__zResizer.__init__@s	����r)r�returnc��yr1r(�r3rs  r*�	availablezResizer.availableCs��03r)c��yr1r()r3�diskdev�partnum�partdev�fss     r*�resizezResizer.resizeFs��58r)N)
r%r&r'rr4r�list�boolr8r>r(r)r*r.r.?s6���v���3��3�$�3��3��8��8r)r.c��eZdZdefd�Zd�Zy)�ResizeGrowPartrc��	tjddgddi��j}tjd|�ry	y#tj$rYywxYw)	N�growpartz--help�LANG�C��
update_envz--update\s+TF)r
�stdout�re�search�ProcessExecutionError)r3r�outs   r*r8zResizeGrowPart.availableKse��	��)�)��X�&�F�C�=���f�
��y�y���-��.�
���)�)�	���	�s�;A�A�Ac�4�t||�}|jj�}tj|d��5}t
jj|d�}d|d�}	t
jj|�stj|d�	tjdd||g|	��	tjd||g|	��	ddd�|t||�fS#tj$rN}
|
jd	k7r(tjtd
||�t!|
�|
�||fcYd}
~
cddd�Sd}
~
wwxYw#tj$r-}
tjtd||�t!|
�|
�d}
~
wwxYw#1swY��xYw)NT)�dir�	needs_exerDrF)rE�TMPDIRi�z	--dry-runrG�z&Failed growpart --dry-run for (%s, %s)zFailed: growpart %s %s)�get_sizer2�get_tmp_exec_pathr�tempdir�os�path�join�exists�mkdirr
rL�	exit_coder�logexc�LOGr,)r3r:r;r<r=�before�tmp_dir�tmpd�growpart_tmp�my_env�es           r*r>zResizeGrowPart.resizeWsj���'�2�&���,�,�0�0�2��
�
�
�G�t�
<�	6���7�7�<�<��j�9�L�!�\�:�F��7�7�>�>�,�/�����u�-�
(��	�	���g�w�?�%��
6��	�	�:�w��8�V�L�-	6�6���"�-�.�.��#�-�-�	
(��;�;�!�#��K�K��@���	�0��2��9���'�'�'	6�	6��	
(���-�-�
6����C�!9�7�G�L�+�A�.�A�5��
6��/	6�	6�sT�AF�C'�6E�'E�::E�4E�5F�E�F�F�(F�F�F�FN�r%r&r'r?r8r>r(r)r*rBrBJs��
��
�!/r)rBc�"�eZdZdZdefd�Zd�Zy)�ResizeGrowFSa�
    Use FreeBSD ``growfs`` service to grow root partition to fill available
    space, optionally adding a swap partition at the end.

    Note that the service file warns us that it uses ``awk(1)``, and as
    such requires ``/usr`` to be present. However, cloud-init is installed
    into ``/usr/local``, so we should be fine.

    We invoke the ``growfs`` with ``service growfs onestart``, so it
    doesn't need to be enabled in ``rc.conf``.
    rc�P�tjjd�xr|dgk(S)z'growfs only works on the root partitionz/etc/rc.d/growfsr)rVrW�isfiler7s  r*r8zResizeGrowFS.available�s"���w�w�~�~�0�1�F�g�#��6F�Fr)c���t||�}	|jjdd��|t||�fS#tj$r+}tjtd�t|�|�d}~wwxYw)N�onestart�growfs)�action�servicezFailed: service growfs onestart)	rSr2�manage_servicer
rLrr\r]r,)r3r:r;r<r=r^rcs       r*r>zResizeGrowFS.resize�sr���'�2�&��	2��L�L�'�'�z�8�'�L�
���"�-�.�.��	�)�)�	2��K�K��>�?�'��*��1��	2�s�9�A7�&A2�2A7N)r%r&r'�__doc__r?r8r>r(r)r*rfrf{s��
�G��G�/r)rfc��eZdZdefd�Zd�Zy)�ResizeGpartrc��	tjddgddiddg��j}tjd|�ry		y
#tj$rYy
wxYw)N�gpart�helprErFrrR)rH�rcszgpart recover TF)r
�stderrrJrKrL)r3r�errs   r*r8zResizeGpart.available�sl��	��)�)��&�!�v�s�m�!�Q����f�
��y�y�*�C�0��1�
���)�)�	���	�s�>A�A�Ac���	tjdd|g�t||�}	tjddd||g�|t||�fS#tj$r@}|jdk7r'tjt
d|�t
|�|�Yd}~��d}~wwxYw#tj$r-}tjt
d||�t
|�|�d}~wwxYw)	a9
        GPT disks store metadata at the beginning (primary) and at the
        end (secondary) of the disk. When launching an image with a
        larger disk compared to the original image, the secondary copy
        is lost. Thus, the metadata will be marked CORRUPT, and need to
        be recovered.
        rs�recoverrzFailed: gpart recover %sNr>z-izFailed: gpart resize -i %s %s)r
rLr[rr\r]r,rS)r3r:r;r<r=rcr^s       r*r>zResizeGpart.resize�s���	6��I�I�w�	�7�3�4��'�2�&��	2��I�I�w��$���A�B�
���"�-�.�.���)�)�	6��{�{�a�����C�!;�W�E�+�A�.�A�5� ��	6���)�)�	2��K�K��<�g�w�O�'��*��1��	2�s.�A�B%�B"�"6B�B"�%C%�8(C � C%Nrdr(r)r*rqrq�s��
��
�/r)rqrr/rr5c�6�d}|dk(r;tD]#\}}||�}|j|��s�!|}n|std��|Si}tD]
\}}	|	||<�||vrtd|z��|||�}
|
j|��r|
}|std|z��|S)Nr)rzNo resizers availablezunknown resize mode %szmode %s not available)�RESIZERSr8�
ValueError�	TypeError)rr/r�resize_class�_name�resizer�cur�mmap�k�v�mclasss           r*�resizer_factoryr��s����L��v�~�&�	�N�E�7��&�/�C��}�}�W�}�-�"���		���4�5�5�"�����	�D�A�q��D��G�	��t���4�t�;�<�<���d��F�#�����G��,�!�L���4�t�;�<�<��r)c��d}	tj|tj�}tj|dtj�|rtj
|�SS#t$rE|dk(r%t|�cY|rtj
|�SSY|rtj
|�yywxYw#|rtj
|�wwxYw)Nr�zfs)rV�open�O_RDONLY�lseek�SEEK_END�close�FileNotFoundError�get_zfs_size)�filenamer=�fds   r*rSrS�s���	
�B�	�
�W�W�X�r�{�{�
+���x�x��A�r�{�{�+���H�H�R�L�����
��;���)�)���H�H�R�L���
��H�H�R�L����
��H�H�R�L��s*�AA%�%B3�>B6�B6�2B3�3B6�6Cc��|jd�d}	tjdddd|g�\}}t|j
��S#tj$r!}tj	d||�Yd}~yd}~wwxYw)Nrr�zpool�getz	-Hpovalue�sizezFailed: zpool get size %s: %s)�splitr
rLr]�debug�int�strip)�datasetr�r��_rcs     r*r�r��sv���M�M�#��q�!�E���)�)�W�e�[�&�%�H�I���a��t�z�z�|�����%�%���	�	�1�5�!�<����s�A�B�A;�;Bc�p�|jd�r|dfStj|�}|std��|d}|d}tj�}|dk(rY|sWtj
tj��}|�.tjj|�r|dfStd��||fS)N�/dev/z,Could not determine device of '%s' % dev_entrrRz	/dev/rootz!Unable to find device '/dev/root')
�
startswithr�get_mount_infor|�is_container�rootdev_from_cmdline�get_cmdlinerVrWrY)�devent�result�devr=�	containers     r*�
devent2devr��s���
����!��t�|��
�
 �
 ��
(�F���G�H�H�
��)�C�	���B��!�!�#�I��k��)��'�'��(8�(8�(:�;���;��w�w�~�~�c�"��D�y� ��@�A�A���7�Nr)c��tjd�stjd�y	tjdd|g�ttj�5tjdd	|g�tjd
|�	ddd�y#tj$rP}|j
dk(rtjd|�n tj
d|j
�Yd}~yd}~wwxYw#1swYyxYw)z�
    Check if a device is an encrypted device. blockdev should have
    a /dev/dm-* path whereas partition is something like /dev/sda1.
    �
cryptsetupz6cryptsetup not found. Assuming no encrypted partitionsF�status�z#Determined that %s is not encryptedzZReceived unexpected exit code %s from cryptsetup status. Assuming no encrypted partitions.N�isLukszDetermined that %s is encryptedT)r
�whichr]r�rLr[�warningr)�blockdev�	partitionrcs   r*�is_encryptedr�s���
�:�:�l�#��	�	�J�K����	�	�<��8�4�5�
�$�,�,�	-���	�	�<��9�5�6��	�	�3�X�>������%�%�	��;�;�!���I�I�;�X�F��K�K�G����
�
��	����s$�B�0C=�C:�*AC5�5C:�=Dc��ddd|g}tj|�d}|jd�std|����	d|jd�d	jd
�d��S#t$r}td|�d|�d
��|�d}~wwxYw)N�dmsetup�depsz--options=devnamerz1 dependz5Expecting '1 dependencies' from 'dmsetup'. Received: r�z: (rR�)zRan `z$`, but received unexpected stdout: `�`)r
r��RuntimeErrorr��
IndexError)r��command�deprcs    r*�get_underlying_partitionr�&s����&�"5�x�@�G��y�y��!�!�$�C��>�>�*�%��C�C�5�I�
�	
���s�y�y��'��*�0�0��5�a�8�9�:�:������G�9�@���Q�G�
��	���s�(A(�(	B	�1B�B	c��tj�stjdfS	tj	�5}tj|�}ddd�d}tj|�}|d}	tjdddd	|g|�
�	tjddd|t|�g�	tj!�tj&d|�d�fS#1swY��xYw#t$r}td�|�d}~wwxYw#tj$r }tjd
|�Yd}~��d}~wwxYw#t$rt#j$td�Y��wxYw#	tjddd|t|�g�n6#tj$r }tjd
|�Yd}~nd}~wwxYw	tj!�w#t$rt#j$td�YwwxYwxYw)z�Use 'cryptsetup resize' to resize LUKS volume.

    The loaded keyfile is json formatted with 'key' and 'slot' keys.
    key is base64 encoded. Example:
    {"key":"XFmCwX2FHIQp0LBWaLEMiHIyfxt1SGm16VvUAVledlY=","slot":5}
    zNo encryption keyfile foundN�key�slotzZCould not load encryption key. This is expected if the volume has been previously resized.r�z
--key-file�-r>)�data�luksKillSlotz--batch-modez<Failed to kill luks slot after resizing encrypted volume: %sz8Failed to remove keyfile after resizing encrypted volumez'Successfully resized encrypted volume '�')�KEYDATA_PATHrYr r!r��json�load�base64�	b64decode�	Exceptionr�r
�strrLr]r��unlinkrr\r")r�r��f�keydatar��decoded_keyr�rcs        r*�resize_encryptedr�7s������ ���� =�>�>�
�
�
�
�
 �	#�A��i�i��l�G�	#��e�n���&�&�s�+���v�����	�	�
�<��h��A��	
�
	��I�I� �"�"����I��
�	����!�	���
1�(��1�=���O	#�	#��
���
6�
��	����,�)�)�	��K�K�N��
�
��	���	��K�K��O�
�	��#	��I�I� �"�"����I��
���)�)�	��K�K�N��
�
��	��
	����!���	��K�K��O�
�	�s��C1�C%�'C1�:E-�#D�;E�%C.�*C1�1	D�:D�D�E�!D<�<E�#E*�)E*�-H�/#F�H�G�&G�<H�G�H�
G�H�#H�H�H�Hc��g}	|j||||�\}}||k(r+|j|tjd|�d|�d�f�|S|�|�9d}	|�|�
d|�d|�d�}	nd|z}	|j|tj|	f�|Sd}	|�|�d|�d|�d|�d	|��}	nd|�d|�d	|��}	|j|tj|	f�	|S#t
$r6}
|j|tjd
|�d|�d|
��f�Yd}
~
|Sd}
~
wwxYw)
Nzno change necessary (z, r�rz	changed (z) size, new size is unknownz&changed (%s) size, new size is unknownz) from z to zfailed to resize: disk=z, ptnum=z: )r>�appendr r#r"r,r$)r�r��disk�ptnumr�r=�info�old�new�msgrcs           r*�
_call_resizerr�ns;��
�D�(
��>�>�$��x��<���S��#�:��K�K���O�O�6:�E�B��
�L�K�?�[�C�K��C���E�M�����
?��I���K�K������5�6�,�K�)�C���E�M�����	���7?��S�I���K�K������5�6��K��!�
������
�
�=A�5�!�L�
�	
�	
��K��
�s%�AC
�;C
�AC
�
	D�+D�Dr�c	��tj|�}g}|�r�|jd�}d}d}	t|�\}}tjd|�|dk(r$t|t�r|t||||||�z
}�f	tj|�}
tj|
j �sEtj"|
j �s&|j	|t
jd|zf���|j%|�}|r�	t'|�}t)||�r_||D�
cgc]}
|
d��	c}
vr&|j+d|�|j+d|���Ft-||�\}}|j	|||f�n&|j	|t
jd|�d	�f����	|j3|�\}}|t||||||�z
}|r���|S#t$r0}	|j	|t
jd|	zf�Yd}	~	���d}	~	wwxYw#t$r3}	|j	|t
jd|�d|	��f�Yd}	~	��3d}	~	wwxYwcc}
w#t.$r2}	|j	|t
j0d
|�d|	��f�Yd}	~	��d}	~	wwxYw#t4tf$r3}	|j	|t
jd|�d|	��f�Yd}	~	���d}	~	wwxYw)
Nrzunable to convert to device: %szgrowpart found fs=%sr�z	stat of 'z
' failed: zdevice '%s' not a block devicezResizing mapped device (z!) skipped as it is not encrypted.zResizing encrypted device (z
) failed: zdevice_part_info()�copy�popr�r|r�r r!r]r��
isinstancerfr�rV�stat�OSError�S_ISBLK�st_mode�S_ISCHR�get_mapped_devicer�r��insertr�r�r$�device_part_infor})r�rr/r�r�r�r�r�r=rc�statret�underlying_blockdevr��xr��messages                r*�resize_devicesr��s����i�i�� �G�
�D�
����Q�������
	�%�f�-�L�H�b�	�	�	�(�"�-���;�:�g�|�<��M�'�6�4���"�M�M�D��
	��g�g�h�'�G��|�|�G�O�O�,�T�\�\��O�O�6
�
�K�K���N�N�4�x�?��
�
�$�6�6�x�@���%
�4�X�>�	�� 3�Y�?� �t�(<�!��1��(<�<� ���q�&�1����q�)�4� �&6�x��&K�O�F�G��K�K�"�"�#����K�K�"�"�N�N�6�x�j�A6�6���$
�
	� �1�1�(�;�K�D�%�	
�
�g�v�t�U�H�b�I�I��U�X�K��K�	��K�K���N�N�5��9��
�
��	��,�	��K�K���N�N�19�1�=��
�
��	��8)=��4�
������
�
�5�h�Z�z�!��M�����
���:�&�	��K�K���N�N�9A�1�E��
�
��	�sx�G�?H�I�(I�4(I�A
I�+J�	H�!%H�H�	I�(I�I�I�	J�!(J�J�K�%(K�K�name�cfg�cloud�argsc��d|vr#tjdt�t|d<|jd�}t	|t
�stj
d�y|jdd�}tj|�r8|dk7rtjd|�d�d	d
��tjd|�ytj|jd
d��rJtjjd�r+tjd�tjd�ytj|ddg�}t|�stjd�y	t!||j"|��}tj(tjdt*|||j"f��}	|	D]I\}
}}|t,j.k(rtj1d|
|��2tjd|
||��Ky#t$t&f$r(}tjd||�|dk7r|�Yd}~yd}~wwxYw)NrDz.No 'growpart' entry in cfg.  Using default: %sz#'growpart' in config was not a dictrr�offz"Growpart's 'mode' key with value 'r�z22.2zUse 'off' instead.)�
deprecated�deprecated_version�
extra_messagezgrowpart disabled: mode=%srFz/etc/growroot-disabledz0growpart disabled: /etc/growroot-disabled existsz&use ignore_growroot_disabled to ignorerrzgrowpart: empty device list)r/rz,growpart unable to find resizer for '%s': %sr�)�logfuncr��funcr�z'%s' resized: %sz'%s' %s: %s)r]r��DEFAULT_CONFIGr�r��dictr�r�is_falser	�	deprecaterVrWrh�get_cfg_option_list�lenr�r/r|r}�log_timer�r r"r�)
r�r�r�r��mycfgrrr�rc�resized�entryrlr�s
             r*�handler�s�������	�	�<�n�	
�)��J���G�G�J��E��e�T�"����9�:���9�9�V�V�$�D��}�}�T���5�=����?��v�Q�G�#)�2�
�
	�	�	�.��5���}�}�U�Y�Y�9�5�A�B�
�7�7�>�>�2�3��I�I�H�I��I�I�>�?���&�&�u�i�#��?�G��w�<��	�	�/�0���!�$�u�|�|�W�M���m�m��	�	��
��w����
-�	�G�&�9���v�s��V�^�^�#��H�H�'���4��I�I�m�U�F�C�8�	9��
�	�"���	�	�@�$��J��6�>��G���	�s�'H�H=�H8�8H=rDrkrs)Bror�r�r��loggingrV�os.pathrJr��abcrr�
contextlibr�pathlibr�typingrr�	cloudinitr	r
rr�cloudinit.cloudr
�cloudinit.configr�cloudinit.config.schemar�cloudinit.distrosrr�cloudinit.settingsr�MODULE_DESCRIPTIONrr�__annotations__r�r�r �	getLoggerr%r]r�r,r.rBrfrqr�r?r�r�rSr�r�r@r�r�r�r�r�r�r{r(r)r*�<module>rs��� �
����	��	��#���"�7�7�!�#�.�1�)����	�
��}��!�	��j��
��u� %����*�+�����g����!��	�I�	�9�c�9�./�W�./�b/�7�/�8#/�'�#/�L�#��v������<�h�s�m���X�c�]���0���6�"4�U�3��8�_�4�n+�\q�G�q�f�q�h49��49�6�49�%�49�t�49��49�p�� �
�|���k���r)

Zerion Mini Shell 1.0