
    Vh                         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  ej                  d      Z G d	 d
e      Zd Zd Zd Zedk(  r e        yy)zI Ansible module for managing device on Dell Technologies (Dell) PowerFlex    )absolute_importdivisionprint_functionao  
module: device
version_added: '1.1.0'
short_description: Manage device on Dell PowerFlex
description:
- Managing device on PowerFlex storage system includes
  adding new device, getting details of device, and removing a device.
author:
- Rajshree Khare (@khareRajshree) <ansible.team@dell.com>
extends_documentation_fragment:
  - dellemc.powerflex.powerflex
options:
  current_pathname:
    description:
    - Full path of the device to be added.
    - Required while adding a device.
    type: str
  device_name:
    description:
    - Device name.
    - Mutually exclusive with I(device_id).
    type: str
  device_id:
    description:
    - Device ID.
    - Mutually exclusive with I(device_name).
    type: str
  sds_name:
    description:
    - The name of the SDS.
    - Required while adding a device.
    - Mutually exclusive with I(sds_id).
    type: str
  sds_id:
    description:
    - The ID of the SDS.
    - Required while adding a device.
    - Mutually exclusive with I(sds_name).
    type: str
  storage_pool_name:
    description:
    - Storage Pool name.
    - Used while adding a storage device.
    - Mutually exclusive with I(storage_pool_id), I(acceleration_pool_id) and
      I(acceleration_pool_name).
    type: str
  storage_pool_id:
    description:
    - Storage Pool ID.
    - Used while adding a storage device.
    - Media type supported are C(SSD) and C(HDD).
    - Mutually exclusive with I(storage_pool_name), I(acceleration_pool_id) and
      I(acceleration_pool_name).
    type: str
  acceleration_pool_name:
    description:
    - Acceleration Pool Name.
    - Used while adding an acceleration device.
    - Media type supported are C(SSD) and C(NVDIMM).
    - Mutually exclusive with I(storage_pool_id), I(storage_pool_name) and
      I(acceleration_pool_name).
    type: str
  acceleration_pool_id:
    description:
    - Acceleration Pool ID.
    - Used while adding an acceleration device.
    - Media type supported are C(SSD) and C(NVDIMM).
    - Mutually exclusive with I(acceleration_pool_name), I(storage_pool_name) and
      I(storage_pool_id).
    type: str
  protection_domain_name:
    description:
    - Protection domain name.
    - Used while identifying a storage pool along with I(storage_pool_name).
    - Mutually exclusive with I(protection_domain_id).
    type: str
  protection_domain_id:
    description:
    - Protection domain ID.
    - Used while identifying a storage pool along with I(storage_pool_name).
    - Mutually exclusive with I(protection_domain_name).
    type: str
  external_acceleration_type:
    description:
    - Device external acceleration types.
    - Used while adding a device.
    type: str
    choices: ['Invalid', 'None', 'Read', 'Write', 'ReadAndWrite']
  media_type:
    description:
    - Device media types.
    - Required while adding a device.
    type: str
    choices: ['HDD', 'SSD', 'NVDIMM']
  state:
    description:
    - State of the device.
    choices: ['present', 'absent']
    required: true
    type: str
  force:
    description:
    - Using the Force flag to add a device.
    - Use this flag, to overwrite existing data on the device.
    - Use this flag with caution, because all data on the device will be
      destroyed.
    type: bool
    default: false
notes:
  - The value for device_id is generated only after successful addition of the
    device.
  - To uniquely identify a device, either I(device_id) can be passed or one of
    I(current_pathname) or I(device_name) must be passed with I(sds_id) or I(sds_name).
  - It is recommended to install Rfcache driver for SSD device on SDS in
    order to add it to an acceleration pool.
  - The I(check_mode) is not supported.
ac	  
- name: Add a device
  dellemc.powerflex.device:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    current_pathname: "/dev/sdb"
    sds_name: "node1"
    media_type: "HDD"
    device_name: "device2"
    storage_pool_name: "pool1"
    protection_domain_name: "domain1"
    external_acceleration_type: "ReadAndWrite"
    state: "present"
- name: Add a device with force flag
  dellemc.powerflex.device:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    current_pathname: "/dev/sdb"
    sds_name: "node1"
    media_type: "HDD"
    device_name: "device2"
    storage_pool_name: "pool1"
    protection_domain_name: "domain1"
    external_acceleration_type: "ReadAndWrite"
    force: true
    state: "present"
