
    Vhs                     P   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 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 G d d      Zd Zedk(  r e        y
y
)zF Ansible module for managing SDS on Dell Technologies (Dell) PowerFlex    )absolute_importdivisionprint_functiona  
module: sds
version_added: '1.1.0'
short_description: Manage SDS on Dell PowerFlex
description:
- Managing SDS on PowerFlex storage system includes
  creating new SDS, getting details of SDS, adding/removing IP to/from SDS,
  modifying attributes of SDS, and deleting SDS.
author:
- Rajshree Khare (@khareRajshree) <ansible.team@dell.com>
- Trisha Datta (@trisha-dell) <ansible.team@dell.com>
extends_documentation_fragment:
  - dellemc.powerflex.powerflex
options:
  sds_name:
    description:
    - The name of the SDS.
    - Mandatory for create operation.
    - It is unique across the PowerFlex array.
    - Mutually exclusive with I(sds_id).
    type: str
  sds_id:
    description:
    - The ID of the SDS.
    - Except create operation, all other operations can be performed
      using I(sds_id).
    - Mutually exclusive with I(sds_name).
    type: str
  protection_domain_name:
    description:
    - The name of the protection domain.
    - Mutually exclusive with I(protection_domain_id).
    type: str
  protection_domain_id:
    description:
    - The ID of the protection domain.
    - Mutually exclusive with I(protection_domain_name).
    type: str
  sds_ip_list:
    description:
    - Dictionary of IPs and their roles for the SDS.
    - At least one IP-role is mandatory while creating a SDS.
    - IP-roles can be updated as well.
    type: list
    elements: dict
    suboptions:
      ip:
        description:
        - IP address of the SDS.
        type: str
        required: true
      role:
        description:
        - Role assigned to the SDS IP address.
        choices: ['sdsOnly', 'sdcOnly', 'all']
        type: str
        required: true
  sds_ip_state:
    description:
    - State of IP with respect to the SDS.
    choices: ['present-in-sds', 'absent-in-sds']
    type: str
  rfcache_enabled:
    description:
    - Whether to enable the Read Flash cache.
    type: bool
  rmcache_enabled:
    description:
    - Whether to enable the Read RAM cache.
    type: bool
  rmcache_size:
    description:
    - Read RAM cache size (in MB).
    - Minimum size is 128 MB.
    - Maximum size is 3911 MB.
    type: int
  sds_new_name:
    description:
    - SDS new name.
    type: str
  performance_profile:
    description:
    - Performance profile to apply to the SDS.
    - The HighPerformance profile configures a predefined set of parameters
      for very high performance use cases.
    - Default value by API is C(HighPerformance).
    choices: ['Compact', 'HighPerformance']
    type: str
  fault_set_name:
    description:
    - Name of the fault set.
    - Mutually exclusive with I(fault_set_id).
    type: str
  fault_set_id:
    description:
    - Unique identifier of the fault set.
    - Mutually exclusive with I(fault_set_name).
    type: str
  state:
    description:
    - State of the SDS.
    choices: ['present', 'absent']
    required: true
    type: str
notes:
  - The maximum limit for the IPs that can be associated with an SDS is 8.
  - There needs to be at least 1 IP for SDS communication and 1 for SDC
    communication.
  - If only 1 IP exists, it must be with role 'all'; else 1 IP
    can be with role 'all'and other IPs with role 'sdcOnly'; or 1 IP must be
    with role 'sdsOnly' and others with role 'sdcOnly'.
  - There can be 1 or more IPs with role 'sdcOnly'.
  - There must be only 1 IP with SDS role (either with role 'all' or
    'sdsOnly').
  - SDS can be created with RF cache disabled, but, be aware that the RF cache
    is not always updated. In this case, the user should re-try the operation.
  - The I(check_mode) is supported.
az  
- name: Create SDS
  dellemc.powerflex.sds:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    sds_name: "node0"
    protection_domain_name: "domain1"
    sds_ip_list:
      - ip: "198.10.xxx.xxx"
        role: "all"
    sds_ip_state: "present-in-sds"
    state: "present"

- name: Create SDS with all parameters
  dellemc.powerflex.sds:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    sds_name: "node1"
    protection_domain_name: "domain1"
    fault_set_name: "faultset1"
    sds_ip_list:
      - ip: "198.10.xxx.xxx"
        role: "sdcOnly"
    sds_ip_state: "present-in-sds"
    rmcache_enabled: true
    rmcache_size: 128
    performance_profile: "HighPerformance"
    state: "present"

