
    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 ddlZ ej                  d	      Z G d
 de      Zd Zd Zd Zd Zd Zd Zd Zedk(  r e        yy)zJ Ansible module for managing volumes on Dell Technologies (Dell) PowerFlex    )absolute_importdivisionprint_functiona  
module: volume
version_added: '1.0.0'
short_description: Manage volumes on Dell PowerFlex
description:
- Managing volumes on PowerFlex storage system includes
  creating, getting details, modifying attributes and deleting volume.
- It also includes adding/removing snapshot policy,
  mapping/unmapping volume to/from SDC and listing
  associated snapshots.
author:
- P Srinivas Rao (@srinivas-rao5) <ansible.team@dell.com>
extends_documentation_fragment:
  - dellemc.powerflex.powerflex
options:
  vol_name:
    description:
    - The name of the volume.
    - Mandatory for create operation.
    - It is unique across the PowerFlex array.
    - Mutually exclusive with I(vol_id).
    type: str
  vol_id:
    description:
    - The ID of the volume.
    - Except create operation, all other operations can be performed
      using I(vol_id).
    - Mutually exclusive with I(vol_name).
    type: str
  storage_pool_name:
    description:
    - The name of the storage pool.
    - Either name or the id of the storage pool is required for creating a
      volume.
    - During creation, if storage pool name is provided then either
      protection domain name or id must be mentioned along with it.
    - Mutually exclusive with I(storage_pool_id).
    type: str
  storage_pool_id:
    description:
    - The ID of the storage pool.
    - Either name or the id of the storage pool is required for creating
      a volume.
    - Mutually exclusive with I(storage_pool_name).
    type: str
  protection_domain_name:
    description:
    - The name of the protection domain.
    - During creation of a volume, if more than one storage pool exists with
      the same name then either protection domain name or id must be
      mentioned along with it.
    - Mutually exclusive with I(protection_domain_id).
    type: str
  protection_domain_id:
    description:
    - The ID of the protection domain.
    - During creation of a volume, if more than one storage pool exists with
      the same name then either protection domain name or id must be
      mentioned along with it.
    - Mutually exclusive with I(protection_domain_name).
    type: str
  vol_type:
    description:
    - Type of volume provisioning.
    choices: ["THICK_PROVISIONED", "THIN_PROVISIONED"]
    type: str
  compression_type:
    description:
    - Type of the compression method.
    choices: ["NORMAL", "NONE"]
    type: str
  use_rmcache:
    description:
    - Whether to use RM Cache or not.
    type: bool
  snapshot_policy_name:
    description:
    - Name of the snapshot policy.
    - To remove/detach snapshot policy, empty
      I(snapshot_policy_id)/I(snapshot_policy_name) is to be passed along with
      I(auto_snap_remove_type).
    type: str
  snapshot_policy_id:
    description:
    - ID of the snapshot policy.
    - To remove/detach snapshot policy, empty
      I(snapshot_policy_id)/I(snapshot_policy_name) is to be passed along with
      I(auto_snap_remove_type).
    type: str
  auto_snap_remove_type:
    description:
    - Whether to remove or detach the snapshot policy.
    - To remove/detach snapshot policy, empty
      I(snapshot_policy_id)/I(snapshot_policy_name) is to be passed along with
      I(auto_snap_remove_type).
    - If the snapshot policy name/id is passed empty then
      I(auto_snap_remove_type) is defaulted to C(detach).
    choices: ['remove', 'detach']
    type: str
  size:
    description:
    - The size of the volume.
    - Size of the volume will be assigned as higher multiple of 8 GB.
    type: int
  cap_unit:
    description:
     - The unit of the volume size. It defaults to 'GB'.
    choices: ['GB' , 'TB']
    type: str
  vol_new_name:
    description:
    - New name of the volume. Used to rename the volume.
    type: str
  allow_multiple_mappings:
    description:
    - Specifies whether to allow or not allow multiple mappings.
    - If the volume is mapped to one SDC then for every new mapping
      I(allow_multiple_mappings) has to be passed as true.
    type: bool
  sdc:
    description:
    - Specifies SDC parameters.
    type: list
    elements: dict
    suboptions:
      sdc_name:
        description:
        - Name of the SDC.
        - Specify either I(sdc_name), I(sdc_id) or I(sdc_ip).
        - Mutually exclusive with I(sdc_id) and I(sdc_ip).
        type: str
      sdc_id:
        description:
        - ID of the SDC.
        - Specify either I(sdc_name), I(sdc_id) or I(sdc_ip).
        - Mutually exclusive with I(sdc_name) and I(sdc_ip).
        type: str
      sdc_ip:
        description:
        - IP of the SDC.
        - Specify either I(sdc_name), I(sdc_id) or I(sdc_ip).
        - Mutually exclusive with I(sdc_id) and I(sdc_ip).
        type: str
      access_mode:
        description:
        - Define the access mode for all mappings of the volume.
        choices: ['READ_WRITE', 'READ_ONLY', 'NO_ACCESS']
        type: str
      bandwidth_limit:
        description:
        - Limit of volume network bandwidth.
        - Need to mention in multiple of 1024 Kbps.
        - To set no limit, 0 is to be passed.
        type: int
      iops_limit:
        description:
        - Limit of volume IOPS.
        - Minimum IOPS limit is 11 and specify 0 for unlimited iops.
        type: int
  sdc_state:
    description:
    - Mapping state of the SDC.
    choices: ['mapped', 'unmapped']
    type: str
  delete_snapshots:
    description:
    - If C(true), the volume and all its dependent snapshots will be deleted.
    - If C(false), only the volume will be deleted.
    - It can be specified only when the I(state) is C(absent).
    - It defaults to C(false), if not specified.
    type: bool
  state:
    description:
    - State of the volume.
    choices: ['present', 'absent']
    required: true
    type: str
notes:
  - The I(check_mode) is not supported.
a  
- name: Create a volume
  dellemc.powerflex.volume:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    vol_name: "sample_volume"
    storage_pool_name: "pool_1"
    protection_domain_name: "pd_1"
    vol_type: "THICK_PROVISIONED"
    compression_type: "NORMAL"
    use_rmcache: true
    size: 16
    state: "present"

- name: Map a SDC to volume
  dellemc.powerflex.volume:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    vol_name: "sample_volume"
    allow_multiple_mappings: true
    sdc:
      - sdc_id: "92A304DB-EFD7-44DF-A07E-D78134CC9764"
        access_mode: "READ_WRITE"
    sdc_state: "mapped"
    state: "present"

