
    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d Zd Zedk(  r e        yy)zT Ansible module for managing Protection Domain on Dell Technologies (Dell) PowerFlex    )absolute_importdivisionprint_functiona  
module: protection_domain
version_added: '1.2.0'
short_description: Manage Protection Domain on Dell PowerFlex
description:
- Managing Protection Domain on PowerFlex storage system includes creating,
  modifying attributes, deleting and getting details of Protection Domain.
author:
- Bhavneet Sharma (@sharmb5) <ansible.team@dell.com>
extends_documentation_fragment:
  - dellemc.powerflex.powerflex
options:
  protection_domain_name:
    description:
    - The name of the protection domain.
    - Mandatory for create operation.
    - It is unique across the PowerFlex array.
    - Mutually exclusive with I(protection_domain_id).
    type: str
  protection_domain_id:
    description:
    - The ID of the protection domain.
    - Except for create operation, all other operations can be performed
      using protection_domain_id.
    - Mutually exclusive with I(protection_domain_name).
    type: str
  protection_domain_new_name:
    description:
    - Used to rename the protection domain.
    type: str
  is_active:
    description:
    - Used to activate or deactivate the protection domain.
    type: bool
  network_limits:
    description:
    - Network bandwidth limit used by all SDS in protection domain.
    type: dict
    suboptions:
      rebuild_limit:
        description:
        - Limit the network bandwidth for rebuild.
        type: int
      rebalance_limit:
        description:
        - Limit the network bandwidth for rebalance.
        type: int
      vtree_migration_limit:
        description:
        - Limit the network bandwidth for vtree migration.
        type: int
      overall_limit:
        description:
        - Limit the overall network bandwidth.
        type: int
      bandwidth_unit:
        description:
        - Unit for network bandwidth limits.
        type: str
        choices: ['KBps', 'MBps', 'GBps']
        default: 'KBps'
  rf_cache_limits:
    description:
    - Used to set the RFcache parameters of the protection domain.
    type: dict
    suboptions:
      is_enabled:
        description:
        - Used to enable or disable RFcache in the protection domain.
        type: bool
      page_size:
        description:
        - Used to set the cache page size in KB.
        type: int
      max_io_limit:
        description:
        - Used to set cache maximum I/O limit in KB.
        type: int
      pass_through_mode:
        description:
        - Used to set the cache mode.
        choices: ['None', 'Read', 'Write', 'ReadAndWrite', 'WriteMiss']
        type: str
  state:
    description:
    - State of the protection domain.
    required: true
    type: str
    choices: ['present', 'absent']
notes:
  - The protection domain can only be deleted if all its related objects have
    been dissociated from the protection domain.
  - If the protection domain set to inactive, then no operation can be
    performed on protection domain.
  - The I(check_mode) is not supported.
a	  
- name: Create protection domain
  dellemc.powerflex.protection_domain:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    protection_domain_name: "domain1"
    state: "present"

- name: Create protection domain with all parameters
  dellemc.powerflex.protection_domain:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    protection_domain_name: "domain1"
    is_active: true
    network_limits:
      rebuild_limit: 10
      rebalance_limit: 17
      vtree_migration_limit: 14
      overall_limit: 20
      bandwidth_unit: "MBps"
    rf_cache_limits:
      is_enabled: true
      page_size: 16
      max_io_limit: 128
      pass_through_mode: "Read"
    state: "present"

- name: Get protection domain details using name
  dellemc.powerflex.protection_domain:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    protection_domain_name: "domain1"
    state: "present"

- name: Get protection domain details using ID
  dellemc.powerflex.protection_domain:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    protection_domain_id: "5718253c00000004"
    state: "present"

- name: Modify protection domain attributes
  dellemc.powerflex.protection_domain:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    protection_domain_name: "domain1"
    protection_domain_new_name: "domain1_new"
    network_limits:
      rebuild_limit: 14
      rebalance_limit: 20
      overall_limit: 25
      bandwidth_unit: "MBps"
    rf_cache_limits:
      page_size: 64
      pass_through_mode: "WriteMiss"
    state: "present"

