
    Vh'                     n    d dl mZmZmZ eZdZdZd dlZd dl	m
Z
  G d de      Zd Zed	k(  r e        yy)
    )absolute_importdivisionprint_functionaD  
module: zfs
short_description: Manage ZFS
description:
  - Manages ZFS file systems, volumes, clones and snapshots.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: partial
    details:
      - In certain situations it may report a task as changed that is not reported as changed when C(check_mode) is disabled.
      - For example, this might occur when the zpool C(altroot) option is set or when a size is written using human-readable
        notation, such as V(1M) or V(1024K), instead of as an unqualified byte count, such as V(1048576).
  diff_mode:
    support: full
options:
  name:
    description:
      - File system, snapshot or volume name, for example V(rpool/myfs).
    required: true
    type: str
  state:
    description:
      - Whether to create (V(present)), or remove (V(absent)) a file system, snapshot or volume. All parents/children are
        created/destroyed as needed to reach the desired state.
    choices: [absent, present]
    required: true
    type: str
  origin:
    description:
      - Snapshot from which to create a clone.
    type: str
  extra_zfs_properties:
    description:
      - A dictionary of zfs properties to be set.
      - See the zfs(8) man page for more information.
    type: dict
    default: {}
author:
  - Johan Wiren (@johanwiren)
a  
- name: Create a new file system called myfs in pool rpool with the setuid property turned off
  community.general.zfs:
    name: rpool/myfs
    state: present
    extra_zfs_properties:
      setuid: 'off'

- name: Create a new volume called myvol in pool rpool.
  community.general.zfs:
    name: rpool/myvol
    state: present
    extra_zfs_properties:
      volsize: 10M

- name: Create a snapshot of rpool/myfs file system.
  community.general.zfs:
    name: rpool/myfs@mysnapshot
    state: present

- name: Create a new file system called myfs2 with snapdir enabled
  community.general.zfs:
    name: rpool/myfs2
    state: present
    extra_zfs_properties:
      snapdir: enabled

- name: Create a new file system by cloning a snapshot
  community.general.zfs:
    name: rpool/cloned_fs
    state: present
    origin: rpool/myfs@mysnapshot

- name: Destroy a filesystem
  community.general.zfs:
    name: rpool/myfs
    state: absent
N)AnsibleModulec                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)Zfsc                    || _         || _        || _        d| _        |j	                  dd      | _        |j	                  dd      | _        |j                  d      d   j                  d      d   | _        t        j                         d   dk(  | _        | j                         | _        | j                         | _        y )	NFzfsTzpool/r   @SunOS)modulenameextra_zfs_propertieschangedget_bin_pathzfs_cmd	zpool_cmdsplitpoolosuname
is_solarischeck_openzfs
is_openzfscheck_enhanced_sharingenhanced_sharing)selfr   r   r   s       i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/zfs.py__init__zZfs.__init__e   s    	$8!**5$7,,Wd;JJsOA&,,S1!4	((*Q-72,,. $ ; ; =    c                 .   | j                   g}|j                  ddg       |j                  | j                         | j                  j                  |d      \  }}}|j                         d   j                         d   }|dk(  ryt        |      dk(  ryy	)
NgetversionTcheck_rc   -i  F)	r   extendappendr   r   run_command
splitlinesr   intr   cmdrcouterrr%   s         r    r   zZfs.check_openzfsq   s    ~~

E9%&

49900t0DS#.."2&,,.q1c>w<4r"   c                 R   | j                   r| j                  s| j                  g}|j                  ddg       |j	                  | j
                         | j                  j                  |d      \  }}}|j                         d   j                         d   }t        |      dk\  ryy)	Nr$   r%   Tr&   r(   r)   "   F)r   r   r   r+   r,   r   r   r-   r.   r   r/   r0   s         r    r   zZfs.check_enhanced_sharing}   s    ??4??>>"CJJy)*JJtyy!![[44S44HNRcnn&r*00215G7|r!r"   c                     | j                   ddd| j                  g}| j                  j                  |      \  }}}|dk(  S )Nlistz-tallr   )r   r   r   r-   )r   r1   r2   dummys       r    existsz
Zfs.exists   s>    ||VT5$))<;;2237E5Qwr"   c                 P   | j                   j                  rd| _        y | j                  }| j                   j                  j                  d      }| j                  g}d| j                  v rd}n|rd}nd}|j                  |       |dv r|dgz  }|r>|j                         D ]+  \  }}|d	k(  r|d
|gz  }|dk(  r|d|gz  } |d|d|gz  }- |r|dk(  r|j                  |       |j                  | j                         | j                   j                  |d       d| _        y )NToriginr   snapshotclonecreate)r@   r?   -pvolsizez-Vvolblocksizez-b-o=r&   )r   
check_moder   r   paramsr$   r   r   r,   itemsr-   )r   r   r=   r1   actionpropvalues          r    r@   z
Zfs.create   s-   ;;!!DL#88##''1||n$))FFF