- name: Unmap a SDC to volume
  dellemc.powerflex.volume:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    vol_name: "sample_volume"
    sdc:
      - sdc_id: "92A304DB-EFD7-44DF-A07E-D78134CC9764"
    sdc_state: "unmapped"
    state: "present"

- name: Map multiple SDCs to a volume
  dellemc.powerflex.volume:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    vol_name: "sample_volume"
    protection_domain_name: "pd_1"
    sdc:
      - sdc_id: "92A304DB-EFD7-44DF-A07E-D78134CC9764"
        access_mode: "READ_WRITE"
        bandwidth_limit: 2048
        iops_limit: 20
      - sdc_ip: "198.10.xxx.xxx"
        access_mode: "READ_ONLY"
    allow_multiple_mappings: true
    sdc_state: "mapped"
    state: "present"

- name: Get the details of the volume
  dellemc.powerflex.volume:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    vol_id: "fe6c8b7100000005"
    state: "present"

- name: Modify the details of the Volume
  dellemc.powerflex.volume:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    vol_name: "sample_volume"
    storage_pool_name: "pool_1"
    new_vol_name: "new_sample_volume"
    size: 64
    state: "present"

- name: Delete the Volume
  dellemc.powerflex.volume:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    vol_name: "sample_volume"
    delete_snapshots: false
    state: "absent"

- name: Delete the Volume and all its dependent snapshots
  dellemc.powerflex.volume:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    vol_name: "sample_volume"
    delete_snapshots: true
    state: "absent"
a!  
changed:
    description: Whether or not the resource has changed.
    returned: always
    type: bool
    sample: 'false'
volume_details:
    description: Details of the volume.
    returned: When volume exists
    type: dict
    contains:
        id:
            description: The ID of the volume.
            type: str
        mappedSdcInfo:
            description: The details of the mapped SDC.
            type: dict
            contains:
                sdcId:
                    description: ID of the SDC.
                    type: str
                sdcName:
                    description: Name of the SDC.
                    type: str
                sdcIp:
                    description: IP of the SDC.
                    type: str
                accessMode:
                    description: Mapping access mode for the specified volume.
                    type: str
                limitIops:
                    description: IOPS limit for the SDC.
                    type: int
                limitBwInMbps:
                    description: Bandwidth limit for the SDC.
                    type: int
        name:
            description: Name of the volume.
            type: str
        sizeInKb:
            description: Size of the volume in Kb.
            type: int
        sizeInGb:
            description: Size of the volume in Gb.
            type: int
        storagePoolId:
            description: ID of the storage pool in which volume resides.
            type: str
        storagePoolName:
            description: Name of the storage pool in which volume resides.
            type: str
        protectionDomainId:
            description: ID of the protection domain in which volume resides.
            type: str
        protectionDomainName:
            description: Name of the protection domain in which volume resides.
            type: str
        snapshotPolicyId:
            description: ID of the snapshot policy associated with volume.
            type: str
        snapshotPolicyName:
            description: Name of the snapshot policy associated with volume.
            type: str
        snapshotsList:
            description: List of snapshots associated with the volume.
            type: str
        "statistics":
            description: Statistics details of the storage pool.
            type: dict
            contains:
                "numOfChildVolumes":
                    description: Number of child volumes.
                    type: int
                "numOfMappedSdcs":
                    description: Number of mapped Sdcs of the volume.
                    type: int
    sample: {
        "accessModeLimit": "ReadWrite",
        "ancestorVolumeId": null,
        "autoSnapshotGroupId": null,
        "compressionMethod": "Invalid",
        "consistencyGroupId": null,
        "creationTime": 1631618520,
        "dataLayout": "MediumGranularity",
        "id": "cdd883cf00000002",
        "links": [
            {
                "href": "/api/instances/Volume::cdd883cf00000002",
                "rel": "self"
            },
            {
                "href": "/api/instances/Volume::cdd883cf00000002/relationships
                        /Statistics",
                "rel": "/api/Volume/relationship/Statistics"
            },
            {
                "href": "/api/instances/VTree::6e86255c00000001",
                "rel": "/api/parent/relationship/vtreeId"
            },
            {
                "href": "/api/instances/StoragePool::e0d8f6c900000000",
                "rel": "/api/parent/relationship/storagePoolId"
            }
        ],
        "lockedAutoSnapshot": false,
        "lockedAutoSnapshotMarkedForRemoval": false,
        "managedBy": "ScaleIO",
        "mappedSdcInfo": null,
        "name": "ansible-volume-1",
        "notGenuineSnapshot": false,
        "originalExpiryTime": 0,
        "pairIds": null,
        "protectionDomainId": "9300c1f900000000",
        "protectionDomainName": "domain1",
        "replicationJournalVolume": false,
        "replicationTimeStamp": 0,
        "retentionLevels": [],
        "secureSnapshotExpTime": 0,
        "sizeInGB": 16,
        "sizeInKb": 16777216,
        "snapshotPolicyId": null,
        "snapshotPolicyName": null,
        "snapshotsList": [
            {
                "accessModeLimit": "ReadOnly",
                "ancestorVolumeId": "cdd883cf00000002",
                "autoSnapshotGroupId": null,
                "compressionMethod": "Invalid",
                "consistencyGroupId": "22f1e80c00000001",
                "creationTime": 1631619229,
                "dataLayout": "MediumGranularity",
                "id": "cdd883d000000004",
                "links": [
                    {
                        "href": "/api/instances/Volume::cdd883d000000004",
                        "rel": "self"
                    },
                    {
                        "href": "/api/instances/Volume::cdd883d000000004
                                /relationships/Statistics",
                        "rel": "/api/Volume/relationship/Statistics"
                    },
                    {
                        "href": "/api/instances/Volume::cdd883cf00000002",
                        "rel": "/api/parent/relationship/ancestorVolumeId"
                    },
                    {
                        "href": "/api/instances/VTree::6e86255c00000001",
                        "rel": "/api/parent/relationship/vtreeId"
                    },
                    {
                        "href": "/api/instances/StoragePool::e0d8f6c900000000",
                        "rel": "/api/parent/relationship/storagePoolId"
                    }
                ],
                "lockedAutoSnapshot": false,
                "lockedAutoSnapshotMarkedForRemoval": false,
                "managedBy": "ScaleIO",
                "mappedSdcInfo": null,
                "name": "ansible_vol_snap_1",
                "notGenuineSnapshot": false,
                "originalExpiryTime": 0,
                "pairIds": null,
                "replicationJournalVolume": false,
                "replicationTimeStamp": 0,
                "retentionLevels": [],
                "secureSnapshotExpTime": 0,
                "sizeInKb": 16777216,
                "snplIdOfAutoSnapshot": null,
                "snplIdOfSourceVolume": null,
                "storagePoolId": "e0d8f6c900000000",
                "timeStampIsAccurate": false,
                "useRmcache": false,
                "volumeReplicationState": "UnmarkedForReplication",
                "volumeType": "Snapshot",
                "vtreeId": "6e86255c00000001"
            }
        ],
        "statistics": {
            "childVolumeIds": [
            ],
            "descendantVolumeIds": [
            ],
            "initiatorSdcId": null,
            "mappedSdcIds": [
            "c42425XXXXXX"
            ],
            "numOfChildVolumes": 0,
            "numOfDescendantVolumes": 0,
            "numOfMappedSdcs": 1,
            "registrationKey": null,
            "registrationKeys": [
            ],
            "replicationJournalVolume": false,
            "replicationState": "UnmarkedForReplication",
            "reservationType": "NotReserved",
            "rplTotalJournalCap": 0,
            "rplUsedJournalCap": 0,
            "userDataReadBwc": {
                "numOccured": 0,
                "numSeconds": 0,
                "totalWeightInKb": 0
            },
            "userDataSdcReadLatency": {
                "numOccured": 0,
                "numSeconds": 0,
                "totalWeightInKb": 0
            },
            "userDataSdcTrimLatency": {
                "numOccured": 0,
                "numSeconds": 0,
                "totalWeightInKb": 0
            },
            "userDataSdcWriteLatency": {
                "numOccured": 0,
                "numSeconds": 0,
                "totalWeightInKb": 0
            },
            "userDataTrimBwc": {
                "numOccured": 0,
                "numSeconds": 0,
                "totalWeightInKb": 0
            },
            "userDataWriteBwc": {
                "numOccured": 0,
                "numSeconds": 0,
                "totalWeightInKb": 0
            }
        },
        "snplIdOfAutoSnapshot": null,
        "snplIdOfSourceVolume": null,
        "storagePoolId": "e0d8f6c900000000",
        "storagePoolName": "pool1",
        "timeStampIsAccurate": false,
        "useRmcache": false,
        "volumeReplicationState": "UnmarkedForReplication",
        "volumeType": "ThinProvisioned",
        "vtreeId": "6e86255c00000001"
    }
)AnsibleModule)utilsNvolumec                      e Zd ZdZd Z	 	 d(dZd(dZ	 	 d)dZd(dZd)dZ		 	 d)d	Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z(y)*PowerFlexVolumezClass with volume operationsc           	      z   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g}d	d
g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vol_namevol_idstorage_pool_namestorage_pool_idprotection_domain_nameprotection_domain_idsnapshot_policy_namesnapshot_policy_idsdc	sdc_stateF)argument_specsupports_check_modemutually_exclusiverequired_togetherrequired_one_ofz3Got the PowerFlex system connection object instancemsgN)r   %get_powerflex_gateway_host_parametersmodule_paramsupdateget_powerflex_volume_parametersr   moduleensure_required_libs%get_powerflex_gateway_host_connectionparamspowerflex_connLOGinfo	Exceptionerrorstr	fail_json)selfmut_ex_argsrequired_together_argsrequired_one_of_argses        l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/powerflex/plugins/modules/volume.py__init__zPowerFlexVolume.__init__,  s<   "HHJ!!"A"CD"H-+->?02HI.0DE "56 "34 ":; "89; $)+"6!7!+X 67 $,, %*402 	""4;;/	."'"M"M""#$DHHJK 	.IIc!fKK!!c!f!--	.s    AC$ $	D:-AD55D:Nc                    |r|n|}	 d}|r(| j                   j                  j                  d|i      }|r(| j                   j                  j                  d|i      }|s-dj                  |      }| j                  j                  |       |d   S # t        $ rV}dj                  |t        |            }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
        Nidfilter_fieldsnamez^Unable to find the protection domain with {0}. Please enter a valid protection domain name/id.r   r   z6Failed to get the protection domain {0} with error {1})