- name: Get device details using device_id
  dellemc.powerflex.device:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    device_id: "d7fe088900000000"
    state: "present"
- name: Get device details using (current_pathname, sds_name)
  dellemc.powerflex.device:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    current_pathname: "/dev/sdb"
    sds_name: "node0"
    state: "present"
- name: Get device details using (current_pathname, sds_id)
  dellemc.powerflex.device:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    current_pathname: "/dev/sdb"
    sds_id: "5717d71800000000"
    state: "present"
- name: Remove a device using device_id
  dellemc.powerflex.device:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    device_id: "76eb7e2f00010000"
    state: "absent"
- name: Remove a device using (current_pathname, sds_id)
  dellemc.powerflex.device:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    current_pathname: "/dev/sdb"
    sds_name: "node1"
    state: "absent"
a  
changed:
    description: Whether or not the resource has changed.
    returned: always
    type: bool
    sample: 'false'
device_details:
    description: Details of the device.
    returned: When device exists
    type: dict
    contains:
        accelerationPoolId:
            description: Acceleration pool ID.
            type: str
        accelerationPoolName:
            description: Acceleration pool name.
            type: str
        accelerationProps:
            description: Indicates acceleration props.
            type: str
        aggregatedState:
            description: Indicates aggregated state.
            type: str
        ataSecurityActive:
            description: Indicates ATA security active state.
            type: bool
        autoDetectMediaType:
            description: Indicates auto detection of media type.
            type: str
        cacheLookAheadActive:
            description: Indicates cache look ahead active state.
            type: bool
        capacity:
            description: Device capacity.
            type: int
        capacityLimitInKb:
            description: Device capacity limit in KB.
            type: int
        deviceCurrentPathName:
            description: Device current path name.
            type: str
        deviceOriginalPathName:
            description: Device original path name.
            type: str
        deviceState:
            description: Indicates device state.
            type: str
        deviceType:
            description: Indicates device type.
            type: str
        errorState:
            description: Indicates error state.
            type: str
        externalAccelerationType:
            description: Indicates external acceleration type.
            type: str
        fglNvdimmMetadataAmortizationX100:
            description: Indicates FGL NVDIMM meta data amortization value.
            type: int
        fglNvdimmWriteCacheSize:
            description: Indicates FGL NVDIMM write cache size.
            type: int
        firmwareVersion:
            description: Indicates firmware version.
            type: str
        id:
            description: Device ID.
            type: str
        ledSetting:
            description: Indicates LED setting.
            type: str
        links:
            description: Device links.
            type: list
            contains:
                href:
                    description: Device instance URL.
                    type: str
                rel:
                    description: Relationship of device with different
                                 entities.
                    type: str
        logicalSectorSizeInBytes:
            description: Logical sector size in bytes.
            type: int
        longSuccessfulIos:
            description: Indicates long successful IOs.
            type: list
        maxCapacityInKb:
            description: Maximum device capacity limit in KB.
            type: int
        mediaFailing:
            description: Indicates media failing.
            type: bool
        mediaType:
            description: Indicates media type.
            type: str
        modelName:
            description: Indicates model name.
            type: str
        name:
            description: Device name.
            type: str
        persistentChecksumState:
            description: Indicates persistent checksum state.
            type: str
        physicalSectorSizeInBytes:
            description: Physical sector size in bytes.
            type: int
        protectionDomainId:
            description: Protection domain ID.
            type: str
        protectionDomainName:
            description: Protection domain name.
            type: str
        raidControllerSerialNumber:
            description: RAID controller serial number.
            type: str
        rfcacheErrorDeviceDoesNotExist:
            description: Indicates RF cache error device does not exist.
            type: bool
        rfcacheProps:
            description: RF cache props.
            type: str
        sdsId:
            description: SDS ID.
            type: str
        sdsName:
            description: SDS name.
            type: str
        serialNumber:
            description: Indicates Serial number.
            type: str
        spSdsId:
            description: Indicates SPs SDS ID.
            type: str
        ssdEndOfLifeState:
            description: Indicates SSD end of life state.
            type: str
        storagePoolId:
            description: Storage Pool ID.
            type: str
        storagePoolName:
            description: Storage Pool name.
            type: str
        storageProps:
            description: Storage props.
            type: list
        temperatureState:
            description: Indicates temperature state.
            type: str
        vendorName:
            description: Indicates vendor name.
            type: str
        writeCacheActive:
            description: Indicates write cache active.
            type: bool
    sample: {
        "accelerationPoolId": null,
        "accelerationProps": null,
        "aggregatedState": "NeverFailed",
        "ataSecurityActive": false,
        "autoDetectMediaType": "SSD",
        "cacheLookAheadActive": false,
        "capacity": 0,
        "capacityLimitInKb": 365772800,
        "deviceCurrentPathName": "/dev/sdb",
        "deviceOriginalPathName": "/dev/sdb",
        "deviceState": "Normal",
        "deviceType": "Unknown",
        "errorState": "None",
        "externalAccelerationType": "None",
        "fglNvdimmMetadataAmortizationX100": 150,
        "fglNvdimmWriteCacheSize": 16,
        "firmwareVersion": null,
        "id": "b6efa59900000000",
        "ledSetting": "Off",
        "links": [
            {
                "href": "/api/instances/Device::b6efa59900000000",
                "rel": "self"
            },
            {
                "href": "/api/instances/Device::b6efa59900000000/relationships
                        /Statistics",
                "rel": "/api/Device/relationship/Statistics"
            },
            {
                "href": "/api/instances/Sds::8f3bb0ce00000000",
                "rel": "/api/parent/relationship/sdsId"
            },
            {
                "href": "/api/instances/StoragePool::e0d8f6c900000000",
                "rel": "/api/parent/relationship/storagePoolId"
            },
            {
                "href": "/api/instances/SpSds::fedf6f2000000000",
                "rel": "/api/parent/relationship/spSdsId"
            }
        ],
        "logicalSectorSizeInBytes": 0,
        "longSuccessfulIos": {
            "longWindow": null,
            "mediumWindow": null,
            "shortWindow": null
        },
        "maxCapacityInKb": 365772800,
        "mediaFailing": false,
        "mediaType": "HDD",
        "modelName": null,
        "name": "device230",
        "persistentChecksumState": "Protected",
        "physicalSectorSizeInBytes": 0,
        "protectionDomainId": "9300c1f900000000",
        "protectionDomainName": "domain1",
        "raidControllerSerialNumber": null,
        "rfcacheErrorDeviceDoesNotExist": false,
        "rfcacheProps": null,
        "sdsId": "8f3bb0ce00000000",
        "sdsName": "node1",
        "serialNumber": null,
        "slotNumber": null,
        "spSdsId": "fedf6f2000000000",
        "ssdEndOfLifeState": "NeverFailed",
        "storagePoolId": "e0d8f6c900000000",
        "storagePoolName": "pool1",
        "storageProps": {
            "destFglAccDeviceId": null,
            "destFglNvdimmSizeMb": 0,
            "fglAccDeviceId": null,
            "fglNvdimmSizeMb": 0
        },
        "temperatureState": "NeverFailed",
        "vendorName": null,
        "writeCacheActive": false
    }
)AnsibleModule)utilsdevicec                       e Zd ZdZd Z	 	 ddZddZ	 	 ddZ	 	 	 ddZ	 	 	 ddZ	d	 Z
d
 Z	 	 	 ddZd Zd Zd Zd Z	 	 	 	 	 	 ddZd Zd Zd Zd Zd Zd Zd Zd Zy)PowerFlexDevicezClass with device operationsc                 n   t        j                         | _        | j                  j                  t	                      ddgddgddgddgd	d
