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

�N�g�6�@s�dZddlZddlmZddlmZzddlmZmZmZm	Z	m
Z
mZmZdZ
Wney3dZ
YnwdZd	Zd
d�Zdd
�Zdd�Zdd�Zdd�Zd&dd�Zd'dd�Zd&dd�Z	d(dd�Zd)dd�Zd d!�Zd"d#�Zd)d$d%�ZdS)*a&

Management of Pure Storage FlashBlade

Installation Prerequisites
--------------------------
- You will need the ``purity_fb`` python package in your python installation
  path that is running salt.

  .. code-block:: bash

      pip install purity_fb

- Configure Pure Storage FlashBlade authentication. Use one of the following
  three methods.

  1) From the minion config

  .. code-block:: yaml

        pure_tags:
          fb:
            san_ip: management vip or hostname for the FlashBlade
            api_token: A valid api token for the FlashBlade being managed

  2) From environment (PUREFB_IP and PUREFB_API)
  3) From the pillar (PUREFB_IP and PUREFB_API)

:maintainer: Simon Dodsley (simon@purestorage.com)
:maturity: new
:requires: purity_fb
:platform: all

.. versionadded:: 2019.2.0

�N)�datetime)�CommandExecutionError)�
FileSystem�FileSystemSnapshot�NfsRule�ProtocolRule�PurityFb�SnapshotSuffix�restTFzrestructuredtext enZpurefbcCstrtSdS)z6
    Determine whether or not to load this module
    )FzKpurefb execution module not loaded: purity_fb python library not available.)�
HAS_PURITY_FB�__virtualname__�r
r
�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/purefb.py�__virtual__NsrcCsz tdd�d�}tdd�d�}|rtrt|�}|��WnOtttfyoztj	�d�}tj	�d�}|rAt|�}|��Wn*t
ttfylztd}ttd�}|��Wn
ttfyitd��wYnwYnwz|�
|�W|Sty�td��w)	ad
    Get Pure Storage FlasBlade configuration

    1) From the minion config
        pure_tags:
          fb:
            san_ip: management vip or hostname for the FlashBlade
            api_token: A valid api token for the FlashBlade being managed
    2) From environment (PUREFB_IP and PUREFB_API)
    3) From the pillar (PUREFB_IP and PUREFB_API)

    Z	pure_tagsZfbZsan_ip�	api_tokenZ	PUREFB_IPZ
PUREFB_APIz-No Pure Storage FlashBlade credentials found.z.Pure Storage FlashBlade authentication failed.)Z__opts__�getZapirZdisable_verify_ssl�KeyError�	NameError�	TypeError�os�environ�
ValueErrorZ
__pillar__rZlogin�	Exception)Z
blade_namer�blader
r
r�
_get_bladeZsF����������rcCs@g}|�|�z
|jj|d�}|jdWStjyYdSw)zE
    Private function to
    check for existence of a filesystem
    )�namesrN)�append�file_systemsZlist_file_systems�itemsr
�ApiException)�namer�_fs�resr
r
r�_get_fs�s
�r#cCsDzd|�d|�d�}|jj|d�}|jdWStjy!YdSw)z-
    Return name of Snapshot
    or None
    zsource='z' and suffix='�')�filterrN)�file_system_snapshotsZlist_file_system_snapshotsrr
r)r �suffixrZfiltr"r
r
r�
_get_snapshot�s�r(cCs>zt||�}|r|jr|WSWdSWdStjyYdSw)zR
    Private function to check
    if a file systeem has already been deleted
    N)r#�	destroyedr
r)r rr!r
r
r�_get_deleted_fs�s

��r*cCs�t�}|dur!dtt��tddddddd����}|�dd�}t||�durHzg}|�|�|jj	|t
|�d�Wd	StjyGYd
Swd
S)a�

    Create a filesystem snapshot on a Pure Storage FlashBlade.

    Will return False if filesystem selected to snap does not exist.

    .. versionadded:: 2019.2.0

    name : string
        name of filesystem to snapshot
    suffix : string
        if specificed forces snapshot name suffix. If not specified defaults to timestamp.

    CLI Example:

    .. code-block:: bash

        salt '*' purefb.snap_create foo
        salt '*' purefb.snap_create foo suffix=bar

    Nzsnap-i��r�.�)Zsourcesr'TF)
r�strr�utcnow�
total_seconds�replacer#rr&Zcreate_file_system_snapshotsr	r
r)r r'r�sourcer
r
r�snap_create�s$�
��r3cCs�t�}t|||�durHz|d|}tdd�}|jj||d�Wntjy+YdSw|durFz
|jj|d�WdStjyEYdSwdSdS)a�

    Delete a filesystem snapshot on a Pure Storage FlashBlade.

    Will return False if selected snapshot does not exist.

    .. versionadded:: 2019.2.0

    name : string
        name of filesystem
    suffix : string
        name of snapshot
    eradicate : boolean
        Eradicate snapshot after deletion if True. Default is False

    CLI Example:

    .. code-block:: bash

        salt '*' purefb.snap_delete foo suffix=snap eradicate=True

    Nr,T)r)�r Z
