
    Vh                     z    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mZ  G d de      Zd	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functionaB  
module: proxmox_pool
short_description: Pool management for Proxmox VE cluster
description:
  - Create or delete a pool for Proxmox VE clusters.
  - For pool members management please consult M(community.general.proxmox_pool_member) module.
version_added: 7.1.0
author: "Sergei Antipov (@UnderGreen) <greendayonfire@gmail.com>"
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
  action_group:
    version_added: 9.0.0
options:
  poolid:
    description:
      - The pool ID.
    type: str
    aliases: ["name"]
    required: true
  state:
    description:
      - Indicate desired state of the pool.
      - The pool must be empty prior deleting it with O(state=absent).
    choices: ['present', 'absent']
    default: present
    type: str
  comment:
    description:
      - Specify the description for the pool.
      - Parameter is ignored when pool already exists or O(state=absent).
    type: str

extends_documentation_fragment:
  - community.general.proxmox.actiongroup_proxmox
  - community.general.proxmox.documentation
  - community.general.attributes
ad  
- name: Create new Proxmox VE pool
  community.general.proxmox_pool:
    api_host: node1
    api_user: root@pam
    api_password: password
    poolid: test
    comment: 'New pool'

- name: Delete the Proxmox VE pool
  community.general.proxmox_pool:
    api_host: node1
    api_user: root@pam
    api_password: password
    poolid: test
    state: absent
z
poolid:
  description: The pool ID.
  returned: success
  type: str
  sample: test
msg:
  description: A short message on what the module did.
  returned: always
  type: str
  sample: "Pool test successfully created"
)AnsibleModule)proxmox_auth_argument_specProxmoxAnsiblec                   &    e Zd Zd Zd ZddZd Zy)ProxmoxPoolAnsiblec                     	 | j                   j                  j                         }|D ]  }|d   |k(  s y y# t        $ r5}| j                  j                  dj                  |             Y d}~yd}~ww xY w)zCheck whether pool already exist

        :param poolid: str - name of the pool
        :return: bool - is pool exists?
        poolidTFzUnable to retrieve pools: {0}msgN)proxmox_apipoolsget	Exceptionmodule	fail_jsonformat)selfr   r   pooles        r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/proxmox_pool.pyis_pool_existingz#ProxmoxPoolAnsible.is_pool_existingX   s{    	Q$$**..0E  >V+   	QKK!!&E&L&LQ&O!PP	Qs   18 8 8 	A6+A11A6c                 2    | j                  |      d   sdS dS )z}Check whether pool has members

        :param poolid: str - name of the pool
        :return: bool - is pool empty?
        membersTF)get_pool)r   r   s     r   is_pool_emptyz ProxmoxPoolAnsible.is_pool_emptyg   s      ==0;tFF    Nc                    | j                  |      r-| j                  j                  d|dj                  |             | j                  j                  ry	 | j
                  j                  j                  ||       y# t        $ r6}| j                  j                  dj                  ||             Y d}~yd}~ww xY w)zCreate Proxmox VE pool

        :param poolid: str - name of the pool
        :param comment: str, optional - Description of a pool
        :return: None
        FzPool {0} already existschangedr   r   N)r   commentz&Failed to create pool with ID {0}: {1}r   )
r   r   	exit_jsonr   
check_moder   r   postr   r   )r   r   r#   r   s       r   create_poolzProxmoxPoolAnsible.create_poolo   s       (KK!!%D]DdDdekDl!m;;!!	b""''vw'G 	bKK!!&N&U&UV\^_&`!aa	bs   'A? ?	B>,B99B>c                     | j                  |      s-| j                  j                  d|dj                  |             | j	                  |      rB| j                  j
                  ry	 | j                  j                  |      j                          y| j                  j                  dj                  |             y# t        $ r6}| j                  j                  dj                  ||             Y d}~yd}~ww xY w)zdDelete Proxmox VE pool

        :param poolid: str - name of the pool
        :return: None
        FzPool {0} doesn't existr!   Nz&Failed to delete pool with ID {0}: {1}r   zJCan't delete pool {0} with members. Please remove members from pool first.)r   r   r$   r   r   r%   r   r   deleter   r   )r   r   r   s      r   delete_poolzProxmoxPoolAnsible.delete_pool   s     $$V,KK!!%D\DcDcdjDk!lf%{{%%f  &&v.557 KK!!&r&y&y  {A  'B!  C  f%%*R*Y*YZ`bc*d%eefs   ()B> >	C=,C88C=)N)__name__
__module____qualname__r   r   r'   r*    r   r   r
   r
   V   s    QGb$Cr   r
   c            	         t               } t        t        ddgd      t        d      t        dddg      	      }| j                  |       t        | d
gdgd      }|j                  d   }|j                  d   }|j                  d   }t        |      }|dk(  r6|j                  ||       |j                  d|dj                  |             y |j                  |       |j                  d|dj                  |             y )NstrnameT)typealiasesrequired)r2   presentabsent)defaultchoices)r   r#   state)api_token_idapi_token_secret)api_passwordr:   )argument_specrequired_togetherrequired_one_ofsupports_check_moder   r#   r9   zPool {0} successfully createdr!   zPool {0} successfully deleted)
r   dictupdater   paramsr
   r'   r$   r   r*   )module_args
pools_argsr   r   r#   r9   proxmoxs          r   mainrG      s   ,.K4@% 9y(.CDJ z"!?@9: 	F ]]8$FmmI&GMM'"E (G	FG,f:Y:`:`ag:hiF#f:Y:`:`ag:hir   __main__N)
__future__r   r   r   r2   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Bansible_collections.community.general.plugins.module_utils.proxmoxr   r   r
   rG   r+   r.   r   r   <module>rP      sZ    C B'R$
 5 {=C =C@j> zF r   