
    Vh%7                         d 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 ddlmZ dd	lmZ  ej$                  d
      Z G d de      Zd Z G d d      Z G d d      Z G d d      Z G d d      Z G d d      Zd Zedk(  r e        yy)zM Ansible module for managing Fault Sets on Dell Technologies (Dell) PowerFlex    )absolute_importdivisionprint_functiona3  
module: fault_set
version_added: '2.2.0'
short_description: Manage Fault Sets on Dell PowerFlex
description:
- Managing fault sets on PowerFlex storage system includes creating,
  getting details, renaming and deleting a fault set.
author:
- Carlos Tronco (@ctronco) <ansible.team@dell.com>
- Trisha Datta (@trisha-dell) <ansible.team@dell.com>
extends_documentation_fragment:
  - dellemc.powerflex.powerflex
options:
  fault_set_name:
    description:
    - Name of the Fault Set.
    - Mutually exclusive with I(fault_set_id).
    type: str
  fault_set_id:
    description:
    - ID of the Fault Set.
    - Mutually exclusive with I(fault_set_name).
    type: str
  protection_domain_name:
    description:
    - Name of protection domain.
    - Mutually exclusive with I(protection_domain_id).
    type: str
  protection_domain_id:
    description:
    - ID of the protection domain.
    - Mutually exclusive with I(protection_domain_name).
    type: str
  fault_set_new_name:
    description:
    - New name of the fault set.
    type: str
  state:
    description:
    - State of the Fault Set.
    choices: ['present', 'absent']
    default: 'present'
    type: str
notes:
  - The I(check_mode) is supported.
  - When I(fault_set_name) is provided, I(protection_domain_name)
    or I(protection_domain_id) must be provided.
ar  

- name: Create Fault Set on Protection Domain
  dellemc.powerflex.fault_set:
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    validate_certs: "{{ validate_certs }}"
    fault_set_name: "{{ fault_set_name }}"
    protection_domain_name: "{{ pd_name }}"
    state: present

- name: Rename Fault Set
  dellemc.powerflex.fault_set:
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    validate_certs: "{{ validate_certs }}"
    fault_set_name: "{{ fault_set_name }}"
    fault_set_new_name: "{{ fault_set_new_name }}"
    state: present

- name: Get details of a Fault Set
  dellemc.powerflex.fault_set:
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    validate_certs: "{{ validate_certs }}"
    fault_set_id: "{{ fault_set_id }}"
    state: present

- name: Delete Fault Set
  dellemc.powerflex.fault_set:
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    validate_certs: "{{ validate_certs }}"
    fault_set_id: "{{ fault_set_id }}"
    state: absent
aC  
changed:
    description: Whether or not the resource has changed.
    returned: always
    type: bool
    sample: 'false'

fault_set_details:
    description: Details of fault set.
    returned: always
    type: dict
    contains:
        protectionDomainId:
            description: Unique identifier of the protection domain.
            type: str
        protectionDomainName:
            description: Name of the protection domain.
            type: str
        name:
            description: Name of the fault set.
            type: str
        id:
            description: Unique identifier of the fault set.
            type: str
        SDS:
            description: List of SDS associated to the fault set.
            type: list
            elements: dict
        links:
            description: Fault set links.
            type: list
            contains:
                href:
                    description: Fault Set instance URL.
                    type: str
                rel:
                    description: Relationship of fault set with different
                                 entities.
                    type: str
    sample: {
        "protectionDomainId": "da721a8300000000",
        "protectionDomainName": "sample-pd",
        "name": "fs_001",
        "id": "eb44b70500000000",
        "links": []
        }

)utils)PowerFlexBase)Configuration)AnsibleModule	fault_setc                   \     e Zd ZdZ fdZ	 ddZ	 ddZd ZddZd Z	d Z
d	 Zd
 Z xZS )PowerFlexFaultSetzClass with FaultSet operationsc                     ddgddgg}ddgg}t               d||d}t        | 	  t        |       t	        di       | _        y	)
