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

�N�gĈ�@sdZddlZddlmZddlmZe�e�ZdZddiZ	ddd�Z
dddd	�Zddddd
�Zdd�Z
d/dd�Zd/dd�Zd/dd�Zd/dd�Zd/dd�Zd0dd�Zd0dd�Z		
	
	d1dd�Zd2dd�Z	
	
		d3d d!�Zd"d#�Zd4d$d%�Zd&d'�Zd(d)�Zd*d+�Zd5d-d.�ZdS)6a�
States for managing zfs datasets

:maintainer:    Jorge Schrauwen <sjorge@blackdot.be>
:maturity:      new
:depends:       salt.utils.zfs, salt.modules.zfs
:platform:      smartos, illumos, solaris, freebsd, linux

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

.. code-block:: yaml

    test/shares/yuki:
      zfs.filesystem_present:
        - create_parent: true
        - properties:
            quota: 16G

    test/iscsi/haruhi:
      zfs.volume_present:
        - create_parent: true
        - volume_size: 16M
        - sparse: true
        - properties:
            readonly: on

    test/shares/yuki@frozen:
      zfs.snapshot_present

    moka_origin:
      zfs.hold_present:
        - snapshot: test/shares/yuki@frozen

    test/shares/moka:
      zfs.filesystem_present:
        - cloned_from: test/shares/yuki@frozen

    test/shares/moka@tsukune:
      zfs.snapshot_absent

�N)�datetime)�OrderedDictZzfs�minute)r�hour�)rr�day)rrr�monthcCst�d�sdStS)z
    Provides zfs state
    Zzfs_support)Fz1The zfs state cannot be loaded: zfs not supported)Z
__grains__�get�__virtualname__�rr�C/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/zfs.py�__virtual__?s
r
FcCs�|iddd�}|��}t�d|||�t�d|||�td|fid|i��rltds9td	|fi||d
���}ntdg�}|d|d
<|d
rXd|d|<d�||�|d<|Sd�||�|d<d|vrj|d|d<|S|�d|�d�|d<|S)aE
    internal shared function for *_absent

    name : string
        name of dataset
    dataset_type : string [filesystem, volume, snapshot, or bookmark]
        type of dataset to remove
    force : boolean
        try harder to destroy the dataset
    recursive : boolean
        also destroy all the child datasets

    T���name�changes�result�commentz%zfs.%s_absent::%s::config::force = %sz)zfs.%s_absent::%s::config::recursive = %s�
zfs.exists�type�test�zfs.destroy)�force�	recursive��	destroyedTrrrz{} {} was destroyedrzfailed to destroy {} {}�error� z
 is absent)�lower�log�debug�__salt__�__opts__r�format)r�dataset_typerr�ret�mod_resrrr�_absentHs>���
����r'cC�6td|�s|idd|��d�}|St|d||�}|S)a�
    ensure filesystem is absent on the system

    name : string
        name of filesystem
    force : boolean
        try harder to destroy the dataset (zfs destroy -f)
    recursive : boolean
        also destroy all the child datasets (zfs destroy -r)

    .. warning::

        If a volume with ``name`` exists, this state will succeed without
        destroying the volume specified by ``name``. This module is dataset type sensitive.

    �zfs.is_datasetF�invalid dataset name: r�
filesystem��	__utils__r'�rrrr%rrr�filesystem_absent~���r/cCr()a�
    ensure volume is absent on the system

    name : string
        name of volume
    force : boolean
        try harder to destroy the dataset (zfs destroy -f)
    recursive : boolean
        also destroy all the child datasets (zfs destroy -r)

    .. warning::

        If a filesystem with ``name`` exists, this state will succeed without
        destroying the filesystem specified by ``name``. This module is dataset type sensitive.

    r)Fr*r�volumer,r.rrr�
volume_absent�r0r2cCr()a
    ensure snapshot is absent on the system

    name : string
        name of snapshot
    force : boolean
        try harder to destroy the dataset (zfs destroy -f)
    recursive : boolean
        also destroy all the child datasets (zfs destroy -r)

    �zfs.is_snapshotF�invalid snapshot name: r�snapshotr,r.rrr�snapshot_absent����r6cCr()a
    ensure bookmark is absent on the system

    name : string
        name of snapshot
    force : boolean
        try harder to destroy the dataset (zfs destroy -f)
    recursive : boolean
        also destroy all the child datasets (zfs destroy -r)

    �zfs.is_bookmarkF�invalid bookmark name: r�bookmarkr,r.rrr�bookmark_absent�r7r;cCsZ|iddd�}t�d||�t�d||�td|�s(d|d<d	|��|d
<|Std|�s8td|�s8|dkrEd|d<d
|��|d
<|Std|�}||vr�tdsatd||fid|i��}ntdg�}|d|d<|dr�||dii|d<d�|�|d
<|Sd�|�|d
<d|vr�|d|d
<|Sd|vr�d|d<|d|d
<|Sd�|�|d
<|S)a
    ensure hold is absent on the system

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

    Trrz*zfs.hold_absent::%s::config::snapshot = %sz+zfs.hold_absent::%s::config::recursive = %sr3Frr4rr8r�invalid tag name: �	zfs.holdsr�zfs.releaser��releasedTr@rzhold {} releasedzfailed to release hold {}zhold {} is absent)rr r-r!r"rr#�rr5rr%Zholdsr&rrr�hold_absent�sZ