gd
dgd	dgddgddgddgg
}t        | j                  d|      | _        t        j                  | j                         	 t        j                  | j                  j                        | _
        t        j                  d       y# t        $ rM}t        j                  t        |             | j                  j!                  t        |             Y d}~yd}~ww xY w)z. Define all parameters required by this modulesds_namesds_iddevice_name	device_idprotection_domain_nameprotection_domain_idstorage_pool_namestorage_pool_idacceleration_pool_nameacceleration_pool_idcurrent_pathnameF)argument_specsupports_check_modemutually_exclusivez3Got the PowerFlex system connection object instancemsgN)r   %get_powerflex_gateway_host_parametersmodule_paramsupdateget_powerflex_device_parametersr   moduleensure_required_libs%get_powerflex_gateway_host_connectionparamspowerflex_connLOGinfo	Exceptionerrorstr	fail_json)selfmut_ex_argses      l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/powerflex/plugins/modules/device.py__init__zPowerFlexDevice.__init__  s)   "HHJ!!"A"CD"H-%{30.0+->?02HI.0AB02EF#Z0#X.#%78
: $,, %*,
 	""4;;/	."'"M"M""#$DHHJK 	.IIc!fKK!!c!f!--	.s   AC 	D4'AD//D4Nc                    	 |r,|r*| j                   j                  j                  ||d      }nV|r,|r*| j                   j                  j                  ||d      }n(| j                   j                  j                  d|i      }t        |      dk(  rd}t        j                  |       y|d   S # t        $ rI}dt        |      z  }t        j                  |       | j                  j                  |	       Y d}~yd}~ww xY w)
