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__/zfs.cpython-310.pyc
o

�N�g���@sdZddlZddlZddlZddlZddlZddlZddlm	Z	dZ
e�e�Z
ddiZdd�Zd	d
�Zdd�Zd
d�Zdd�Zd0dd�Zdd�Zd0dd�Zdd�Zdd�Zd0dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Z d*d+�Z!d,d-�Z"d.d/�Z#dS)1a�
Module for running ZFS command

:codeauthor:    Nitin Madhok <nmadhok@g.clemson.edu>, Jorge Schrauwen <sjorge@blackdot.be>
:maintainer:    Jorge Schrauwen <sjorge@blackdot.be>
:maturity:      new
:depends:       salt.utils.zfs
:platform:      illumos,freebsd,linux

.. versionchanged:: 2018.3.1
  Big refactor to remove duplicate code, better type conversions and improved
  consistency in output.

�N)�OrderedDictZzfs�list_�listcCst�d�rtSdS)z5
    Only load when the platform has zfs support
    Zzfs_support)Fz2The zfs module cannot be loaded: zfs not supported)Z
__grains__�get�__virtualname__�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/zfs.py�__virtual__"s
r	cKsJi}|�dd�r|�d�|d<tdtdd||d�ddd	�}|d
dkS)a�
    Check if a ZFS filesystem or volume or snapshot exists.

    name : string
        name of dataset
    type : string
        also check if dataset is of a certain type, valid choices are:
        filesystem, snapshot, volume, bookmark, or all.

    .. versionadded:: 2015.5.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.exists myzpool/mydataset
        salt '*' zfs.exists myzpool/myvolume type=volume

    �typeF�-t�cmd.run_all�zfs.zfs_commandr)�command�opts�targetT)�python_shellZignore_retcode�retcoder)r�__salt__�	__utils__)�name�kwargsr�resrrr�exists,s��
rcKs�g}i}|�di�}|�dd�r|�d�|�dd�r&|�dd�r&|�d�|�dd�r9td	|�d�dd
�|d<tdtd
d||||d�dd�}td|d�S)a�
    Create a ZFS File System.

    name : string
        name of dataset or volume
    volume_size : string
        if specified, a zvol will be created instead of a dataset
    sparse : boolean
        create sparse volume
    create_parent : boolean
        creates all the non-existing parent datasets. any property specified on the
        command line using the -o option is ignored.
    properties : dict
        additional zfs properties (-o)

    .. note::

        ZFS properties can be specified at the time of creation of the filesystem by
        passing an additional argument called "properties" and specifying the properties
        with their respective values in the form of a python dictionary::

            properties="{'property1': 'value1', 'property2': 'value2'}"

    .. versionadded:: 2015.5.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.create myzpool/mydataset [create_parent=True|False]
        salt '*' zfs.create myzpool/mydataset properties="{'mountpoint': '/export/zfs', 'sharenfs': 'on'}"
        salt '*' zfs.create myzpool/volume volume_size=1G [sparse=True|False]`
        salt '*' zfs.create myzpool/volume volume_size=1G properties="{'volblocksize': '512'}" [sparse=True|False]

    �
properties�
create_parentF�-p�sparseZvolume_sizeN�-szzfs.to_size�Zconvert_to_humanz-Vrr
�create)r�flagsr�filesystem_propertiesr�r�zfs.parse_command_result�created)r�appendrr)rrr rr!rrrrrVs,&



���rcKsrg}|�dd�r
|�d�|�dd�r|�d�|�dd�r#|�d�tdtd	d
||d�dd�}td
|d�S)av
    Destroy a ZFS File System.

    name : string
        name of dataset, volume, or snapshot
    force : boolean
        force an unmount of any file systems using the unmount -f command.
    recursive : boolean
        recursively destroy all children. (-r)
    recursive_all : boolean
        recursively destroy all dependents, including cloned file systems
        outside the target hierarchy. (-R)

    .. warning::
        watch out when using recursive and recursive_all

    .. versionadded:: 2015.5.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.destroy myzpool/mydataset [force=True|False]

    �forceF�-f�
recursive_all�-R�	recursive�-rrr
�destroy�rr rr"r#Z	destroyed�rr%rr�rrr rrrrr,�s 


��	r,cKs�g}g}td|�r,|�dd�rt�d�|�dd�r t�d�|�dd�r+|�d�n!|�dd�r7|�d	�|�dd�rB|�d
�|�dd�rMt�d�|�|�|�|�tdtd
d||d�dd�}td|d�S)a/
    Rename or Relocate a ZFS File System.

    name : string
        name of dataset, volume, or snapshot
    new_name : string
        new name of dataset, volume, or snapshot
    force : boolean
        force unmount any filesystems that need to be unmounted in the process.
    create_parent : boolean
        creates all the nonexistent parent datasets. Datasets created in
        this manner are automatically mounted according to the mountpoint
        property inherited from their parent.
    recursive : boolean
        recursively rename the snapshots of all descendent datasets.
        snapshots are the only dataset that can be renamed recursively.

    .. versionadded:: 2015.5.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.rename myzpool/mydataset myzpool/renameddataset

    zzfs.is_snapshotrFz>zfs.rename - create_parent=True cannot be used with snapshots.r&z6zfs.rename - force=True cannot be used with snapshots.r*r+rr'z<zfs.rename - recursive=True can only be used with snapshots.rr
�renamer-r"r#Zrenamed)rr�log�warningr%r)r�new_namerr rrrrrr0�s:�

�




��	r0c
	Ks�t�}|�dd�}t|t�s|�d�}d|vr |�d�d|vs|�dd�dg}i}|�dd�r6|�d	�|�dd�rI|�d
d�rI|�d
�|d<|�dd�rV|�d�|d
<|�dd�}|rt||vrt|�dd��d�rp||d<n||d<t|t�r�d�	|�|d<n||d<t
dtdd|||d�dd�}|ddkr�|d��D]8}|�dd�r�tdttt
||�d�����}	ntd ttt
||�d����dd!�}	|	||	d<||	dd=q�|Std"|�S)#aF
    Return a list of all datasets or a specified dataset on the system and the
    values of their used, available, referenced, and mountpoint properties.

    name : string
        name of dataset, volume, or snapshot
    recursive : boolean
        recursively list children
    depth : int
        limit recursion to depth
    properties : string
        comma-separated list of properties to list, the name property will always be added
    type : string
        comma-separated list of types to display, where type is one of
        filesystem, snapshot, volume, bookmark, or all.
    sort : string
        property to sort on (default = name)
    order : string [ascending|descending]
        sort order (default = ascending)
    parsable : boolean
        display numbers in parsable (exact) values
        .. versionadded:: 2018.3.0

    .. versionadded:: 2015.5.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.list
        salt '*' zfs.list myzpool/mydataset [recursive=True|False]
        salt '*' zfs.list myzpool/mydataset properties="sharenfs,mountpoint"

    rzused,avail,refer,mountpoint�,rr�-Hr*Fr+�depth�-dr
r�sort�orderZ	ascending�ar�-S�-orr
r�rr rrr"r�stdout�parsableTzzfs.from_auto_dict�	zzfs.to_auto_dictrr#)rr�
isinstancer�split�remove�insertr%�
startswith�joinrr�
splitlines�zip)
rr�retrr rZkwargs_sortr�ds�ds_datarrrrs^#


�


��	���cCsftdtddd�dd�}|ddkr-t�}|d	��D]}|��}|d
||d<q|Std|�S)z�
    List mounted zfs filesystems

    .. versionadded:: 2018.3.1

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.list_mount

    rr
�mount)rFr"rrr>���r#)rrrrGrB)rrIrLrrr�
list_mountys��rNcKsfg}i}|�dd�r|�d�|�dd�r|�d�|d<tdtdd|||d	�dd
�}td|d�S)
a�
    Mounts ZFS file systems

    name : string
        name of the filesystem, having this set to None will mount all filesystems. (this is the default)
    overlay : boolean
        perform an overlay mount.
    options : string
        optional comma-separated list of mount options to use temporarily for
        the duration of the mount.

    .. versionadded:: 2016.3.0
    .. versionchanged:: 2018.3.1

    .. warning::

            Passing '-a' as name is deprecated and will be removed in 3001.

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.mount
        salt '*' zfs.mount myzpool/mydataset
        salt '*' zfs.mount myzpool/mydataset options=ro

    ZoverlayFz-O�optionsr<rr
rLr=r"r#Zmountedr.)rrr rrrrrrL�s 
��
rLcKs\g}|�dd�r
|�d�|dvr|�d�d}tdtdd	||d
�dd�}td|d
�S)a}
    Unmounts ZFS file systems

    name : string
        name of the filesystem, you can use None to unmount all mounted filesystems.
    force : boolean
        forcefully unmount the file system, even if it is currently in use.

    .. warning::

        Using ``-a`` for the name parameter will probably break your system, unless your rootfs is not on zfs.

    .. versionadded:: 2016.3.0
    .. versionchanged:: 2018.3.1

    .. warning::

            Passing '-a' as name is deprecated and will be removed in 3001.

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.unmount myzpool/mydataset [force=True|False]

    r&Fr')N�-arPNrr
�unmountr-r"r#Z	unmountedr.r/rrrrQ�s

��	rQcKs^g}|�dd�r
|�d�|�dd�r|�d�tdtdd|||d	�dd
�}td|d�S)
a&
    Clears the specified property

    prop : string
        name of property
    name : string
        name of the filesystem, volume, or snapshot
    recursive : boolean
        recursively inherit the given property for all children.
    revert : boolean
        revert the property to the received value if one exists; otherwise
        operate as if the -S option was not specified.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.inherit canmount myzpool/mydataset [recursive=True|False]

    r*Fr+Zrevertr;rr
�inherit)rr �
property_namerr"r#Z	inheritedr.)Zproprrr rrrrrRs

��
rRc
Ks�dg}g}|�dd�r|�d�|�dd�r|�d�|�|�|r'|�|�tdtdd	||d
�dd�}|d
dkrBtd|�S|�dd�sv|�dd�rvt�}|d��D]}|��}td|dd�}d�|dd��}	|	||<qW|S|d��}|S)a

    Display the difference between a snapshot of a given filesystem and
    another snapshot of that filesystem from a later time or the current
    contents of the filesystem.

    name_a : string
        name of snapshot
    name_b : string
        (optional) name of snapshot or filesystem
    show_changetime : boolean
        display the path's inode change time as the first column of output. (default = True)
    show_indication : boolean
        display an indication of the type of file. (default = True)
    parsable : boolean
        if true we don't parse the timestamp to a more readable date (default = True)

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.diff myzpool/mydataset@yesterday myzpool/mydataset

    r5Zshow_changetimeTrZshow_indicationz-Frr
�diffr-Fr"rrr#r?r>zdateutils.strftimez%Y-%m-%d.%H:%M:%S.%fz		�N)rr%rrrrGrBrF)
�name_a�name_brr rrrI�entryZentry_timestampZ
entry_datarrrrT2s>



��	�
�rTcKs�g}|�dd�r
|�d�|�dd�r|�d�|�dd�r5|�dd�s*|�dd�r0|�d�nt�d�td	td
d||d�dd
�}td|d�S)a
    Roll back the given dataset to a previous snapshot.

    name : string
        name of snapshot
    recursive : boolean
        destroy any snapshots and bookmarks more recent than the one
        specified.
    recursive_all : boolean
        destroy any more recent snapshots and bookmarks, as well as any
        clones of those snapshots.
    force : boolean
        used with the -R option to force an unmount of any clone file
        systems that are to be destroyed.

    .. warning::

        When a dataset is rolled back, all data that has changed since
        the snapshot is discarded, and the dataset reverts to the state
        at the time of the snapshot. By default, the command refuses to
        roll back to a snapshot other than the most recent one.

        In order to do so, all intermediate snapshots and bookmarks
        must be destroyed by specifying the -r option.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.rollback myzpool/mydataset@yesterday

    r(Fr)r*r+r&r'zTzfs.rollback - force=True can only be used with recursive_all=True or recursive=Truerr
�rollbackr-r"r#Z
rolledback)rr%r1r2rrr/rrrrYws(%

���	rYcKslg}g}|�di�}|�dd�r|�d�|�|�|�|�tdtdd|||d�dd	�}td
|d�S)ak
    Creates a clone of the given snapshot.

    name_a : string
        name of snapshot
    name_b : string
        name of filesystem or volume
    create_parent : boolean
        creates all the non-existing parent datasets. any property specified on the
        command line using the -o option is ignored.
    properties : dict
        additional zfs properties (-o)

    .. note::

        ZFS properties can be specified at the time of creation of the filesystem by
        passing an additional argument called "properties" and specifying the properties
        with their respective values in the form of a python dictionary::

            properties="{'property1': 'value1', 'property2': 'value2'}"

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.clone myzpool/mydataset@yesterday myzpool/mydataset_yesterday

    rrFrrr
�clone�rr r!rr"r#Zclonedr.)rVrWrr rr!rrrrrZ�s"!


��
rZcCs*tdtdd|d�dd�}td|d�S)	a5
    Promotes a clone file system to no longer be dependent on its "origin"
    snapshot.

    .. note::

        This makes it possible to destroy the file system that the
        clone was created from. The clone parent-child dependency relationship
        is reversed, so that the origin file system becomes a clone of the
        specified file system.

        The snapshot that was cloned, and any snapshots previous to this
        snapshot, are now owned by the promoted clone. The space they use moves
        from the origin file system to the promoted clone, so enough space must
        be available to accommodate these snapshots. No new space is consumed
        by this operation, but the space accounting is adjusted. The promoted
        clone must not have any conflicting snapshot names of its own. The
        rename subcommand can be used to rename any conflicting snapshots.

    name : string
        name of clone-filesystem

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.promote myzpool/myclone

    rr
�promote�rrFr"r#Zpromoted)rr)rrrrrr\�s!��r\cCsVtd�s
tdg�Sg}|�|�|�|�tdtdd|d�dd�}td	|d
�S)an
    Creates a bookmark of the given snapshot

    .. note::

        Bookmarks mark the point in time when the snapshot was created,
        and can be used as the incremental source for a zfs send command.

        This feature must be enabled to be used. See zpool-features(5) for
        details on ZFS feature flags and the bookmarks feature.

    snapshot : string
        name of snapshot to bookmark
    bookmark : string
        name of bookmark

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.bookmark myzpool/mydataset@yesterday myzpool/mydataset#complete

    zzfs.has_feature_flags)�errorzbookmarks are not supportedrr
�bookmarkr]Fr"r#Z
bookmarked)rrr%r)�snapshotr_rrrrrr_"s



��r_cKs�dg}g}|�dd�r|�d�|�|�tdtdd||d�dd	�}td
|�}|ddkrQ|d
��D]}tttgd�|�d����}|d||d�	�<q6|S)aj
    Lists all existing user references for the given snapshot or snapshots.

    snapshot : string
        name of snapshot
    recursive : boolean
        lists the holds that are set on the named descendent snapshots also.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.holds myzpool/mydataset@baseline

    r5r*Fr+rr
�holdsr-r"r#rrr>)r�tag�	timestampr@rcrb)
rr%rrrGrrrHrB�strip)r`rr rrrI�holdZ	hold_datarrrraTs4