- name: Delete protection domain using name
  dellemc.powerflex.protection_domain:
    hostname: "{{hostname}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    port: "{{port}}"
    protection_domain_name: "domain1_new"
    state: "absent"
a+  
changed:
    description: Whether or not the resource has changed.
    returned: always
    type: bool
    sample: 'false'
protection_domain_details:
    description: Details of the protection domain.
    returned: When protection domain exists
    type: dict
    contains:
        fglDefaultMetadataCacheSize:
            description: FGL metadata cache size.
            type: int
        fglDefaultNumConcurrentWrites:
            description: FGL concurrent writes.
            type: str
        fglMetadataCacheEnabled:
            description: Whether FGL cache enabled.
            type: bool
        id:
            description: Protection domain ID.
            type: str
        links:
            description: Protection domain links.
            type: list
            contains:
                href:
                    description: Protection domain instance URL.
                    type: str
                rel:
                    description: Protection domain's relationship with
                                 different entities.
                    type: str
        mdmSdsNetworkDisconnectionsCounterParameters:
            description: MDM's SDS counter parameter.
            type: dict
            contains:
                longWindow:
                    description: Long window for Counter Parameters.
                    type: int
                mediumWindow:
                    description: Medium window for Counter Parameters.
                    type: int
                shortWindow:
                    description: Short window for Counter Parameters.
                    type: int
        name:
            description: Name of the protection domain.
            type: str
        overallIoNetworkThrottlingEnabled:
            description: Whether overall network throttling enabled.
            type: bool
        overallIoNetworkThrottlingInKbps:
            description: Overall network throttling in KBps.
            type: int
        protectedMaintenanceModeNetworkThrottlingEnabled:
            description: Whether protected maintenance mode network throttling
                         enabled.
            type: bool
        protectedMaintenanceModeNetworkThrottlingInKbps:
            description: Protected maintenance mode network throttling in
                         KBps.
            type: int
        protectionDomainState:
            description: State of protection domain.
            type: int
        rebalanceNetworkThrottlingEnabled:
            description: Whether rebalance network throttling enabled.
            type: int
        rebalanceNetworkThrottlingInKbps:
            description: Rebalance network throttling in KBps.
            type: int
        rebuildNetworkThrottlingEnabled:
            description: Whether rebuild network throttling enabled.
            type: int
        rebuildNetworkThrottlingInKbps:
            description: Rebuild network throttling in KBps.
            type: int
        rfcacheAccpId:
            description: Id of RF cache acceleration pool.
            type: str
        rfcacheEnabled:
            description: Whether RF cache is enabled or not.
            type: bool
        rfcacheMaxIoSizeKb:
            description: RF cache maximum I/O size in KB.
            type: int
        rfcacheOpertionalMode:
            description: RF cache operational mode.
            type: str
        rfcachePageSizeKb:
            description: RF cache page size in KB.
            type: bool
        sdrSdsConnectivityInfo:
            description: Connectivity info of SDR and SDS.
            type: dict
            contains:
                clientServerConnStatus:
                    description: Connectivity status of client and server.
                    type: str
                disconnectedClientId:
                    description: Disconnected client ID.
                    type: str
                disconnectedClientName:
                    description: Disconnected client name.
                    type: str
                disconnectedServerId:
                    description: Disconnected server ID.
                    type: str
                disconnectedServerIp:
                    description: Disconnected server IP.
                    type: str
                disconnectedServerName:
                    description: Disconnected server name.
                    type: str
        sdsSdsNetworkDisconnectionsCounterParameters:
            description: Counter parameter for SDS-SDS network.
            type: dict
            contains:
                longWindow:
                    description: Long window for Counter Parameters.
                    type: int
                mediumWindow:
                    description: Medium window for Counter Parameters.
                    type: int
                shortWindow:
                    description: Short window for Counter Parameters.
                    type: int
        storagePool:
            description: List of storage pools.
            type: list
        systemId:
            description: ID of system.
            type: str
        vtreeMigrationNetworkThrottlingEnabled:
            description: Whether V-Tree migration network throttling enabled.
            type: bool
        vtreeMigrationNetworkThrottlingInKbps:
            description: V-Tree migration network throttling in KBps.
            type: int
    sample: {
        "fglDefaultMetadataCacheSize": 0,
        "fglDefaultNumConcurrentWrites": 1000,
        "fglMetadataCacheEnabled": false,
        "id": "7bd6457000000000",
        "links": [
            {
                "href": "/api/instances/ProtectionDomain::7bd6457000000000",
                "rel": "self"
            },
            {
                "href": "/api/instances/ProtectionDomain::7bd6457000000000/
                        relationships/Statistics",
                "rel": "/api/ProtectionDomain/relationship/Statistics"
            },
            {
                "href": "/api/instances/ProtectionDomain::7bd6457000000000/
                        relationships/Sdr",
                "rel": "/api/ProtectionDomain/relationship/Sdr"
            },
            {
                "href": "/api/instances/ProtectionDomain::7bd6457000000000/
                        relationships/AccelerationPool",
                "rel": "/api/ProtectionDomain/relationship/AccelerationPool"
            },
            {
                "href": "/api/instances/ProtectionDomain::7bd6457000000000/
                        relationships/StoragePool",
                "rel": "/api/ProtectionDomain/relationship/StoragePool"
            },
            {
                "href": "/api/instances/ProtectionDomain::7bd6457000000000/
                        relationships/Sds",
                "rel": "/api/ProtectionDomain/relationship/Sds"
            },
            {
                "href": "/api/instances/ProtectionDomain::7bd6457000000000/
                        relationships/ReplicationConsistencyGroup",
                "rel": "/api/ProtectionDomain/relationship/
                        ReplicationConsistencyGroup"
            },
            {
                "href": "/api/instances/ProtectionDomain::7bd6457000000000/
                        relationships/FaultSet",
                "rel": "/api/ProtectionDomain/relationship/FaultSet"
            },
            {
                "href": "/api/instances/System::0989ce79058f150f",
                "rel": "/api/parent/relationship/systemId"
            }
        ],
        "mdmSdsNetworkDisconnectionsCounterParameters": {
            "longWindow": {
                "threshold": 700,
                "windowSizeInSec": 86400
            },
            "mediumWindow": {
                "threshold": 500,
                "windowSizeInSec": 3600
            },
            "shortWindow": {
                "threshold": 300,
                "windowSizeInSec": 60
            }
        },
        "name": "domain1",
        "overallIoNetworkThrottlingEnabled": false,
        "overallIoNetworkThrottlingInKbps": null,
        "protectedMaintenanceModeNetworkThrottlingEnabled": false,
        "protectedMaintenanceModeNetworkThrottlingInKbps": null,
        "protectionDomainState": "Active",
        "rebalanceNetworkThrottlingEnabled": false,
        "rebalanceNetworkThrottlingInKbps": null,
        "rebuildNetworkThrottlingEnabled": false,
        "rebuildNetworkThrottlingInKbps": null,
        "rfcacheAccpId": null,
        "rfcacheEnabled": true,
        "rfcacheMaxIoSizeKb": 128,
        "rfcacheOpertionalMode": "WriteMiss",
        "rfcachePageSizeKb": 64,
        "sdrSdsConnectivityInfo": {
            "clientServerConnStatus": "CLIENT_SERVER_CONN_STATUS_ALL
                                      _CONNECTED",
            "disconnectedClientId": null,
            "disconnectedClientName": null,
            "disconnectedServerId": null,
            "disconnectedServerIp": null,
            "disconnectedServerName": null
        },
        "sdsConfigurationFailureCounterParameters": {
            "longWindow": {
                "threshold": 700,
                "windowSizeInSec": 86400
            },
            "mediumWindow": {
                "threshold": 500,
                "windowSizeInSec": 3600
            },
            "shortWindow": {
                "threshold": 300,
                "windowSizeInSec": 60
            }
        },
        "sdsDecoupledCounterParameters": {
            "longWindow": {
                "threshold": 700,
                "windowSizeInSec": 86400
            },
            "mediumWindow": {
                "threshold": 500,
                "windowSizeInSec": 3600
            },
            "shortWindow": {
                "threshold": 300,
                "windowSizeInSec": 60
            }
        },
        "sdsReceiveBufferAllocationFailuresCounterParameters": {
            "longWindow": {
                "threshold": 2000000,
                "windowSizeInSec": 86400
            },
            "mediumWindow": {
                "threshold": 200000,
                "windowSizeInSec": 3600
            },
            "shortWindow": {
                "threshold": 20000,
                "windowSizeInSec": 60
            }
        },
        "sdsSdsNetworkDisconnectionsCounterParameters": {
            "longWindow": {
                "threshold": 700,
                "windowSizeInSec": 86400
            },
            "mediumWindow": {
                "threshold": 500,
                "windowSizeInSec": 3600
            },
            "shortWindow": {
                "threshold": 300,
                "windowSizeInSec": 60
            }
        },
        "storagePool": [
            {
                "id": "8d1cba1700000000",
                "name": "pool1"
            }
        ],
        "systemId": "0989ce79058f150f",
        "vtreeMigrationNetworkThrottlingEnabled": false,
        "vtreeMigrationNetworkThrottlingInKbps": null
    }
)AnsibleModule)utilsprotection_domainc                   r    e Zd ZdZd Zd Zd Zd Z	 	 ddZd Z	d	 Z
d
 Z	 ddZd Z	 ddZd Zd Zd Zy)PowerFlexProtectionDomainz'Class with protection domain operationsc                 D   t        j                         | _        | j                  j                  t	                      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protection_domain_nameprotection_domain_idF)argument_specsupports_check_modemutually_exclusiverequired_one_ofz3Got the PowerFlex system connection object instancemsgN)r   %get_powerflex_gateway_host_parametersmodule_paramsupdate*get_powerflex_protection_domain_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_one_of_argses       w/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/powerflex/plugins/modules/protection_domain.py__init__z"PowerFlexProtectionDomain.__init__  s    "HHJ!!"L"NO02HIJ!9!7!9  : $,, %*0	2 	""4;;/	."'"M"M""#$DHHJK 	.IIc!fKK!!c!f!--	.s   AC	 		DADDc                    g d}d}|D ]  }| j                   j                  |   t        | j                   j                  |   j                               xs+ | j                   j                  |   j	                  d      dkD  dk(  s~|j                  |      }| j                   j                  |        | j                   j                  d   q| j                   j                  d   d   T| j                   j                  d   d   dk  r4d	}t        j                  |       | j                   j                  |       yyyy)
