HOME


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

܍~cL���UdZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
ddlmZddlmZdd	lmZmZdd
lmZdZe	d��Zd
gZdddeeee	d��gegd�Zeed<ee��ZdZeje��ZdZeje��Z ejdez��Z!dZ"dZ#dZ$dZ%ej&e'��Z(d�Z)d�Z*d�Z+d-d�Z,d-d�Z-d.d �Z.d!e/d"e/d#dfd$�Z0d/d%�Z1d&�Z2d'e/d(ed)ed*ed+e3d#dfd,�Z4dS)0z-Mounts: Configure mount points and swap files�N)�Logger)�
whitespace)�dedent)�subp�
type_utils�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�PER_INSTANCEa
This module can add or remove mountpoints from ``/etc/fstab`` as well as
configure swap. The ``mounts`` config key takes a list of fstab entries to add.
Each entry is specified as a list of ``[ fs_spec, fs_file, fs_vfstype,
fs_mntops, fs-freq, fs_passno ]``. For more information on these options,
consult the manual for ``/etc/fstab``. When specifying the ``fs_spec``, if the
device name starts with one of ``xvd``, ``sd``, ``hd``, or ``vd``, the leading
``/dev`` may be omitted.

Any mounts that do not appear to either an attached block device or network
resource will be skipped with a log like "Ignoring nonexistent mount ...".

Cloud-init will attempt to add the following mount directives if available and
unconfigured in `/etc/fstab`::

    mounts:
        - ["ephemeral0", "/mnt", "auto","defaults,nofail,x-systemd.requires=cloud-init.service", "0", "2"]
        - ["swap", "none", "swap", "sw", "0", "0"]

In order to remove a previously listed mount, an entry can be added to
the `mounts` list containing ``fs_spec`` for the device to be removed but no
mountpoint (i.e. ``[ swap ]`` or ``[ swap, null ]``).

The ``mount_default_fields`` config key allows default options to be specified
for the values in a ``mounts`` entry that are not specified, aside from the
``fs_spec`` and the ``fs_file``. If specified, this must be a list containing 6
values. It defaults to::

    mount_default_fields: [none, none, "auto","defaults,nofail,x-systemd.requires=cloud-init.service", "0", "2"]

Non-systemd init systems will vary in ``mount_default_fields``.

Swap files can be configured by setting the path to the swap file to create
with ``filename``, the size of the swap file with ``size`` maximum size of
the swap file if using an ``size: auto`` with ``maxsize``. By default no
swap file is created.
a<    # Mount ephemeral0 with "noexec" flag, /dev/sdc with mount_default_fields,
    # and /dev/xvdh with custom fs_passno "0" to avoid fsck on the mount.
    # Also provide an automatically sized swap with a max size of 10485760
    # bytes.
    mounts:
        - [ /dev/ephemeral0, /mnt, auto, "defaults,noexec" ]
        - [ sdc, /opt/data ]
        - [ xvdh, /opt/data, auto, "defaults,nofail", "0", "0" ]
    mount_default_fields: [None, None, auto, "defaults,nofail", "0", "2"]
    swap:
        filename: /my/swapfile
        size: auto
        maxsize: 10485760
    �all�	cc_mounts�Mountsz%Configure mount points and swap filesz�        # Create a 2 GB swap file at /swapfile using human-readable values
        swap:
            filename: /swapfile
            size: 2G
            maxsize: 2G
        )�id�name�title�description�distros�examples�	frequency�activate_by_schema_keys�metaz&^([x]{0,1}[shv]d[a-z][0-9]*|sr[0-9]+)$z^.+:.*z[%s]+z