r%   protection_domaingetformatr!   r+   r(   r*   r&   r)   )r,   r   r   
name_or_id
pd_detailserr_msgr0   errormsgs           r1   get_protection_domainz%PowerFlexVolume.get_protection_domainP  s    .B)' 		0J#!00BBFF#')="> G @
 &!00BBFF#)+A"B G D
 &&,fZ&8  %%'%2a=  	0$$*F:s1v$> IIhKK!!h!//		0   B	B 	C1AC,,C1c                    |r|n|}	 d}|r(| j                   j                  j                  d|i      }|r(| j                   j                  j                  d|i      }|s-dj                  |      }| j                  j                  |       |d   S # t        $ rV}dj                  |t        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)	zGet snapshot policy details
            :param snap_pol_name: Name of the snapshot policy
            :param snap_pol_id: ID of the snapshot policy
            :return: snapshot policy details
        Nr4   r5   r7   zZUnable to find the snapshot policy with {0}. Please enter a valid snapshot policy name/id.r   r   z4Failed to get the snapshot policy {0} with error {1})
r%   snapshot_policyr9   r:   r!   r+   r(   r*   r&   r)   )r,   snap_pol_idsnap_pol_namer;   snap_pol_detailsr=   r0   r>   s           r1   get_snapshot_policyz#PowerFlexVolume.get_snapshot_policyq  s     %0[]
	0##'#6#6#F#F#J#J#'"5 $K $7  #'#6#6#F#F#J#J#)="9 $K $;  $&&,fZ&8  %%'%2#A&& 	0$$*F:s1v$> IIhKK!!h!//		0r@   c                    |r|n|}	 d}|r(| j                   j                  j                  d|i      }|r(| j                   j                  j                  d|i      }t        |      dkD  r/|-dj	                  |      }| j
                  j                  |       t        |      dkD  r+|r)| j                   j                  j                  ||d      }|s-d	j	                  |      }| j
                  j                  |       |d
   S # t        $ rV}dj	                  |t        |            }t        j                  |       | j
                  j                  |       Y d}~yd}~ww xY w)a  Get storage pool details
            :param protection_domain_id: ID of the protection domain
            :param storage_pool_name: The name of the storage pool
            :param storage_pool_id: The storage pool id
            :return: Storage pool details
        Nr4   r5   r7      zlMore than one storage pool found with {0}, Please provide protection domain Name/Id to fetch the unique poolr   )r7   protectionDomainIdzLUnable to find the storage pool with {0}. Please enter a valid pool name/id.r   z1Failed to get the storage pool {0} with error {1})r%   storage_poolr9   lenr:   r!   r+   r(   r*   r&   r)   )	r,   r   r   r   r;   