zValidate the input parameters)r   protection_domain_new_namer   zPlease provide the valid {0}N r   r   network_limitsoverall_limitz8Overall limit cannot be negative. Provide a valid value )	r   r   lenstripcountformatr"   r   r   )r#   name_paramsr   n_itemerr_msg	error_msgs         r'   validate_input_paramsz/PowerFlexProtectionDomain.validate_input_params  s2   /,! 	3F{{!!&)53KK&&v.446<8 <9;?F66&<**/%*q<9=>;? **V,%%'%2	3 ;;./;{{!!"23ODPKK&&'78IAM5	#%%)%4	 N Q <    c                     | j                   j                  d   s| j                   j                  d   r4d}t        j                  |       | j                   j	                  |       yy)z@Checking if protection domain id or new names present in create r*   r   zprotection_domain_new_name/protection_domain_id are not supported during creation of protection domain. Please try with protection_domain_name.r   N)r   r   r   r   r"   )r#   r5   s     r'   is_id_or_new_name_in_createz5PowerFlexProtectionDomain.is_id_or_new_name_in_create$  sZ     ;;:;""#9:JI HHYKK!!i!0 ;r7   c                 l   	 g }| j                   j                  j                  |      }|D ]-  }t               }|d   |d<   |d   |d<   |j	                  |       / |S # t
        $ rL}d|dt        |      }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)z
        Get Storage pools details
        :param protection_domain_id: Name of the protection domain
        :type protection_domain_id: str
        :return: list containing storage pools which are present in
                 protection domain
        r   idnamez=Failed to get the storage pools present in protection domain z with error r   N)r   r   get_storage_poolsdictappendr   r!   r   r    r   r"   )r#   r   sps_listrespitems