/etc/fstabzcomment=cloudconfig�i@c�~�|dvrdSdD]3}|�|��r|�d��dkrdS�4dS)N)�ami�root�swapT)�	ephemeral�ebs�:���F)�
startswith�find)r�enumnames  �</usr/lib/python3/dist-packages/cloudinit/config/cc_mounts.py�is_meta_device_namer'|sY���&�&�&��t�)�����?�?�8�$�$�	����3���2�)=�)=��4�4���5�c�>�t�|��rdSdS)NTF)�NETWORK_NAME_RE�match)rs r&�is_network_devicer,�s"�����T�"�"���t��5r(c��t|��d|��d|��g}|D]+}|�|��}tj�|��r|cS�,dS)N�pz-part)�str�os�path�exists)�device_path�partition_number�potential_suffixes�suffix�potential_partition_devices     r&�_get_nth_partition_for_devicer8�s{�������!�!�#�#�%�%�'���
%�.�.��/:�{�F�F�%C�"�
�7�>�>�4�5�5�	.�-�-�-�-�	.��4r(c��tj�|���d��d}tj�d|��}|�Vtj�|tj�|���d��d��}tj�|��S)N�/r"z/sys/block/)r0r1�realpath�split�joinr2)r3�partition_path�device_name�sys_paths    r&�_is_block_devicerA�s����'�"�"�;�/�/�5�5�c�:�:�2�>�K��w�|�|�M�;�7�7�H��!��7�<�<��b�g�&�&�~�6�6�<�<�S�A�A�"�E�
�
���7�>�>�(�#�#�#r(c��|�d|��|}|dkrd}|�d��t|��r|Stj|��\}}|}|r3|�||��}||kr|�d||��t|��rA||��}|sdS|�d��sd|��}|�d||��nt�|��rd|��}d}|�t|d	��}nt||��}|�dSt||��r|�|S|SdS)
Nz+Attempting to determine the real name of %sr�
ephemeral0z2Adjusted mount option from ephemeral to ephemeral0zMapped device alias %s to %sr:z/dev/zMapped metadata name %s to %s�)�debugr,r�expand_dotted_devname�getr'r#�DEVICE_NAME_REr+r8rA)	�	startname�transformer�log�aliases�devnamer3r4�origr>s	         r&�sanitize_devnamerO�s����I�I�;�Y�G�G�G��G��+������	�	�F�G�G�G���#�#����$(�$>�w�$G�$G�!�K�!��D��I��k�k�+�{�;�;���;����I�I�4�d�K�H�H�H��;�'�'�	5�!�k�+�.�.���	��4��%�%�c�*�*�	5�	5�'2�{�4�K��	�	�1�4��E�E�E�E����	�*�*�	5�	5�'2�{�4�K��N���6�{�A�F�F���6��)�
�
���!��4���^�4�4���%�!�!����4r(c	�,�|�tj��d}|dz}d||d�}|�|�|}nm|rgtj|��}|j|jz}||d<|�!t
t|dz��|��}n ||dzkrt|dz��}n|�|}||d<|dtzkr|}nJ|d	tzkrdtz}n1ttj|tz����tz}t
||��}||d
<i}	|���D]0\}
}t|t��rd|tzz|	|
<�+||	|
<�1t�d|	d
|	d
|	d|	d|	d��|S)N�total��na)�avail�max_in�memrT�g�������?�max��sizez%s MBzCsuggest %s swap for %s memory with '%s' disk given max=%s [max=%s]'rVrU)r�read_meminfor0�statvfs�f_frsize�f_bfree�min�int�GB�round�math�sqrt�items�
isinstance�MB�LOGrE)�memsize�maxsize�fsys�sugg_max�infor\rT�minsizerZ�pinfo�k�vs            r&�suggested_swapsizerr�s������#�%�%�g�.����{�H��W�W�=�=�D��|������	
���*�T�"�"��� �7�?�2����W�
��?��#�e�a�i�.�.�(�3�3�G�G�
����
&�
&��%�#�+�&�&�G��	�����D��K���R�������	�2��7�	�	��b�&�����	�'�B�,�/�/�0�0�2�5���w�� � �D��D��L��E��
�
�������1��a����	��!�b�&�)�E�!�H�H��E�!�H�H��I�I�M�
�f�
�
�e��
�g��
�h��
�e��
����Kr(�fnamerZ�returnc����d���fd�}tj�|��}tj|��tj|��d��dkrtj��dks�dkr|||d��nK	|||d��n<#tj$r*t�
d	��|||d��YnwxYwtj�|��rtj|d
��	tjd|g��dS#tj$rtj
|���wxYw)
zSize is in MiB.z6Failed to create swapfile '%s' of size %sMB via %s: %sc�J��t�d|�|��|dkr
ddd|z|g}n|dkr
ddd|zdd	|zg}	tj|d
���dS#tj$r8}t��||||��tj|���d}~wwxYw)Nz3Creating swapfile in '%s' on fstype '%s' using '%s'�	fallocatez-lz%sM�ddzif=/dev/zerozof=%szbs=1Mzcount=%sT)�capture)rhrEr�ProcessExecutionErrorrmr�del_file)rsrZ�method�cmd�e�errmsg�fstypes     ��r&�create_swapz$create_swapfile.<locals>.create_swaps�����	�	�A����		
�	
�	
��[� � ���e�d�l�E�:�C�C�
�t�^�^����%����T�!��C�	��I�c�4�(�(�(�(�(�(���)�	�	�	��H�H�V�U�D�&�!�4�4�4��M�%� � � ������	���s�A�B"�*3B�B"rD�xfs)rW��btrfsrxrwz4fallocate swap creation failed, will attempt with ddi��mkswapN)r0r1�dirnamer�
ensure_dir�get_mount_info�kernel_versionrrzrhrmr2�chmodr{)rsrZr��swap_dirrr�s    @@r&�create_swapfiler�s�����F�F�������4�w���u�%�%�H��O�H����
�
 ��
*�
*�1�
-�F�	�%���D�/�1�1�G�;�;�	�7�	�	���E�4��&�&�&�&�	+��K��t�[�1�1�1�1���)�	+�	+�	+��H�H�K�L�L�L��K��t�T�*�*�*�*�*�	+����
�w�~�~�e���!��
�5�%� � � ���	�8�U�#�$�$�$�$�$���%�����
�e����
����s�

B�6C�C�	D!�!%Ec�2�tj�|��}t|�����dkrl	tj��d}n+#t$rt�	d��YdSwxYwtj
|��t|||���}tt|dz����}|st�	d��dStj
tj	dt||g�	��|S)
z�
    fname: full path string of filename to setup
    size: the size to create. set to "auto" for recommended
    maxsize: the maximum size
    �autorQz)Not creating swap: failed to read meminfoN)rkrjrirz'Not creating swap: suggested size was 0zSetting up swap file)�msg�func�args)r0r1r�r/�lowerrr[�IOErrorrhrEr�rrr`�log_timer�)rsrZrjr�ri�mibsizes      r&�setup_swapfiler�Hs���w���u�%�%�H�
�4�y�y�����F�"�"�	��'�)�)�'�2�G�G���	�	�	��I�I�A�B�B�B��F�F�	����	
���!�!�!�!��7�G�
�
�
���#�d�e�n�%�%�&�&�G����	�	�;�<�<�<����M��	�"�
��W�
�	�����Ls�A � $B�Bc�p�t|t��st�d��dS|�dd��}|�dd��}|�dd��}|r|st�d��dStj�|��r�tj�d	��st�d
|��|S	tj
d	�����D]9}|�|dz��rt�d|��|cS�:t�d
|��n-#t$r t�d|��|cYSwxYw	t|t��r|dkrtj|��}t|t��rtj|��}t!|||���S#t$r%}t�d|��Yd}~nd}~wwxYwdS)zahandle the swap config, calling setup_swap if necessary.
    return None or (filename, size)
    z%input for swap config was not a dict.N�filenamez	/swap.imgrZrrjzno need to setup swapz/proc/swapsz:swap file %s exists, but no /proc/swaps exists, being safe� zswap file %s already in usez+swap file %s exists, but not in /proc/swapsz.swap file %s exists. Error reading /proc/swapsr�)rsrZrjzfailed to setup swap: %s)rf�dictrh�warningrGrEr0r1r2r�	load_file�
splitlinesr#�	Exceptionr/�human2bytesr�)�swapcfgrsrZrj�liner~s      r&�handle_swapcfgr�jsM���g�t�$�$�����;�<�<�<��t��K�K�
�K�0�0�E��;�;�v�q�!�!�D��k�k�)�T�*�*�G���U���	�	�)�*�*�*���	�w�~�~�e�����w�~�~�m�,�,�	��I�I�L��
�
�
��L�
	���}�5�5�@�@�B�B�
!�
!���?�?�5�3�;�/�/�!��I�I�;�U�C�C�C� �L�L�L�!�
�I�I�C�U�K�K�K�K���	�	�	��K�K�@�%�
�
�
��L�L�L�		����3��d�C� � �	*�T�V�^�^��#�D�)�)�D��g�s�#�#�	0��&�w�/�/�G��E��g�F�F�F�F���3�3�3����.��2�2�2�2�2�2�2�2�����3�����4s2�0AE,�E,�,'F�F�A)H�
H3�H.�.H3r�cfg�cloudrKr�c	�^�%�&�d}|j���}|rd}ddd|ddg}|�d|��}ddd|d	ddggd
�g}g}	d|vr|d}	t�d|	��g}
i}g}t
j�t��r�tj
t�����D]m}
t|
vr|�
|
���!	t�|
��}n#t $rYnwxYw|
||d
<|
�
|
���n|�di��}t#t%|	����D�]C}t'|	|t(��s3|�d|dzt-j|	|�����Qt1|	|d
��}t3||j||���}||kr|�d|�d|����|�|�d|����||vr|�d|||����||	|d
<t#t%|	|����D]5}|	||��t1|	||��|	||<�6��Et#t%|	����D]�}t#t%|����D]\}t%|	|��|kr"|	|�
||���=|	||�|||	||<�]|	|d�;t#|��D]+}|	|d
|	|d
krd|	|d<�,��|D]�}|d
}t3||j||���}||kr|�d|�d|����|�|�d|���\||vr|�d|||���~||d
<d}|	D]}|d
|d
krd}n�|r|�d|����|	�
|����g}|	D]<}|d�|�d|d
���'|�
|���=t9|�di����}|r|�
|dddddg��t%|��d
kr|�d��dSg}d}d}g}|D]�}
|
d	�d t��|
d	<|
d!dkrd}|
d�d"��r|�
|
d��|�
d#�|
������d$�tj��� ��D��}|D]F}	tj!|��n&#t $rtj"|d%|��YnwxYw|s||vrd}�Gd&�|D���%d'�|D���&�%fd(��&D���&fd)��%D��z} |
�#|��d*d+�|
��z}!tj$t|!��g}"|r|"�
d,d-g��t%| ��d
kr|�d.��n|�d/| ��d}|r0|"�
d0d-g��|r|"�
d1d2g��d3}#|"D]�}$d4d5�|$��z}#	tKj%|$��|�|#d6���F#tJj&$r/|�|#d7��tj"||#d7��Y��wxYwdS)8Nzdefaults,nobootwaitz=defaults,nofail,x-systemd.requires=cloud-init.service,_netdevr��0�2�mount_default_fieldsrCz/mnt�)r�noner�swr�r��mountszmounts configuration is %sr�device_aliasesz,Mount option %s not a list, got a %s insteadrD)rLzchanged z => z#Ignoring nonexistent named mount %sz&Device %s already defined in fstab: %szchanged default device z+Ignoring nonexistent default named mount %sFTz-Not including %s, already previously includedz$Skipping nonexistent device named %srr�r�z No modifications to fstab needed�,rRr:�	c�,�g|]\}}d|v�	|d��S)�
mountpoint�)�.0rprqs   r&�
<listcomp>zhandle.<locals>.<listcomp>=s1����� �A�q�\�Q�=N�=N��,��=N�=N�=Nr(z Failed to make '%s' config-mountc�D�g|]}t�d|����S�r���WS�sub�r��ns  r&r�zhandle.<locals>.<listcomp>Ks$��.�.�.��R�V�V�C��^�^�.�.�.r(c�D�g|]}t�d|����Sr�r�r�s  r&r�zhandle.<locals>.<listcomp>Ls$��
4�
4�
4��b�f�f�S�!�n�n�
4�
4�
4r(c�"��g|]}|�v�d|z��S)z- r�)r��drop�saddss  �r&r�zhandle.<locals>.<listcomp>Ns'���@�@�@�D�d�%�.?�.?�D�4�K�.?�.?�.?r(c�"��g|]}|�v�d|z��S)z+ r�)r��add�sdropss  �r&r�zhandle.<locals>.<listcomp>Ns1���D�D�D��s�&�'8�'8��s�
�'8�'8�'8r(z%s
�
�swaponz-azNo changes to /etc/fstab made.zChanges to fstab: %s�mount�	systemctlz
daemon-reloadz#Activating swap and mounts with: %szActivate mounts: %s:r��PASS�FAIL)'�distro�uses_systemdrGrhrEr0r1r2�
FSTAB_PATHrr�r��MNT_COMMENT�appendr�r<r��range�lenrf�listr�r�obj_namer/rO�device_name_to_devicermr�r#r=r�rer��logexc�extend�
write_filerrz)'rr�r�rKr��def_mnt_optsr��defvals�defmnts�cfgmnt�fstab_lines�
fstab_devs�
fstab_removedr��toksr��i�start�	sanitized�j�defmnt�
cfgmnt_has�cfgm�actlist�x�swapret�cc_lines�needswap�need_mount_all�dirs�mount_points�d�sops�contents�
activate_cmds�fmtr}r�r�s'                                     @@r&�handler��s	����)�L��<�,�,�.�.�L��
�K�	��T�6�<��c�:�G��g�g�,�g�6�6�G�
�v�v�w�q�z�3��<�0�0�0��G�
�F��3����X����I�I�*�F�3�3�3��K��J��M�	�w�~�~�j�!�!�%��N�:�.�.�9�9�;�;�
	%�
	%�D��d�"�"��$�$�T�*�*�*��
��x�x��~�~�����
�
�
���
����"&�J�t�A�w�����t�$�$�$�$��W�W�-�r�2�2�N�
�3�v�;�;�
�
�$1�$1���&��)�T�*�*�	��K�K�>��Q���#�F�1�I�.�.�
�
�
�

��F�1�I�a�L�!�!��$��5�.��^�
�
�
�	������I�I�I�E�E�E�9�9�=�>�>�>����I�I�;�U�C�C�C��
�*�
$�
$��H�H�8���9�%�
�
�
�

� ��q�	�!���s�6�!�9�~�~�&�&�	1�	1�A��a�y��|�#��"�6�!�9�Q�<�0�0��q�	�!���		1��3�v�;�;�
�
�(�(���s�7�|�|�$�$�	*�	*�A��6�!�9�~�~��"�"��q�	� � ����,�,�,�,����1��%�&�q�z��q�	�!���
�!�9�Q�<���1�X�X�
(�
(���!�9�Q�<�6�!�9�Q�<�/�/�#'�F�1�I�a�L��������q�	��$��5�.��^�
�
�
�	������I�I�I�5�5�5�)�)�L�M�M�M����I�I�C�U�K�K�K��
�*�
$�
$��I�I�8���9�%�
�
�
�

���q�	��
��	�	�D��A�w�&��)�#�#�!�
���$��	��I�I�E�u�M�M�M���
�
�f������G�
�����Q�4�<��I�I�<�a��d�C�C�C�C��N�N�1������S�W�W�V�R�0�0�1�1�G��B��������s�C�@�A�A�A�
�7�|�|�q����	�	�4�5�5�5����H��H��N�
�D��)�)��!�!�W�W�W�k�k�2��Q����7�f����H���7���c�"�"�	!��K�K��Q�� � � �����	�	�$���(�(�(�(���$(�K�M�M�$7�$7�$9�$9����L��	"�	"��	D��O�A�������	D�	D�	D��K��?��C�C�C�C�C�	D����
�	"�!�<�"7�"7�!�N��.�.�X�.�.�.�E�
4�
4�m�
4�
4�
4�F�@�@�@�@�F�@�@�@�D�D�D�D�#�D�D�D��D����x� � � ���	�	�+�.�.�.�H��O�J��)�)�)��M��/����h��-�.�.�.�
�4�y�y�A�~�~��	�	�2�3�3�3�3��	�	�(�$�/�/�/����A����g�t�_�-�-�-��	A�� � �+��!?�@�@�@�
/�C��*�*��$�s�x�x��}�}�4��	*��I�c�N�N�N��I�I�c�6�"�"�"�"���)�	*�	*�	*��K�K��V�$�$�$��K��S�&�)�)�)�)�)�	*����*�*s6�2D
�
D�D�W)�) X�X�*],�,;^*�)^*)N)NNN)NN)5�__doc__�loggingrcr0�rer�stringr�textwrapr�	cloudinitrrr�cloudinit.cloudr	�cloudinit.configr
�cloudinit.config.schemarr�cloudinit.settingsr
�MODULE_DESCRIPTION�examplerr�__annotations__�DEVICE_NAME_FILTER�compilerH�NETWORK_NAME_FILTERr*r�r�r�rgra�	getLogger�__name__rhr'r,r8rArOrrr/r�r�r�r�r�r�r(r&�<module>rs���4�3�3���������	�	�	�	�	�	�	�	�������������������,�,�,�,�,�,�,�,�,�,�!�!�!�!�!�!�#�#�#�#�#�#�<�<�<�<�<�<�<�<�+�+�+�+�+�+�&��P�&�����$�'����
4�%�����
�	
�	
���!�'���j����,�,�t�
�
��?�����.�/�/�����"�*�0�1�1���R�Z��:�&�'�'��
�
�#��
��
���g���!�!��	�	�	����
�
�
�$�$�$�$�.�.�.�.�b6�6�6�6�r5�3�5�c�5�d�5�5�5�5�p����D-�-�-�`S*�

�S*��S*�#(�S*�/5�S*�=A�S*�	�S*�S*�S*�S*�S*�S*r(