�
���
������rBcCsT|iddd�}t�d||�t�d||�td|�s(d|d<d	|��|d
<|Std|�s8td|�s8|dkrEd|d<d
|��|d
<|Std|�}||vrYd�||�|d
<|Stdsktd||fid|i��}ntdg�}|d|d<|dr�t|t|dfg�fg�|d<d|�d|��|d
<|Sd|�d|��|d
<d|vr�|d|d
<|S)a
    ensure hold is present on the system

    name : string
        name of holdt
    snapshot : string
        name of snapshot
    recursive : boolean
        recursively add hold with the given tag on the snapshots of all descendent file systems.

    Trrz+zfs.hold_present::%s::config::snapshot = %sz,zfs.hold_present::%s::config::recursive = %sr3Frr4rr8rr<r=zhold {} is present for {}r�zfs.holdr��heldTrErzhold z
 added to zfailed to add hold z to )rr r-r!r#r"rrArrr�hold_present-sD
�
���
�rFcCs�|iddd�}|dvr
d}|duri}td|�}|r(td|�}|�d	|i�d
�t|����}t�d|||�t�d|||�t�d
|||�t�d|||�t�d|||�td|�sld|d<d|��|d<|S|r�td|�s�d|d<|�d�|d<|Std|fid|i��}	|	r�t|�dkr�|�d|�d�|d<|S|	�rgt|�dk�rgtd|||dddd��	|t
��}
g}|D]}||
vr�t�d|||�q�|
|d||kr�|�|�q�|D]P}t
d s�td!|fi|||i��}
nt
d"g�}
|
d#�r||d$v�r
i|d$|<|||d$||<q�d|d<|ddk�r'd%|d<d&�|d|�|d<q�|d�rJ||d$v�rJ|�d|�d'�|d<|S|d�r[|�d|�d�|d<|S|�d|�d(�|d<|S|	�s�|�rod)nd*}t
d �r~t
|dfg�}
n(|�r�|�r�||d	<td+||fi||d,���}
ntd-|fi||||d.���}
|
||d<|d�r�||d$|<|�r�||d$|<d/�|||�|d<|Sd0�|dd1�||�|d<d2|
v�r�|
d2|d<|S)3aT
    internal handler for filesystem_present/volume_present

    dataset_type : string
        volume or filesystem
    name : string
        name of volume
    volume_size : string
        size of volume
    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.
    cloned_from : string
        name of snapshot to clone
    properties : dict
        additional zfs properties (-o)

    .. note::
        ``cloned_from`` is only use if the volume does not exist yet,
        when ``cloned_from`` is set after the volume exists it will be ignored.

    .. note::
        Properties do not get cloned, if you specify the properties in the state file
        they will be applied on a subsequent run.

        ``volume_size`` is considered a property, so the volume's size will be
        corrected when the properties get updated if it differs from the
        original volume.

        The sparse parameter is ignored when using ``cloned_from``.

    Trr)r+r1r+N�zfs.from_auto_dictz
zfs.from_sizeZvolsize�,z,zfs.%s_present::%s::config::volume_size = %sz'zfs.%s_present::%s::config::sparse = %sz.zfs.%s_present::%s::config::create_parent = %sz,zfs.%s_present::%s::config::cloned_from = %sz+zfs.%s_present::%s::config::properties = %sr)Frr*rr3z is not a snapshotrrrrz is uptodate�zfs.get�value)�
propertiesr�fields�depth�parsablez1zfs.%s_present::%s::update - unknown property: %srzzfs.set)�setTrOrz*The following properties were not updated:z{} {}z was updatedz failed to be updatedZcloned�createdz	zfs.clone)�
create_parentrKz
zfs.create)rQrK�volume_size�sparsez{} {} was {}zfailed to {} {} {}���r)r-�update�join�sorted�keysrr r!�lenr	r�warning�appendr"r#)r$rrKrRrSrQ�cloned_fromr%Z	propnames�existsZproperties_currentZproperties_updateZpropr&Zmod_res_actionrrr�_dataset_presentis�+����f��
�
�
�

6
�4�2�
�����

��
�
r^cCstd||||d�S)a�
    ensure filesystem exists and has properties set

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

    .. note::
        ``cloned_from`` is only use if the filesystem does not exist yet,
        when ``cloned_from`` is set after the filesystem exists it will be ignored.

    .. note::
        Properties do not get cloned, if you specify the properties in the
        state file they will be applied on a subsequent run.

    r+)rQr\�r^)rrQrKr\rrr�filesystem_present0s�r`c	Cstd||||||d�S)a
    ensure volume exists and has properties set

    name : string
        name of volume
    volume_size : string
        size of volume
    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.
    cloned_from : string
        name of snapshot to clone
    properties : dict
        additional zfs properties (-o)

    .. note::
        ``cloned_from`` is only use if the volume does not exist yet,
        when ``cloned_from`` is set after the volume exists it will be ignored.

    .. note::
        Properties do not get cloned, if you specify the properties in the state file
        they will be applied on a subsequent run.

        ``volume_size`` is considered a property, so the volume's size will be
        corrected when the properties get updated if it differs from the
        original volume.

        The sparse parameter is ignored when using ``cloned_from``.

    r1)rSrQr\r_)rrRrSrQrKr\rrr�volume_presentPs(�racCs<|iddd�}t�d||�td|�s!d|d<d|��|d	<|Sd
|vr:d|vr:d�|d
|�d��|�}||d<td|�sMd|d<d|��|d	<|Std|fiddi��s�tdsetd||�}ntdg�}|d|d<|dr�||d|<|�d|��|d	<|Sd|��|d	<d|vr�|d|d	<|Sd|d	<|S)z|
    ensure bookmark exists

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

    Trrz/zfs.bookmark_present::%s::config::snapshot = %sr3Frr4r�#�/z{}#{}N�@rr8r9rrr:rzzfs.bookmark)�
bookmarkedTrerz bookmarked as zfailed to bookmark rzbookmark is present)rr r-r#�indexr!r"r)rr5r%r&rrr�bookmark_present�s8

	��rgcCs|iddd�}t�d||�t�d||�|rtd|�}td|�s0d|d	<d
|��|d<|Std|fid
di��s�tdsNtd|fi||d���}ntdg�}|d|d	<|d	rud|d|<|rk||d|<d|�d�|d<|Sd|��|d<d|vr�|d|d<|Sd|d<|S)a8
    ensure snapshot exists and has properties set

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

    .. note:
        Properties are only set at creation time

    Trrz0zfs.snapshot_present::%s::config::recursive = %sz1zfs.snapshot_present::%s::config::properties = %srGr3Frr4rrrr5r�zfs.snapshot)rrK��snapshottedTrjrz	snapshot z was createdzfailed to create snapshot rzsnapshot is present)rr r-r!r"r)rrrKr%r&rrr�snapshot_present�s<��
	��rkcCs|iddd�}td|�sd|d<d|��|d<|Std	|fid
di��s4d|d<d|�d
�|d<|Std|fidddd���|dddkrS|�d�|d<|Stds^td|�}ntdg�}|d|d<|dr|d|d|<|�d�|d<|Sd|��|d<d|vr�|d|d<|S)z�
    ensure a dataset is not a clone

    name : string
        name of fileset or volume

    .. warning::

        only one dataset can be the origin,
        if you promote a clone the original will now point to the promoted dataset

    Trrr)Frr*rrr�filesystem,volume�dataset � does not existrI�originrJ)rKrLrN�-z already promotedrzzfs.promote)�promotedTrqrz	 promotedzfailed to promote r)r-r!r"r)rr%r&rrrrq�sH
��
������
�rqcCs�ttd|fidddd������D]9}||�d�dd�}|�|�d��s(qtd	|�}|s7|d
�|�|D]}||d��vrJ||�|�q9q|S)aA
    Update snapshots dict with current snapshots

    dataset: string
        name of filesystem or volume
    prefix : string
        prefix for the snapshots
        e.g. 'test' will result in snapshots being named 'test-yyyymmdd_hhmm'
    snapshots : OrderedDict
        preseeded OrderedDict with configuration

    zzfs.listTrr5)rrMrrdNrpr=�	_prunable�	_schedule)rWr!rXrf�
startswithr[)�dataset�prefix�	snapshotsZsnapZ	snap_nameZ
snap_holds�holdrrr�_schedule_snapshot_retrieve,s(�
����rycCsZdj||t���d�d�}t��jddd�}g|d|<|d��D]�\}}|dkr+q"||r�t�||d|�d	|�d
��jddd�}|dkrM||krMq"|dkrb|jdit��|jdit��krbq"|d
krw|jdit��|jdit��krwq"|dkr�|jdit	��|jdit	��kr�q"|dkr�|jdit
��|jdit
��kr�q"|d|�|�q"|S)aG
    Update snapshots dict with info for a new snapshot

    dataset: string
        name of filesystem or volume
    prefix : string
        prefix for the snapshots
        e.g. 'test' will result in snapshots being named 'test-yyyymmdd_hhmm'
    snapshots : OrderedDict
        preseeded OrderedDict with configuration

    z{dataset}@{prefix}-{timestamp}z
%Y%m%d_%H%M%S)rurv�	timestampr)�second�microsecond�_creatersrTrdz-%Y%m%d_%H%M%Srrrr�yearNr)r#r�now�strftime�replace�items�strptime�	comp_hour�comp_day�
comp_month�	comp_yearr[)rurvrwZsnapshot_create_nameZ
timestamp_nowrx�
hold_countrzrrr�_schedule_snapshot_prepareXsZ�
����������r�Tc
Cs"|iddd�}gd�}tdt�fdgfdt�fg�}td|�s+d	|d
<d|��|d<td
|fiddi��sCd|�d�|d<d	|d
<|rKt|�dkrWd|�d�|d<d	|d
<d}|D]6}g||<||vrld|d|<nt||t�r||||d|<n
d	|d
<d�|�|d<n	||d|7}q[|d
r�|dkr�d	|d
<d|d<|d
s�|St|||�}t|||�}t	�
d||�t	�
d||�t	�
d||�|d��D]�\}	}
|
s�q�tds�td|	fid|i��}ntdg�}|ds�d	|d
<d |	�d!�|d<n7|
D]4}td�std"||	fid|i��}ntd#g�}|d$�s,d	|d
<d%�||	�|d<n||�
|	�q�|d
�rSd&|d<d'|d(v�rJg|d(d'<|d(d'�
|	�q�|d��D]_\}}|d
�r�t||�|k�r�||�d�}	td�s�td)||	fid|i��}ntd*g�}|d+�s�d	|d
<d%�||	�|d<td,|	��s�|d�
|	�|d
�r�t||�|k�sl�qZ|dD],}	td�s�td-|	fid|i��}ntd.g�}|d/�s�d	|d
<d0�|	�|d<n�q�|d
�r|d�rd&|d<|d|d(d1<|d
�r|d(�sd2|d<|S)3a�
    maintain a set of snapshots based on a schedule

    name : string
        name of filesystem or volume
    prefix : string
        prefix for the snapshots
        e.g. 'test' will result in snapshots being named 'test-yyyymmdd_hhmm'
    recursive : boolean
        create snapshots for all children also
    schedule : dict
        dict holding the schedule, the following keys are available (minute, hour,
        day, month, and year) by default all are set to 0 the value indicated the
        number of snapshots of that type to keep around.

    .. warning::

        snapshots will only be created and pruned every time the state runs.
        a schedule must be setup to automatically run the state. this means that if
        you run the state daily the hourly snapshot will only be made once per day!

    .. versionchanged:: 2018.3.0

        switched to localtime from gmtime so times now take into account timezones.

    Trr)rrrrr~r}rrrsr)Frr*rrrrlrmrn�zprefix (z) must be at least 4 longrz'schedule value for {} is not an integerz:schedule is not valid, you need to keep atleast 1 snapshotz2zfs.scheduled_snapshot::%s::config::recursive = %sz/zfs.scheduled_snapshot::%s::config::prefix = %sz*zfs.scheduled_snapshot::%s::snapshots = %srrhrrirjzerror creating snapshot (�)rCrDrEz'error adding hold ({}) to snapshot ({})zscheduled snapshots updatedrPrr>r?r@r=rrrzerror prunding snapshot ({1})Zprunedz"scheduled snapshots are up to date)rr-r!rY�
isinstance�intr#ryr�rr r�r"r[�pop)
rrvrZscheduler%Zschedule_holdsrwZtotal_countrxZ
snapshot_nameZsnapshot_holdsr&r�rrr�scheduled_snapshot�s�����

��

�
�
��

���


��r�)FF)F)NFFN)FNN)FFNN)FN)TN)�__doc__�loggingrZsalt.utils.odictr�	getLogger�__name__rr
r�r�r�r�r
r'r/r2r6r;rBrFr^r`rargrkrqryr�r�rrrr�<module>sH-


	
6




E@
�
H#
�3
8:7,>