z-Define all parameters required by this modulefault_set_namefault_set_idprotection_domain_nameprotection_domain_idT)argument_specsupports_check_modemutually_exclusiverequired_one_ofF)changedfault_set_detailsN)"get_powerflex_fault_set_parameterssuper__init__r	   dictresult)selfr   r   ansible_module_params	__class__s       o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/powerflex/plugins/modules/fault_set.pyr   zPowerFlexFaultSet.__init__   sk     ~.%'=>
 -n=> @A#'"4.	!
 	(=> 
    c                 d    t        | j                  | j                        j                  ||      S )zRGet the details of a protection domain in a given PowerFlex storage
        system)r   r   )r   powerflex_connmoduleget_protection_domain)r   r   r   s      r    r%   z'PowerFlexFaultSet.get_protection_domain   s6    
 T00$++>TT#9Pd U f 	fr!   c                 b    t        | j                  | j                        j                  |      S )z`Get the details of SDS associated to given fault set in a given PowerFlex storage
        systemr   )r   r#   r$   get_associated_sds)r   r   s     r    r(   z$PowerFlexFaultSet.get_associated_sds   s1    
 T00$++>QQ% R ' 	'r!   c                    	 | j                   j                  sDd| d| }t        j                  |       | j                  j
                  j                  ||       | j                  ||      S # t        $ rL}d| dt        |       }t        j                  |       | j                   j                  |       Y d}~yd}~ww xY w)	a(  
        Create Fault Set
        :param fault_set_name: Name of the fault set
        :type fault_set_name: str
        :param protection_domain_id: ID of the protection domain
        :type protection_domain_id: str
        :return: Boolean indicating if create operation is successful
        zCreating fault set with name: z on protection domain with id: )namer   r   r   zCreate fault set z operation failed with error msgN)r$   
check_modeLOGinfor#   r
   createget_fault_set	Exceptionstrerror	fail_json)r   r   r   r-   e	error_msgs         r    create_fault_setz"PowerFlexFaultSet.create_fault_set   s    	1;;))77G H55I4JL##--44'>R 5  %%-%9 & ; ;  	1,^,< =''*1vh0IIIi KK!!i!00		1s   A,A/ /	C8AB??Cc                 f    t        | j                  | j                        j                  |||      S )a  Get fault set details
            :param fault_set_name: Name of the fault set
            :param fault_set_id: Id of the fault set
            :param protection_domain_id: ID of the protection domain
            :return: Fault set details
            :rtype: dict
        )r   r   r   )r   r#   r$   r2   )r   r   r   r   s       r    r2   zPowerFlexFaultSet.get_fault_set   s8     T00$++>LL)[o M q 	qr!   c                 &    |d   |d   |d   k7  ryy)z0To get the details of the fields to be modified.fault_set_new_namer*   TF )r   r   fault_set_paramss      r    is_rename_requiredz$PowerFlexFaultSet.is_rename_required   s*     01= !56:KF:SSr!   c                 L   	 | j                   j                  s'| j                  j                  j	                  ||       | j                  |      S # t        $ rI}dt        |       }t        j                  |       | j                   j                  |       Y d}~yd}~ww xY w)z'Perform rename operation on a fault set)r   r*   r'   z3Failed to rename the fault set instance with error r,   N)r$   r.   r#   r
   renamer2   r3   r4   r/   r5   r6   )r   r   new_namer7   r-   s        r    rename_fault_setz"PowerFlexFaultSet.rename_fault_set   s    	+;;))##--44!-! 5 # %%) & + + 	+!!$Q*CIIcNKK!!c!**		+s   AA 	B#?BB#c                    	 | j                   j                  sTt        j                  d|        | j                  j
                  j                  |       t        j                  d       y| j                  |      S # t        $ rL}d| dt        |       }t        j                  |       | j                   j                  |       Y d}~yd}~ww xY w)zDelete the Fault SetzRemoving Fault Set r,   zreturning NoneNr'   z failed with error )r$   r.   r/   r0   r#   r
   deleter2   r3   r4   r5   r6   )r   r   r7   errormsgs       r    delete_fault_setz"PowerFlexFaultSet.delete_fault_set  s    	0;;))2<.AB##--44\B)*%%) & + + 	0,\N:McRSfXVHIIhKK!!h!//	0s   A)A> ,A> >	CACCc                 V   |d   |d   g}|D ]U  }|t        |j                               dk(  s#d}t        j                  |       | j                  j                  |       W |d   @|d   :|d   4d}t        j                  |       | j                  j                  |       y y y y )	Nr   r<   r   zLProvide valid value for name for the creation/modification of the fault set.r,   r   r   zHProvide protection_domain_id/protection_domain_name with fault_set_name.)lenstripr/   r5   r$   r6   )r   r>   paramsparamr8   s        r    validate_parametersz%PowerFlexFaultSet.validate_parameters  s    "#346FG[6\] 	5E S%71%<F			)$%%)%4	5 ,-9 !78@EUVnEoEwbIIIi KK!!i!0 Fx@ :r!   )NN)N)NNN)__name__
