HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/lvm.cpython-310.pyc
o

�N�gf4�@spdZddlZddlZdd�Zdd�Zdd�Zd	d
�Zddd�Zd
d�Z										ddd�Z
ddd�ZdS)a]
Management of Linux logical volumes
===================================

A state module to manage LVMs

.. code-block:: yaml

    /dev/sda:
      lvm.pv_present

    my_vg:
      lvm.vg_present:
        - devices: /dev/sda

    lvroot:
      lvm.lv_present:
        - vgname: my_vg
        - size: 10G
        - stripes: 5
        - stripesize: 8K
�NcCstjj�d�r	dSdS)z2
    Only load the module if lvm is installed
    Zlvm)Fzlvm command not found)�salt�utils�path�which�rr�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/lvm.py�__virtual__srcCst|���}|dd�}|��rd}n|dkr$|dd�}|dd�}n|dd�}|dd���r7t|�}n
tj�d|�d���|dkrK|d}|S|dkrS|}|S|d	kr]|d
}|S|dkri|d
d
}|S|dkrw|d
d
d
}|Stj�d
|�d���)N����m�b���zSize z is invalid.�si�gi�t�pzUnit )�str�lower�isdigit�intr�
exceptionsZArgumentValueError)�sizeZstr_sizeZunitZtarget_sizerrr�_convert_to_mb&s6
�	����rcKs�id|dd�}td|dd�rd|�d�|d<|Std	r+d|�d
�|d<d|d<|Std
|fi|��}td|�rJd|��|d<||dd<|Sd|��|d<d|d<|S)z�
    Set a Physical Device to be used as an LVM Physical Volume

    name
        The device name to initialize.

    kwargs
        Any supported options to pvcreate. See
        :mod:`linux_lvm <salt.modules.linux_lvm>` for more details.
    �T��changes�comment�name�result�
lvm.pvdisplay��quiet�Physical Volume � already presentr�test� is set to be createdNrzlvm.pvcreatezCreated Physical Volume r�createdz!Failed to create Physical Volume F��__salt__�__opts__)r�kwargs�retrrrr�
pv_presentFs ��r+cCs�id|dd�}td|dd�sd|�d�|d<|Std	r+d|�d
�|d<d|d<|Std
|�}td|dd�rFd|��|d<d|d<|Sd|��|d<||dd<|S)zq
    Ensure that a Physical Device is not being used by lvm

    name
        The device name to initialize.
    rTrrrr!z does not existrr#� is set to be removedNrzlvm.pvremovez!Failed to remove Physical Volume FzRemoved Physical Volume r�removedr&�rr*rrrr�	pv_absentes ��r/c	Ks�id|dd�}t|t�r|�d�}td|dd�r�d|�d�|d	<|D]�}tj�|�}td
|dd�}|r�|�|d�r�||d
|krQd�|d	|�d��|d	<q#||d
dvr�td||�td
|dd�}||d
|kr}|d�	|d|��i�q#d�|d	|�d��|d	<d|d<q#d�|d	d�|||d
��|d	<d|d<q#d�|d	d|�d��|d	<d|d<q#|St
dr�d|�d�|d	<d|d<|Std||fi|��}td|�r�d|��|d	<||dd<|Sd|��|d	<d|d<|S) a#
    Create an LVM Volume Group

    name
        The Volume Group name to create

    devices
        A list of devices that will be added to the Volume Group

    kwargs
        Any supported options to vgcreate. See
        :mod:`linux_lvm <salt.modules.linux_lvm>` for more details.
    rTr�,�
lvm.vgdisplayr�
Volume Group r"rr)�realNzVolume Group Namez{}
{}z is part of Volume Group)rz
#orphans_lvm2zlvm.vgextendrz	added to z could not be addedFrz{} is part of {}zpv z is not presentr#r$zlvm.vgcreatezCreated Volume Group r%zFailed to create Volume Group )�
isinstancer�splitr'�osr�realpath�get�format�updater()rZdevicesr)r*ZdeviceZrealdevZpvsrrrr�
vg_present�s\


