
    Vh*                         d Z ddlmZmZmZ eZdZdZddl	m
Z
mZ ddlmZmZmZmZmZ dZ	 ddlmZmZ ed
        Zed        Zed        Zd Zd Zd Zd Zd Zedk(  r e        yy# e$ r d	ZY >w xY w)z<This module creates, deletes or modifies pools on Infinibox.    )absolute_importdivisionprint_functiona  
---
module: infini_pool
version_added: '2.3.0'
short_description: Create, Delete and Modify Pools on Infinibox
description:
    - This module to creates, deletes or modifies pools on Infinibox.
author: David Ohlemacher (@ohlemacher)
options:
  name:
    description:
      - Pool Name
    required: true
    type: str
  state:
    description:
      - Creates/Modifies Pool when present or removes when absent
    required: false
    default: present
    choices: [ "stat", "present", "absent" ]
    type: str
  size:
    description:
      - Pool Physical Capacity in MB, GB or TB units.
        If pool size is not set on pool creation, size will be equal to 1TB.
        See examples.
    required: false
    type: str
  vsize:
    description:
      - Pool Virtual Capacity in MB, GB or TB units.
        If pool vsize is not set on pool creation, Virtual Capacity will be equal to Physical Capacity.
        See examples.
    required: false
    type: str
  ssd_cache:
    description:
      - Enable/Disable SSD Cache on Pool
    required: false
    default: yes
    type: bool
  compression:
    description:
      - Enable/Disable Compression on Pool
    required: false
    default: yes
    type: bool
  physical_capacity_warning:
    description:
      - Capacity, in percent, for a warning notification.
    required: false
    type: int
    default: 80
  physical_capacity_critical:
    description:
      - Capacity, in percent, for a critical notification.
    required: false
    type: int
    default: 90

notes:
  - Infinibox Admin level access is required for pool modifications
extends_documentation_fragment:
    - infinibox
requirements:
    - capacity
a  
- name: Make sure pool foo exists. Set pool physical capacity to 10TB
  infini_pool:
    name: foo
    size: 10TB
    vsize: 10TB
    user: admin
    password: secret
    system: ibox001

- name: Disable SSD Cache on pool
  infini_pool:
    name: foo
    ssd_cache: false
    user: admin
    password: secret
    system: ibox001

- name: Disable Compression on pool
  infini_pool:
    name: foo
    compression: false
    user: admin
    password: secret
    system: ibox001
)AnsibleModulemissing_required_lib)HAS_INFINISDKapi_wrapperinfinibox_argument_specget_pool
get_systemT)KiBCapacityFc                    | j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                   d   }| j                  s|s5|s3|j                  j                  |t	        d      t	        d      ||	      }	n|r5|s3|j                  j                  |t	        |      t	        |      ||	      }	ni|s5|r3|j                  j                  |t	        d      t	        |      ||	      }	n2|j                  j                  |t	        |      t	        |      ||	      }	|s|	j                  |       |s|	j                  |       | j                  d
d       y)z Create Pool namesizevsize	ssd_cachecompressionphysical_capacity_warningphysical_capacity_critical1TB)r   physical_capacityvirtual_capacityr   r   TPool createdchangedmsgN)params
check_modepoolscreater   update_ssd_enabledupdate_compression_enabled	exit_json)
modulesystemr   r   r   r   r   r   r   pools
             s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/infinidat/infinibox/plugins/modules/infini_pool.pycreate_poolr)      s    == D== DMM'"Ek*I--.K &.I J!'/K!LE<<&&DHUOfnotfuAZ  xR ' SD%<<&&DHTNemnresAZ  xR ' SD%<<&&DHUOfnotfuAZ  xR ' SD <<&&DHTNemnsetAZ  xR ' SD ##I.++K8
T~6    c                    d}| j                   d   }| j                   d   }| j                   d   }| j                   d   }|rSt        |      j                  dt        z        }|j	                         |k7  r| j
                  s|j                  |       d}|rSt        |      j                  dt        z        }|j                         |k7  r| j
                  s|j                  |       d}|j                         |k7  r| j
                  s|j                  |       d}|j                         |k7  r| j
                  s|j                  |       d}| j                   j                  d      }	|j                         }