- name: Get SDS details using name
  dellemc.powerflex.sds:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    sds_name: "node0"
    state: "present"

- name: Get SDS details using ID
  dellemc.powerflex.sds:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    sds_id: "5718253c00000004"
    state: "present"

- name: Modify SDS attributes using name
  dellemc.powerflex.sds:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    sds_name: "node0"
    sds_new_name: "node0_new"
    rfcache_enabled: true
    rmcache_enabled: true
    rmcache_size: 256
    performance_profile: "HighPerformance"
    state: "present"

- name: Modify SDS attributes using ID
  dellemc.powerflex.sds:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    sds_id: "5718253c00000004"
    sds_new_name: "node0_new"
    rfcache_enabled: true
    rmcache_enabled: true
    rmcache_size: 256
    performance_profile: "HighPerformance"
    state: "present"

- name: Add IP and role to an SDS
  dellemc.powerflex.sds:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    sds_name: "node0"
    sds_ip_list:
      - ip: "198.10.xxx.xxx"
        role: "sdcOnly"
    sds_ip_state: "present-in-sds"
    state: "present"

- name: Remove IP and role from an SDS
  dellemc.powerflex.sds:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    sds_name: "node0"
    sds_ip_list:
      - ip: "198.10.xxx.xxx"
        role: "sdcOnly"
    sds_ip_state: "absent-in-sds"
    state: "present"

- name: Delete SDS using name
  dellemc.powerflex.sds:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    sds_name: "node0"
    state: "absent"

- name: Delete SDS using ID
  dellemc.powerflex.sds:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    sds_id: "5718253c00000004"
    state: "absent"
ag  
changed:
    description: Whether or not the resource has changed.
    returned: always
    type: bool
    sample: 'false'