sp_name_idr&   errmsgs           r'   get_storage_poolz*PowerFlexProtectionDomain.get_storage_pool/  s    	.H&&88!!7K!L  ,!V
#(;
4 %*6]
6"
+	,
 O 	.3GQQFIIfKK!!f!--		.s   AA 	B3'AB..B3Nc                    |r|n|}	 |r)| j                   j                  j                  d|i      }n(| j                   j                  j                  d|i      }t        |      dk(  rd|z  }t        j                  |       y| j                  |d   d         |d   d<   |d   S # t        $ rM}d|d	t        |      d
}t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)z
        Get 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 if exists
        :rtype: dict
        r<   )filter_fieldsr=   r   z/Unable to find the protection domain with '%s'.NstoragePoolz%Failed to get the protection domain 'z' with error ''r   )r   r   getr.   r   r   rF   r   r!   r    r   r"   )r#   r   r   
name_or_id
pd_detailsr5   r&   s          r'   get_protection_domainz/PowerFlexProtectionDomain.get_protection_domainI  s!    .B)' 		1#!00BBFF#')="> G @
 "00BBFF#)+A"B G D
 :!#$&01	# ,0+@+@BCBEEIBK ,LJqM-(a=  	1(2CF<IIIi KK!!i!00		1s   A;B& !B& &	C</AC77C<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)	z
        Create Protection Domain
        :param protection_domain_name: Name of the protection domain
        :type protection_domain_name: str
        :return: Boolean indicating if create operation is successful
        z)Creating protection domain with name: %s )r=   TzCreate protection domain '' operation failed with error 'rJ   r   N)