��	���racO�^g}g}|�dd�r|�d�|�|�|�|�tdtdd||d�dd�}td	|d
�S)a,
    Adds a single reference, named with the tag argument, to the specified
    snapshot or snapshots.

    .. note::

        Each snapshot has its own tag namespace, and tags must be unique within that space.

        If a hold exists on a snapshot, attempts to destroy that snapshot by
        using the zfs destroy command return EBUSY.

    tag : string
        name of tag
    snapshot : string
        name of snapshot(s)
    recursive : boolean
        specifies that a hold with the given tag is applied recursively to
        the snapshots of all descendent file systems.

    .. versionadded:: 2016.3.0
    .. versionchanged:: 2018.3.1

    .. warning::

        As of 2018.3.1 the tag parameter no longer accepts a comma-separated value.
        It's is now possible to create a tag that contains a comma, this was impossible before.

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.hold mytag myzpool/mydataset@mysnapshot [recursive=True]
        salt '*' zfs.hold mytag myzpool/mydataset@mysnapshot myzpool/mydataset@myothersnapshot
    r*Fr+rr
rer-r"r#Zheld�rr%�extendrr�rbr`rr rrrrrre�s&


��	recOrf)a
    Removes a single reference, named with the tag argument, from the
    specified snapshot or snapshots.

    .. note::

        The tag must already exist for each snapshot.
        If a hold exists on a snapshot, attempts to destroy that
        snapshot by using the zfs destroy command return EBUSY.

    tag : string
        name of tag
    snapshot : string
        name of snapshot(s)
    recursive : boolean
        recursively releases a hold with the given tag on the snapshots of
        all descendent file systems.

    .. versionadded:: 2016.3.0
    .. versionchanged:: 2018.3.1

    .. warning::

        As of 2018.3.1 the tag parameter no longer accepts a comma-separated value.
        It's is now possible to create a tag that contains a comma, this was impossible before.

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.release mytag myzpool/mydataset@mysnapshot [recursive=True]
        salt '*' zfs.release mytag myzpool/mydataset@mysnapshot myzpool/mydataset@myothersnapshot

    r*Fr+rr