sds_details:
    description: Details of the SDS.
    returned: When SDS exists
    type: dict
    contains:
        authenticationError:
            description: Indicates authentication error.
            type: str
        certificateInfo:
            description: Information about certificate.
            type: str
        configuredDrlMode:
            description: Configured DRL mode.
            type: str
        drlMode:
            description: DRL mode.
            type: str
        faultSetId:
            description: Fault set ID.
            type: str
        fglMetadataCacheSize:
            description: FGL metadata cache size.
            type: int
        fglMetadataCacheState:
            description: FGL metadata cache state.
            type: str
        fglNumConcurrentWrites:
            description: FGL concurrent writes.
            type: int
        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
        lastUpgradeTime:
            description: Last time SDS was upgraded.
            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
        maintenanceType:
            description: Maintenance type.
            type: str
        mdmConnectionState:
            description: MDM connection state.
            type: str
        membershipState:
            description: Membership state.
            type: str
        name:
            description: Name of the SDS.
            type: str
        numOfIoBuffers:
            description: Number of IO buffers.
            type: int
        numRestarts:
            description: Number of restarts.
            type: int
        onVmWare:
            description: Presence on VMware.
            type: bool
        perfProfile:
            description: Performance profile.
            type: str
        port:
            description: SDS port.
            type: int
        protectionDomainId:
            description: Protection Domain ID.
            type: str
        protectionDomainName:
            description: Protection Domain Name.
            type: str
        raidControllers:
            description: Number of RAID controllers.
            type: int
        rfcacheEnabled:
            description: Whether RF cache is enabled or not.
            type: bool
        rfcacheErrorApiVersionMismatch:
            description: RF cache error for API version mismatch.
            type: bool
        rfcacheErrorDeviceDoesNotExist:
            description: RF cache error for device does not exist.
            type: bool
        rfcacheErrorInconsistentCacheConfiguration:
            description: RF cache error for inconsistent cache configuration.
            type: bool
        rfcacheErrorInconsistentSourceConfiguration:
            description: RF cache error for inconsistent source configuration.
            type: bool
        rfcacheErrorInvalidDriverPath:
            description: RF cache error for invalid driver path.
            type: bool
        rfcacheErrorLowResources:
            description: RF cache error for low resources.
            type: bool
        rmcacheEnabled:
            description: Whether Read RAM cache is enabled or not.
            type: bool
        rmcacheFrozen:
            description: RM cache frozen.
            type: bool
        rmcacheMemoryAllocationState:
            description: RM cache memory allocation state.
            type: bool
        rmcacheSizeInKb:
            description: RM cache size in KB.
            type: int
        rmcacheSizeInMb:
            description: RM cache size in MB.
            type: int
        sdsConfigurationFailure:
            description: SDS configuration failure.
            type: str
        sdsDecoupled:
            description: SDS decoupled.
            type: str
        sdsReceiveBufferAllocationFailures:
            description: SDS receive buffer allocation failures.
            type: str
        sdsState:
            description: SDS state.
            type: str
        softwareVersionInfo:
            description: SDS software version information.
            type: str
    sample: {
        "authenticationError": "None",
        "certificateInfo": null,
        "configuredDrlMode": "Volatile",
        "drlMode": "Volatile",
        "faultSetId": null,
        "fglMetadataCacheSize": 0,
        "fglMetadataCacheState": "Disabled",
        "fglNumConcurrentWrites": 1000,
        "id": "8f3bb0cc00000002",
        "ipList": [
            {
                "ip": "10.47.xxx.xxx",
                "role": "all"
            }
        ],
        "lastUpgradeTime": 0,
        "links": [
            {
                "href": "/api/instances/Sds::8f3bb0cc00000002",
                "rel": "self"
            },
            {
                "href": "/api/instances/Sds::8f3bb0cc00000002/relationships
                        /Statistics",
                "rel": "/api/Sds/relationship/Statistics"
            },
            {
                "href": "/api/instances/Sds::8f3bb0cc00000002/relationships
                        /SpSds",
                "rel": "/api/Sds/relationship/SpSds"
            },
            {
                "href": "/api/instances/Sds::8f3bb0cc00000002/relationships
                        /Device",
                "rel": "/api/Sds/relationship/Device"
            },
            {
                "href": "/api/instances/ProtectionDomain::9300c1f900000000",
                "rel": "/api/parent/relationship/protectionDomainId"
            }
        ],
        "maintenanceState": "NoMaintenance",
        "maintenanceType": "NoMaintenance",
        "mdmConnectionState": "Connected",
        "membershipState": "Joined",
        "name": "node0",
        "numOfIoBuffers": null,
        "numRestarts": 2,
        "onVmWare": true,
        "perfProfile": "HighPerformance",
        "port": 7072,
        "protectionDomainId": "9300c1f900000000",
        "protectionDomainName": "domain1",
        "raidControllers": null,
        "rfcacheEnabled": true,
        "rfcacheErrorApiVersionMismatch": false,
        "rfcacheErrorDeviceDoesNotExist": false,
        "rfcacheErrorInconsistentCacheConfiguration": false,
        "rfcacheErrorInconsistentSourceConfiguration": false,
        "rfcacheErrorInvalidDriverPath": false,
        "rfcacheErrorLowResources": false,
        "rmcacheEnabled": true,
        "rmcacheFrozen": false,
        "rmcacheMemoryAllocationState": "AllocationPending",
        "rmcacheSizeInKb": 131072,
        "rmcacheSizeInMb": 128,
        "sdsConfigurationFailure": null,
        "sdsDecoupled": null,
        "sdsReceiveBufferAllocationFailures": null,
        "sdsState": "Normal",
        "softwareVersionInfo": "R3_6.0.0"
    }
)AnsibleModule)utils)PowerFlexBase)ConfigurationNsdsc                        e Zd ZdZ fdZd Zd ZddZ	 ddZddZ	d Z
	 	 d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 xZS )PowerFlexSDSzClass with SDS operationsc                    t        j                         | _        | j                  j                  t	                      ddgddgddg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sds_namesds_idprotection_domain_nameprotection_domain_idfault_set_namefault_set_idsds_ip_listsds_ip_stateT)argument_specsupports_check_modemutually_exclusiverequired_one_ofrequired_togetherF)changedsds_detailsN)