a  Get device details
            :param current_pathname: Device path name
            :type current_pathname: str
            :param sds_id: ID of the SDS
            :type sds_id: str
            :param device_name: Name of the device
            :type device_name: str
            :param device_id: ID of the device
            :type device_id: str
            :return: Details of device if it exist
            :rtype: dict
        )deviceCurrentPathNamesdsIdfilter_fields)namer2   idr   zDevice not foundNz(Failed to get the device with error '%s'r   )r$   r   getlenr%   r&   r'   r)   r(   r    r*   )	r+   r   r   r   r   device_detailsr   r-   	error_msgs	            r.   get_device_detailsz"PowerFlexDevice.get_device_details  s   	1F!%!4!4!;!;!?!?<L,2#4 "@ "5 !%!4!4!;!;!?!?+6,2#4 "@ "5 "&!4!4!;!;!?!?#'"3 "@ "5 >"a'(!!$$ 	1BSVKIIIi KK!!i!00	1s   B)B1 ,B1 1	D:?C>>Dc                    |r|n|}	 d}|r(| j                   j                  j                  d|i      }|r(| j                   j                  j                  d|i      }|s6d|z  }t        j	                  |       | j
                  j                  |       |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
            :param sds_id: ID of the SDS
            :return: SDS details
            :rtype: dict
        Nr6   r3   r5   zCUnable to find the SDS with '%s'. Please enter a valid SDS name/id.r   r   zFailed to get the SDS '' with error '')	r$   sdsr7   r%   r(   r    r*   r'   r)   )r+   r   r   
name_or_idsds_detailsr:   r-   s          r.   get_sdszPowerFlexDevice.get_sds  s      &V8
	1K"115599#'. : 2 "115599#)8"4 : 6 9;EF			)$%%)%4q>! 	1%s1v/IIIi KK!!i!00		1   BB 	C1$AC,,C1c                    |r|n|}	 d}|r(| j                   j                  j                  d|i      }|r(| j                   j                  j                  d|i      }|s6d|z  }t        j	                  |       | j
                  j                  |       |d   S # t        $ rM}d|d	t        |      d
}t        j	                  |       | j
                  j                  |       Y d}~yd}~ww xY w)zGet protection domain details
            :param protection_domain_name: Name of the protection domain
            :param protection_domain_id: ID of the protection domain
            :return: Protection domain details
            :rtype: dict
        Nr6   r3   r5   z_Unable to find the protection domain with '%s'. Please enter a valid protection domain name/id.r   r   z%Failed to get the protection domain 'r=   r>   )	r$   protection_domainr7   r%   r(   r    r*   r'   r)   )r+   r   r   r@   