r   r   r   r   creater   r!   r    r   r"   )r#   r   r&   r5   s       r'   create_protection_domainz2PowerFlexProtectionDomain.create_protection_domainp  s}    	1HH@+-1123 	1.Dc!fNIIIi KK!!i!00		1s   <? 	BABBc                     |dk(  ri|sg| j                          | j                  |      }|rD| j                  |      }dj                  t	        |            }t
        j                  |       ||fS d|fS )z0performing creation of protection domain detailspresentzMProtection domain created successfully, fetched protection domain details {0}F)r9   rR   rN   r1   r!   r   r   )r#   staterM   r   create_changer   s         r'   perform_create_operationz2PowerFlexProtectionDomain.perform_create_operation  s     Ij,,. (()?@ !))*@A 7F3z?+  $j00j  r7   c                 X    | j                   j                  d   dk(  r|r||||	 yyyy)zCheck if modification requiredrU   rT   NT)r   r   )r#   rM   r,   rf_cache_limitsr*   	is_actives         r'   is_modify_requiredz,PowerFlexProtectionDomain.is_modify_required  sI     KKw'94*+/J.:i?? ;E4r7   c                 Z   	 dj                  t        |            }t        j                  |       d|v sd|v sd|v sd|v rk| j                  j
                  j                  ||d   |d   |d   |d          dj                  |d   |d   |d   |d         }t        j                  |       y# t        $ rt}|rd	j                  |t        |            }nd