r   %get_powerflex_gateway_host_parametersmodule_paramsupdateget_powerflex_sds_parameterssuper__init__r   dictresult)selfmut_ex_argsrequired_together_argsrequired_one_of_argsansible_module_params	__class__s        i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/powerflex/plugins/modules/sds.pyr"   zPowerFlexSDS.__init__  s    "HHJ!!">"@A"H-02HI(.9; $1."A!B!+X 67 :;#'"-3!7!
 	(=>
    c                 z    |9|du r4d}t         j                  |       | j                  j                  |       yyy)Validate the input parametersNFzbRM cache size can be set only when RM cache is enabled, please enable it along with RM cache size.msg)LOGerrormodule	fail_json)r%   rmcache_enabledrmcache_size	error_msgs       r+   validate_rmcache_size_parameterz,PowerFlexSDS.validate_rmcache_size_parameter  sD     #5(@&I IIi KK!!i!0 )A#r,   c                     |t        |      dk(  r4d}t        j                  |       | j                  j	                  |       yy)r.   Nr   zUProvide valid values for sds_ip_list as 'ip' and 'role' for Create/Modify operations.r/   )lenr1   r2   r3   r4   )r%   r   r7   s      r+   validate_ip_parameterz"PowerFlexSDS.validate_ip_parameter!  sE     #k"2a"7&I 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 SDS details
            :param sds_name: Name of the SDS
            :type sds_name: str
            :param sds_id: ID of the SDS
            :type sds_id: str
            :return: Details of SDS if it exist
            :rtype: dict
        namefilter_fieldsidr   "SDS with identifier '%s' not foundNFailed to get the SDS '' with error ''r/   )powerflex_connr
   getr:   r1   info	Exceptionstrr2   r3   r4   )r%   r   r   
id_or_namer   r0   er7   s           r+   get_sds_detailszPowerFlexSDS.get_sds_details+  s      &V8
	1"115599#)8"4 : 6 #115599#'. : 2 ;1$:ZGq>! 	1%s1v/IIIi KK!!i!00		1s   A;B	 B	 		CACCc                 d    t        | j                  | j                        j                  ||      S )zRGet the details of a protection domain in a given PowerFlex storage
        system)r   r   )r	   rE   r3   get_protection_domain)r%   r   r   s      r+   rN   z"PowerFlexSDS.get_protection_domainL  s6    
 T00$++>TT#9Pd U f 	fr,   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	   rE   r3   get_fault_set)r%   r   r   r   s       r+   rQ   zPowerFlexSDS.get_fault_setT  s8     T00$++>LL)[o M q 	qr,   c                 >    g }|D ]  }|j                  d|i        |S )a!  Restructure IP role dict
            :param sds_ip_list: List of one or more IP addresses and
                                their roles
            :type sds_ip_list: list[dict]
            :return: List of one or more IP addresses and their roles
            :rtype: list[dict]
        SdsIp)append)r%   r   new_sds_ip_listitems       r+   restructure_ip_role_dictz%PowerFlexSDS.restructure_ip_role_dict_  s0      	4D""GT?3	4r,   c
                 v   |t        |j                               dk(  r3d}
t        j                  |
       | j                  j                  |
       |3d}
t        j                  |
       | j                  j                  |
       |t        |      dk(  r3d}
t        j                  |
       | j                  j                  |
       |8|dk7  r3d}
t        j                  |
       | j                  j                  |
       |r4d}
t        j                  |
       | j                  j                  |
       y y )	Nr   z8Please provide valid sds_name value for creation of SDS.r/   z[Protection Domain is a mandatory parameter for creating an SDS. Please enter a valid value.z<Please provide valid sds_ip_list values for creation of SDS.present-in-sdsz-Incorrect IP state given for creation of SDS.z=Creation of SDS is allowed using sds_name only, sds_id given.)r:   stripr1   r2   r3   r4   rG   )r%   r   r   r   r   r   sds_new_namer5   r6   r   r7   s              r+   validate_createzPowerFlexSDS.validate_createl  s    s8>>#349+IIIi KK!!i!0'KIIIi KK!!i!0#k"2a"7+IIIi KK!!i!0#8H(HGIIIi KK!!i!0.IHHYKK!!i!0	 r,   c
                 h   	 | j                  |||||||||		       | j                  |       | j                  j                  s|r|dk(  r| j	                  |      }|| j                  ||       |dz  }d|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)a}  Create SDS
            :param protection_domain_id: ID of the Protection Domain
            :type protection_domain_id: str
            :param sds_ip_list: List of one or more IP addresses associated
                                with the SDS over which the data will be
                                transferred.
            :type sds_ip_list: list[dict]
            :param sds_ip_state: SDS IP state
            :type sds_ip_state: str
            :param sds_name: SDS name
            :type sds_name: str
            :param rmcache_enabled: Whether to enable the Read RAM cache
            :type rmcache_enabled: bool
            :param rmcache_size: Read RAM cache size (in MB)
            :type rmcache_size: int
            :param fault_set_id: ID of the Fault Set
            :type fault_set_id: str
            :return: Boolean indicating if create operation is successful
        )	r   r   r   r   r   r[   r5   r6   r   rY   N)r5   r6      zprotection_domain_id: z, sds_ip_list: z, sds_name: z, rmcache_enabled: z,  rmcache_size_KB: z,  fault_set_id: zCreating SDS with params: %s)r   sds_ipsr=   r5   rmcache_size_in_kbr   )r   zCreate SDS z operation failed with error r/   )r\   r;   r3   