pd_detailsr:   r-   s          r.   get_protection_domainz%PowerFlexDevice.get_protection_domain5  s    .B)' 		1J#!00BBFF#')="> G @
 &!00BBFF#)+A"B G D
 ')34	 		)$%%)%4a=  	1(2CF<IIIi KK!!i!00		1rC   c                    |r|n|}	 d}|r(| j                   j                  j                  d|i      }|r)| j                   j                  j                  ||d      }|s6d|z  }t        j	                  |       | j
                  j                  |       |d   S # t        $ rM}d|d	t        |      d
}t        j	                  |       | j
                  j                  |       Y d}~yd}~ww xY w)a#  Get storage pool details
            :param storage_pool_name: Name of the storage pool
            :param storage_pool_id: ID of the storage pool
            :param protection_domain_id: ID of the protection domain
            :return: Storage pool details
            :rtype: dict
        Nr6   r3   r5   protectionDomainIdzUUnable to find the storage pool with '%s'. Please enter a valid storage pool name/id.r   r   z Failed to get the storage_pool 'r=   r>   )	r$   storage_poolr7   r%   r(   r    r*   r'   r)   )r+   r   r   r   r@   storage_pool_detailsr:   r-   s           r.   get_storage_poolz PowerFlexDevice.get_storage_poolX  s    )8_=N
	1#' '+':':'G'G'K'K#'"9 (L (;$ !'+':':'G'G'K'K+<9M#O (L ($
 (')34	 		)$%%)%4'** 	1(2CF<IIIi KK!!i!00		1   BB 	C2%AC--C2c                    |r|n|}	 d}|r(| j                   j                  j                  d|i      }|r)| j                   j                  j                  ||d      }|s6d|z  }t        j	                  |       | j
                  j                  |       |d   S # t        $ rM}d|d	t        |      d
}t        j	                  |       | j
                  j                  |       Y d}~yd}~ww xY w)aA  Get acceleration pool details
            :param acceleration_pool_name: Name of the acceleration pool
            :param acceleration_pool_id: ID of the acceleration pool
            :param protection_domain_id: ID of the protection domain
            :return: Acceleration pool details
            :rtype: dict
        Nr6   r3   rI   z_Unable to find the acceleration pool with '%s'. Please enter a valid acceleration pool name/id.r   r   z%Failed to get the acceleration pool 'r=   r>   )	r$   acceleration_poolr7   r%   r(   r    r*   r'   r)   )r+   r   r   r   r@   acceleration_pool_detailsr:   r-   s           r.   get_acceleration_poolz%PowerFlexDevice.get_acceleration_pool~  s    $ *)? 		1(,%#,0,?,?%%cc294c '5 * &,0,?,?%%cc 6.B9Dc 'E *
 -')34	 		)$%%)%4,Q// 	1(2CF<IIIi KK!!i!00		1rN   c                    	 |t        |j                               dk(  r3d}t        j                  |       | j                  j                  |       |t        |j                               dk(  r3d}t        j                  |       | j                  j                  |       |t        |j                               dk(  r3d}t        j                  |       | j                  j                  |       |5|3d}t        j                  |       | j                  j                  |       d|d	|d
|d|d|d|d|d}	t        j                  d|	       | j                  j                  j                  |||||||| j                  j                  d          y# t        $ rM}
d|dt        |
      d}t        j                  |       | j                  j                  |       Y d}
~
yd}
~
ww xY w)a  Add device
            :param device_name: Device name
            :type device_name: str
            :param current_pathname: Current pathname of device
            :type current_pathname: str
            :param sds_id: SDS ID
            :type sds_id: str
            :param storage_pool_id: Storage Pool ID
            :type storage_pool_id: str
            :param media_type: Media type of device
            :type media_type: str
            :param acceleration_pool_id: Acceleration pool ID
            :type acceleration_pool_id: str
            :param external_acceleration_type: External acceleration type
            :type external_acceleration_type: str
            return: Boolean indicating if add device operation is successful
        Nr   z;Please provide valid device_name value for adding a device.r   zdCurrent pathname of device is a mandatory parameter for adding a device. Please enter a valid value.z6Please provide valid sds_id value for adding a device.z\Please provide either storage pool name/ID or acceleration pool name/ID for adding a device.zcurrent_pathname: z
