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/modules/__pycache__/xfs.cpython-310.pyc
o

�N�g�<�@sdZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
mZe�e
�Zdd�Zd,dd�Zdd	�Zd
d�Zdd
�Zdd�Zd-dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Z										d.d$d%�Zd/d&d'�Z d(d)�Z!d*d+�Z"dS)0z'
Module for managing XFS file systems.
�N)�CommandExecutionErrorcCstjj��o
t�d�dkS)z)
    Only work on POSIX-like systems
    Zkernel�Linux)�salt�utils�platformZ
is_windowsZ
__grains__�get�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/xfs.py�__virtual__*sr
cCs^|�dd�r+|dr-|rt�d|�t�d|�d��t�d|�dd��t|d��dSdS)	zC
    Crash to the log if command execution was not successful.
    �retcoder�stderrz
Command: "%s"zReturn code: %szError output:
%szN/AN)r�log�debugr)�out�cmdrrr	�_verify_run1s�rcCs�|�d�r
|dd���}|�dd��dd�}g}|�d�D] }|r&d|vr,|�|�q|t|�dd||t|�d<qdd	�|D�S)
z0
    Parse one line of the XFS info output.
    �=�Nz = z=*** z =� cSsg|]	}t|�d���qS�r)�tuple�split)�.0�itemsrrr	�
<listcomp>Rsz$_xfs_info_get_kv.<locals>.<listcomp>)�
startswith�strip�replacer�append�len)Z
serialized�optZtknrrr	�_xfs_info_get_kv?s
&r!cs�i}t�d��d}�fdd�|�d�D�D]4}|rd|vrqt|�}|�d�s>|�d�}d||d	d
kr6d	p7di||d<||d�t|��q|S)z:
    Parse output from "xfs_info" or "xfs_growfs -n".
    �\s+Ncs$g|]}��d|����dd��qS)rz, )�subrr�r�l�Zsprrr	r\s$z#_parse_xfs_info.<locals>.<listcomp>�
rr�sectionrz***)�re�compilerr!r�pop�update�dict)�data�ret�entry�lineZnforr&r	�_parse_xfs_infoUs


$r2cCs@tdd|���}|�d�rt|d�dd�����t|d�S)z
    Get filesystem geometry information.

    CLI Example:

    .. code-block:: bash

        salt '*' xfs.info /dev/sda1
    �cmd.run_allz	xfs_info rz	xfs_info:��stdout)�__salt__rrrrr2��devicerrrr	�infohs

r9cCs i}g}d}dd�|�d�D�D]t}t�dd|�}|�d�r(|�d�d	|d
<nD|�d�r7t�dd|�|d
<n5|�d�rFt�dd|�|d<n&|�d�rUt�dd|�|d<n|�d�rdt�dd|�|d<n|�d�rld}q|�d�r{|r{|�|���q|�d�s�|r�d}q|r�d�|�|d<|S)z2
    Parse CLI output of the xfsdump utility.
    FcSsg|]
}|��r|���qSr�rr$rrr	r�sz#_xfsdump_output.<locals>.<listcomp>r'z
^xfsdump: r4zsession id:r���z
Session IDzsession label:z^session label: z
Session labelzmedia file sizez^media file size\s+z
Media sizezdump complete:z^dump complete:\s+z
Dump completezDump Status:z^Dump Status:\s+ZStatusz
Dump Summary:TZSummary)rr)r#rrr�join)r.rZsummaryZ
summary_blockr1rrr	�_xfsdump_outputxs4





�r=cCs�tjj�d�std��|r|pt�d|�d�t����dd�}dg}|�	d�|s.|�	d�|�	d	|�d��|�	d
|���|�	d|���|�	|�d�
|�}td
|�}t||d�t
|d�S)ah
    Dump filesystem device to the media (file, tape etc).

    Required parameters:

    * **device**: XFS device, content of which to be dumped.
    * **destination**: Specifies a dump destination.

    Valid options are:

    * **label**: Label of the dump. Otherwise automatically generated label is used.
    * **level**: Specifies a dump level of 0 to 9.
    * **noerase**: Pre-erase media.

    Other options are not used in order to let ``xfsdump`` use its default
    values, as they are most optimal. See the ``xfsdump(8)`` manpage for
    a more complete description of these options.

    CLI Example:

    .. code-block:: bash

        salt '*' xfs.dump /dev/sda1 /detination/on/the/client
        salt '*' xfs.dump /dev/sda1 /detination/on/the/client label='Company accountancy'
        salt '*' xfs.dump /dev/sda1 /detination/on/the/client noerase=True
    Zxfsdumpz1Utility "xfsdump" has to be installed or missing.zXFS dump for "z" of %Y.%m.%d, %H:%M�'�"z-Fz-Ez-L 'z-l z-f rr3�rr5)rr�path�whichr�time�strftime�	localtimerrr<r6rr=)r8Zdestination�level�labelZnoeraserrrrr	�dump�s,���



rHcCsXdd�|���dd�D�}t|�dkrd|d�d�S|\}}d|���d|���d	�S)
z2
    Parse xfsrestore output keyset elements.
    cS�g|]}|r|�qSrr�rZelmrrr	r��z!_xr_to_keyset.<locals>.<listcomp>�:rr>rz': z': 'z',)rrr)r1Ztkns�key�valrrr	�
_xr_to_keyset�s
rOcCs&g}dd�|�d�D�}t|�dkr d|d��vr d|diSd}|�d�|d	d
�D]A}tdd�|���d�D��dkrgtt�d
d|��}||krXt|�D]}|�d�qP|}|�t|��|�d�q-|�t|��q-t|d�D]}|�d�qu|�d�t	d�
|��d}|d
|d<|S)z]
    Transform xfsrestore inventory data output to a Python dict source and evaluate it.
    cS�g|]}|��r|�qSrr:)rr1rrr	r��z)_xfs_inventory_output.<locals>.<listcomp>r'rzrestore statusrZrestore_status�{Nr;cSrIrrrJrrr	r�rKrLz[^	]r4z},)rr�lowerrrr)r#�rangerO�evalr<)rr.�identr1Zn_ident�steprrr	�_xfs_inventory_output�s,
 
rXcC� tdd�}t|�t|d�S)z�
    Display XFS dump inventory without restoration.

    CLI Example:

    .. code-block:: bash

        salt '*' xfs.inventory
    r3z
xfsrestore -Ir5)r6rrX�rrrr	�	inventory�
r[c	Cs�i}g}d}dd�|�d�D�D]}|�d�r|rnd}q|r%|�|�qdd�|dd	�D�D]}d
d�|�dd�D�\}}|||���d
d�<q1|�d�|krT|pUiS)z
    Parse prune output.
    FcSsg|]}|r|���qSrr:r$rrr	rrQz%_xfs_prune_output.<locals>.<listcomp>r'�-TcSsg|]}d|vr|�qS)rLr)r�errr	r"rQrNcss�|]}|��VqdS�Nr:)r�trrr	�	<genexpr>#s�z$_xfs_prune_output.<locals>.<genexpr>rLr�_�uuid)rrrrSrr)	rrcr.ZcntZcutpointr1ZksetrMrNrrr	�_xfs_prune_outputs 

�rdcCsBtdd|�d��}t|�t|d|�}|r|Std|�d���)z�
    Prunes the dump session identified by the given session id.

    CLI Example:

    .. code-block:: bash

        salt '*' xfs.prune_dump b74a3586-e52e-4a4a-8775-c3334fa8ea2c

    r3zxfsinvutil -s z -Fr5zSession UUID "�" was not found.)r6rrdr)Z	sessionidrr.rrr	�
prune_dump)srfc
Cs�dd�}i}||�d��D]4}i}||���d��D]}|�dd�\}}|||��<q|�dd�d	krA|�d
�|d
<|||�d�<q
t�}|D]}	|�|	�rW||	�||	�qG|S)z
    Parse blkid output.
    cSsdd�|D�S)NcSrPrr:)r�elrrr	rDrQz._blkid_output.<locals>.flt.<locals>.<listcomp>r)r.rrr	�fltCsz_blkid_output.<locals>.fltz