check_moderW   r8   r1   rG   rE   r
   createrL   rH   rI   r2   r4   )r%   r   r   r   r   r   r[   r5   r6   r   create_paramsrK   r7   s                r+   
create_sdszPowerFlexSDS.create_sds  sT   *,	1   6J-8|*26P\1@|.:	 ! < &&{3;;))<3C#C"&"?"?"LK+88FR 9 T $0$#6L %9+$,o|$0"2 7G##''..)='!$3'3!- / / ''':: 	1%hZ/LSQRVHUIIIi KK!!i!00	1s   CC 	D1%AD,,D1c                 p   i }|||d   k7  r||d<   t               }||d<   ||d<   ||d<   g d}	|	D ]  }
||
   	||
   ||
   k7  s||
   ||
<    |d| j                  ||       |d   dz  }||k7  rE|d   r||d<   |S d	|d   z  }t        j                  |       | j                  j                  |
       |S )a  
        :param sds_details: Details of the SDS
        :type sds_details: dict
        :param sds_new_name: New name of SDS
        :type sds_new_name: str
        :param rfcache_enabled: Whether to enable the Read Flash cache
        :type rfcache_enabled: bool
        :param rmcache_enabled: Whether to enable the Read RAM cache
        :type rmcache_enabled: bool
        :param rmcache_size: Read RAM cache size (in MB)
        :type rmcache_size: int
        :param performance_profile: Performance profile to apply to the SDS
        :type performance_profile: str
        :return: Dictionary containing the attributes of SDS which are to be
                 updated
        :rtype: dict
        r=   rfcacheEnabledrmcacheEnabledperfProfile)rf   rg   rh   rmcacheSizeInKbr^   rmcacheSizeInMBz}Failed to update RM cache size for the SDS '%s' as RM cache is disabled previously, please enable it before setting the size.r/   )r#   r8   r1   r2   r3   r4   )r%   r   r[   rfcache_enabledr5   r6   performance_profilemodify_dictparam_input
param_listparamexisitng_size_mbr7   s                r+   	to_modifyzPowerFlexSDS.to_modify  s   & #F 33".Kf(7$%(7$%%8M"H
 	8E5!-&+e*<<%0%7E"	8
 #001=?*+<=D///05AK 12 !4 #.f"5	!6I
 IIi(KK))i)8r,   c                 \   	 dt        |      z  }t        j                  |       | j                  j                  srd|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 rF| j
                  j                  j                  ||d
          d|d
   z  }t        j                  |       | j                  |      S # t        $ rb}|rd|dt        |      d}nd|dt        |      d}t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)a  Modify SDS attributes
            :param sds_id: SDS ID
            :type sds_id: str
            :param modify_dict: Dictionary containing the attributes of SDS
                                which are to be updated
            :type modify_dict: dict
            :param create_flag: Flag to indicate whether modify operation is
                                followed by create operation or not
            :type create_flag: bool
            :return: Boolean indicating if the operation is successful
        zADictionary containing attributes which are to be updated is '%s'.r=   z4The name of the SDS is updated to '%s' successfully.rf   z0The use RFcache is updated to '%s' successfully.rg   z0The use RMcache is updated to '%s' successfully.rj   z4The size of RMcache is updated to '%s' successfully.rh   z*The performance profile is updated to '%s'r   z8Create SDS is successful, but failed to update the SDS 'rC   rD   zFailed to update the SDS 'r/   N)rI   r1   rG   r3   ra   rE   r
   renameset_rfcache_enabledset_rmcache_enabledset_rmcache_sizeset_performance_parametersrL   rH   r2   r4   )r%   r   rm   create_flagr0   rK   r7   s          r+   modify_sds_attributesz"PowerFlexSDS.modify_sds_attributes  s   2	1&),[)9;CHHSM;;))[(''++226;v;NOP'/0CHHSM#{2''++??,< =?L'(89:CHHSM#{2''++??,< =?L'(89:CHHSM$3''++<<,= >@P'(9:;CHHSM K/''++FFM :<F'67CHHSM''v'66 		1  &s1v/	   &s1v/	IIi KK!!i!00		1s   F=G   	H+	AH&&H+c                 r   |d   }g }g }g }|r|D ]  }|j                  |d           |D ]  }	|	d   }||vs|j                  |	        t        j                  d|       t        |      dk7  r|D ]  }|j	                  |        |D cg c]  }||vr|
 }}t        j                  d|       ||fS c c}w )NipListipzIP(s) to be added: %sr   zRole update needed for: %s)rT   r1   rG   r:   remove)
