
    Vh                     H   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 dd
lZ ej&                  d      ZdZdZ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 G d d      Zd Z e!dk(  r e         y
y
) z? Ansible module for managing SDT on Dell Technologies PowerFlex    )absolute_importdivisionprint_functiona	  
module: sdt
version_added: '2.6.0'
short_description: Manage SDT (also called NVMe Target) on Dell PowerFlex
description:
- Managing SDT (also called NVMe Target) on PowerFlex storage system includes
  creating new SDT, getting details of SDT, managing IP or role of SDT,
  modifying attributes of SDT, and deleting SDT.
- Support only for Powerflex 4.5 versions and above.
author:
- Yuhao Liu (@RayLiu7) <yuhao_liu@dell.com>
extends_documentation_fragment:
  - dellemc.powerflex.powerflex
options:
  discovery_port:
    description:
    - Discovery port of the SDT.
    type: int
  maintenance_mode:
    description:
    - Maintenance mode state of the SDT.
    choices: ['active', 'inactive']
    type: str
  nvme_port:
    description:
    - NVMe port of the SDT.
    type: int
  protection_domain_name:
    description:
    - The name of the protection domain.
    type: str
  sdt_ip_list:
    description:
    - Dictionary of IPs and their roles for the SDT.
    - At least one IP-role is mandatory while creating a SDT.
    - IP-roles can be updated as well.
    type: list
    elements: dict
    suboptions:
      ip:
        description:
        - IP address of the SDT.
        type: str
        required: true
      role:
        description:
        - Role assigned to the SDT IP address.
        choices: ['StorageOnly', 'HostOnly', 'StorageAndHost']
        type: str
        required: true
  sdt_name:
    description:
    - The name of the SDT.
    - Mandatory for all operations.
    - It is unique across the PowerFlex array.
    required: true
    type: str
  sdt_new_name:
    description:
    - SDT new name, can only be used for renaming the SDT.
    - Only used for updates. Ignored during creation.
    type: str
  state:
    description:
    - State of the SDT.
    choices: ['present', 'absent']
    default: present
    type: str
  storage_port:
    description:
    - Storage port of the SDT.
    type: int
attributes:
  check_mode:
    description: Runs task to validate without performing action on the target
                 machine.
    support: full
  diff_mode:
    description: Runs the task to report the changes made or to be made.
    support: full
notes:
  - IP addresses, and IP address roles must be configured for each SDT.
  - You can assign both storage and host roles to the same target IP addresses.
  - Alternatively, assign the storage role to one target IP address, and add
    another target IP address for the host role.
  - Both roles must be configured on each NVMe target.
af  
- name: Create SDT
  dellemc.powerflex.sdt:
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    validate_certs: "{{ validate_certs }}"
    sdt_name: "sdt_example"
    sdt_ip_list:
      - ip: "172.169.xx.xx"
        role: "StorageAndHost"
      - ip: "172.169.yy.yy"
        role: "StorageAndHost"
    protection_domain_name: "PD1"
    storage_port: 12200
    nvme_port: 4420
    discovery_port: 8009
    state: "present"

- name: Rename SDT
  dellemc.powerflex.sdt:
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    validate_certs: "{{ validate_certs }}"
    sdt_name: "sdt_example"
    sdt_new_name: "sdt_new_example"
    state: "present"

- name: Modify SDT port
  dellemc.powerflex.sdt:
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    validate_certs: "{{ validate_certs }}"
    sdt_name: "sdt_example"
    nvme_port: 4421
    discovery_port: 8008
    state: "present"

- name: Change maintenance mode
  dellemc.powerflex.sdt:
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    validate_certs: "{{ validate_certs }}"
    sdt_name: "sdt_example"
    maintenance_mode: "active"
    state: "present"

- name: Set IP and role to SDT
  dellemc.powerflex.sdt:
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    validate_certs: "{{ validate_certs }}"
    sdt_name: "sdt_example"
    sdt_ip_list:
      - ip: "172.169.xx.xx"
        role: "StorageAndHost"
      - ip: "172.169.zz.zz"
        role: "StorageAndHost"
    state: "present"

- name: Remove SDT
  dellemc.powerflex.sdt:
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    validate_certs: "{{ validate_certs }}"
    sdt_name: "sdt_example"
    state: "absent"
ak  
changed:
    description: Whether or not the resource has changed.
    returned: always
    type: bool
    sample: 'false'