sp_detailsr=   r0   r>   s	            r1   get_storage_poolz PowerFlexVolume.get_storage_pool  s~    )8_" 	!	0J!00==AA#'"9 B ;
 !!00==AA#)+<"= B ?
 :"';'C" #)&):";  %%'%2:"';!00==AA+<';#= B >
 %%+VJ%7  %%'%2a=  	0#VJA7 IIhKK!!h!//		0s   C?D 	E'AE""E'c                    |r|n|}	 |r)| j                   j                  j                  d|i      }n(| j                   j                  j                  d|i      }t        |      dk(  r'dj	                  |      }t
        j                  |       yd|d   v r*|d   d   r"t        j                  |d   d   d      |d   d	<   d}d}d
|d   v r=|d   d
   r5| j                  |d   d
         }t        |      dkD  r|d   |d   d<   |d   }|r.d|v r*|d   r%| j                  |      }||d   d<   |d   |d   d<   |d   d   *|d   d   }	|	|d   d<   | j                  |	      d   |d   d<   |d   S # t        $ rX}
d}|j	                  |t        |
            }t
        j                  |       | j                  j!                  |       Y d}
~
yd}
~
ww xY w)zGet volume details
            :param vol_name: Name of the volume
            :param vol_id: ID of the volume
            :return: Details of volume if exist.
        r7   r5   r4   r   $Volume with identifier {0} not foundNsizeInKbKBsizeInGBstoragePoolIdstoragePoolNamerI   r   protectionDomainNamesnplIdOfSourceVolumesnapshotPolicyIdsnapshotPolicyName+Failed to get the volume {0} with error {1}r   )r%   r   r9   rK   r:   r&   r'   r   get_size_in_gbrM   r?   rF   r(   r*   r)   r!   r+   )r,   r   r   
id_or_namevolume_detailsr   sppd_idpdsnap_policy_idr0   	error_msgs               r1   
get_volumezPowerFlexVolume.get_volume  sK     &V8
3	1!%!4!4!;!;!?!?#)8"4 "@ "6 "&!4!4!;!;!?!?#'. "@ "2 >"a'<CC  ^A.."1%j1050D0D"1%j1419q!*- BE."33"1%o6)).*;O*LM r7Q;;=f:N1%&7834E *b0+,//U/K:?q!"67<>vJq!"89 a !78D!/!23I!J8Fq!"45,,^<VD q!"67 "!$$ 	1EI!((SV<IIIi KK!!i!00		1s    BE0 CE0 0	G9AGGc                 b   |r|}n|r|}n|}	 |r)| j                   j                  j                  d|i      }nS|r)| j                   j                  j                  d|i      }n(| j                   j                  j                  d|i      }t        |      dk(  r-dj	                  |      }| j
                  j                  |       |d   d   S # t        $ rV}dj	                  |t        |            }t        j                  |       | j
                  j                  |       Y d	}~y	d	}~ww xY w)
zGet the SDC ID
            :param sdc_name: The name of the SDC
            :param sdc_ip: The IP of the SDC
            :param sdc_id: The ID of the SDC
            :return: The ID of the SDC
        r7   r5   sdcIpr4   r   z&Unable to find SDC with identifier {0}r   z(Failed to get the SDC {0} with error {1}N)r%   r   r9   rK   r:   r!   r+   r(   r*   r&   r)   )	r,   sdc_namesdc_ipsdc_id
id_ip_namesdc_detailsrb   r0   r>   s	            r1   
get_sdc_idzPowerFlexVolume.get_sdc_id  s4    !JJJ	0"115599#)8"4 : 6"115599#*F"3 : 5 #115599#'. : 2 ;1$DKK 	%%)%4q>$'' 	0#VJA7 IIhKK!!h!//		0s   C C 	D.AD))D.c                 r   	 |t        |j                               dk(  r| j                  j                  d       |s| j                  j                  d       d}|r| j	                  |      }|d   }|r4|r2|dk7  r-d	j                  |      }	| j                  j                  |	       | j                  j                  j                  ||||||
       y# t        $ rV}
dj                  |t        |
            }t        j                  |       | j                  j                  |       Y d}
~
yd}
~
ww xY w)a  Create volume
            :param use_rmcache: Boolean indicating whether to use RM cache.
            :param comp_type: Type of compression method for the volume.
            :param vol_type: Type of volume.
            :param size: Size of the volume.
            :param pool_id: Id of the storage pool.
            :param vol_name: The name of the volume.
            :return: Boolean indicating if create operation is successful
        Nr   !Please provide valid volume name.r   zNSize is a mandatory parameter for creating a volume. Please enter a valid sizer   
dataLayoutFineGranularity~compression_type for volume can only be mentioned when storage pools have Fine Granularity layout. Storage Pool found with {0})r   
size_in_gbr7   volume_typeuse_rmcachecompression_methodTz1Create volume {0} operation failed with error {1})rK   stripr!   r+   rM   r:   r%   r   creater(   r*   r&   r)   )r,   r   pool_idsizevol_typert   	comp_typepool_data_layoutpool_detailsr=   r0   r>   s               r1   create_volumezPowerFlexVolume.create_volume   s=   	03x~~'7#8A#=%%*M%N%% +?% @  $#44W4M#/#= -$(99& '-f-=&>  %%'%2 &&-- 'Dx$+#, . .  	0##)6(CF#; IIhKK!!h!//		0s   CC 	D6 AD11D6c                 H   	 d}|D ]8  }|d   s	| j                   j                  j                  ||d   |d          d}: |S # t        $ rU}dj	                  t        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)	a%  Modify access mode of SDCs mapped to volume
            :param vol_id: The volume id
            :param access_mode_list: List containing SDC ID's
             whose access mode is to modified
            :return: Boolean indicating if modifying access
             mode is successful
        F