j                  |t        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)a=  
        Modify Protection domain attributes
        :param protection_domain_id: ID of the protection domain
        :type protection_domain_id: str
        :param nw_modify_dict: Dictionary containing the attributes of
                               protection domain which are to be updated
        :type nw_modify_dict: dict
        :param create_flag: Flag to indicate whether modify operation is
                            followed by create operation or not
        :type create_flag: bool
        :return: Boolean indicating if the operation is successful
        )Dict containing network modify params {0}rebuild_limitrebalance_limitvtree_migration_limitr-   )r   r^   r_   r`   r-   zBThe Network limits are updated to {0}, {1}, {2}, {3} successfully.TzbCreate protection domain is successful, but failed to update the network limits {0} with error {1}zKFailed to update the network limits of protection domain {0} with error {1}r   N)r1   r!   r   r   r   r   r,   r   r    r   r"   )r#   r   nw_modify_dictcreate_flagr   r&   r4   s          r'   modify_nw_limitsz*PowerFlexProtectionDomain.modify_nw_limits  sM   !	/=s>*+ HHSM.04E"5#&="'#&5&G##55DD)="0"A$23D$E*89P*Q"0"A E C*F>/:)*;<)*AB)/:<   	/0067K7:1v1? 
AF/Q8  IIgKK!!g!..	/s   B*B- -	D*6A*D%%D*c                    	 dj                  t        |            }t        j                  |       d|v rK|d   F| j                  j
                  j                  ||d          d|d   z  }t        j                  |       d|v sd|v sd|v rc| j                  j
                  j                  ||d   |d   |d          d	j                  |d   |d   |d         }t        j                  |       y
# t        $ rt}|rdj                  |t        |            }ndj                  |t        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)a.  
        Modify Protection domain attributes
        :param protection_domain_id: ID of the protection domain
        :type protection_domain_id: str
        :param rf_modify_dict: Dict containing the attributes of rf cache
                               which are to be updated
        :type rf_modify_dict: dict
        :param create_flag: Flag to indicate whether modify operation is
                            followed by create operation or not
        :type create_flag: bool
        :return: Boolean indicating if the operation is successful
        r]   
is_enabledNz,The RFcache is enabled to '%s' successfully.	page_sizemax_io_limitpass_through_mode)r   rf   rg   rh   z4The RFcache parameters are updated to {0}, {1},{2}.'TzcCreate protection domain is successful, but failed to update the rf cache limits {0} with error {1}zLFailed to update the rf cache limits of protection domain {0} with error {1}r   )r1   r!   r   r   r   r   set_rfcache_enabledrfcache_parametersr   r    r   r"   )r#   r   rf_modify_dictrb   r   r&   r4   s          r'   modify_rf_limitsz*PowerFlexProtectionDomain.modify_rf_limits  s   &	/=s>*+ HHSM~-"<0<##55II(.*FHD&|45n,"1#&9^&K##55HH)=,[9!/!?&45H&I	 I K
 MVN;7*>:*+>?A   	/0067K7:1v1? 
AF/Q8  IIgKK!!g!..	/s   C-C0 0	E-9A*E((E-c                    	 dt        |      z  }t        j                  |       d|v rF| j                  j                  j                  ||d          d|d   z  }t        j                  |       d|v rK|d   rF| j                  j                  j                  ||d          d|d   z  }t        j                  |       d|v rK|d   sF| j                  j                  j                  ||d          d|d   z  }t        j                  |       y# t        $ rt}|rdj                  |t        |            }nd	j                  |t        |            }t        j                  |       | j                  j                  |
       Y d}~yd}~ww xY w)a4  
        Modify Protection domain attributes
        :param protection_domain_id: ID of the protection domain
        :type protection_domain_id: str
        :param modify_dict: Dictionary containing the attributes of
                            protection domain which are to be updated
        :type modify_dict: dict
        :param create_flag: Flag to indicate whether modify operation is
                            followed by create operation or not
        :type create_flag: bool
        :return: Boolean indicating if the operation is successful
        zCDictionary containing attributes which need to be updated are '%s'.r*   zBThe name of the protection domain is updated to '%s' successfully.rZ   zOThe protection domain is activated successfully, by setting as is_active: '%s' zQThe protection domain is inactivated successfully, by setting as is_active: '%s' TzeCreate protection domain is successful, but failed to update the protection domain {0} with error {1}z9Failed to update the protection domain {0} with error {1}r   N)r!   r   r   r   r   renameactivate
inactivater   r1   r    r   r"   )r#   r   modify_dictrb   r   r&   r4   s          r'   modify_pd_attributesz.PowerFlexProtectionDomain.modify_pd_attributes	  s   *	/'*-k*:<CHHSM+{:##55F/&'CDF+!">?@ k)k+.F##55H1;{3KL4!+./ k)+k2J##55J3[5MN7!+./  	/0067K7:1v1? 
,,2F3G36q6-;  IIgKK!!g!..	/s   DD 	FA*FFc                 ,   	 | j                   j                  j                  |       t        j	                  d       y# t
        $ rM}d|dt        |      d}t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)z
        Delete Protection Domain
        :param protection_domain_id: ID of the protection domain
        :type protection_domain_id: str
        :return: Boolean indicating if delete operation is successful
        z'Protection domain deleted successfully.TzDelete protection domain 'rP   rJ   r   N)
r   r   deleter   r   r   r!   r    r   r"   )r#   r   r&   r5   s       r'   delete_protection_domainz2PowerFlexProtectionDomain.delete_protection_domainC  sw    	111889MNHH>? 	1.BCFLIIIi KK!!i!00		1s   := 	BABBc                    | j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                  | j                   j                  d         }| j                   j                  d   }| j                   j                  d   }d}t        dd	
      }	| j	                          | j                  ||      }
|
r#|
d   }d|d|d}t        j                  |       d}| j                  ||
|      \  }}
i }i }i }| j                  |
||||      r`t        |
||      }t        |
|      }t        |
|      }dt        |      dt        |      dt        |      }t        j                  |       d}t        d |j                         D              }t        d |j                         D              }|s|dk(  r| j!                  |
d   ||      }|s|dk(  r| j#                  |
d   ||      }|r|dk(  r| j%                  |
d   ||      }|r8| j                  |
d         }
dt        |
      z  }t        j                  |       d}|dk(  r|
r| j'                  |
d         }|s|s|rd}|dk(  r| j                  |
d         }
|
|	d<   ||	d<    | j                   j(                  di |	 y	)zs
        Perform different actions on protection domain based on parameters
        passed in the playbook
        r   r   r*   rZ   r,   rY   rU   FN)changedprotection_domain_detailsr<   z/Fetched the protection domain details with id 'z	', name 'rJ   z*Parameters to be modified are as follows: r+   z, c              3   $   K   | ]  }|d u  
 y wN .0values     r'   	<genexpr>zEPowerFlexProtectionDomain.perform_module_operation.<locals>.<genexpr>       ME%4-M   c              3   $   K   | ]  }|d u  
 y wrz   r{   r|   s     r'   r   zEPowerFlexProtectionDomain.perform_module_operation.<locals>.<genexpr>  r   r   rT   r;   z2Protection domain details after modification: '%s'absentTrx   rw   r{   )r   r   convert_limits_in_kbpsr?   r6   rN   r   r   rW   r[   	to_modifyto_nw_limit_modifyto_rf_limit_modifyr!   allvaluesrc   rl   rr   ru   	exit_json)r#   r   r   r*   rZ   r,   rY   rU   rw   resultrM   r   create_changedrq   ra   rk   modify_changedis_nw_limitis_rf_limitdelete_changeds                       r'   perform_module_operationz2PowerFlexProtectionDomain.perform_module_operationT  s7   
 "&!3!34L!M#{{112HI%)[[%7%7(&*"KK&&{3	44KK/02++,,->?""7+ &*
 	""$ //0F0DF
 #-d#3 13IKCHHSM %)$$UJ%;= 	#

 "":~#2#=yJ $J0J$-/K/
NKN/
OLN%s>':(*C HHSM M^5J5J5LMMM^5J5J5LMMu	1!22:d3C3A3ACN u	1!22:d3C3A3ACN 5I-!$$Z%5{%35  33%/%5 4 7J
O,CHHSM H!((D)9:  ^~G I33%/%5 4 7J2<F./#y''r7   c                     g d}t               }d|d<   d|d<   d|d<   d|d<   |y|D ]@  }||   	||v s|d   dk(  r||   d	z  d	z  ||<   %|d   d
k(  r||   d	z  ||<   9||   ||<   B |S )z
        Convert the limits into KBps

        :param network_limits: dict containing all Network bandwidth limits
        :rtype: converted network limits
        )r^   r_   r`   r-   Nr^   r_   r`   r-   bandwidth_unitGBpsi   MBpsr?   )r#   r,   limit_paramsmodified_limitslimitss        r'   r   z0PowerFlexProtectionDomain.convert_limits_in_kbps  s    B&+/(-1)*37/0+/(!$ 	EFf%1f6L!"23v=&v.5< $F+#$45?.<V.Dt.KOF+.<V.DOF+	E r7   )NN)F)__name__
__module____qualname____doc__r(   r6   r9   rF   rN   rR   rW   r[   rc   rl   rr   ru   r   r   r{   r7   r'   r
   r
     sd    1.65,	1.4 <@37%1N1*!& &+//b4/n */8/t1"b(Hr7   r
   c                 n    t               }||| d   k7  r||d<   || d   dk(  r|r
| d   dk(  r|r||d<   |S )a  
    Check if modification required for rename and is_active for protection
    domain
    :param pd_details: Details of the protection domain
    :type pd_details: dict
    :param protection_domain_new_name: To rename protection domain
    :type protection_domain_new_name: str
    :param is_active: Whether to activate protection domain
    :type is_active: bool
    :return: Dictionary containing the attributes of protection domain
             which are to be updated
    :rtype: dict
    r=   r*   protectionDomainStateActiveInactiverZ   r   )rM   r*   rZ   rq   s       r'   r   r     sf     &K!-&*V*<<& 	01 01X=01Z?#,K r7   c                     i }|td|d<   d|d<   d|d<   d|d<   |d   | d   |d   k7  r|d   |d<   |d   | d   |d   k7  r|d   |d<   |d   | d   |d   k7  r|d   |d<   |d   | d	   |d   k7  r|d   |d<   |S )
a  
    Check if modification required network bandwidth limit for protection
    domain
    :param pd_details: Details of the protection domain
    :type pd_details: dict
    :param network_limits: dict of Network bandwidth limit
    :type network_limits: dict
    :return: Dictionary containing the attributes of protection domain
             which are to be updated
    :rtype: dict
    Nr^   r_   r`   r-   rebuildNetworkThrottlingInKbps rebalanceNetworkThrottlingInKbps%vtreeMigrationNetworkThrottlingInKbps overallIoNetworkThrottlingInKbpsr{   )rM   r,   rq   s      r'   r   r     s    K!'+O$)-%&/3+,'+O$/*6;<@__+9/+JK(+,8=>!"345-;<M-NK)*12>BC6783ABY3ZK/0/*6=>/0+9/+JK(r7   c                     i }|td|d<   d|d<   d|d<   d|d<   |d   | d   |d   k7  r|d   |d<   |d   | d   |d   k7  r|d   |d<   |d   | d   |d   k7  r|d   |d<   |d   | d	   |d   k7  r|d   |d<   |S )
ai  
    Check if modification required for RF cache for protection domain
    :param pd_details: Details of the protection domain
    :type pd_details: dict
    :param rf_cache_limits: dict for RF cache
    :type rf_cache_limits: dict
    :return: Dictionary containing the attributes of protection domain
             which are to be updated
    :rtype: dict
    Nre   rf   rg   rh   rfcacheEnabledrfcachePageSizeKbrfcacheMaxIoSizeKbrfcacheOpertionalModer{   )rM   rY   rq   s      r'   r   r     s     K"$(L!#'K &*N#+/'(<(4DT9U-:.(7(EK%;'3
CV8W,9-'6{'CK$>*6:FZ;[/<0*9.*IK'./;23GZ7[[/>?R/SK+,r7   c                     t        t               t               t               t        d      t        dt        t        d      t        d      t        d      t        d      t        g dd            	      t        dt        t        d      t        d      t        d      t        g d
            	      t        ddddg            S )zZThis method provides parameters required for the protection domain
    module on PowerFlexbool)typer?   int)KBpsr   r   r   )choicesdefault)r^   r_   r`   r-   r   )r   options)NoneReadWriteReadAndWrite	WriteMiss)r   )re   rf   rg   rh   Tr!   rT   r   )requiredr   r   )r   r*   r   rZ   r,   rY   rU   r   r{   r7   r'   r   r   C  s     #v#'6!VF#". $% 0&*&6".#,D,2 4"	
 V,E*!u-"& 0M #N	"
 Duy(6KL1 r7   c                  8    t               } | j                          y)zn Create PowerFlex protection domain object and perform actions on it
        based on user input from playbookN)r
   r   )objs    r'   mainr   b  s     $
%C  "r7   __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
   r   r   r   r   r   r   r{   r7   r'   <module>r      s    [ B B_BQfh
T	 5 e*+b bJ>'T"J># zF r7   