sdt_details:
    description: Details of the SDT.
    returned: When SDT exists
    type: dict
    contains:
        authenticationError:
            description: Indicates authentication error.
            type: str
        certificateInfo:
            description: Information about certificate.
            type: dict
            contains:
                issuer:
                    description: Issuer of the certificate.
                    type: str
                subject:
                    description: Subject of the certificate.
                    type: str
                thumbprint:
                    description: Thumbprint of the certificate.
                    type: str
                validFrom:
                    description: Date and time the certificate is valid from.
                    type: str
                validFromAsn1Format:
                    description: Valid from date in ASN.1 format.
                    type: str
                validTo:
                    description: Date and time the certificate is valid to.
                    type: str
                validToAsn1Format:
                    description: Valid to date in ASN.1 format.
                    type: str
        discoveryPort:
            description: Discovery port.
            type: int
        faultSetId:
            description: Fault set ID.
            type: str
        id:
            description: SDS ID.
            type: str
        ipList:
            description: SDS IP list.
            type: list
            contains:
                ip:
                    description: IP present in the SDS.
                    type: str
                role:
                    description: Role of the SDS IP.
                    type: str
        links:
            description: SDS links.
            type: list
            contains:
                href:
                    description: SDS instance URL.
                    type: str
                rel:
                    description: SDS's relationship with different entities.
                    type: str
        maintenanceState:
            description: Maintenance state.
            type: str
        mdmConnectionState:
            description: MDM connection state.
            type: str
        membershipState:
            description: Membership state.
            type: str
        name:
            description: Name of the SDS.
            type: str
        nvmePort:
            description: NVMe port.
            type: int
        persistentDiscoveryControllersNum:
            description: Number of persistent discovery controllers.
            type: int
        protectionDomainId:
            description: Protection Domain ID.
            type: str
        protectionDomainName:
            description: Protection Domain Name.
            type: str
        sdtState:
            description: SDS state.
            type: str
        softwareVersionInfo:
            description: SDS software version information.
            type: str
        storagePort:
            description: Storage port.
            type: int
        systemId:
            description: System ID.
            type: str
    sample: {
        "authenticationError": "None",
        "certificateInfo": {
            "issuer": "/GN=MDM/CN=CA-804696a4dbe1d90f/L=Hopkinton/ST=Massachusetts/C=US/O=EMC/OU=ASD",
            "subject": "/GN=sdt-comp-0/CN=host41/L=Hopkinton/ST=Massachusetts/C=US/O=EMC/OU=ASD",
            "thumbprint": "07:1E:FC:48:03:42:E6:45:14:1D:AA:97:1F:4F:B9:B2:B4:11:99:09",
            "validFrom": "Oct 8 02:35:00 2024 GMT",
            "validFromAsn1Format": "241008023500Z",
            "validTo": "Oct 7 03:35:00 2034 GMT",
            "validToAsn1Format": "341007033500Z"
        },
        "discoveryPort": 8009,
        "faultSetId": null,
        "id": "917d28ed00000000",
        "ipList": [
            {
                "ip": "172.169.xx.xx",
                "role": "StorageAndHost"
            },
            {
                "ip": "172.169.yy.yy",
                "role": "StorageAndHost"
            }
        ],
        "links": [
            {
                "href": "/api/instances/Sdt::917d28ed00000000",
                "rel": "self"
            },
            {
                "href": "/api/instances/Sdt::917d28ed00000000/relationships/Statistics",
                "rel": "/api/Sdt/relationship/Statistics"
            },
            {
                "href": "/api/instances/ProtectionDomain::b4787fa100000000",
                "rel": "/api/parent/relationship/protectionDomainId"
            }
        ],
        "maintenanceState": "NoMaintenance",
        "mdmConnectionState": "Connected",
        "membershipState": "Joined",
        "name": "Sdt-pf460-svm-1",
        "nvmePort": 4420,
        "persistentDiscoveryControllersNum": 0,
        "protectionDomainId": "b4787fa100000000",
        "protectionDomainName": "PD1",
        "sdtState": "Normal",
        "softwareVersionInfo": "R4_5.2100.0",
        "storagePort": 12200,
        "systemId": "804696a4dbe1d90f"
}
)AnsibleModule)utils)PowerFlexBase)ConfigurationNsdtzXProvide valid values for sdt_ip_list as 'ip' and 'role' for Create or Modify operations.zIProvide valid value for name for the creation or modification of the SDT.zTProtection Domain is a mandatory parameter for creating an SDT. Enter a valid value.c                        e Zd ZdZ fdZd ZddZd Zd Z	 ddZ	d Z
	 	 	 dd	Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )PowerFlexSDTzClass with SDT operationsc                     t        j                         | _        | j                  j                  t	                      t	               dd}t
        |   t        |       | j                  j                  di i d       y)z-Define all parameters required by this moduleT)argument_specsupports_check_modeF)changedsdt_detailsdiffN)	r   %get_powerflex_gateway_host_parametersmodule_paramsupdateget_powerflex_sdt_parameterssuper__init__r   result)selfansible_module_params	__class__s     i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/powerflex/plugins/modules/sdt.pyr   zPowerFlexSDT.__init__c  sj    "HHJ!!">"@A :;#'!
 	(=>uRLM    c                     |t        |      dk(  r8t        }t        j                  |       | j                  j                  |       yy)zValidate the input parametersNr   msg)lenSDT_IP_LIST_INVALID_ERROR_MSGLOGerrormodule	fail_json)r   sdt_ip_list	error_msgs      r   validate_ip_parameterz"PowerFlexSDT.validate_ip_parameterq  sA     #k"2a"75IIIi KK!!i!0 #8r   c                    |r|n|}	 |r)| j                   j                  j                  d|i      }n(| j                   j                  j                  d|i      }t        |      dk(  rd|z  }t        j                  |       y|d   S # t        $ rM}d|dt        |      d	}t        j                  |       | j                  j                  |
       Y d}~yd}~ww xY w)zGet SDT details
        :param sdt_name: Name of the SDT
        :type sdt_name: str
        :param sdt_id: ID of the SDT
        :type sdt_id: str
        :return: Details of SDT if it exists
        :rtype: dict
        namefilter_fieldsidr   "SDT with identifier '%s' not foundNFailed to get the SDT '' with error ''r    )powerflex_connr
   getr"   r$   info	Exceptionstrr%   r&   r'   )r   sdt_namesdt_id