accessModerh   )	volume_idrh   access_modeTz9Modify access mode of SDC operation failed with error {0}r   N)
r%   r   set_access_mode_for_sdcr(   r:   r*   r&   r)   r!   r+   )r,   r   access_mode_listchangedtempr0   r>   s          r1   modify_access_modez"PowerFlexVolume.modify_access_modeL  s    	0G( #%''..FF"(h$($6 G 8 #G# N 	0((.s1v IIhKK!!h!//		0s   A 3A 	B!ABB!c                 &   	 d}|d   |d   ( | j                   j                  j                  d
i | d}|S # t        $ rO}d|d   dt	        |      }t
        j                  |       | j                  j                  |	       Y d}~yd}~ww xY w)zModify IOPS and bandwidth limits of SDC's mapped to volume
            :param payload: Dict containing SDC ID's whose bandwidth and
                   IOPS is to modified
            :return: Boolean indicating if modifying limits is successful
        Fbandwidth_limitN
iops_limitTz$Modify bandwidth/iops limits of SDC rh   z operation failed with error r    )	r%   r   set_mapped_sdc_limitsr(   r*   r&   r)   r!   r+   )r,   payloadr   r0   r>   s        r1   modify_limitszPowerFlexVolume.modify_limitsd  s    	0G()5L)5@##**@@K7KN 	0181BCFLHIIhKK!!h!//		0s   58 	BABBc                    	 | j                   j                  j                  ||       y# t        $ rV}dj	                  |t        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zDelete volume
            :param vol_id: The volume id
            :param remove_mode: Removal mode for the volume
            :return: Boolean indicating if delete operation is successful
        Tz1Delete volume {0} operation failed with error {1}r   N)
r%   r   deleter(   r:   r*   r&   r)   r!   r+   )r,   r   remove_moder0   r>   s        r1   delete_volumezPowerFlexVolume.delete_volumex  st    	0&&--fkB 	0##)6&#a&#9 IIhKK!!h!//		0s   &) 	BABBc                    |d   }g }g }d}|r|D ]  }|j                  |d           |D ]k  }d|v r|d   r| j                  |d         }n4d|v r|d   r| j                  |d         }n| j                  |d   	      }||v s[|j                  |       m t        j                  d
|       t	        |      dk(  ry	 |D ]+  }| j
                  j                  j                  |d   |       - y# t        $ rZ}dj                  ||d   t        |            }	t        j                  |	       | j                  j                  |	       Y d}~yd}~ww xY w)zUnmap SDC's from volume
            :param volume: volume details
            :param sdc: List of SDCs to be unmapped
            :return: Boolean indicating if unmap operation is successful
        mappedSdcInfoNsdcIdrf   rf   rg   rg   rh   rh   zSDC IDs to remove %sr   Fr4   Tz3Unmap SDC {0} from volume {1} failed with error {2}r   )appendrk   r&   r'   rK   r%   r   remove_mapped_sdcr(   r:   r*   r)   r!   r+   )
r,   r   r   current_sdcscurrent_sdc_idssdc_id_listrh   r   r0   r>   s
             r1   unmap_volume_from_sdcz%PowerFlexVolume.unmap_volume_from_sdc  ss    o.$ 6&&tG}56  	+DT!d:&6$z2BCT!d8nX?X?(""6*	+ 	'5{q 		0% *##**<<4L&**  	0#VFF4L#a&A IIhKK!!h!//		0s   ?0C0 0	E9AEEc                 v   |d   }g }g }g }g }| j                  |      }|D ]p  }	| j                  |	      }
|
|vr5|j                  |
       | j                  |	|
       |j                  |	       Mt	        ||
|	      \  }}| j                  ||||       r t        j                  d|       |sd||fS 	 d}|D ]  }|d   |d   |d   | j                  j                  d   d} | j                  j                  j                  di | |d	   s|d
   r9|d   |d   |d	   |d
   d} | j                  j                  j                  di | d} |||fS # t        $ r]}dj                  |d   |d   t!        |            }t        j#                  |       | j                  j%                  |       Y d}~yd}~ww xY w)zMap SDC's to volume
            :param volume: volume details
            :param sdc: List of SDCs
            :return: Boolean indicating if mapping operation is successful
        r   zSDC to add: %sFr4   rh   r   allow_multiple_mappings)r   rh   r   r   r   r   r   rh   r   r   Tz3Mapping volume {0} to SDC {1} failed with error {2}r7   r   Nr   )get_current_sdcsget_sdc_id_from_inputr   update_temp_datacheck_for_sdc_modificationupdate_sdc_listsr&   r'   r!   r$   r%   r   add_mapped_sdcr   r(   r:   r*   r)   r+   )r,   r   r   r   r   sdc_map_listsdc_modify_list1sdc_modify_list2r   r   rh   access_mode_dictlimits_dictr   r   r0   r>   s                    r1   map_volume_to_sdcz!PowerFlexVolume.map_volume_to_sdc  s    o.//= 
	ED//5F_,""6*%%dF3##D)0JFD1*- +%%&68H&6E
	E 	!<0*,<<<	0G# !'!(m#&}#5**+DE :##**99DGD()S->%+D\"%h-+./@+A&),&7	G ED''..DDOwO'( ,.>>> 	0//5vfVn69(mSV0M  IIhKK!!h!//	0s   2BE 	F8AF33F8c                 R    |r|j                  |       |r|j                  |       y y Nr   )r,   r   r   r   r   s        r1   r   z PowerFlexVolume.update_sdc_lists  s*    ##$45##K0     c                     d|v r|d   r| j                  |d         }|S d|v r|d   r| j                  |d         }|S | j                  |d         }|S )Nrf   r   rg   r   rh   r   )rk   r,   r   rh   s      r1   r   z%PowerFlexVolume.get_sdc_id_from_input  ss    $z"2__d:.>_?F
 	 $x.__DN_;F  __DN_;Fr   c                 ^    ||d<   d|v rt        |d         |d<   d|vrd |d<   d|vrd |d<   y y )Nrh   r   r   r   get_access_moder   s      r1   r   z PowerFlexVolume.update_temp_data  sT    XD ] 34 D(&*D"#t#!%D $r   c                 D    g }|r|D ]  }|j                  |d           |S )Nr   r   )r,   r   r   r   s       r1   r   z PowerFlexVolume.get_current_sdcs	  s1    $ 6&&tG}56r   c                 T   | j                   j                  d   }| j                   j                  d   }| j                   j                  d   }|r]|D ]X  }	t        |	d   |	d   g      s't        |	d   |	d   g      st        |	d   |	d   g      s=| j                   j                  d       Z ||s| j                   j                  d
       |r7|5|3d}