|	|
k7  r| j
                  s|j                  |	       d}| j                   j                  d	      }|j!                         }||k7  r| j
                  s|j#                  |       d}|rd
}nd}| j%                  ||       y)z Update Pool Fr   r   r   r   i  Tr   r   Pool updatedzPool did not require updatingr   N)r   r   roundupr   get_physical_capacityr   update_physical_capacityget_virtual_capacityupdate_virtual_capacityis_ssd_enabledr"   is_compression_enabledr#   getget_physical_capacity_critical!update_physical_capacity_criticalget_physical_capacity_warning update_physical_capacity_warningr$   )r%   r'   r   r   r   r   r   r   r   r   #existing_physical_capacity_criticalr   "existing_physical_capacity_warningr   s                 r(   update_poolr;      s    G== DMM'"Ek*I--.K $TN226C<@%%'+<<$$--.?@G#E?226C<@$$&*::$$,,-=>G	)  ##I.""$3  ++K8G!'!2!23O!P*.*M*M*O'!%HH  223MNG & 1 12M N)-)K)K)M& $FF  112KLG-
W#.r*   c                 f    | j                   s|j                          d}| j                  d|       y)z Delete Pool zPool deletedTr   N)r   deleter$   )r%   r'   r   s      r(   delete_poolr>      s.     
C
Ts+r*   c                 $   t        |       }t        | |      }| j                  d   }|s| j                  d| d       |j	                         }|j                  dd      }|j                  dd      }|j                         }|j                         }|j                         }	|j                         }
t        dt        |      ||t        |	      t        |
      |j                         |j                         |d	

      } | j                  di | y)z Show details about a pool r   zPool z
 not foundr   free_physical_capacityNidFzPool stat found)
r   rA   r   r   r   r   r   compression_enabledrB   r    )r   r   r   	fail_json
get_fieldsr4   r7   r5   r.   r0   dictstrr2   r3   r$   )r%   r&   r'   r   fieldsrA   pool_idr   r   r   r   results               r(   handle_statrL      s   FFF#D== DuTF*56__F#ZZ(@$Gjjt$G $ B B D!%!D!D!F224002"#9:";#=/0-.%%' 779F Fvr*   c                     t        |       }t        | |      }|s t        | |       | j                  dd       yt	        | |      }| j                  |d       y)z Create pool Tr   r   r,   N)r   r   r)   r$   r;   )r%   r&   r'   r   s       r(   handle_presentrN     sW    FFF#DFF#>:fd+n=r*   c                     t        |       }t        | |      }|s| j                  dd       yt        | |       | j                  dd       y)z Remove pool FzPool already absentr   TzPool removedN)r   r   r$   r>   )r%   r&   r'   s      r(   handle_absentrP     sL    FFF#D,ABFD!>:r*   c                 *   | j                   d   }	 |dk(  rt        |        n7|dk(  rt        |        n&|dk(  rt        |        n| j	                  d|        t        |       }|j                          y# t        |       }|j                          w xY w)z3Determine which state function to execute and do sostatestatpresentabsentz'Internal handler error. Invalid state: r@   N)r   rL   rN   rP   rE   r   logout)r%   rR   r&   s      r(   execute_staterW     s    MM'"EF?i6"h&!#J5'!RSF# F#s   AA5 5Bc                     t               } | j                  t        t        d      t        dg d      t               t               t        dd      t        dd      t        dd	      t        dd
                   t        | d      }t        s|j                  t        d             t        s|j                  t        d             |j                  d   r	 t        |j                  d          |j                  d   r	 t        |j                  d          t        |       y# t        $ r |j                  d       Y Qw xY w# t        $ r |j                  d       Y Jw xY w)z Main T)requiredrT   )rS   rT   rU   )defaultchoicesbool)typerZ   intP   Z   )r   rR   r   r   r   r   r   r   )supports_check_mode	infinisdkr@   capacityr   zDsize (Physical Capacity) should be defined in MB, GB, TB or PB unitsr   zDvsize (Virtual Capacity) should be defined in MB, GB, TB or PB unitsN)r
   updaterG   r   r   rE   r   HAS_CAPACITYr   r   	ExceptionrW   )argument_specr%   s     r(   mainrh   -  sB   +-Mt$y2OP&5&$7&*r&B'+'C		
 =dCF1+>?1*=>}}V	iV]]6*+ }}W	iV]]7+, &  	i!gh	i  	i!gh	is$   D+ E +E	E	E*)E*__main__N) __doc__
__future__r   r   r   r]   __metaclass__DOCUMENTATIONEXAMPLESansible.module_utils.basicr   r   Fansible_collections.infinidat.infinibox.plugins.module_utils.infiniboxr   r	   r
   r   r   re   rc   r   r   ImportErrorr)   r;   r>   rL   rN   rP   rW   rh   __name__rD   r*   r(   <module>rs      s    C
 C BBH: K  &
 7 7B 4/ 4/n , ,@	>;"$N zF m  Ls   A) )A32A3