id_or_namer   r!   er)   s           r   get_sdt_detailszPowerFlexSDT.get_sdt_detailsy  s      &V8
	1"115599#)8"4 :  #115599v9W;1$:ZGq>! 	1AI IIi KK!!i!00	1s   A;B	 B	 		CACCc                     |d   dk(  ri S i }||d   |d   |d   |d   |d   |d   d	}|S t        j                  |      }| j                  ||      }|j                         D ]
  }||   ||<    |S )
zGet diff between playbook input and sdt details
        :param sdt_params: Dictionary of parameters input from playbook
        :param sdt_params: Dictionary of sdt details
        :return: Dictionary of parameters of differencesstateabsentdiscovery_port	nvme_portprotection_domain_namer(   r9   storage_port)rA   rB   rC   r(   r9   rD   )copydeepcopyis_sdt_modify_requiredkeys)r   
sdt_paramsr   	diff_dictmodify_dictkeys         r   get_diff_afterzPowerFlexSDT.get_diff_after  s     g(*II"&01A&B!+K!8.89Q.R#-m#< *: 6$.~$>	 	 !MM+6	"99*iP&++- 6C%0%5IcN6r   c           	          | j                  ||d   |d   |d   |d   |d         }|d   r*| j                  |d   |d         \  }}}|s|s|r|d   |d<   |S )	z
        Check if the SDT needs to be modified.
        :param sdt_params: Dictionary of parameters input from playbook
        :param sdt_details: Dictionary of sdt details
        :return: Dictionary of parameters of differences
        sdt_new_namerD   rB   rA   maintenance_moder   rO   rD   rB   rA   rP   r(   ipList)	to_modifyclassify_ip_list_change)r   rI   r   rK   
ips_to_addips_to_removeroles_to_updates          r   rG   z#PowerFlexSDT.is_sdt_modify_required  s     nn##N3#N3 -%&67'(:; % 
 m$9=9U9U=);x+@:6J ]o(2=(AH%r   c                 d    t        | j                  | j                        j                  ||      S )zRGet the details of a protection domain in a given PowerFlex storage
        system)rC   protection_domain_id)r	   r4   r&   get_protection_domain)r   rC   rY   s      r   rZ   z"PowerFlexSDT.get_protection_domain  s4    
 T00$++>TT#9!5 U 
 	