, sds_id: z, acceleration_pool_id: z,external_acceleration_type: z,media_type: z,device_name: z,storage_pool_id: ,zAdding device with params: %sforce)r   r   r   external_acceleration_type
media_typer5   r   rU   TzAdding device z operation failed with error 'r>   )r8   stripr%   r(   r    r*   r&   r$   r   creater#   r'   r)   )r+   r   r   r   r   rW   r   rV   r:   
add_paramsr-   s              r.   
add_devicezPowerFlexDevice.add_device  s   (6	1"c+*;*;*=&>!&C/			)$%%)%4'3/?/E/E/G+HA+M+	 		)$%%)%4~V\\^!4!93			)$%%)%4&+?+G&	 		)$%%)%4 .v17'(,.J HH4jA&&--!14H+E%K /kk((1 . 3  	1(3SV=IIIi KK!!i!00		1s   FF 	G5(AG00G5c                 0   	 t         j                  d|       | j                  j                  j	                  |       y# t
        $ rM}d|dt        |      d}t         j                  |       | j                  j                  |       Y d}~yd}~ww xY w)	zRemove device
            :param device_id: Device ID
            :type device_id: str
            return: Boolean indicating if remove device operation is
                    successful
        zDevice to be removed: %s)r   TzRemove device 'z' operation failed with error 'r>   r   N)