��
��
�
��r;cCs�id|dd�}td|dd�sd|�d�|d<|Std	r+d|�d
�|d<d|d<|Std
|�}td|dd�sHd|��|d<||dd<|Sd|��|d<d|d<|S)zQ
    Remove an LVM volume group

    name
        The volume group to remove
    rTrr1rr2� already absentrr#r,Nrzlvm.vgremovezRemoved Volume Group rr-zFailed to remove Volume Group Fr&r.rrr�	vg_absent�s ��r=rFc

Ks�id|dd�}|r|rd|d<d|d<|S|rt|�}d}
|r#|}
|}|r1d	�|�d
�d|�}nd|�d
|��}td
|dd�}|�|�}|s�tdrZd|�d�|d<d|d<|Std||f|||
||||d�|
��}td
|�r�d|��|d<||dd<|Sd�||d�|d<d|d<|Sd|�d�|d<|s�|�rKt|d�}t|dd�}|r�|}ndt|�vr�d�||�|d<|}|}|dur�||ks�||kr�d|d<d|d<|S||ks�||k�rKtdr�d �|�|d<d|d<|S|�rtd!|||	|d"�}n
td!|||	|d#�}|�sd$|d<d|d<td
|dd�|}t|dd�}||k�r=d%|��|d<||dd&<|Sd'�||d(�|d<d|d<|S))a�
    Ensure that a Logical Volume is present, creating it if absent.

    name
        The name of the Logical Volume

    vgname
        The name of the Volume Group on which the Logical Volume resides

    size
        The size of the Logical Volume in megabytes, or use a suffix
        such as S, M, G, T, P for 512 byte sectors, megabytes, gigabytes
        or terabytes respectively. The suffix is case insensitive.

    extents
        The number of logical extents allocated to the Logical Volume
        It can be a percentage allowed by lvcreate's syntax, in this case
        it will set the Logical Volume initial size and won't be resized.

    snapshot
        The name of the snapshot

    pv
        The Physical Volume to use

    kwargs
        Any supported options to lvcreate. See
        :mod:`linux_lvm <salt.modules.linux_lvm>` for more details.

    .. versionadded:: 2016.11.0

    thinvolume
        Logical Volume is thinly provisioned

    thinpool
        Logical Volume is a thin pool

    .. versionadded:: 2018.3.0

    force
        Assume yes to all prompts

    .. versionadded:: 3002

    resizefs
        Use fsadm to resize the logical volume filesystem if needed

    rTrz-Only one of extents or size can be specified.rFrNz
/dev/{}/{}�/r�/dev/�
lvm.lvdisplayrr#�Logical Volume r$zlvm.lvcreate)r�extents�snapshot�pv�
thinvolume�thinpool�forcezCreated Logical Volume rr%z-Failed to create Logical Volume {}. Error: {}zOutput from lvcreater"z"Current Logical Extents AssociatedzLogical Volume Sizer
�%z7Logical Volume {} already present, {} won't be resized.z7To reduce a Logical Volume option 'force' must be True.z&Logical Volume {} is set to be resizedzlvm.lvresize)�lvpathr�resizefsrG)rIrBrJrGz/Failed to resize Logical Volume. Unknown Error.zResized Logical Volume Zresizedz-Failed to resize Logical Volume {}.
Error: {}zOutput from lvresize)rr9r5r'r8r(rr)r�vgnamerrBrCrDrErFrGrJr)r*Zsize_mbZ	_snapshotrIZlv_inforZold_extentsZold_size_mbZnew_size_mbrrr�
lv_present�s�=
��
�
F��A�
�������
���rLcCs�id|dd�}d|�d|��}td|dd�s!d|�d	�|d
<|Stdr3d|�d�|d
<d
|d<|Std||�}td|dd�sQd|��|d
<||dd<|Sd|��|d
<d|d<|S)z�
    Remove a given existing Logical Volume from a named existing volume group

    name
        The Logical Volume to remove

    vgname
        The name of the Volume Group on which the Logical Volume resides
    rTrr?r>r@rrAr<rr#r,Nrzlvm.lvremovezRemoved Logical Volume rr-z Failed to remove Logical Volume Fr&)rrKr*rIrrrr�	lv_absent�s"
��rM)N)	NNNNrFFFF)�__doc__r6Zsalt.utils.pathrrrr+r/r;r=rLrMrrrr�<module>s*	 
C
�4