r   c                 B   |t        |j                               dk(  r7t        }t        j	                  |       | j
                  j                  |       |7t        }t        j	                  |       | j
                  j                  |       | j                  |       y )Nr   r    )	r"   stripSDT_NAME_INVALID_ERROR_MSGr$   r%   r&   r'   PD_INVALID_ERROR_MSGr*   )r   rY   r(   r9   r)   s        r   validate_createzPowerFlexSDT.validate_create  s{    s8>>#3492IIIi KK!!i!0',IIIi KK!!i!0"";/r   c                    	 | j                  |||       | j                  j                  sUd|d|d|d|d|d|}t        j	                  d|       | j
                  j                  j                  ||||||	       | j                  |
      S # t        $ rL}d| dt        |       }	t        j                  |	       | j                  j                  |	       Y d}~yd}~ww xY w)aO  Create SDT
        :param protection_domain_id: ID of the Protection Domain
        :type protection_domain_id: str
        :param sdt_ip_list: List of one or more IP addresses and
                            their roles
        :type sdt_ip_list: list[dict]
        :param sdt_name: SDT name
        :type sdt_name: str
        :param storage_port: Storage port of SDT
        :type storage_port: int
        :param nvme_port: NVMe port of SDT
        :type nvme_port: int
        :param discovery_port: Discovery port of SDT
        :type discovery_port: int
        :return: dict
        )rY   r(   r9   zprotection_domain_id: z, sdt_ip_list: z, sdt_name: z, storage_port: z, nvme_port: z, discovery_port: zCreating SDT with params: %s)rY   sdt_ipsr9   rD   rB   rA   )r9   zCreate SDT z operation failed with error r    N)r_   r&   
check_moder$   r6   r4   r
   creater=   r7   r8   r%   r'   )
r   rY   r(   r9   rD   rB   rA   create_paramsr<   r)   s
             r   
create_sdtzPowerFlexSDT.create_sdt  s    2)	1   %9'! !  ;;)) -# $!&   7G##''..)='%!-'#1 /  ''':: 	1%hZ/LSQRVHUIIIi KK!!i!00	1s   BB 	C(AC##C(c                     i }|||d   k7  r||d<   |||d   k7  r||d<   |||d   k7  r||d<   |||d   k7  r||d<   |$|dk(  r|d   dk7  rd|d<   |dk(  r|d   d	k7  rd|d<   |S )
am  
        :param sdt_details: Details of the SDT
        :type sdt_details: dict
        :param sdt_new_name: New name of SDT
        :type sdt_new_name: str
        :param storage_port: Storage port of SDT
        :type storage_port: int
        :param nvme_port: NVMe port of SDT
        :type nvme_port: int
        :param discovery_port: Discovery port of SDT
        :type discovery_port: int
        :param maintenance_mode: Maintenance mode of SDT
        :type maintenance_mode: str
        :return: Dictionary containing the attributes of SDT which are to be
                 updated
        :rtype: dict
        r,   storagePortnvmePortdiscoveryPortactivemaintenanceStateInMaintenanceinactiveNoMaintenance )r   r   rO   rD   rB   rA   rP   rK   s           r   rS   zPowerFlexSDT.to_modify)  s    4 #F8K(K".K#M8R(R)5K& Y+j2I%I&/K
#&+o">>+9K(' H, 23F2:./ J. 23F2<./r   c                 |   	 dt        |      z  }t        j                  |       | j                  j                  sd|v rF| j
                  j                  j                  ||d          d|d   z  }t        j                  |       d|v rF| j
                  j                  j                  ||d          d|d   z  }t        j                  |       d|v rF| j
                  j                  j                  ||d          d|d   z  }t        j                  |       d|v rF| j
                  j                  j                  ||d          d	|d   z  }t        j                  |       d