t        j                  |
       | j                   j                  |
       |dk(  r || j                   j                  d       y	y	y	)zValidate the input parametersr   cap_unitry   rh   rg   rf   z2sdc_id, sdc_ip and sdc_name are mutually exclusiver   NzScap_unit can be specified along with size only. Please enter a valid value for sizezyTo remove/detach snapshot policy, please provide empty snapshot policy name/id along with auto_snap_remove_type parameterpresentzJdelete_snapshots can be specified only when the state is passed as absent.)r!   r$   allr+   r&   r)   )r,   auto_snap_remove_typerC   rD   delete_snapsstater   r   ry   r   r=   s              r1   validate_parametersz#PowerFlexVolume.validate_parameters  s@    kk  ';;%%j1{{!!&) Hhh89T(^T*-=>?T(^T*-=>?KK)) /G) H	H  $KK!! '8! 9 !]%:'8G IIgKK!!g!.I,":KK!!, " - #;r   c                    	 dj                  t        |            }t        j                  |       d|v r|d   }dj                  ||d         }t        j                  |       | j                  j
                  j                  |d   ||       dj                  |      }t        j                  |       d|vrVd|v rR| j                  j
                  j                  |d   |       dj                  |d         }t        j                  |       d|v rR| j                  j                  j                  ||d          dj                  |d         }t        j                  |       d	|v r[| j                  j                  j                  ||d	          d
j                  t        |d	               }t        j                  |       d|v rR| j                  j                  j                  ||d          dj                  |d         }t        j                  |       d|v rR| j                  j                  j                  ||d          dj                  |d         }t        j                  |       y# t        $ rV}dj                  |t        |            }t        j                  |       | j                  j!                  |       Y d}~yd}~ww xY w)z
        Update the volume attributes
        :param vol_id: Id of the volume
        :param modify_dict: Dictionary containing the attributes of
         volume which are to be updated
        :return: True, if the operation is successful
        z@Dictionary containing attributes which are to be updated is {0}.r   zlRemoving/detaching the snapshot policy from a volume. auto_snap_remove_type: {0} and snapshot policy id: {1}rC   z/The snapshot policy has been {0}ed successfullyz8Attached the snapshot policy {0} to volume successfully.new_namez5The name of the volume is updated to {0} sucessfully.new_sizez6The size of the volume is extended to {0} sucessfully.rt   z.The use RMcache is updated to {0} sucessfully.r{   z6The compression method is updated to {0} successfully.Tz.Failed to update the volume {0} with error {1}r   N)r:   r*   r&   r'   r%   rB   remove_source_volumeadd_source_volumer   renameextendset_use_rmcacheset_compression_methodr(   r)   r!   r+   )r,   r   modify_dictr   	snap_typer0   r=   s          r1   modify_volumezPowerFlexVolume.modify_volume2  s   ;	/%%+VC,<%= HHSM&+5'(?@	 #F9k-.HI  ##33HH.	C%%+VI%6 &k9%4##33EE.8''-vk-.H'I [(##**11&2=j2IK--3VK
4K-L [(##**11&2=j2IK%%+VCJ0G,H%I +##**::K68&&,f[-G&H k)##**AAK46''-vk+.F'G  	/((.vs1v(> IIgKK!!g!..		/s   I-I0 0	K9AK

Kc                    i }|r:|d   }	| j                  |	      }
|
d   }| j                  |       ||d   k7  r||d<   | j                  |||       t        j                  |d   d      }| j                  |||       | j                  |||       ||dk(  r|r|d	   r||d
<   |d	   |d<   |6|dk7  r1|r#|d	   rd}| j                  j                  |       |
|d	   ||d<   |S )a  

        :param vol_details: Details of the volume
        :param new_size: Size of the volume
        :param use_rmcache: Bool value of use rm cache
        :param comp_type: Type of compression method
        :param new_name: The new name of the volume
        :param snap_pol_id: Id of the snapshot policy
        :param auto_snap_remove_type: Whether to remove or detach the policy
        :return: Dictionary containing the attributes of
         volume which are to be updated
        rS   rn   ro   compressionMethodr{   rP   rQ    rW   r   rC   zWTo remove/detach a snapshot policy, provide the snapshot policy name/id as empty stringr   )	rM   pool_data_layout_fineupdate_use_rmcacher   r[   update_new_sizeupdate_new_namer!   r+   )r,   vol_detailsr   rt   r{   r   rC   r   r   rx   r}   r|   vol_size_in_gbr=   s                 r1   	to_modifyzPowerFlexVolume.to_modifyw  s7    !/2G000IL+L9&&'78K(;<<+4K([+F--k*.EtLX{NC[(K@"{b'8%+6L*M3HK/023 & "{b'8$5K)LE%%'%2$, 67?-8M*r   c                     |I|t        |j                               dk(  r| j                  j                  d       ||d   k7  r||d<   y y y )Nr   rm   r   r7   r   )rK   rv   r!   r+   )r,   r   r   r   s       r1   r   zPowerFlexVolume.update_new_name  s\    3x~~'7#8A#=%% +2% 3;v..*2J' /	  r   c                 6    ||dz
  |cxk  r|k  sn ||d<   y y y )N   r   r   )r,   r   r   r   s       r1   r   zPowerFlexVolume.update_new_size  s/    $q(HFF&.K
# G  r   c                 &    ||d   |k7  r||d<   y y y )N
useRmcachert   r   )r,   r   rt   r   s       r1   r   z"PowerFlexVolume.update_use_rmcache  s)    "L)[8)4K& 9 #r   c                 j    |dk7  r.dj                  |      }| j                  j                  |       y y )Nrp   rq   r   )r:   r!   r+   )r,   r|   r=   s      r1   r   z%PowerFlexVolume.pool_data_layout_fine  s>    00 #F#34  KK!!g!. 1r   c                    |r(d|v r$||d   k7  r| j                   j                  d       |r(d|v r$||d   k7  r| j                   j                  d       |r$||d   k7  r| j                   j                  d       |r$||d   k7  r| j                   j                  d	       |r$||d
   k7  r| j                   j                  d       |r&||d   k7  r| j                   j                  d       yyy)au  
        :param vol_details: Details of the volume
        :param snap_pol_name: Name of the snapshot policy
        :param snap_pol_id: Id of the snapshot policy
        :param pd_name: Name of the protection domain
        :param pd_id: Id of the protection domain
        :param pool_name: Name of the storage pool
        :param pool_id: Id of the storage pool
        rX   zEntered snapshot policy id does not match with the snapshot policy's id attached to the volume. Please enter a correct snapshot policy id.r   rY   zEntered snapshot policy name does not match with the snapshot policy's name attached to the volume. Please enter a correct snapshot policy name.rI   zEntered protection domain id does not match with the volume's protection domain id. Please enter a correct protection domain id.rS   zqEntered storage pool id does not match with the volume's storage pool id. Please enter a correct storage pool id.rV   zEntered protection domain name does not match with the volume's protection domain name. Please enter a correct protection domain name.rT   zwEntered storage pool name does not match with the volume's storage pool name. Please enter a correct storage pool name.N)r!   r+   )r,   r   rD   rC   pd_namer_   	pool_namerx   s           r1   verify_paramszPowerFlexVolume.verify_params  s,    -<{+=>>KK!! 'G! H
 /;>-A!BBKK!! '/! 0 Uk*>??KK!! '?! @
 w+o">>KK!! 'D! E
 w+.D"EEKK!! 'K! L
 k2C&DDKK!! 'F! G E9r   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   }| j                   j                  d   }t        j                  | j                   j                  d         }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j	                  |      }t        |      }| j	                  |      }d}t        di       }| j                  ||
|	||       | j                  |	|
|      }| j                  ||      }| j                  ||      }| j                  |||      }| j                  |	|
      }