�releaser-r"r#Zreleasedrgrirrrrj�s%


��	rjcOsXg}|�di�}|�dd�r|�d�tdtdd||t|�d�dd	�}td
|d�S)aP
    Creates snapshots with the given names.

    snapshot : string
        name of snapshot(s)
    recursive : boolean
        recursively create snapshots of all descendent datasets.
    properties : dict
        additional zfs properties (-o)

    .. note::

        ZFS properties can be specified at the time of creation of the filesystem by
        passing an additional argument called "properties" and specifying the properties
        with their respective values in the form of a python dictionary::

            properties="{'property1': 'value1', 'property2': 'value2'}"

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.snapshot myzpool/mydataset@yesterday [recursive=True]
        salt '*' zfs.snapshot myzpool/mydataset@yesterday myzpool/myotherdataset@yesterday [recursive=True]

    rr*Fr+rr
r`r[r"r#Zsnapshotted)rr%rrr)r`rr r!rrrrr`s
��
r`cOsVtjjjd	i|��}tdtddt|���t|���t|�d�dd�}td|d�S)
a!
    Sets the property or list of properties to the given value(s) for each dataset.

    dataset : string
        name of snapshot(s), filesystem(s), or volume(s)
    properties : string
        additional zfs properties pairs

    .. note::

        properties are passed as key-value pairs. e.g.

            compression=off

    .. note::

        Only some properties can be edited.

        See the Properties section for more information on what properties
        can be set and acceptable values.

        Numeric values can be specified as exact values, or in a human-readable
        form with a suffix of B, K, M, G, T, P, E (for bytes, kilobytes,
        megabytes, gigabytes, terabytes, petabytes, or exabytes respectively).

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.set myzpool/mydataset compression=off
        salt '*' zfs.set myzpool/mydataset myzpool/myotherdataset compression=off
        salt '*' zfs.set myzpool/mydataset myzpool/myotherdataset compression=lz4 canmount=off

    rr