|v r|| j
                  j                  j                  | j
                  j                  j                  d}|j                  |d
         }|r% ||       d|d
   z  }t        j                  |       y# t        $ rM}d|dt        |      d}t        j                  |       | j                  j!                  |       Y d}~yd}~ww xY w)aV  
        Modify SDT attributes
            :param sdt_id: SDT ID
            :type sdt_id: str
            :param modify_dict: Dictionary containing the attributes of SDT
                                which are to be updated
            :type modify_dict: dict
            :return: Boolean indicating if the operation is successful
        zADictionary containing attributes which are to be updated is '%s'.r,   z4The name of the SDT is updated to '%s' successfully.rg   z1The storage port is updated to '%s' successfully.rh   z.The nvme port is updated to '%s' successfully.ri   z3The discovery port is updated to '%s' successfully.rk   )rj   rm   z5The maintenance mode is updated to '%s' successfully.TzFailed to update the SDT 'r2   r3   r    N)r8   r$   r6   r&   rb   r4   r
   renameset_storage_portset_nvme_portset_discovery_portenter_maintenance_modeexit_maintenance_moder5   r7   r%   r'   )r   r:   rK   r!   mode_map	mode_funcr<   r)   s           r   modify_sdt_attributesz"PowerFlexSDT.modify_sdt_attributes`  s>   C	1$'*;'79  HHSM;;))[(''++226;v;NON%f-.  HHSM K/''++<<M : L%m45  HHSM,''++99J 7 I%j12  HHSM"k1''++>>O < N%o67  HHSM%4"&"5"5"9"9"P"P$($7$7$;$;$Q$Q H !)[9K-L MI !&)S)*<=>   	1AI IIi KK!!i!00	1s   G"G% %	H;.AH66H;c                 <   g }g }g }|D ](  t        fd|D              r|j                         * |D ](  t        fd|D              r|j                         * |D ]2  |D ]+  }|d   d   k(  s|d   d   k7  s|j                         - 4 |||fS )Nc              3   4   K   | ]  }|d    d    k(    ywipNro   .0ip_dest	ip_sources     r   	<genexpr>z7PowerFlexSDT.classify_ip_list_change.<locals>.<genexpr>  s#      5<40   c              3   4   K   | ]  }|d    d    k(    ywr|   ro   r~   s     r   r   z7PowerFlexSDT.classify_ip_list_change.<locals>.<genexpr>  s     SGwt}	$7Sr   r}   role)anyappend)r   r(   sdt_details_ip_listrU   rV   rW   r   r   s          @r   rT   z$PowerFlexSDT.classify_ip_list_change  s     
 % 	-I @S  !!),		- - 	0IS{SS$$Y/	0
 % 	6I. 6DMYt_49V+<<#**956	6 =/99r   c                    	 | j                   j                  sf|D ]a  }t        j                  d|d          | j                  j
                  j                  |d   |d   |d          t        j                  d       c y# t        $ rP}d|d	   d
t        |      d}t        j                  |       | j                   j                  |       Y d}~yd}~ww xY w)a9  Add IP to SDT
        :param sdt_details: Details of the SDT
        :type sdt_details: str
        :param sdt_ip_list: List of one or more IP addresses and
                            their roles
        :type sdt_ip_list: list[dict]
        :return: Boolean indicating if add IP operation is successful
        zIP to add: %sr}   r/   r   r:   r}   r   zIP added successfully.TzAdd IP to SDT 'r,   ' operation failed with error 'r3   r    N)r&   rb   r$   r6   r4   r
   add_ipr7   r8   r%   r'   r   r   r(   r}   r<   r)   s         r   r   zPowerFlexSDT.add_ip  s    	1;;))% 7BHH_bh7''++22*40RXBvJ 3  HH567  	1F#AI IIi KK!!i!00	1s   A<A? ?	CACCc                    	 | j                   j                  sb|D ]]  }t        j                  d|d          | j                  j
                  j                  |d   |d          t        j                  d       _ y# t        $ rP}d|d   d	t        |      d
}t        j                  |       | j                   j                  |       Y d}~yd}~ww xY w)aB  Remove IP from SDT
        :param sdt_details: Details of the SDT
        :type sdt_details: str
        :param sdt_ip_list: List of one or more IP addresses and
                            their roles.
        :type sdt_ip_list: list[dict]
        :return: Boolean indicating if remove IP operation is successful
        zIP to remove: %sr}   r/   )r:   r}   zIP removed successfully.TzRemove IP from SDT 'r,   r   r3   r    N)r&   rb   r$   r6   r4   r
   	remove_ipr7   r8   r%   r'   r   s         r   r   zPowerFlexSDT.remove_ip  s    	1;;))% 9BHH/D:''++55*40RX 6  HH789  	1 !,F 3SV=  IIi KK!!i!00	1s   A8A; ;	CACCc                    	 | j                   j                  sr|D ]m  }t        j                  d|       | j                  j
                  j                  |d   |d   |d          d|d   d|d   d}t        j                  |       o y	# t        $ rP}d