6((D6MC399; ;e9$D%=(C^+D%=(CDT5"9::C; f'JJv

499d3r"   c                     | j                   j                  rd| _        y | j                  dd| j                  g}| j                   j                  |d       d| _        y )NTdestroyz-Rr&   )r   rF   r   r   r   r-   )r   r1   s     r    rM   zZfs.destroy   sM    ;;!!DL||Ydii8d3r"   c                     | j                   j                  rd| _        y | j                  d|dz   t	        |      z   | j
                  g}| j                   j                  |d       y )NTsetrE   r&   )r   rF   r   r   strr   r-   )r   rJ   rK   r1   s       r    set_propertyzZfs.set_property   sS    ;;!!DL||UD3JU$;TYYGd3r"   c                 8   di idi id}| j                         }| j                  j                         D ]E  \  }}| j                  ||      }||k7  s| j	                  ||       ||d   d   |<   ||d   d   |<   G | j
                  j                  r|S | j                         }| j                  D ]g  }| j                  ||      }|| j
                  j                  d|z         | j                  ||      |k7  rd| _        ||d   d   v s]||d   d   |<   i |S )Nr   beforeafterrT   rU   z8zfsprop was not present after being successfully set: %smsgT)	list_propertiesr   rH   get_propertyrQ   r   rF   	fail_jsonr   )r   diffcurrent_propertiesrJ   rK   current_valueupdated_propertiess          r    set_properties_if_changedzZfs.set_properties_if_changed   sV   126BXZ\A]^!11344::< 	DKD% --d4FGM%!!$.?LX56t<>CW45d;	D ;;!!K!113-- 	DD%%d,>?E}%%*dgk*k%l  '9:eC#tG}%;<<>CW45d;	D r"   c                 0   | j                   dddddg}| j                  r|dgz  }|d| j                  gz  }| j                  j	                  |      \  }}}g }|j                         D ],  }|j                  d      \  }}|d	v s|j                  |       . |S )
Nr$   -HrA   rD   zproperty,source-er9   	)localreceivedr*   )r   r   r   r   r-   r.   r   r,   )	r   r1   r2   r3   r4   
propertieslinerJ   sources	            r    rX   zZfs.list_properties   s    ||UD$6GH  D6MCtyy!!{{..s3C
NN$ 	(D::d+LD& 33!!$'	( r"   c                     | j                   r|dk(  rd}n|dk(  rd}||vry | j                  ddddd	g}| j                   r|d
gz  }||| j                  gz  }| j                  j	                  |      \  }}}|dk7  ry |d d S )Nsharenfsz	share.nfssharesmbz	share.smbr$   ra   rA   rD   rK   rb   r   r(   )r   r   r   r   r-   )r   r   list_of_propertiesr1   r2   r3   r4   s          r    rY   zZfs.get_property   s      z!"#"))||UD$g>  D6MCdii  {{..s3C7 3Bxr"   N)__name__
__module____qualname__r!   r   r   r;   r@   rM   rQ   r_   rX   rY    r"   r    r   r   c   s5    
>
	
 D4, r"   r   c                  $   t        t        t        dd      t        ddddg      t        d      t        di 	      
      d      } | j                  j                  d      }| j                  j                  d      }| j                  j                  d      rd|v r| j	                  d       | j                  d   j                         D ]Q  \  }}t        |t              r*|du rd| j                  d   |<   -d| j                  d   |<   @|| j                  d   |<   S t        ||      }t        | || j                  d         }|dk(  rA|j                         r|j                         |d<   nT|j                          ddid|id|d<   n7|dk(  r2|j                         r|j                          ddid|id|d<   ni |d<   ||d   d<   ||d   d<   |j                  |j                         |j                  |d<    | j                   di | y )NrP   T)typerequiredabsentpresent)rr   rs   choices)rr   dict)rr   default)r   stater=   r   )argument_specsupports_check_modery   r   r=   r   z2cannot specify origin when operating on a snapshotrV   r   onoff)r   ry   r[   rS   before_headerafter_headerr   rp   )r   rw   rG   r$   rZ   rH   
isinstanceboolr   r;   r_   r@   rM   updater   r   	exit_json)r   ry   r   rJ   rK   resultr
   s          r    mainr      s   540ED8Y:OPU#!%62!>	
 !F MMg&E==V$D}}"sd{QR }}%;<BBD @eeT"}>B45d;>C45d;:?FMM01$7@ F
 fdFMM*@A
BC	::< ::<F6NJJL)0((;wPUFVWF6N	(	::<KKM)0)(<QVGWXF6NF6N&*F6N?#%)F6N>"
MM#**+F9Fvr"   __main__)
__future__r   r   r   rr   __metaclass__DOCUMENTATIONEXAMPLESr   ansible.module_utils.basicr   objectr   r   rm   rp   r"   r    <module>r      sT    A @)V%N 
 4T& Tn6r zF r"   