�set)rrSZproperty_valuerFr"r#Nr)	�salt�utils�argsZclean_kwargsrrr�keys�values)�datasetrr!rrrrrk=s'

��
rkc
Os�dg}i}|�dd�r|�d�|d<n|�dd�r|�d�|�dd��d	�}d
|vr0|�d
�d|vr9|�d�|�dd
�|�d
d�d	�|�|d<tjj�	�s_|�dd�r_|�d�|d<|�dd�rl|�d�|d<|�dd�}t
dtdd|||t|�d�dd�}td|�}|ddkr�|d�
�D]R}ttt||�d����}	d|	vr�|�dd �r�td!|	d|	d�|	d<ntd"|	d|	dd d#�|	d<|	d
|vr�t�||	d
<|	||	d
|	d<|	d
=|	d=q�|S)$a
    Displays properties for the given datasets.

    dataset : string
        name of snapshot(s), filesystem(s), or volume(s)
    properties : string
        comma-separated list of properties to list, defaults to all
    recursive : boolean
        recursively list children
    depth : int
        recursively list children to depth
    fields : string
        comma-separated list of fields to include, the name and property field will always be added
    type : string
        comma-separated list of types to display, where type is one of
        filesystem, snapshot, volume, bookmark, or all.

        .. versionchanged:: 3004

        type is ignored on Solaris 10 and 11 since not a valid parameter on those platforms

    source : string
        comma-separated list of sources to display. Must be one of the following:
        local, default, inherited, temporary, and none. The default value is all sources.
    parsable : boolean
        display numbers in parsable (exact) values (default = True)
        .. versionadded:: 2018.3.0

    .. note::
        If no datasets are specified, then the command displays properties
        for all datasets on the system.

    .. versionadded:: 2016.3.0

    CLI Example:

    .. code-block:: bash

        salt '*' zfs.get
        salt '*' zfs.get myzpool/mydataset [recursive=True|False]
        salt '*' zfs.get myzpool/mydataset properties="sharenfs,mountpoint" [recursive=True|False]
        salt '*' zfs.get myzpool/mydataset myzpool/myotherdataset properties=available fields=value depth=1

    r5r6Fr7r*r+�fieldszvalue,sourcer4r�propertyrrUr<r
r�sourcerr�allrr
r)rr rrSrr"r#rr>r@�valuer?Tz
zfs.from_autozzfs.to_autor)rr%rBrCrDrFrlrm�platformZis_sunosrrrrGrrH)
rqrr rrrrSrrIrJrKrrrrtsf/


��
�
�r)N)$�__doc__�loggingZsalt.modules.cmdmodrlZsalt.utils.argsZsalt.utils.pathZsalt.utils.platformZsalt.utils.versionsZsalt.utils.odictrr�	getLogger�__name__r1Z__func_alias__r	rrr,r0rrNrLrQrRrTrYrZr\r_rarerjr`rkrrrrr�<module>sB
�
*E3
Ch
56
/EB=,28>=67