r%   r&   r$   r   deleter'   r)   r(   r    r*   )r+   r   r-   r:   s       r.   remove_devicezPowerFlexDevice.remove_device  sz    	1HH/;&&--	-B 	1(13q6;IIIi KK!!i!00		1s   <? 	BABBc                    | j                  |||       | j                  |||       | j                  |||       | j                  |||       |Ot	        |j                               dk(  r3d}t        j                  |       | j                  j                  |       |:|7|4d}t        j                  |       | j                  j                  |       yyyy)zValidate the input parametersNr   z:Please provide valid device_id value to identify a device.r   zBPlease specify a valid parameter combination to identify a device.)
validate_current_pathnamevalidate_device_namevalidate_sds_namevalidate_sds_idr8   rX   r%   r(   r    r*   )r+   r   r   r   r   r   r:   s          r.   validate_input_parametersz)PowerFlexDevice.validate_input_parameters  s     	&&'76J!!+x@{,<hG[*:FC S):%;q%@$IIIi KK!!i!0#(;%-IIIi KK!!i!0	 & )<#    c                    |rr|t        |j                               dk(  rS|t        |j                               dk(  r4d}t        j                  |       | j                  j                  |       y y y |Qt        |j                               dk(  r4d}t        j                  |       | j                  j                  |       y y y )Nr   z[current_pathname or device_name is mandatory along with sds_id. Please enter a valid value.r   z&Please enter a valid value for sds_id.r8   rX   r%   r(   r    r*   )r+   r   r   r   r:   s        r.   rc   zPowerFlexDevice.validate_sds_id$  s     ('--/0A5$, 1 1 349M			)$%%)%4	 : 6 C$71$<@IIIi KK!!i!0 %=re   c                    |rr|t        |j                               dk(  rS|t        |j                               dk(  r4d}t        j                  |       | j                  j                  |       y y y |Qt        |j                               dk(  r4d}t        j                  |       | j                  j                  |       y y y )Nr   z]current_pathname or device_name is mandatory along with sds_name. Please enter a valid value.r   z(Please enter a valid value for sds_name.rg   )r+   r   r   r   r:   s        r.   rb   z!PowerFlexDevice.validate_sds_name3  s     ('--/0A5$, 1 1 349O			)$%%)%4	 : 6 !c(..*:&;q&@BIIIi KK!!i!0 'A!re   c                    |rr|t        |j                               dk(  rS|t        |j                               dk(  r4d}t        j                  |       | j                  j                  |       y y y |Qt        |j                               dk(  r4d}t        j                  |       | j                  j                  |       y y y )Nr   zSsds_name or sds_id is mandatory along with device_name. Please enter a valid value.r   z+Please enter a valid value for device_name.rg   )r+   r   r   r   r:   s        r.   ra   z$PowerFlexDevice.validate_device_nameB  s     C(8$9Q$>3v||~+>!+CG			)$%%)%4	 ,D %? $[->->-@)AQ)FEIIIi KK!!i!0 *G$re   c                    |rr|t        |j                               dk(  rS|t        |j                               dk(  r4d}t        j                  |       | j                  j                  |       y y y |Qt        |j                               dk(  r4d}t        j                  |       | j                  j                  |       y y y )Nr   zXsds_name or sds_id is mandatory along with current_pathname. Please enter a valid value.r   z0Please enter a valid value for current_pathname.rg   )r+   r   r   r   r:   s        r.   r`   z)PowerFlexDevice.validate_current_pathnameO  s     C(8$9Q$>3v||~+>!+CL			)$%%)%4	 ,D %? )(..01Q6JIIIi KK!!i!0 7 *re   c                     |r3d}t         j                  |       | j                  j                  |       |r@|=|:|7|4d}t         j	                  |       | j                  j                  |       yyyyyy)z"Validate the add device parameterszFAddition of device is allowed using device_name only, device_id given.r   NzeStorage Pool ID/name or Acceleration Pool ID/name is mandatory along with external_acceleration_type.)r%   r&   r    r*   r(   )r+   r   rV   r   r   r   r   r:   s           r.   validate_add_parametersz'PowerFlexDevice.validate_add_parameters]  s     =IHHYKK!!i!0%/*A%-(0*26I IIi KK!!i!0 3 1 . +B%re   c                    | j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d	   }	| j                   j                  d
   }
| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }t        di       }| j                  |||||       |r| j	                  |      }| j                  ||||      }|r|d   }dt        |      z  }t        j                  |       d}|dk(  rV|rt        |||      }| j                  |       n| j                  ||||||||	||
||      \  }}| j                  |      }||d<   d}|dk(  r|r| j                  |      }|xs ||d<    | j                   j                  di | y)zh
        Perform different actions on device based on parameters passed in
        the playbook
        r   r   r   r   r   r   r   r   r   r   r   rV   rW   stateF)changedr9   r6   zFetched the device details %spresentr9   absentro   N )r    r#   dictrd   
get_sds_idr;   r)   r%   r&   	to_modify
can_modifycreate_deviceshow_outputr^   	exit_json)r+   r   r   r   r   r   r   r   r   r   r   r   rV   rW   rn   resultr9   r   add_changedmodify_dictremove_changeds                        r.   perform_module_operationz(PowerFlexDevice.perform_module_operationt  s   
  ;;--.@Akk((7KK&&{3	;;%%j1##H- KK../BC++,,->?#{{112HI!%!3!34L!M!%!3!34L!M#{{112HI%)[[%7%7(&*"[[''5
""7+ 
 	&&{I'76	K __X.F 001A171:< &t,I-^1DE I'
(BD,
 *.););$k9f#%68L*,@*,F* &	; "--i8N'5F#$ H!//	:N (9>y''re   c           	      \   |
r|s|r| j                  |
      }	|r| j                  ||	      }|r| j                  ||	      }| j                  ||||||       | j	                  |||||||      }|r;| j                  ||      }|d   }dt        |      z  }t        j                  |       ||fS )N)r   r   r6   z6Device created successfully, fetched device details %s)	get_protection_domain_idget_storage_pool_idget_acceleration_pool_idrl   r[   r;   r)   r%   r&   )r+   r   r   r   r   r   r   r   r   r   r   rV   rW   r{   r9   r   s                   r.   rw   zPowerFlexDevice.create_device  s    
 "&*@#'#@#@&$(  "66!#79O "#'#@#@&(<$>  	$$Y%?%4%6%9%;	= ook3C&,oz&:&@B !44' 5 8N&t,IN+-CHHSM+%%re   c                 p    |r4d}t         j                  |       | j                  j                  |       y y )NzPModification of device attributes is currently not supported by Ansible modules.r   )r%   r&   r    r*   )r+   r|   r:   s      r.   rv   zPowerFlexDevice.can_modify  s2    >IHHYKK!!i!0	 re   c                     |r:| j                  ||      }|r|d   }dd|d}t        j                  |       |S d}t        j                  |       | j                  j	                  |       S )N)r   r   r6   z/Fetched the acceleration pool details with id '	', name 'r>   zuProtection domain name/id is required to uniquely identify a acceleration pool, only acceleration_pool_name is given.r   )rR   r%   r&   r    r*   )r+   r   r   rQ   r   r   r:   s          r.   r   z(PowerFlexDevice.get_acceleration_pool_id  s    (,(B(B'=%9 )C );% )'@'F$%9%;=C HHSM $#8I HHYKK!!i!0##re   c                     |r:| j                  ||      }|r|d   }dd|d}t        j                  |       |S d}t        j                  |       | j                  j	                  |       S )N)r   r   r6   z*Fetched the storage pool details with id 'r   r>   zkProtection domain name/id is required to uniquely identify a storage pool, only storage_pool_name is given.r   )rM   r%   r&   r    r*   )r+   r   r   rL   r   r   r:   s          r.   r   z#PowerFlexDevice.get_storage_pool_id  s    #'#8#8"3%9 $9 $;  $"6t"<.0ACCHHSM .I HHYKK!!i!0re   c                 r    | j                  |      }|r|d   }dd|d}t        j                  |       |S )Nr6   z/Fetched the protection domain details with id 'r   r>   )rG   r%   r&   )r+   r   rF   r   r   s        r.   r   z(PowerFlexDevice.get_protection_domain_id  sD    //"$
#-d#3 !5!79 	##re   c                 r    | j                  |      }|r|d   }dd|d}t        j                  |       |S )Nr6   z!Fetched the SDS details with id 'r   r>   )rB   r%   r&   )r+   r   rA   r   r   s        r.   rt   zPowerFlexDevice.get_sds_id  s:    ll8, &Fx!re   c                 6   	 | 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 rU|d   d
   rM| j                  |d   d
         }|d   |d   d<   |d   }||d   d<   | j                  |      }|d   |d   d<   d|d   v rU|d   d   rM| j                  |d   d         }|d   |d   d<   |d   }||d   d<   | j                  |      }|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 device details
            :param device_id: ID of the device
            :type device_id: str
            :return: Details of device
            :rtype: dict
        r6   r3   r   z%Device with identifier '%s' not foundNr2   )r   r5   sdsNamestoragePoolId)r   storagePoolNamerJ   )r   protectionDomainNameaccelerationPoolId)r   accelerationPoolNamezFailed to get the device 'r=   r>   r   )r$   r   r7   r8   r%   r(   rB   rM   rG   rR   r'   r)   r    r*   )r+   r   r9   r   rA   
sp_detailspd_idrF   
ap_detailsr-   r:   s              r.   rx   zPowerFlexDevice.show_output(  s-   .	1!0077;;#Y/ < 1N >"a'=	I		# .++q0A'0J"ll.2CG2LlM/:6/Bq!), ."33&q)/:!22$21$5o$F 3 H
7A&7Iq!"34"#78:?q!"67!77). 8 0
<Fv<Nq!"89 $~a'88&q)*>?!77)7):,*. 8 /
 =Gv<Nq!"89"#78:?q!"67!77). 8 0
<Fv<Nq!"89!!$$ 	1$c!f.IIIi KK!!i!00		1s    AE C.E 	FAFF)NNNN)NN)NNN)NNNNN)NNNNNN)__name__
__module____qualname____doc__r/   r;   rB   rG   rM   rR   r[   r^   rd   rc   rb   ra   r`   rl   r~   rw   rv   r   r   r   rt   rx   rr   re   r.   r
   r
     s    &.B @D7;&1P1@ <@37!1F 26)-.2$1L <@3737&1PJ1X1" EIBF)-1B1111 15;?0426597;1.J(X&&P1$&$	$61re   r
   c                     i }|| d   |k7  r||d<   || d   |k7  r||d<   t        |      dk7  rt        j                  d|       |S )z)Identify device attributes to be modified	mediaTypeexternalAccelerationTyper   zAttributes to be modified: %s)r8   r%   r&   )r9   rW   rV   r|   s       r.   ru   ru   a  sq     K;':5#-K !-56)* ) 	./ ;10+>re   c                  H   t        t               t               t               t               t               t               t               t               t               t               t               t        g d      t        g d      t        ddddg      t        d	d
            S )zMThis method provide parameter required for the device module on
    PowerFlex)InvalidNoneReadWriteReadAndWrite)choices)HDDSSDNVDIMMTr)   rp   rq   )requiredtyper   boolF)r   default)r   r   r   r   r   r   r   r   r   r   r   rV   rW   rn   rU   )rs   rr   re   r.   r   r   u  sr     TVtv$&TV#vdf!VHAJ 89Duy(6KL.
 
re   c                  8    t               } | j                          y)zc Create PowerFlex device object and perform actions on it
        based on user input from playbookN)r
   r~   )objs    r.   mainr     s     
C  "re   __main__N)r   
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Gansible_collections.dellemc.powerflex.plugins.module_utils.storage.dellr   
get_loggerr%   objectr
   ru   r   r   r   rr   re   r.   <module>r      s    P B BtlPdl
\ 5 ex U
1f U
1p( # zF re   