
    Vh                     ~    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ g dZ G d d	e      Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functionuc  
module: zfs_facts
short_description: Gather facts about ZFS datasets
description:
  - Gather facts from ZFS dataset properties.
author: Adam Števko (@xen0l)
extends_documentation_fragment:
  - community.general.attributes
  - community.general.attributes.facts
  - community.general.attributes.facts_module
options:
  name:
    description:
      - ZFS dataset name.
    required: true
    aliases: ["ds", "dataset"]
    type: str
  recurse:
    description:
      - Specifies if properties for any children should be recursively displayed.
    type: bool
    default: false
  parsable:
    description:
      - Specifies if property values should be displayed in machine friendly format.
    type: bool
    default: false
  properties:
    description:
      - Specifies which dataset properties should be queried in comma-separated format. For more information about dataset
        properties, check zfs(1M) man page.
    default: all
    type: str
  type:
    description:
      - Specifies which datasets types to display. Multiple values have to be provided as a list or in comma-separated form.
      - Value V(all) cannot be used together with other values.
    choices: ['all', 'filesystem', 'volume', 'snapshot', 'bookmark']
    default: [all]
    type: list
    elements: str
  depth:
    description:
      - Specifies recursion depth.
    type: int
    default: 0
a  
- name: Gather facts about ZFS dataset rpool/export/home
  community.general.zfs_facts:
    dataset: rpool/export/home

- name: Report space usage on ZFS filesystems under data/home
  community.general.zfs_facts:
    name: data/home
    recurse: true
    type: filesystem

- ansible.builtin.debug:
    msg: 'ZFS dataset {{ item.name }} consumes {{ item.used }} of disk space.'
  with_items: '{{ ansible_zfs_datasets }}'
aS  
name:
  description: ZFS dataset name.
  returned: always
  type: str
  sample: rpool/var/spool
parsable:
  description: If parsable output should be provided in machine friendly format.
  returned: if O(parsable=True)
  type: bool
  sample: true
recurse:
  description: If we should recurse over ZFS dataset.
  returned: if O(recurse=True)
  type: bool
  sample: true
zfs_datasets:
  description: ZFS dataset facts.
  returned: always
  type: str
  sample:
    "aclinherit": "restricted"
    "aclmode": "discard"
    "atime": "on"
    "available": "43.8G"
    "canmount": "on"
    "casesensitivity": "sensitive"
    "checksum": "on"
    "compression": "off"
    "compressratio": "1.00x"
    "copies": "1"
    "creation": "Thu Jun 16 11:37 2016"
    "dedup": "off"
    "devices": "on"
    "exec": "on"
    "filesystem_count": "none"
    "filesystem_limit": "none"
    "logbias": "latency"
    "logicalreferenced": "18.5K"
    "logicalused": "3.45G"
    "mlslabel": "none"
    "mounted": "yes"
    "mountpoint": "/rpool"
    "name": "rpool"
    "nbmand": "off"
    "normalization": "none"
    "org.openindiana.caiman:install": "ready"
    "primarycache": "all"
    "quota": "none"
    "readonly": "off"
    "recordsize": "128K"
    "redundant_metadata": "all"
    "refcompressratio": "1.00x"
    "referenced": "29.5K"
    "refquota": "none"
    "refreservation": "none"
    "reservation": "none"
    "secondarycache": "all"
    "setuid": "on"
    "sharenfs": "off"
    "sharesmb": "off"
    "snapdir": "hidden"
    "snapshot_count": "none"
    "snapshot_limit": "none"
    "sync": "standard"
    "type": "filesystem"
    "used": "4.41G"
    "usedbychildren": "4.41G"
    "usedbydataset": "29.5K"
    "usedbyrefreservation": "0"
    "usedbysnapshots": "0"
    "utf8only": "off"
    "version": "5"
    "vscan": "off"
    "written": "29.5K"
    "xattr": "on"
    "zoned": "off"
)defaultdict)AnsibleModule)all
filesystemvolumesnapshotbookmarkc                       e Zd Zd Zd Zd Zy)ZFSFactsc                 8   || _         |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        |j                  d   | _        t        t              | _
        g | _        y )Nnamerecurseparsable
propertiestypedepth)moduleparamsr   r   r   r   r   r   r   dict	_datasetsfacts)selfr   s     o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/zfs_facts.py__init__zZFSFacts.__init__   s|    MM&)	}}Y/j1 --5MM&)	]]7+
$T*
    c                     | j                   j                  d      d| j                  g}| j                   j                  |      \  }}}|dk(  S )Nzfslistr   )r   get_bin_pathr   run_command)r   cmdrcouterrs        r   dataset_existszZFSFacts.dataset_exists   sD    {{''.		B005S#Qwr   c                    | j                   j                  d      ddg}| j                  r|j                  d       | j                  r|j                  d       t        | j                        dk7  r/|j                  d       |j                  d| j                  z         | j                  r;|j                  d	       |j                  d
j                  | j                               |j                  dd| j                  | j                  g       | j                   j                  |      \  }}}|dk7  r+| j                   j                  d| j                  z  ||       |j                         D ]7  }|j                  d      \  }}}| j                   |   j#                  ||i       9 | j                   j%                         D ]3  \  }	}
|
j#                  d|	i       | j&                  j                  |
       5 d| j&                  iS )Nr    getz-Hz-pz-rr   z-dz%sz-t,z-ozname,property,valuez5Error while trying to get facts about ZFS dataset: %s)msgstderrr%   	r   ansible_zfs_datasets)r   r"   r   appendr   intr   r   joinextendr   r   r#   	fail_json
splitlinessplitr   updateitemsr   )r   r$   r%   r&   r'   linedatasetpropertyvaluekvs              r   	get_factszZFSFacts.get_facts   s   {{''.t<==JJt<<JJttzz?aJJtJJtdjj()99JJtJJsxx		*+

D/$))LM005S#7KK!!&]`d`i`i&i),%' " ) NN$ 	>D'+zz$'7$GXuNN7#**He+<=	>
 NN((* 	!DAqHHfa[!JJa 	! '

33r   N)__name__
__module____qualname__r   r(   r?    r   r   r   r      s    4r   r   c                     t        t        t        dddgd      t        dd      t        dd      t        d	d      t        d	d
dt              t        dd            d      } d	| j                  d   v r-t	        | j                  d         dkD  r| j                  d       t        |       }i }d|d<   |j                  |d<   |j                  r|j                  |d<   |j                  r|j                  |d<   |j                         s| j                  d|j                  z         |j                         |d<    | j                  di | y )NTdsr:   str)requiredaliasesr   Fbool)defaultr   r   r!   )rJ   r   elementschoicesr   r1   )r   r   r   r   r   r   )argument_specsupports_check_moder      zHValue 'all' for parameter 'type' is mutually exclusive with other values)r,   changedr   r   r   zZFS dataset %s does not exist!ansible_factsrC   )r   r   SUPPORTED_TYPESr   lenr4   r   r   r   r   r(   r?   	exit_json)r   	zfs_factsresults      r   mainrW      s?   tdI->UKV4%f5E6e&5/Zqu-
 !
F f%%#fmmF.C*Dq*Hgh IFF9^^F6N&//z%--y##%=	NO'113F?Fvr   __main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNcollectionsr   ansible.module_utils.basicr   rR   objectr   rW   r@   rC   r   r   <module>ra      sb    A @.` M
^ $ 4 J44v 44n!H zF r   