r%   r   r   r   existing_ip_role_listupdate_role
ips_to_addexisting_ip_listr~   given_ips
             r+   identify_ip_role_addz!PowerFlexSDS.identify_ip_role_addG  s     !,H 5
  + 2 ''412# 	,H$B))!!(+	, 	(*5z?a  '""2&' %0 ;b$99  ; ;-{;;&&;s   B4c                     |d   }|dk(  rP|D cg c]  }||v r|
 }}t        |      dk7  rt        j                  d|       |S t        j                  d       g S y c c}w )Nr}   absent-in-sdsr   zIP(s) to remove: %szIP(s) do not exists.)r:   r1   rG   )r%   r   r   r   r   r~   ips_to_removes          r+   identify_ip_role_removez$PowerFlexSDS.identify_ip_role_removec  sy     !,H 5?**? 3B "k 1   3M 3=!Q&.>$$/0	 +3s   Ac                    	 | j                   j                  sY|D ]T  }t        j                  d|       | j                  j
                  j                  ||       t        j                  d       V y# t        $ rM}d|dt        |      d}t        j                  |       | j                   j                  |       Y d	}~y	d	}~ww xY w)
a;  Add IP to SDS
            :param sds_id: SDS ID
            :type sds_id: str
            :param sds_ip_list: List of one or more IP addresses and
                                their roles
            :type sds_ip_list: list[dict]
            :return: Boolean indicating if add IP operation is successful
        zIP to add: %s)r   sds_ipzIP added successfully.TzAdd IP to SDS '' operation failed with error 'rD   r/   N)r3   ra   r1   rG   rE   r
   add_iprH   rI   r2   r4   r%   r   r   r~   rK   r7   s         r+   r   zPowerFlexSDS.add_ipq  s    	1;;))% 7BHH_b1''++22&2LHH567  	1(.A8IIIi KK!!i!00		1s   A/A2 2	C;ACCc                    	 | j                   j                  st        j                  d|       t	        |      dk7  rn|D ]i  }t        j                  d|       | j
                  j                  j                  ||d   |d          d|d   d|d   d}t        j                  |       k y	# t        $ rM}d
|dt        |      d}t        j                  |       | j                   j                  |       Y d}~yd}~ww xY w)aI  Update IP's role for an SDS
            :param sds_id: SDS ID
            :type sds_id: str
            :param sds_ip_list: List of one or more IP addresses and
                                their roles
            :type sds_ip_list: list[dict]
            :return: Boolean indicating if add IP operation is successful
        zRole updates for: %sr   zip-role: %sr~   rolez
The role 'z
' for IP 'z' is updated successfully.TzUpdate role of IP for SDS 'r   rD   r/   N)r3   ra   r1   rG   r:   rE   r
   set_ip_rolerH   rI   r2   r4   )r%   r   r   r~   r0   rK   r7   s          r+   r   zPowerFlexSDS.update_role  s    	1;;))/={#q() &3++//;;FBtH<>vJH 24FRXG&  	1-3SV=IIIi KK!!i!00		1s   B(B+ +	D4AC<<Dc                    	 | j                   j                  s\|D ]W  }t        j                  d|       | j                  j
                  j                  ||d          t        j                  d       Y y# t        $ rM}d|dt        |      d}t        j                  |       | j                   j                  |	       Y d
}~y
d
}~ww xY w)aD  Remove IP from SDS
            :param sds_id: SDS ID
            :type sds_id: str
            :param sds_ip_list: List of one or more IP addresses and
                                their roles.
            :type sds_ip_list: list[dict]
            :return: Boolean indicating if remove IP operation is successful
        zIP to remove: %sr~   )r   r~   zIP removed successfully.TzRemove IP from SDS 'r   rD   r/   N)r3   ra   r1   rG   rE   r
   	remove_iprH   rI   r2   r4   r   s         r+   r   zPowerFlexSDS.remove_ip  s    	1;;))% 9BHH/4''++55V45QHH789  	1(.A8IIIi KK!!i!00		1s   A2A5 5	C>ACCc                 R   	 | j                   j                  s&| j                  j                  j	                  |       y| j                  |      S # t        $ rM}d|dt        |      d}t        j                  |       | j                   j                  |       Y d}~yd}~ww xY w)zDelete SDS
            :param sds_id: SDS ID
            :type sds_id: str
            :return: Boolean indicating if delete operation is successful
        Nrt   zDelete SDS 'r   rD   r/   )r3   ra   rE   r
   deleterL   rH   rI   r1   r2   r4   )r%   r   rK   r7   s       r+   
