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/config/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_growpart.cpython-311.pyc
�

܍~c�M���UdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
mZddlmZddlmZddlmZdd	lmZ
dd
lmZmZmZddlmZddlmZdd
lmZm Z ddl!m"Z"m#Z#ddl$m%Z%dZ&e%Z'ddde&e"ge'ed��ed��ggd�Z(ee)d<e e(��Zddgdd�Z*ed��Z+Gd�d��Z,e
j-e.��Z/de0d e#fd!�Z1Gd"�d#e2��Z3Gd$�d%e	��Z4Gd&�d'e4��Z5Gd(�d)e4��Z6d*�Z7d+�Z8d,�Z9d-�Z:d.e;fd/�Z<d0�Z=d.ee0e0ffd1�Z>d2�Z?d3e0d4ed5ed6ed7e@d.dfd8�ZAd9e5fd:e6ffZBdS);zGrowpart: Grow partitions�N)�ABC�abstractmethod)�suppress)�Logger)�Path)�dedent)�Tuple)�log)�subp�
temp_utils�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�ALL_DISTROS�Distro)�
PER_ALWAYSa�Growpart resizes partitions to fill the available disk space.
This is useful for cloud instances with a larger amount of disk space available
than the pristine image uses, as it allows the instance to automatically make
use of the extra space.

The devices on which to run growpart are specified as a list under the
``devices`` key.

There is some functionality overlap between this module and the ``growroot``
functionality of ``cloud-initramfs-tools``. However, there are some situations
where one tool is able to function and the other is not. The default
configuration for both should work for most cloud instances. To explicitly
prevent ``cloud-initramfs-tools`` from running ``growroot``, the file
``/etc/growroot-disabled`` can be created. By default, both ``growroot`` and
``cc_growpart`` will check for the existence of this file and will not run if
it is present. However, this file can be ignored for ``cc_growpart`` by setting
``ignore_growroot_disabled`` to ``true``. For more information on
``cloud-initramfs-tools`` see: https://launchpad.net/cloud-initramfs-tools

Growpart is enabled by default on the root partition. The default config for
growpart is::

    growpart:
      mode: auto
      devices: ["/"]
      ignore_growroot_disabled: false
�cc_growpart�GrowpartzGrow partitionsz�            growpart:
              mode: auto
              devices: ["/"]
              ignore_growroot_disabled: false
            z�            growpart:
              mode: growpart
              devices:
                - "/"
                - "/dev/vdb1"
              ignore_growroot_disabled: true
            )�id�name�title�description�distros�	frequency�examples�activate_by_schema_keys�meta�auto�/F)�mode�devices�ignore_growroot_disabledz/cc_growpart_keydatac��eZdZdZdZdZdZdS)�RESIZE�SKIPPED�CHANGED�NOCHANGE�FAILEDN)�__name__�
__module__�__qualname__r'r(r)r*���>/usr/lib/python3/dist-packages/cloudinit/config/cc_growpart.pyr&r&fs"�������G��G��H�
�F�F�Fr/r&r"�distroc�d�d}|dkrBtD](\}}||��}|���r|}n�)|std���nei}tD]
\}}|||<�||vrtd|z���|||��}	|	���r|	}|std|z���|S)Nr zNo resizers availablezunknown resize mode %szmode %s not available)�RESIZERS�	available�
ValueError�	TypeError)
r"r1�resize_class�_name�resizer�cur�mmap�k�v�mclasss
          r0�resizer_factoryr?ps���L��v�~�~� (�	�	��U�G��'�&�/�/�C��}�}���
�"����
��	6��4�5�5�5�	6����	�	�F�Q���D��G�G��t����4�t�;�<�<�<���d��F�#�#�������	"�!�L��	=��4�t�;�<�<�<��r/c��eZdZdS)�ResizeFailedExceptionN)r+r,r-r.r/r0rArA�s�������Dr/rAc�L�eZdZdefd�Zedefd���Zed���ZdS)�Resizerr1c��||_dS�N)�_distro)�selfr1s  r0�__init__zResizer.__init__�s
������r/�returnc��dSrEr.)rGs r0r4zResizer.available�����r/c��dSrEr.)rG�diskdev�partnum�partdevs    r0�resizezResizer.resize�rKr/N)	r+r,r-rrHr�boolr4rPr.r/r0rCrC�sq�������v�������4�����^������^���r/rCc��eZdZd�Zd�ZdS)�ResizeGrowPartc���tj���}d|d<	tjddg|���\}}t	jd|��rdSn#tj$rYnwxYwdS)	N�C�LANG�growpartz--help��envz--update\s+TF��os�environ�copyr�re�search�ProcessExecutionError)rG�myenv�out�_errs    r0r4zResizeGrowPart.available�s����
���!�!����f�
�	��)�Z��$:��F�F�F�K�S�$��y���-�-�
��t�
���)�	�	�	��D�	�����us�0A�A*�)A*c��tj���}d|d<t|��}|j���}t
j|d���5}tj�	|d��}tj�
|��stj|d��||d<	tjdd||g|�	��nc#tj
$rQ}	|	jd
kr,tjt"d||��t%|	��|	�||fcYd}	~	cddd��Sd}	~	wwxYw	tjd||g|�	��nC#tj
$r1}	tjt"d||��t%|	��|	�d}	~	wwxYw	ddd��n#1swxYwY|t|��fS)
NrUrVT)�dir�	needs_exerWi��TMPDIRz	--dry-runrX�z&Failed growpart --dry-run for (%s, %s)zFailed: growpart %s %s)r[r\r]�get_sizerF�get_tmp_exec_pathr�tempdir�path�join�exists�mkdirrr`�	exit_coder
�logexc�LOGrA)
rGrMrNrOra�before�tmp_dir�tmpd�growpart_tmp�es
          r0rPzResizeGrowPart.resize�sG���
���!�!����f�
��'�"�"���,�0�0�2�2��
�
�G�t�
<�
<�
<�	6���7�<�<��j�9�9�L��7�>�>�,�/�/�
.����u�-�-�-�*�E�(�O�

(��	���g�w�?�U��������-�	
(�	
(�	
(��;�!�#�#��K��@���	���0��2�2��9���'�'�'�'�'�'�%	6�	6�	6�	6�	6�	6�	6�	6�����	
(����
6��	�:�w��8�e�D�D�D�D�D���-�
6�
6�
6���C�!9�7�G�L�L�L�+�A�.�.�A�5�����
6����E�+	6�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6����	6�	6�	6�	6�4���)�)�*�*sg�"AF&�=C�F&�D8�':D3�!D8�"F&�3D8�8F&�<E�F&�F�%,F�F�F&�&F*�-F*N�r+r,r-r4rPr.r/r0rSrS�s2���������"+�"+�"+�"+�"+r/rSc��eZdZd�Zd�ZdS)�ResizeGpartc���tj���}d|d<	tjddg|ddg���\}}t	jd|��rd	Sn#tj$rYnwxYwd
S)NrUrV�gpart�helprrh)rY�rcszgpart recover TFrZ)rGra�_out�errs    r0r4zResizeGpart.available�s����
���!�!����f�
�	��)�W�f�$5�5�q�!�f�M�M�M�K�T�3��y�*�C�0�0�
��t�
���)�	�	�	��D�	�����us�3A�A-�,A-c���	tjdd|g��nR#tj$r@}|jdkr+tjt
d|��t
|��|�Yd}~nd}~wwxYwt|��}	tjddd||g��nC#tj$r1}tjt
d||��t
|��|�d}~wwxYw|t|��fS)	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.
        r|�recoverrzFailed: gpart recover %sNrPz-izFailed: gpart resize -i %s %s)rr`rpr
rqrrrAri)rGrMrNrOrwrss      r0rPzResizeGpart.resize�s��	6��I�w�	�7�3�4�4�4�4���)�	6�	6�	6��{�a�����C�!;�W�E�E�E�+�A�.�.�A�5� ���������	6����
�'�"�"��	2��I�w��$���A�B�B�B�B���)�	2�	2�	2��K��<�g�w�O�O�O�'��*�*��1�����	2�������)�)�*�*s,��A)�6A$�$A)�<B�C�%,C�CNrxr.r/r0rzrz�s2���������+�+�+�+�+r/rzc���tj|tj��}	tj|dtj��tj|��S#tj|��wxYw)Nr)r[�open�O_RDONLY�lseek�SEEK_END�close)�filename�fds  r0riri�sN��	���2�;�	'�	'�B���x��A�r�{�+�+�
�����������������s�A�A+c���tj�|��}tj�|��}d|z}t	j��rVdt	j|��z}tjd|��}|�	d��|�	d��fSt	j
��rVdt	j|��z}tjd|��}|�	d��|�	d��fStj�|��st|�d|�d����tj�|d	��}tj�|��std
|z���t	j|�����}tj�|��}	tj�|	��}
t	jtj�|
d�������}tj�d|z��}||fS)
Nz/sys/class/block/%s�/dev/z^(/dev/.+)p([0-9])$rh�z^(/dev/.+)s([0-9])$z had no syspath (�)�	partitionz%s not a partition�devz
/dev/block/%s)r[rl�realpath�basenamer
�
is_FreeBSD�find_freebsd_partr^r_�group�is_DragonFlyBSD�find_dragonflybsd_partrnr5rmr6�	load_file�rstrip�dirname)
�devpath�rpath�bname�syspath�freebsd_part�m�dragonflybsd_part�ptpath�ptnum�rsyspath�disksyspath�
diskmajmin�diskdevpaths
             r0�device_part_infor�s���

�G���W�%�%�E��G���U�#�#�E�#�e�+�G�����(���!7��!@�!@�@���I�+�\�:�:������
�
�A�G�G�A�J�J�'�'�	
�	�	�	�(�#�d�&A�'�&J�&J�J���I�+�->�?�?������
�
�A�G�G�A�J�J�'�'�
�7�>�>�'�"�"�H��W�W�W�g�g�g�F�G�G�G�
�W�\�\�'�;�
/�
/�F�
�7�>�>�&�!�!�8��,�w�6�7�7�7��N�6�"�"�)�)�+�+�E��w����(�(�H��'�/�/�(�+�+�K�������[�%� @� @�A�A�H�H�J�J�J��'�"�"�?�Z�#?�@�@�K�
���r/c�r�|�d��r|Stj|��}|std���|d}tj��}|dkrY|sWtjtj����}|�0tj�	|��r|Std���|S)Nr�z,Could not determine device of '%s' % dev_entrz	/dev/rootz!Unable to find device '/dev/root')
�
startswithr
�get_mount_infor5�is_container�rootdev_from_cmdline�get_cmdliner[rlrn)�devent�resultr��	containers    r0�
devent2devr�,s���
����!�!���
��$�V�,�,���	M��K�L�L�L��Q�i���!�#�#�I��k���)���'��(8�(:�(:�;�;���;��w�~�~�c�"�"�
��
��@�A�A�A��Jr/c��tj�|��}|�d��rt�d||��|SdS)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[rlr�r�rr�debug)�blockdevr�s  r0�get_mapped_devicer�CsP���w����)�)�H����:�&�&���	�	�8�(�H�M�M�M����4r/rIc�*�tjd��st�d��dS	tjdd|g��nd#tj$rR}|jdkrt�d|��n t�d|j��Yd}~dSd}~wwxYwttj��5tjdd	|g��t�d
|��	ddd��dS#1swxYwYdS)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�whichrrr�r`rp�warningr)r�r�rws   r0�is_encryptedr�Ssg��
�:�l�#�#���	�	�J�K�K�K��u���	�<��8�4�5�5�5�5���%�	�	�	��;�!����I�I�;�X�F�F�F�F��K�K�G���
�
�
�
�u�u�u�u�u�����	����
�$�,�	-�	-����	�<��9�5�6�6�6��	�	�3�X�>�>�>����������������������5s*�A
�
B+�AB&�&B+�4D�D�Dc�R�ddd|g}tj|��d}|�d��std|�����	d|�d��d	�d
��d��S#t$r}td|�d|�d
���|�d}~wwxYw)N�dmsetup�depsz--options=devnamerz1 dependz5Expecting '1 dependencies' from 'dmsetup'. Received: r�z: (rhr�zRan `z$`, but received unexpected stdout: `�`)rr��RuntimeError�split�
IndexError)r��command�deprws    r0�get_underlying_partitionr�ns����&�"5�x�@�G��y��!�!�!�$�C��>�>�*�%�%�
��I�C�I�I�
�
�	
��:�s�y�y��'�'��*�0�0��5�5�a�8�:�:�:�������G�G�G�G��G�G�G�
�
��	��������s�	6B�
B&�
B!�!B&c�^�t���stjdfS	t���5}tj|��}ddd��n#1swxYwY|d}tj|��}|d}n"#t$r}td��|�d}~wwxYw	tjdddd	|g|�
��	tjddd|t|��g��n7#tj
$r%}t�d
|��Yd}~nd}~wwxYw	t���n�#t$rt#jtd��Yn�wxYw#	tjddd|t|��g��n7#tj
$r%}t�d
|��Yd}~nd}~wwxYw	t���w#t$rt#jtd��YwwxYwxYwtjd|�d�fS)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�-rP)�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_PATHrnr&r'r��json�load�base64�	b64decode�	Exceptionr�r�strr`rrr��unlinkr
rqr()r�r��f�keydatar��decoded_keyr�rws        r0�resize_encryptedr�s!����� � �?��� =�>�>�
�
�
�
�
 �
 �	#�A��i��l�l�G�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#����	#�	#�	#�	#��e�n���&�s�+�+���v����������
6�
�
��	�����������	�
�<��h��A��	
�	
�	
�	
�
	��I� �"�"����I�I��
�
�
�
���)�	�	�	��K�K�N��
�
�
�
�
�
�
�
�����	����
	����!�!�!�!���	�	�	��K��O�
�
�
�
�
�	�����#	��I� �"�"����I�I��
�
�
�
���)�	�	�	��K�K�N��
�
�
�
�
�
�
�
�����	����
	����!�!�!�!���	�	�	��K��O�
�
�
�
�
�	�������	��=�(�=�=�=��s��B�A#�B�#A'�'B�*A'�+'B�
B2�B-�-B2�6E5�&C9�9D-�D(�(D-�1E�$E2�1E2�5H�7&F�H�G�-G
�H�
G�H�G0�/H�0$H�H�H�Hc��tj|��}g}|�r+|�d��}	t|��}n<#t$r/}|�|t
jd|zf��Yd}~�]d}~wwxYw	tj|��}n?#t$r2}|�|t
jd|�d|��f��Yd}~��d}~wwxYwtj
|j��s@tj|j��s'|�|t
jd|zf����t|��}|r�	t|��}t||��rh|d�|D��vr.|�d|��|�d|�����t#||��\}	}
|�||	|
f��n&|�|t
jd|�d�f��n?#t$$r2}|�|t
jd	|�d
|��f��Yd}~nd}~wwxYw��	t)|��\}}nG#t*tf$r3}|�|t
jd|�d
|��f��Yd}~��gd}~wwxYw	|�|||��\}
}|
|kr*|�|t
jd|�d
|�d�f��n.|�|t
jd|�d
|�d|
�d|��f��nB#t2$r5}|�|t
jd|�d|�d|��f��Yd}~nd}~wwxYw|��+|S)Nrzunable to convert to device: %sz	stat of 'z
' failed: zdevice '%s' not a block devicec��g|]
}|d��S)rr.)�.0�xs  r0�
<listcomp>z"resize_devices.<locals>.<listcomp>�s��(<�(<�(<�!��1��(<�(<�(<r/zResizing mapped device (z!) skipped as it is not encrypted.zResizing encrypted device (z
) failed: zdevice_part_info(zno change necessary (z, r�z	changed (z) from z to zfailed to resize: disk=z, ptnum=�: )r]�popr�r5�appendr&r'r[�stat�OSError�S_ISBLK�st_mode�S_ISCHRr�r�r��insertr�r�r*r�r6rPr)r(rA)r9r#�infor�r�rw�statret�underlying_blockdevr�r��message�diskr��old�news               r0�resize_devicesr��s����i�� � �G�
�D�
�y����Q����
	�!�&�)�)�H�H���	�	�	��K�K���N�5��9��
�
�
�
�H�H�H�H�����	����
	��g�h�'�'�G�G���	�	�	��K�K���N�N�19���1�1�=��
�
�
�
�H�H�H�H�����	�����|�G�O�,�,�
	�T�\��O�6
�6
�
	�
�K�K���N�4�x�?��
�
�
�
�/��9�9���)	�%
�4�X�>�>�	�� 3�Y�?�?�� �(<�(<�t�(<�(<�(<�<�<� ���q�&�1�1�1����q�)�4�4�4� �&6�x��&K�&K�O�F�G��K�K�"�"�#�������K�K�"�"�N�6�x�6�6�6��������
�
�
������
�M�h�M�M�!�M�M��������������
����
�
	�,�X�6�6�M�T�5�5���:�&�	�	�	��K�K���N�N�9A���1�1�E��
�
�
�
�H�H�H�H�����	����	� ����e�X�>�>�J�S�#��c�z�z��������:>�$�$����F��������������4�4�������S�S�2�������%�	�	�	��K�K���M�M��t�t�U�U�U�A�A�'��
�
�
�
�
�
�
�
�����	����c�y�v�Ks��A�
A9�
%A4�4A9�=B�
C�(C	�	C�<AG*�AG*�*
H&�4(H!�!H&�,H?�?J�(I>�>J�A8L�
L?�
+L:�:L?r�cfg�cloudr
�argsc	��d|vr'|�dtz��t|d<|�d��}t|t��s|�d��dS|�dd��}t
j|��r9|dkr|�d|�d���|�d	|z��dSt
j|�d
d����rKtj	�
d��r,|�d
��|�d��dSt
j|ddg��}t|��s|�d��dS	t||j��}nB#tt f$r.}	|�d|�d|	����|dkr|	�Yd}	~	dSd}	~	wwxYwt
j|jdt$||f���}
|
D]P\}}}
|t&jkr|�d|�d|
�����2|�d|�d|�d|
�����QdS)NrWz.No 'growpart' entry in cfg.  Using default: %sz#'growpart' in config was not a dictr"r �offzDEPRECATED: growpart mode 'z#' is deprecated. Use 'off' instead.zgrowpart disabled: mode=%sr$Fz/etc/growroot-disabledz0growpart disabled: /etc/growroot-disabled existsz&use ignore_growroot_disabled to ignorer#r!zgrowpart: empty device listz%growpart unable to find resizer for 'z': r�)�logfunc�msg�funcr�r�z' resized: z' r�)r��DEFAULT_CONFIG�get�
isinstance�dictr�r
�is_falser[rl�isfile�get_cfg_option_list�lenr?r1r5r6�log_timer�r&r(r�)rr�r�r
r��mycfgr"r#r9rw�resized�entry�actionr�s              r0�handler9s��������	�	�<�~�M�	
�	
�	
�)��J���G�G�J���E��e�T�"�"�����9�:�:�:����9�9�V�V�$�$�D��}�T�����5�=�=��K�K�%�d�%�%�%�
�
�
�	�	�	�.��5�6�6�6����}�U�Y�Y�9�5�A�A�B�B��
�7�>�>�2�3�3�	��I�I�H�I�I�I��I�I�>�?�?�?��F��&�u�i�#��?�?�G��w�<�<���	�	�/�0�0�0����!�$���5�5�����	�"�����	�	�	�D�D�D�!�!�L�M�M�M��6�>�>��G�����������	�����m��	��
��w�
�	���G�!(�<�<������V�^�#�#��H�H�H�5�5�5�#�#�6�7�7�7�7��I�I�I�u�u�u�f�f�f�c�c�:�;�;�;�;�	<�<s�F�G�(#G�GrWr|)C�__doc__r�r]r�r[�os.pathr^r��abcrr�
contextlibr�loggingr�pathlibr�textwrapr�typingr	�	cloudinitr
rrr
�cloudinit.cloudr�cloudinit.configr�cloudinit.config.schemarr�cloudinit.distrosrr�cloudinit.settingsr�MODULE_DESCRIPTIONrr�__annotations__r�r�r&�	getLoggerr+rrr�r?r�rArCrSrzrir�r�r�rQr�r�r�r��listrr3r.r/r0�<module>rs�� ���
�
�
�
���������	�	�	�	�����	�	�	�	�����#�#�#�#�#�#�#�#�������������������������������$�$�$�$�$�$�,�,�,�,�,�,�,�,�,�,�!�!�!�!�!�!�#�#�#�#�#�#�<�<�<�<�<�<�<�<�1�1�1�1�1�1�1�1�)�)�)�)�)�)���8
�	�
��
�%��}����
�	
�	
�	��
�		
�		
��( "�7���j����<�,�t�
�
��
��u� %�����t�*�+�+�����������g���!�!���#��v�����<	�	�	�	�	�I�	�	�	�
�
�
�
�
�c�
�
�
�0+�0+�0+�0+�0+�W�0+�0+�0+�f$+�$+�$+�$+�$+�'�$+�$+�$+�N���( �( �( �V���.
�
�
� ������6���"4�U�3��8�_�4�4�4�4�n@�@�@�F5<�

�5<��5<�#(�5<�/5�5<�=A�5<�	�5<�5<�5<�5<�p��(�7�K�*@�A���r/