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

�N�gv5�@sZdZddlZddlZddlmZe�e�ZdZdd�Z	ddd�Z
	dd	d
�Zddd
�ZdS)a#
States for managing zpools

:maintainer:    Jorge Schrauwen <sjorge@blackdot.be>
:maturity:      new
:depends:       salt.utils.zfs, salt.modules.zpool
: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

    oldpool:
      zpool.absent:
        - export: true

    newpool:
      zpool.present:
        - config:
            import: false
            force: true
        - properties:
            comment: salty storage pool
        - layout:
            - mirror:
              - /dev/disk0
              - /dev/disk1
            - mirror:
              - /dev/disk2
              - /dev/disk3

    partitionpool:
      zpool.present:
        - config:
            import: false
            force: true
        - properties:
            comment: disk partition salty storage pool
            ashift: '12'
            feature@lz4_compress: enabled
        - filesystem_properties:
            compression: lz4
            atime: on
            relatime: on
        - layout:
            - /dev/disk/by-uuid/3e43ce94-77af-4f52-a91b-6cdbb0b0f41b

    simplepool:
      zpool.present:
        - config:
            import: false
            force: true
        - properties:
            comment: another salty storage pool
        - layout:
            - /dev/disk0
            - /dev/disk1

.. warning::

    The layout will never be updated, it will only be used at time of creation.
    It's a whole lot of work to figure out if a devices needs to be detached, removed,
    etc. This is best done by the sysadmin on a case per case basis.

    Filesystem properties are also not updated, this should be managed by the zfs state module.

�N)�OrderedDictZzpoolcCst�d�sdStS)z
    Provides zpool state
    Zzfs_support)Fz3The zpool state cannot be loaded: zfs not supported)�
__grains__�get�__virtualname__�rr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/zpool.py�__virtual__Ss
rcCsg}|rtj�|�sd}t|t�r:|D]$}t|t�r#|�t||��q|r2|ddkr2tj�||�}|�	|�q|St|t�r}|D]9}|�
d�d}||}|dkrW|�	|�t|t�sa|�
d�}|D]}|rt|ddkrttj�||�}|�	|�qcqA|Sd}|S)a�
    Turn the layout data into usable vdevs spedcification

    We need to support 2 ways of passing the layout:

    .. code::
        layout_new:
          - mirror:
            - disk0
            - disk1
          - mirror:
            - disk2
            - disk3

    .. code:
        layout_legacy:
          mirror-0:
            disk0
            disk1
          mirror-1:
            disk2
            disk3

    Nr�/�-�disk� )�os�path�exists�
isinstance�listr�extend�_layout_to_vdev�join�append�split)�layout�
device_dir�vdevsZvdevZ	vdev_typeZ	vdev_diskrrrrr\s6


�


�	�rcCs�|iddd�}ddddd�}tddkrd	|d
<n
tddkr#d|d
<|r*|�|�|}|r5td
|�}n|dur;i}|rDtd
|�}n|durJi}t||d
�}|rY|�d|�t�d||�t�d||�t�d||�t�d||�d|d<tdr�td|�r�d|d<d�	|d�|d<|Sd|d<|dr�dnd|d|<d�	||d|�|d<|Std|��rKd|d<td|dd�}g}	|r�|D]+}
|
|vr�t�
d ||
�q�|
�d!�r�||
d"kr�d#}n||
}|||
kr�|	�|
�q�|	D]B}
td$||
||
�}|d%�r||dv�ri|d|<||
|d||
<q�d|d<|ddk�r.d&|d<d'�	|d|
�|d<q�|d�rI|d�rEd(nd)|d<|S|d�rvtd*||d+|d,d-�}
|
d|d<|d�rvd|d|<d.|�d/�|d<|d�s�|�r�t�d0|�td1||d+||d2��}
|
d|d<|d�r�d|d|<d.|�d3�|d<nd4|
v�r�|
d4|d<nd5|��|d<|d�s�|�s�d6�	|�|d<|S)7aE	
    ensure storage pool is present on the system

    name : string
        name of storage pool
    properties : dict
        optional set of properties to set for the storage pool
    filesystem_properties : dict
        optional set of filesystem properties to set for the storage pool (creation only)
    layout: dict
        disk layout to use if the pool does not exist (creation only)
    config : dict
        fine grain control over this state

    .. note::

        The following configuration properties can be toggled in the config parameter.
          - import (true) - try to import the pool before creating it if absent
          - import_dirs (None) - specify additional locations to scan for devices on import (comma-separated)
          - device_dir (None, SunOS=/dev/dsk, Linux=/dev) - specify device directory to prepend for none
            absolute device paths
          - force (false) - try to force the import or creation

    .. note::

        It is no longer needed to give a unique name to each top-level vdev, the old
        layout format is still supported but no longer recommended.

        .. code-block:: yaml

            - mirror:
              - /tmp/vdisk3
              - /tmp/vdisk2
            - mirror:
              - /tmp/vdisk0
              - /tmp/vdisk1

        The above yaml will always result in the following zpool create:

        .. code-block:: bash

            zpool create mypool mirror /tmp/vdisk3 /tmp/vdisk2 mirror /tmp/vdisk0 /tmp/vdisk1

    .. warning::

        The legacy format is also still supported but not recommended,
        because ID's inside the layout dict must be unique they need to have a suffix.

        .. code-block:: yaml

            mirror-0:
              /tmp/vdisk3
              /tmp/vdisk2
            mirror-1:
              /tmp/vdisk0
              /tmp/vdisk1

    .. warning::

        Pay attention to the order of your dict!

        .. code-block:: yaml

            - mirror:
              - /tmp/vdisk0
              - /tmp/vdisk1
            - /tmp/vdisk2

        The above will result in the following zpool create:

        .. code-block:: bash

            zpool create mypool mirror /tmp/vdisk0 /tmp/vdisk1 /tmp/vdisk2

        Creating a 3-way mirror! While you probably expect it to be mirror
        root vdev with 2 devices + a root vdev of 1 device!

    N���name�changes�result�commentTF)�import�import_dirsr�forceZkernel�SunOSz/dev/dskr�Linuxz/devzzfs.from_auto_dictrzzpool.present::%s::config - %szzpool.present::%s::vdevs - %sz#zpool.present::%s::properties -  %sz.zpool.present::%s::filesystem_properties -  %sr�test�zpool.existszstorage pool {} is {}Zuptodaterr Zimported�createdrz"storage pool {} would have been {}z	zpool.get)Zparsablez0zpool.present::%s::update - unknown property: %szfeature@Zactive�enabledz	zpool.set�setz*The following properties were not updated:z{} {}zproperties updatedzno update neededzzpool.importr"r!)r"�dir�
storage pool z
 was importedzzpool.present::%s::creatingzzpool.create)r"�
properties�filesystem_propertiesz was created�errorzcould not create storage pool zJstorage pool {} was not imported, no (valid) layout specified for creation)
r�updateZ	__utils__r�insert�log�debug�__opts__�__salt__�format�warning�
startswithr)rr,r-rZconfig�retZdefault_configrZproperties_currentZproperties_updateZpropZeffective_property�res�mod_resrrr�present�s�Q�

�c��_��
�

�/
��
�

�r;FcCs�|iddd�}t�d||�t�d||�td|�rqi}d|d<td	r*d
|d<n|r;td||d�}|d
|d<ntd||d�}|d|d<|dre|rQd
nd|d|<d�||d|�|d<|Sd|vro|d|d<|Sd
|d<d|�d�|d<|S)z�
    ensure storage pool is absent on the system

    name : string
        name of storage pool
    export : boolean
        export instead of destroy the zpool if present
    force : boolean
        force destroy or export

    Nrrz$zpool.absent::%s::config::force = %sz%zpool.absent::%s::config::export = %sr&Frr%Tzzpool.export)r"Zexportedz
zpool.destroyZ	destroyedrzstorage pool {} was {}rr.r+z
 is absent)r1r2r4r3r5)rZexportr"r8r:rrr�absent�s.
��r<)N)NNNN)FF)
�__doc__�loggingr
Zsalt.utils.odictr�	getLogger�__name__r1rrrr;r<rrrr�<module>sG

	J
�i