r'rr�typeN�xfsrGZdevname)rrrSr+r�_get_mountsr,)
rrhr.Zdev_meta�devrrMrN�mountsr8rrr	�
_blkid_output>s"�
�rncCrY)z�
    Get known XFS formatted devices on the system.

    CLI Example:

    .. code-block:: bash

        salt '*' xfs.devices
    r3zblkid -o exportr5)r6rrnrZrrr	�devicesXr\roc	Csbt�d�}i}dd�|�d�D�dd�D]}|�d|��d�\}}}}}||||d�||<q|S)	z$
    Parse xfs_estimate output.
    r"cSrPrr:r$rrr	rnrQz(_xfs_estimate_output.<locals>.<listcomp>r'rNr)zblock _size�blocks�	megabytes�logsize)r)r*rr#)	rZspcr.r1�	directoryZbsizerprqrrrrr	�_xfs_estimate_outpuths
 �rtcCsBtj�|�std|�d���tdd|���}t|�t|d�S)a`
    Estimate the space that an XFS filesystem will take.
    For each directory estimate the space that directory would take
    if it were copied to an XFS filesystem.
    Estimation does not cross mount points.

    CLI Example:

    .. code-block:: bash

        salt '*' xfs.estimate /path/to/file
        salt '*' xfs.estimate /path/to/dir/*
    zPath "rer3zxfs_estimate -v r5)�osrA�existsrr6rrt)rArrrr	�estimatezs
rwc
Csdd�}dg}|r|�d�|�d|�d��|r#|�d�|�|�d|fd|fd	|	fd
|fd|
fd|fd
|ffD]&\}
}z||�rM|�|
�|�|�Wq:ty`td|�d|
�d���w|sh|�d�|�|�d�|�}td|�}t||d�t|d�S)al
    Create a file system on the specified device. By default wipes out with force.

    General options:

    * **label**: Specify volume label.
    * **ssize**: Specify the fundamental sector size of the filesystem.
    * **noforce**: Do not force create filesystem, if disk is already formatted.

    Filesystem geometry options:

    * **bso**: Block size options.
    * **gmo**: Global metadata options.
    * **dso**: Data section options. These options specify the location, size,
               and other parameters of the data section of the filesystem.
    * **ino**: Inode options to specify the inode size of the filesystem, and other inode allocation parameters.
    * **lso**: Log section options.
    * **nmo**: Naming options.
    * **rso**: Realtime section options.

    See the ``mkfs.xfs(8)`` manpage for a more complete description of corresponding options description.

    CLI Example:

    .. code-block:: bash

        salt '*' xfs.mkfs /dev/sda1
        salt '*' xfs.mkfs /dev/sda1 dso='su=32k,sw=6' noforce=True
        salt '*' xfs.mkfs /dev/sda1 dso='su=32k,sw=6' lso='logdev=/dev/sda2,size=10000b'
    cSs0t|r	d|vr	|sdrdd�|�d�D�pg�S)NrcSsg|]}|�d��qSr)r)r�kwrrr	r�sz)mkfs.<locals>.getopts.<locals>.<listcomp>�,)r-r)�argsrrr	�getopts�s��zmkfs.<locals>.getoptszmkfs.xfs�-Lr>z-sz-bz-mz-nz-iz-dz-lz-rzWrong parameters "z" for option "r?z-frr3r@r5)r�	Exceptionrr<r6rr2)r8rGZssizeZnoforceZbsoZgmo�inoZlsoZrsoZnmoZdsor{rZswitch�optsrrrr	�mkfs�sB,


�	

���


r�cCs|s|dur|durtd|�d���dg}|r%|�d�|�d|�d��|dur4|�d�|�d	�n|r@|�d�|�d
�|durO|�d�|�d�n|r[|�d�|�d
�|�|�d�|�}ttd|�|d�tdd|���}t|�t|d�S)a
    Modify parameters of an XFS filesystem.

    CLI Example:

    .. code-block:: bash

        salt '*' xfs.modify /dev/sda1 label='My backup' lazy_counting=False
        salt '*' xfs.modify /dev/sda1 uuid=False
        salt '*' xfs.modify /dev/sda1 uuid=True
    Nz(Nothing specified for modification for "z" deviceZ	xfs_adminr|r>Fz-c�0�1z-U�nilZgeneraterr3r@zblkid -o export r5)rrr<rr6rn)r8rGZ
lazy_countingrcrrrrr	�modify�s4
�








r�c	Cs�i}tjj�d��1}tjj�|���D]}|���d�\}}}}}}|dkr'q||�d�d�||<qWd�|S1s=wY|S)z#
    List mounted filesystems.
    z/proc/mountsrrjry)Zmount_point�optionsN)	rr�filesZfopenr.�decode�	readlinesrr)	rmZfhrr1r8ZmntpntZfstyper�Zfs_freqZ	fs_passnorrr	rks ���
��rkcCsR|dkrtd��t��|�std|�d���tdd|���}t|�d|diS)	z�
    Defragment mounted XFS filesystem.
    In order to mount a filesystem, device should be properly mounted and writable.

    CLI Example:

    .. code-block:: bash

        salt '*' xfs.defragment /dev/sda1
    �/zRoot is not a device.zDevice "z" is not mountedr3zxfs_fsr r
r5)rrkrr6rr7rrr	�
defragment,sr�r_)rNN)
NNNNNNNNNN)NNN)#�__doc__�loggingrur)rCZsalt.utils.datarZsalt.utils.filesZsalt.utils.pathZsalt.utils.platformZsalt.exceptionsr�	getLogger�__name__r
r
rr!r2r9r=rHrOrXr[rdrfrnrortrwr�r�rkr�rrrr	�<module>sR


#5$
�
Y.