| j                  ||      \  }}|r|r| j                  ||	|
||||       d}|dk(  r|s| j                  |||||||||	      \  }}}i }|rK|dk(  rF| j!                  ||||||
|      }dj#                  t%        |            }t&        j)                  |       d}d}d}|dk(  r |r|r|dk(  r| j+                  |||      \  }}}d}|dk(  r|r|r|dk(  r| j-                  ||      }d}|r|dk(  r| j/                  ||      }d}|dk(  r|r| j1                  ||      }|xs |xs |xs |xs
 |xs |xs |}| j3                  |||       ||d<    | j                   j4                  di | y)zh
        Perform different actions on volume based on parameters passed in
        the playbook
        r   r   rz   compression_typer   r   r   r   r   r   r   rt   ry   r   vol_new_namer   r   delete_snapshotsr   F)r   r]   r   z-Parameters to be modified are as follows: {0}mappedunmappedabsentr   Nr   )r!   r$   copydeepcopycheck_null_capitalizeget_vol_typedictr   get_auto_snap_rtget_size_dataget_pd_detailsget_sp_detailsget_snap_pol_detailsget_volr   create_new_volumer   r:   r*   r&   r'   sdc_state_mappedr   r   delete_operationprepare_output	exit_json) r,   r   r   rz   r   sp_namesp_idr   r_   rD   rC   r   rt   ry   r   r   r   r   r   r   r   resultr]   create_changedr   r   map_changedmode_changedlimits_changedunmap_changedmodify_changeddel_changeds                                    r1   perform_module_operationz(PowerFlexVolume.perform_module_operation  sR   
 ;;%%j1##H-;;%%j1;;--.@A++$$%89""#45++$$%=>""#9:**+ABkk(()=> $ 2 23J Kkk((7{{!!&);;%%j1{{)).9mmDKK..u56KK&&{3	;;--.@A""7+556FG) $ : :!!# 
 	  !6!.0@%	I !% 5 5m6A6K!M !!$1##GU3##GUE://{K "&h!?{GU 
 In595K5K&(,<eT<6A2FNN
 ey0..k3Ck+@BK""(&[)9": HHSM I.SX%8<8M8M^9-5L.+ I.SZ' 66~sKM 5I-!//DN H//8HIK! %] %k %$%(3%7C%$ 	
 	FE62#y''r   c                 <    |dk(  r| j                  |      }||d<   y y )Nr   r]   )show_output)r,   r   r   r   r   s        r1   r   zPowerFlexVolume.prepare_outpute  s*    I**62K'2F#$ r   c                     | j                  ||      }|r|d   }dj                  t        |            }t        j	                  |       ||fS )Nr4   zFetched the volume details {0})rc   r:   r*   r&   r'   )r,   r   r   r]   r   s        r1   r   zPowerFlexVolume.get_volj  sJ    6:#D)F.55c.6IJv%%r   c                 "    |s|dk(  s|dk(  rd}|S )Nr   Detachr   )r,   rD   rC   r   s       r1   r   z PowerFlexVolume.get_auto_snap_rtr  s     $"$r(9$,!$$r   c                 &    |r|sd}|dk(  r|dz  }|S )NGBTB   r   )r,   ry   r   s      r1   r   zPowerFlexVolume.get_size_datax  s#    4d{r   c                     |r?| j                  |      }|r|d   }dj                  ||      }t        j                  |       |S )Nr4   z;Fetched the protection domain details with id {0}, name {1})r?   r:   r&   r'   )r,   r   r_   r<   r   s        r1   r   zPowerFlexVolume.get_pd_details  sH    33G<J"4($fUG4 HHSMr   c                     |rA| j                  ||      }|r|d   }dj                  ||      }t        j                  |       |S )N)r   r   r4   z1Fetched the storage pool details id {0}, name {1})rM   r:   r&   r'   )r,   r   r_   r   rL   r   s         r1   r   zPowerFlexVolume.get_sp_details  sS    ..DI / KJ"4($fUG4 HHSMr   c                     |Kd }|r| j                  |      }|r|d   }|dk(  rd}dj                  ||      }t        j                  |       |S )N)rD   r4   r   z9Fetched the snapshot policy details with id {0}, name {1})rF   r:   r&   r'   )r,   rD   rC   rE   r   s        r1   r   z$PowerFlexVolume.get_snap_pol_details  sh    $#,,=,I !.t4" $f[-@ HHSMr   c
                 >   |r| j                   j                  d       |r| j                   j                  d       | j                  ||||||      }
|
rE| j                  |      }	|	d   }dj	                  t        |	            }t        j                  |       ||	|
fS )Nz@Creation of volume is allowed using vol_name only, vol_id given.r   zpvol_new_name parameter is not supported during creation of a volume. Try renaming the volume after the creation.r4   z7Volume created successfully, fetched volume details {0})r!   r+   r~   rc   r:   r*   r&   r'   )r,   r   r   rz   r   r   rt   ry   r   r]   r   r   s               r1   r   z!PowerFlexVolume.create_new_volume  s     KK!! '2! 3 KK!!! " " ++HeT,4k,<> !__X6N#D)F%%+VC,?%@ HHSM~~55r   c                     d}d}d}| j                  ||      \  }}}t        |      dkD  r| j                  ||      }t        |      dkD  r+|D ]&  }	|d   |	d   |	d   |	d   d}
| j                  |
      }( |||fS )NFr   r4   rh   r   r   r   )r   rK   r   r   )r,   r   r   r]   r   r   r   r   limits_listr   r   s              r1   r   z PowerFlexVolume.sdc_state_mapped  s    "">37 	3%{ 1$2263CEL{a# =!/!5"8n'+,='>"&|"4	 "&!3!3G!<= ^[88r   c                 F    |du rd}||du rd}| j                  ||      }|S )NTINCLUDING_DESCENDANTSFONLY_ME)r   )r,   r   r   r   s       r1   r   z PowerFlexVolume.delete_operation  s@    t#6#'75'@(v'78 	r   c                 *    |r|j                         }|S r   )
capitalize)r,   	input_strs     r1   r   z%PowerFlexVolume.check_null_capitalize  s    !,,.Ir   c                 B   	 | j                   j                  j                  d|i      }t        |      dk(  r'dj	                  |      }t
        j                  |       yd|d   v r*|d   d   r"t        j                  |d   d   d      |d   d<   d}d}d	|d   v r=|d   d	   r5| j                  |d   d	         }t        |      dkD  r|d
   |d   d<   |d   }|r.d|v r*|d   r%| j                  |      }||d   d<   |d
   |d   d<   |d   d   +|d   d   }||d   d<   | j                  |      d
   |d   d<   nd|d   d<   d|d   d<   | j                   j                  j                  d|d   d   i      }||d   d<   | j                   j                  j                  |d   d         }	|	r|	ni |d   d<   |d   S # t        $ rX}