attributesF�r )rr(rr&Zupdate_file_system_snapshotsr
r�delete_file_system_snapshots)r r'�	eradicater�snapnameZnew_attrr
r
r�snap_delete�s(

���r9cCsRt�}t|||�dur'|d|}z
|jj|d�WdStjy&YdSwdS)an

    Eradicate a deleted filesystem snapshot on a Pure Storage FlashBlade.

    Will return False if snapshot is not in a deleted state.

    .. versionadded:: 2019.2.0

    name : string
        name of filesystem
    suffix : string
        name of snapshot

    CLI Example:

    .. code-block:: bash

        salt '*' purefb.snap_eradicate foo suffix=snap

    Nr,r5TF)rr(r&r6r
r)r r'rr8r
r
r�snap_eradicates�r:�NFS�*(rw,no_root_squash)c	Cs�t|�dkr|dd�}t�}t|�t||�dur||dur%tdd�}ntd|�}|��dkr?t||d|td|d�d	�}n(|��d
krRt||d|tdd�d�}n|��d
kret||d|tdd�d�}ndSz	|j	�
|�WdStjy{YdSwdS)a�

    Create a filesystem on a Pure Storage FlashBlade.

    Will return False if filesystem already exists.

    .. versionadded:: 2019.2.0

    name : string
        name of filesystem (truncated to 63 characters)
    proto : string
        (Optional) Sharing protocol (NFS, CIFS or HTTP). If not specified default is NFS
    snapshot: boolean
        (Optional) Are snapshots enabled on the filesystem. Default is False
    nfs_rules : string
        (Optional) export rules for NFS. If not specified default is
        ``*(rw,no_root_squash)``. Refer to Pure Storage documentation for
        formatting rules.
    size : string
        if specified capacity of filesystem. If not specified default to 32G.
        Refer to Pure Storage documentation for formatting rules.

    CLI Example:

    .. code-block:: bash

        salt '*' purefb.fs_create foo proto=CIFS
        salt '*' purefb.fs_create foo size=10T

    �?rN�stringutils.human_to_bytesZ32G�nfsT)�enabled�rules)r �provisioned�fast_remove_directory_enabled�snapshot_directory_enabledr?Zcifs�r@)r rBrCrD�smb�http)r rBrCrDrGF)
�lenr�printr#�	__utils__�lowerrrrrZcreate_file_systemsr
r)r �size�protoZ	nfs_rules�snapshotrZfs_objr
r
r�	fs_create%sP!
����rOcCs�t�}t||�durJz|jj|ttdd�tdd�tdd�dd�d�Wntjy.YdSw|durHz	|j�	|�WdStjyGYdSwdSdS)a�

    Delete a share on a Pure Storage FlashBlade.

    Will return False if filesystem doesn't exist or is already in a deleted state.

    .. versionadded:: 2019.2.0

    name : string
        name of filesystem
    eradicate : boolean
        (Optional) Eradicate filesystem after deletion if True. Default is False

    CLI Example:

    .. code-block:: bash

        salt '*' purefb.fs_delete foo eradicate=True

    NFrET)r?rFrGr)r4)
rr#r�update_file_systemsrrrr
r�delete_file_systems)r r7rr
r
r�	fs_deleters0�
�	��rRcCsBt�}t||�durz	|j�|�WdStjyYdSwdS)a,

    Eradicate a deleted filesystem on a Pure Storage FlashBlade.

    Will return False is filesystem is not in a deleted state.

    .. versionadded:: 2019.2.0

    name : string
        name of filesystem

    CLI Example:

    .. code-block:: bash

        salt '*' purefb.fs_eradicate foo

    NTF)rr*rrQr
r)r rr
r
r�fs_eradicate�s�rScCs�i}t�}t||�}|dur?td|�|jkr=ztd|�|d<tdi|��}|jj||d�WdStjy<YdSwdSdS)a�

    Resize an existing filesystem on a Pure Storage FlashBlade.

    Will return False if new size is less than or equal to existing size.

    .. versionadded:: 2019.2.0

    name : string
        name of filesystem
    size : string
        New capacity of filesystem.
        Refer to Pure Storage documentation for formatting rules.

    CLI Example:

    .. code-block:: bash

        salt '*' purefb.fs_extend foo 10T

    Nr>rBr4TFr
)	rr#rJrBrrrPr
r)r rL�attrrr!�n_attrr
r
r�	fs_extend�s
�rVcCszt�}i}t||�}|dur;z!|jjrt|d�|d<||d<tdi|��}|jj||d�WdStj	y:YdSwdS)	a_

    Update filesystem on a Pure Storage FlashBlade.

    Allows for change of NFS export rules and enabling/disabled
    of snapshotting capability.

    .. versionadded:: 2019.2.0

    name : string
        name of filesystem
    rules : string
        NFS export rules for filesystem
        Refer to Pure Storage documentation for formatting rules.
    snapshot: boolean
        (Optional) Enable/Disable snapshots on the filesystem. Default is False

    CLI Example:

    .. code-block:: bash

        salt '*' purefb.fs_nfs_update foo rules='10.234.112.23(ro), 10.234.112.24(rw)' snapshot=True

    N)rAr?rDr4TFr
)
rr#r?r@rrrrPr
r)r rArNrrTr!rUr
r
r�	fs_update�s
�rW)N)NF)Nr;r<F)F)�__doc__rrZsalt.exceptionsrZ	purity_fbrrrrrr	r
r�ImportErrorZ
__docformat__rrrr#r(r*r3r9r:rOrRrSrVrWr
r
r
r�<module>s4&$
�+

*
-"
�
M/(