|d   dt        |      d}t        j                  |       | j                   j                  |       Y d}~yd}~ww xY w)aL  Update IP's role for an SDT
        :param sdt_details: Details of the SDT
        :type sdt_details: str
        :param sdt_ip_list: List of one or more IP addresses and
                            their roles
        :type sdt_ip_list: list[dict]
        :return: Boolean indicating if update role operation is successful
        zip role to update: %sr/   r}   r   r   z
The role 'z
' for IP 'z' is updated successfully.TzUpdate role of IP for SDT 'r,   r   r3   r    N)r&   rb   r$   r6   r4   r
   set_ip_roler7   r8   r%   r'   )r   r   r(   r}   r!   r<   r)   s          r   update_rolezPowerFlexSDT.update_role  s    	1;;))% 	"BHH4b9''++77*40RXBvJ 8  6
4C HHSM	"  	1 &1%8#a&B  IIi KK!!i!00	1s   BB 	C$ACC$c                 d   	 | j                   j                  s)| j                  j                  j	                  |d          y| j                  |d         S # t        $ rP}d|d   dt        |      d}t        j                  |       | j                   j                  |       Y d}~yd}~ww xY w)	zyDelete SDT
        :param sdt_details: Details of SDT
        :type sdtsdt_details_id: str
        :return: dict
        r/   Nr:   zDelete SDT 'r,   r   r3   r    )r&   rb   r4   r
   deleter=   r7   r8   r$   r%   r'   )r   r   r<   r)   s       r   
delete_sdtzPowerFlexSDT.delete_sdt  s    	1;;))##''..{4/@A''{4/@'AA 	1F#AI IIi KK!!i!00	1s   >A A 	B/AB**B/c                    	 | j                   j                  j                  d|i      }t        |      dk(  rd|z  }t        j                  |       yd|d   v r+|d   d   r#| j                  |d   d         }|d   |d   d	<   |d   S # t        $ rM}d
|dt        |      d}t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zShow SDT details
        :param sdt_id: ID of the SDT
        :type sdt_id: str
        :return: Details of SDT
        :rtype: dict
        r/   r-   r   r0   NprotectionDomainId)rY   r,   protectionDomainNamer1   r2   r3   r    )r4   r
   r5   r"   r$   r%   rZ   r7   r8   r&   r'   )r   r:   r   r!   
pd_detailsr<   r)   s          r   show_outputzPowerFlexSDT.show_output2  s    	1--1155T6N5SK;1$:VC		# %A6N#78!77)4Q8L)M 8 
 :DF9KA56q>! 	1HNPSTUPVWIIIi KK!!i!00	1s   AB
 6B
 
	C ACC c                     |d   |d   g}|D ]Y  }|t        |j                               dk(  s#t        }t        j	                  |       | j
                  j                  |       [ y )Nr9   rO   r   r    )r"   r\   r]   r$   r%   r&   r'   )r   rI   paramsparamr)   s        r   validate_nameszPowerFlexSDT.validate_namesS  sc    Z(*^*DE 	5E S%71%<6			)$%%)%4		5r   )NN)NNN)__name__