delete_sdszPowerFlexSDS.delete_sds  s    		1;;))##''..v6''v'66 	1!3q6+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
|d   v r$|d   d
   r|d   d
   dz  }t        |      |d   d<   d|d   v r2|d   d   r*| j                  |d   d   |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 SDS details
            :param sds_id: ID of the SDS
            :type sds_id: str
            :return: Details of SDS
            :rtype: dict
        r@   r>   r   rA   NprotectionDomainId)r   r=   protectionDomainNameri   r^   rmcacheSizeInMb
faultSetId)r   r   faultSetNamerB   rC   rD   r/   )rE   r
   rF   r:   r1   r2   rN   intrQ   rH   rI   r3   r4   )	r%   r   r   r0   
pd_detailsrmcache_size_mb
fs_detailsrK   r7   s	            r+   show_outputzPowerFlexSDS.show_output  s   $	1--1155#Vn 6 .K ;1$:VC		# ${1~5#A';<!77)4Q8L)M 8 O
9CF9KA56 !KN2#A'89"-a.1B"Cd"J474HA01 {1~-#A|4!//!,Q!=)4Q8L)M 0 O
 2<F1CA~.q>! 	1!3q6+IIIi KK!!i!00		1s    AC. BC. .	E7AD??Ec                     |d   |d   g}|D ]U  }|t        |j                               dk(  s#d}t        j                  |       | j                  j                  |       W y )Nr   r[   r   zFProvide valid value for name for the creation/modification of the SDS.r/   )r:   rZ   r1   r2   r3   r4   )r%   
sds_paramsparamsrp   r7   s        r+   validate_parametersz PowerFlexSDS.validate_parameters  sf    Z(*^*DE 	5E S%71%<@			)$%%)%4	5r,   )NN)NNN)F)__name__
__module____qualname____doc__r"   r8   r;   rL   rN   rQ   rW   r\   rd   rr   r{   r   r   r   r   r   r   r   r   __classcell__)r*   s   @r+   r   r     s    #
8	111D AEf	q RV%)1D `dA1F4n +0?1B'81,161,1",1\5r,   r   c                     t        t               t               t               t               t               t        ddt        t        d      t        dg d                  t        d	d
g      t        d      t        d      t        d      t        ddg      t               t               t        ddddg            S )zJThis method provide parameter required for the SDS module on
    PowerFlexlistr#   T)required)allsdsOnlysdcOnly)r   choices)r~   r   )typeelementsoptionsrY   r   )r   bool)r   r   CompactHighPerformancerI   presentabsent)r   r   r   )r   r   r[   r   r   r   r   rk   r5   r6   rl   r   r   state)r#    r,   r+   r    r      s     vV#v!V&$&4 2= >3
 #3_"EF&)&)u% )5F)GHvVDuy(6KL) r,   c                       e Zd Zd Zy)SDSExitHandlerc                     |r#|j                  |d         |j                  d<   nd |j                  d<    |j                  j                  di |j                   y )Nr@   rt   r   r   )r   r$   r3   	exit_json)r%   sds_objr   s      r+   handlezSDSExitHandler.handle  sP    ,3,?,?{SWGX,?,YGNN=),0GNN=)   27>>2r,   Nr   r   r   r   r   r,   r+   r   r     s    3r,   r   c                       e Zd Zd Zy)SDSDeleteHandlerc                     |d   dk(  r%|r#|j                  |d         }d|j                  d<   t               j                  ||       y )Nr   r   r@   Tr   )r   r$   r   r   )r%   r   r   r   s       r+   r   zSDSDeleteHandler.handle&  sG    g(*{!,,[->?K(,GNN9%5r,   Nr   r   r,   r+   r   r   %  s    6r,   r   c                       e Zd Zd Zy)SDSRemoveIPHandlerc                     |d   dk(  r[|rYd}|d   dk(  rO|j                  |       |j                  |||d         }|r|j                  |d   |      }|rd|j                  d<   t	               j                  |||       y )	Nr   r   Fr   r   r@   Tr   )r;   r   r   r$   r   r   )r%   r   r   r   r   remove_ip_changedr   s          r+   r   zSDSRemoveIPHandler.handle/  s    g)+ %.)_<--k: ' ? ?[@J>@Z!\ (/(9(9+d:K]([%$04GNN9-!!':{Cr,   Nr   r   r,   r+   r   r   .  s    Dr,   r   c                       e Zd Zd Zy)SDSAddIPHandlerc                 >   |d   dk(  ry|rwd}d}|d   dk(  rX|j                  |       |j                  |||d         \  }}|r|j                  |d   |      }|r|j                  |d   |      }|s|rd|j                  d<   t               j                  ||||       y )	Nr   r   Fr   rY   r@   Tr   )r;   r   r   r   r$   r   r   )	r%   r   r   r   r   add_ip_changedupdate_role_changedr   roles_to_updates	            r+   r   zSDSAddIPHandler.handleA  s    g)+ #N"'.)-==--k:.5.J.Jj.H/J+
O%,^^K4Ez%RN"*1*=*=k$>O>M+O' !4,0y)##GZkRr,   Nr   r   r,   r+   r   r   @  s    Sr,   r   c                       e Zd Zd Zy)SDSModifyHandlerc           	          |d   dk(  rP|rN|j                  ||d   |d   |d   |d   |d         }|r&|j                  |d	   ||
      }d|j                  d<   t               j	                  ||||       y )Nr   r   r[   rk   r5   r6   rl   )r   r[   rk   r5   r6   rl   r@   )r   rm   rz   Tr   )rr   r{   r$   r   r   )r%   r   r   r   rz   r   rm   s          r+   r   zSDSModifyHandler.handleX  s    g)+!++9CN9S<FGX<Y<FGX<Y9CN9S@JK`@a , cK %;;;tCTHSHS < U -1y)  *k;Or,   Nr   r   r,   r+   r   r   W  s    Pr,   r   c                       e Zd Zd Zy)SDSCreateHandlerc                     d}t        j                  |d         }|d   dk(  r?|s=|j                  |d   |d   |d   |||d   |d	   |d
   |	      }d|j                  d<   d}t	               j                  |||||       y )NFr   r   r   r   r   r[   r   r5   r6   )	r   r   r[   r   r   r   r5   r6   r   Tr   )copydeepcopyrd   r$   r   r   )r%   r   r   r   r   r   rz   r   s           r+   r   zSDSCreateHandler.handlej  s    mmJ}$=>g)+K!,,j6L4>x4H:D^:TBV9D:D^:T=GHY=Z:D^:T:F - HK )-GNN9%K!!':{KQ\]r,   Nr   r   r,   r+   r   r   i  s    ^r,   r   c                       e Zd Zd Zy)