__module____qualname____doc__r   r%   r(   r9   r2   r?   rC   rG   rM   __classcell__)r   s   @r    r   r      sA    (
. AEf  '16	q+"01r!   r   c                      t        t               t               t               t               t               t        dddg            S )zXThis method provide parameter required for the Ansible Fault Set module on
    PowerFlexpresentabsent)defaultchoices)r   r   r   r   r<   state)r   r=   r!   r    r   r   -  s9     vV#v!V69y(.CD r!   c                       e Zd Zd Zy)FaultSetExitHandlerc                    ||j                   d<   |rM|j                  |d         d   |j                   d   d<   |j                  |d         |j                   d   d<    |j                  j                  d	i |j                    y )
Nr   protectionDomainId)r   r*   protectionDomainNameidr'   SDSr=   )r   r%   r(   r$   	exit_json)r   fault_set_objr   s      r    handlezFaultSetExitHandler.handle;  s    4E0133):;O)P 4 RRXZ   !456LM 00!24!8 1 :   !45e< 	'&&>)=)=>r!   NrN   rO   rP   rb   r=   r!   r    rZ   rZ   :  s    	?r!   rZ   c                       e Zd Zd Zy)FaultSetDeleteHandlerc                     |d   dk(  r%|r#|j                  |d         }d|j                  d<   t               j                  ||       y )NrX   rU   r^   Tr   )rG   r   rZ   rb   )r   ra   r>   r   s       r    rb   zFaultSetDeleteHandler.handleH  sN    G$05F - > >?PQU?V W.2M  +$$]4EFr!   Nrc   r=   r!   r    re   re   G  s    Gr!   re   c                       e Zd Zd Zy)FaultSetRenameHandlerc                     |d   dk(  r>|r<|j                  ||      }|r(|j                  |d   |d         }d|j                  d<   t               j	                  |||       y )NrX   rT   r^   r<   )r   rB   Tr   )r?   rC   r   re   rb   )r   ra   r>   r   r?   s        r    rb   zFaultSetRenameHandler.handleQ  s{    G$	16G!.!A!ABSUe!f!$1$B$BPabfPgL\]qLr %C %t!26$$Y/&&}6FHYZr!   Nrc   r=   r!   r    rh   rh   P  s    [r!   rh   c                       e Zd Zd Zy)FaultSetCreateHandlerc                     |d   dk(  r'|s%|j                  |d   |      }d|j                  d<   t               j                  |||       y )NrX   rT   r   r+   Tr   )r9   r   rh   rb   )r   ra   r>   r   pd_ids        r    rb   zFaultSetCreateHandler.handle]  s\    G$	1:K - > >N^_oNpTY !? ![.2M  +&&}6FHYZr!   Nrc   r=   r!   r    rk   rk   \  s    [r!   rk   c                       e Zd Zd Zy)FaultSetHandlerc                     |j                  |       d }|d   s|d   r|j                  |d   |d         d   }|j                  |d   |d   |      }t               j	                  ||||       y )	N)r>   r   r   )r   r   r^   r   r   )r   r   r   )rM   r%   r2   rk   rb   )r   ra   r>   rm   r   s        r    rb   zFaultSetHandler.handleg  s    ));K)L237GH`7a!77%56L%M'78P'Q 8 SSWYE *77EUVdEeGWXhGiMR 8 T 	&&}6FHY[`ar!   Nrc   r=   r!   r    ro   ro   f  s    
br!   ro   c                  t    t               } t               j                  | | j                  j                         y)zf Create PowerFlex fault set object and perform action on it
        based on user input from playbook.N)r   ro   rb   r$   rK   )objs    r    mainrs   t  s)     
CS#**"3"34r!   __main__N)rQ   
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURNGansible_collections.dellemc.powerflex.plugins.module_utils.storage.dellr   `ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.powerflex_baser   _ansible_collections.dellemc.powerflex.plugins.module_utils.storage.dell.libraries.configurationr   ansible.module_utils.basicr	   
get_loggerr/   r   r   rZ   re   rh   rk   ro   rs   rN   r=   r!   r    <module>r      s    T @ @/d'R/
d 4 e{#D1 D1N

? 
?G G	[ 	[[ [b b5 zF r!   