__module____qualname____doc__r   r*   r=   rM   rG   rZ   r_   re   rS   ry   rT   r   r   r   r   r   r   __classcell__)r   s   @r   r   r   `  su    #N1!1F40 AE
0& B1H5nM1^:<14141<1&1B5r   r   c                  ,   t        t        d      t               t               t        ddt        t        d      t        dg d                  t        d	
      t        d	
      t        d	
      t        dddg      t        dddgd      	      S )zKThis method provide parameters required for the SDT module on
    PowerFlexT)requiredlistdict)StorageAndHostStorageOnlyHostOnly)r   choices)r}   r   )typeelementsoptionsint)r   r8   rj   rm   )r   r   presentr@   )r   r   default)	r9   rO   rC   r(   rD   rB   rA   rP   r?   )r   ro   r   r   r   r   \  s     t$V#v&!+X	
 u%E"'58Z2HI	8'<iP% r   c                       e Zd ZdZd Zy)SDTExitHandlerz!SDT Handler to manage the output.c                     |r#|j                  |d         |j                  d<   nd |j                  d<    |j                  j                  di |j                   y )Nr/   r   r   ro   )r   r   r&   	exit_json)r   sdt_objr   s      r   handlezSDTExitHandler.handlex  sW    ,3,?,?"4( -@ -GNN=) -1GNN=)   27>>2r   Nr   r   r   r   r   ro   r   r   r   r   u  s
    +3r   r   c                       e Zd ZdZd Zy)SDTDeleteHandlerz,SDT Handler to process the delete operation.c                     |d   dk(  r"|r |j                  |      }d|j                  d<   t               j                  ||       y )Nr?   r@   Tr   )r   r   r   r   )r   r   rI   r   s       r   r   zSDTDeleteHandler.handle  sB    g(*{!,,[9K(,GNN9%5r   Nr   ro   r   r   r   r     s
    66r   r   c                       e Zd ZdZd Zy)SDTChangeIPListHandlerz4SDT Handler to process the IP list change operation.c                 L   |d   dk(  r|r|r}|s{|j                  |       |j                  ||d         \  }}}|r|j                  ||       |r|j                  ||       |r|j	                  ||       |s|s|rd|j
                  d<   t               j                  |||       y )Nr?   r   rR   Tr   )r*   rT   r   r   r   r   r   r   )	r   r   rI   r   create_sdt_flagr(   rU   rV   rW   s	            r   r   zSDTChangeIPListHandler.handle  s    w9,#))+6//[=RS 7J {J7##KA!!+}=_,0y)!!':{Cr   Nr   ro   r   r   r   r     s    >Dr   r   c                       e Zd ZdZd Zy)SDTModifyHandlerz6SDT Handler to process the attribute modify operation.c           	          |d   dk(  rQ|rO|sM|j                  ||d   |d   |d   |d   |d         }|r%|j                  |d	   |
       d|j                  d<   t               j	                  |||||       y )Nr?   r   rO   rD   rB   rA   rP   rQ   r/   )r:   rK   Tr   )rS   ry   r   r   r   )r   r   rI   r   r   r(   rK   s          r   r   zSDTModifyHandler.handle  s    g)+O!++''7'7$[1)*:;!+,>!? , K --&t,+ .  -1y) ''Zo{	
r   Nr   ro   r   r   r   r     s
    @
r   r   c                       e Zd ZdZd Zy)SDTCreateHandlerz,SDT Handler to process the create operation.c           	          d}t        j                  |d         }|d   dk(  r6|s4|j                  |d   |||d   |d   |d   	      }d
|j                  d<   d
}t	               j                  |||||       y )NFr(   r?   r   r9   rD   rB   rA   )r9   rY   r(   rD   rB   rA   Tr   )rE   rF   re   r   r   r   )r   r   rI   r   rY   r   r(   s          r   r   zSDTCreateHandler.handle  s    mmJ}$=>g)+K!,,#J/%9''7$[1)*:; - K )-GNN9%"O!!Zo{	
r   Nr   ro   r   r   r   r     s
    6
r   r   c                       e Zd ZdZd Zy)
SDTHandlerz(SDT Handler to preprocess the operation.c                 `   |j                  |       |j                  |d         }d }|d   r|j                  |d         d   }i }i }|j                  ||      }|i }n|}|j                  j
                  rt        ||      |j                  d<   t               j                  ||||       y )N)rI   r9   rC   )rC   r/   )beforeafterr   )
r   r=   rZ   rM   r&   _diffr   r   r   r   )r   r   rI   r   rY   before_dictrJ   s          r   r   zSDTHandler.handle  s    *5--j.DE#./#*#@#@'12J'K $A $$  	**:{C	K%K>>%)I%NGNN6"!!Z.B	
r   Nr   ro   r   r   r   r     s
    2
r   r   c                  t    t               } t               j                  | | j                  j                         y)z[Create PowerFlex SDT object and perform action on it
    based on user input from playbook.N)r   r   r   r&   r   )objs    r   mainr     s'     .CLSZZ../r   __main__)"r   
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Gansible_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	   rE   
get_loggerr$   r#   r]   r^   r   r   r   r   r   r   r   r   r   r   ro   r   r   <module>r      s    F @ @VpHT[
z 5 eu z O  n y5= y5x2
3 
36 6D D8
 
0
 
.
 
60 zF r   