
    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 d dlmZ  G d d	e      Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functionuN  
module: zpool_facts
short_description: Gather facts about ZFS pools
description:
  - Gather facts from ZFS pool properties.
author: Adam Števko (@xen0l)
extends_documentation_fragment:
  - community.general.attributes
  - community.general.attributes.facts
  - community.general.attributes.facts_module
options:
  name:
    description:
      - ZFS pool name.
    type: str
    aliases: ["pool", "zpool"]
    required: false
  parsable:
    description:
      - Specifies if property values should be displayed in machine friendly format.
    type: bool
    default: false
    required: false
  properties:
    description:
      - Specifies which dataset properties should be queried in comma-separated format. For more information about dataset
        properties, check zpool(1M) man page.
    type: str
    default: all
    required: false
a  
- name: Gather facts about ZFS pool rpool
  community.general.zpool_facts: pool=rpool

- name: Gather space usage about all imported ZFS pools
  community.general.zpool_facts: properties='free,size'

- name: Print gathered information
  ansible.builtin.debug:
    msg: 'ZFS pool {{ item.name }} has {{ item.free }} free space out of {{ item.size }}.'
  with_items: '{{ ansible_zfs_pools }}'
a  
ansible_facts:
  description: Dictionary containing all the detailed information about the ZFS pool facts.
  returned: always
  type: complex
  contains:
    ansible_zfs_pools:
      description: ZFS pool facts.
      returned: always
      type: str
      sample:
        "allocated": "3.46G"
        "altroot": "-"
        "autoexpand": "off"
        "autoreplace": "off"
        "bootfs": "rpool/ROOT/openindiana"
        "cachefile": "-"
        "capacity": "6%"
        "comment": "-"
        "dedupditto": "0"
        "dedupratio": "1.00x"
        "delegation": "on"
        "expandsize": "-"
        "failmode": "wait"
        "feature@async_destroy": "enabled"
        "feature@bookmarks": "enabled"
        "feature@edonr": "enabled"
        "feature@embedded_data": "active"
        "feature@empty_bpobj": "active"
        "feature@enabled_txg": "active"
        "feature@extensible_dataset": "enabled"
        "feature@filesystem_limits": "enabled"
        "feature@hole_birth": "active"
        "feature@large_blocks": "enabled"
        "feature@lz4_compress": "active"
        "feature@multi_vdev_crash_dump": "enabled"
        "feature@sha512": "enabled"
        "feature@skein": "enabled"
        "feature@spacemap_histogram": "active"
        "fragmentation": "3%"
        "free": "46.3G"
        "freeing": "0"
        "guid": "15729052870819522408"
        "health": "ONLINE"
        "leaked": "0"
        "listsnapshots": "off"
        "name": "rpool"
        "readonly": "off"
        "size": "49.8G"
        "version": "-"
name:
  description: ZFS pool name.
  returned: always
  type: str
  sample: rpool
parsable:
  description: If parsable output should be provided in machine friendly format.
  returned: if O(parsable=true)
  type: bool
  sample: true
)defaultdict)	iteritems)AnsibleModulec                       e Zd Zd Zd Zd Zy)
ZPoolFactsc                     || _         |j                  d   | _        |j                  d   | _        |j                  d   | _        t        t              | _        g | _        y )Nnameparsable
properties)	moduleparamsr   r   r   r   dict_poolsfacts)selfr   s     q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/zpool_facts.py__init__zZPoolFacts.__init__~   sL    MM&)	j1 --5!$'
    c                     | j                   j                  d      d| j                  g}| j                   j                  |      \  }}}|dk(  S )Nzpoollistr   )r   get_bin_pathr   run_command)r   cmdrcdummys       r   pool_existszZPoolFacts.pool_exists   sE    {{''0&$))D;;2237E5Qwr   c                    | j                   j                  d      ddg}| j                  r|j                  d       |j                  d       |j                  d       |j                  | j                         | j
                  r|j                  | j
                         | j                   j                  |d      \  }}}|j                         D ]7  }|j                  d	      \  }}}| j                  |   j                  ||i       9 t        | j                        D ]3  \  }	}
|
j                  d
|	i       | j                  j                  |
       5 d| j                  iS )Nr   getz-Hz-pz-ozname,property,valueT)check_rc	r   ansible_zfs_pools)r   r   r   appendr   r   r   
splitlinessplitr   updater   r   )r   r   r   outerrlinepoolpropvaluekvs              r   	get_factszZPoolFacts.get_facts   s&   {{''0%>==JJt

4

()

4??#99JJtyy!{{..sT.BCNN$ 	4D $

4 0D$KK$$dE]3	4
 dkk* 	!DAqHHfa[!JJa 	! $TZZ00r   N)__name__
__module____qualname__r   r    r2    r   r   r
   r
   }   s    
1r   r
   c            
         t        t        t        ddgd      t        dd      t        dd      	      d
      } t        |       }d|j                  d}|j                  r|j                  |d<   |j                  D|j                         r|j                         |d<   n3| j                  d|j                  z         n|j                         |d<    | j                  di | y )Nr-   r   str)aliasestypeFbool)defaultr:   all)r   r   r   T)argument_specsupports_check_mode)changedr   r   ansible_factszZFS pool %s does not exist!)msgr6   )	r   r   r
   r   r   r    r2   	fail_json	exit_json)r   zpool_factsresults      r   mainrG      s    vw/e<%f5E6

 !F V$K   F (11z#""$&1&;&;&=F?#!>AQAQ!QR"-"7"7"9Fvr   __main__N)
__future__r   r   r   r:   __metaclass__DOCUMENTATIONEXAMPLESRETURNcollectionsr   ansible.module_utils.sixr   ansible.module_utils.basicr   objectr
   rG   r3   r6   r   r   <module>rR      s[    A @@<
| $ . 4$1 $1N< zF r   