SDSHandlerc                    |j                  |d   |d         }|j                  |       d }|d   s|d   r|j                  |d   |d         d   }d }|d   s|d	   rU|j                  |d   |d	   |
      }|4d}t        j                  |       |j                  j                  |       n|d   }t               j                  |||||       y )Nr   r   )r   r   r   )r   r   r@   r   r   rP   zBThe specified Fault set is not in the specified Protection Domain.r/   )
rL   r   rN   rQ   r1   r2   r3   r4   r   r   )r%   r   r   r   r   r   fault_set_detailsr7   s           r+   r   zSDSHandler.handle~  s   --j.DjQYFZ[##z#:#,-<T1U#*#@#@%/0F%G'12J'K $A $MMQ$S  &':n+E ' 5 5ZP`EaCMnC]K_ !6 !a !(`			)$((Y(706!!':{DXZfgr,   Nr   r   r,   r+   r   r   }  s    hr,   r   c                  t    t               } t               j                  | | j                  j                         y)z` Create PowerFlex SDS object and perform action on it
        based on user input from playbook.N)r   r   r   r3   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	   r   
get_loggerr1   r   r    r   r   r   r   r   r   r   r   r   r   r,   r+   <module>r      s    M B BunDL`
D 5 euG5= G5T63 36 6D D$S S.P P$^ ^(h h.0 zF r,   