d}|j	                  |t        |
            }t
        j                  |       | j                  j!                  |       Y d}
~
yd}
~
ww xY w)zyShow volume details
            :param vol_id: ID of the volume
            :return: Details of volume if exist.
        r4   r5   r   rO   NrP   rQ   rR   rS   r7   rT   rI   rU   rV   rW   rX   rY   ancestorVolumeIdsnapshotsList
statisticsrZ   r   )r%   r   r9   rK   r:   r&   r)   r   r[   rM   r?   rF   get_statisticsr(   r*   r!   r+   )r,   r   r]   r   r^   r_   r`   ra   list_of_snapsr  r0   rb   s               r1   r  zPowerFlexVolume.show_output  s   <	1!0077;;#Vn < .N >"a'<CC		# ^A.."1%j1050D0D"1%j1419q!*- BE."33"1%o6)).*;O*LM r7Q;;=f:N1%&7834E *b0+,//U/K:?q!"67<>vJq!"89 a !78D!/!23I!J8Fq!"45,,^<VD q!"67 9=q!"45:>q!"67 !//66::1>!3DT3JK ; MM1>N1o. ,,33BBq!$')J<FjBN1l+!!$$ 	1EI!((Q8IIIi KK!!i!00		1s    AF= EF= =	HAHH)NN)NNN))__name__
__module____qualname____doc__r2   r?   rF   rM   rc   rk   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r  r   r   r1   r
   r
   )  s    &".H <@370B0> HL.2+0Z<1|#0J ?C26*0X000(0 '0R<0|1& -DC/J0d3/
5
/1Gfm(^3
&%	 609(
B1r   r
   c                 $   t               }t               }| d   D ]q  }|d   |k(  st        ||||       |d   |d   k7  s|d   |d   k7  r>||d<   d|d<   d|d<   |d   |d   k7  r|d   |d<   |d   t        |d         k7  r|d   |d<    ||fS  ||fS )	z
    :param volume: The volume details
    :param sdc_id: The ID of the SDC
    :param sdc_details: The details of SDC
    :return: Dictionary with SDC attributes to be modified
    r   r   	limitIopsr   limitBwInMbpsr   rh   N)r   update_access_modeget_limits_in_mb)r   rh   rj   r   r   r   s         r1   r   r   %  s     v&Ko& w<6!v{4DcJ;;|#<<(K8I,JJ(.H%,0L)15-.{#{<'@@0;L0IK-'(5F)GHI $$56   12[(( [((r   c                 Z    |d   t        |d         k7  r| |d<   t        |d         |d<   y y )Nr   r   rh   r   )rh   rj   r   r   s       r1   r$  r$  A  sD    
<K678%+")8&*(&8r   c                     | r| dz  S y)z?
    :param limits: Limits in KB
    :return: Limits in MB
    r
  Nr   )limitss    r1   r%  r%  I  s     } r   c                 0    dddd}|j                  |       S )z^
    :param access_mode: Access mode of the SDC
    :return: The enum for the access mode
    	ReadWriteReadOnlyNoAccess
READ_WRITE	READ_ONLY	NO_ACCESSr9   )r   r   s     r1   r   r   S  s(     "
 ,,r   c                 6    ddd}| r|j                  |       } | S )zg
    :param vol_type: Type of the volume
    :return: Corresponding value for the entered vol_type
    ThickProvisionedThinProvisioned)THICK_PROVISIONEDTHIN_PROVISIONEDr1  )rz   vol_type_dicts     r1   r   r   a  s+     0-M  $$X.Or   c                     t        d-i dt               dt               dt               dt               dt               dt               dt        d	      d
t               dt               dt        d	      dt        ddg      dt        ddg      dt        ddg      dt        ddg      dt               dt        d	      dt        d	      dt        dd t        t               t               t               t        g d!      t        d	      t        d	      "      #      d$t        d%d&g      d't        d(d)d*d+g,      S ).zMThis method provide parameter required for the volume
    module on PowerFlexr   r   r   r   r   r   rt   bool)typer   r   ry   intr   r  r	  )choicesrz   r5  r6  r   NORMALNONEr   detachremover   r   r   r   listr   r-  )rh   rg   rf   r   r   r   )r:  elementsoptionsr   r   r   r   Tr*   r   r   )requiredr:  r<  r   )r   r   r   r1   r    r    o  sv      $&26&  $v =AF f%	 =AF	
  6 u tTl+ 24FGH x&89 #Hh+?@ V !%& 1 6* &$vdf  *7 8 $% 0U+3	
0 *5612 Duy(6KL3 r   c                  8    t               } | j                          y)zc Create PowerFlex volume object and perform actions on it
        based on user input from playbookN)r
   r  )objs    r1   mainrG    s     
C  "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   r   
get_loggerr&   objectr
   r   r$  r%  r   r   r    rG  r  r   r   r1   <module>rR     s    Q B Bsjm^o
b 5 ex y1f y1x)8(-@# zF r   