
    Vhv0                        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d	Z G d
 de      Zd Zd Zd Zd Zd Zedk(  r e        yy)z/Ansible module for managing FileSystem on Unity    )absolute_importdivisionprint_functiona(  

module: filesystem
version_added: '1.1.0'
short_description: Manage filesystem on Unity storage system
description:
- Managing filesystem on Unity storage system includes
  Create new filesystem,
  Modify snapschedule attribute of filesystem,
  Modify filesystem attributes,
  Display filesystem details,
  Display filesystem snapshots,
  Display filesystem snapschedule,
  Delete snapschedule associated with the filesystem,
  Delete filesystem,
  Create new filesystem with quota configuration,
  Enable, modify and disable replication.

extends_documentation_fragment:
  -  dellemc.unity.unity

author:
- Arindam Datta (@dattaarindam) <ansible.team@dell.com>
- Meenakshi Dembi (@dembim) <ansible.team@dell.com>
- Spandita Panigrahi (@panigs7) <ansible.team@dell.com>

options:
  filesystem_name:
    description:
    - The name of the filesystem. Mandatory only for the create operation.
      All the operations are supported through I(filesystem_name).
    - It is mutually exclusive with I(filesystem_id).
    type: str
  filesystem_id:
    description:
    - The id of the filesystem.
    - It can be used only for get, modify, or delete operations.
    - It is mutually exclusive with I(filesystem_name).
    type: str
  pool_name:
    description:
    - This is the name of the pool where the filesystem will be created.
    - Either the I(pool_name) or I(pool_id) must be provided to create a new
      filesystem.
    type: str
  pool_id:
    description:
    - This is the ID of the pool where the filesystem will be created.
    - Either the I(pool_name) or I(pool_id) must be provided to create a new
      filesystem.
    type: str
  size:
    description:
     - The size of the filesystem.
    type: int
  cap_unit:
    description:
     - The unit of the filesystem size. It defaults to C(GB), if not specified.
    choices: ['GB' , 'TB']
    type: str
  nas_server_name:
    description:
    - Name of the NAS server on which filesystem will be hosted.
    type: str
  nas_server_id:
    description:
    - ID of the NAS server on which filesystem will be hosted.
    type: str
  supported_protocols:
    description:
    - Protocols supported by the file system.
    - It will be overridden by NAS server configuration if NAS Server is C(Multiprotocol).
    type: str
    choices: ['NFS', 'CIFS', 'MULTIPROTOCOL']
  description:
    description:
    - Description about the filesystem.
    - Description can be removed by passing empty string ("").
    type: str
  smb_properties:
    description:
    - Advance settings for SMB. It contains optional candidate variables.
    type: dict
    suboptions:
      is_smb_sync_writes_enabled:
        description:
        - Indicates whether the synchronous writes option is enabled on the
          file system.
        type: bool
      is_smb_notify_on_access_enabled:
        description:
        - Indicates whether notifications of changes to directory file
          structure are enabled.
        type: bool
      is_smb_op_locks_enabled:
        description:
        - Indicates whether opportunistic file locking is enabled on the file
          system.
        type: bool
      is_smb_notify_on_write_enabled:
        description:
        - Indicates whether file write notifications are enabled on the file
          system.
        type: bool
      smb_notify_on_change_dir_depth:
        description:
        - Integer variable, determines the lowest directory level to which
          the enabled notifications apply.
        - Minimum value is C(1).
        type: int
  data_reduction:
    description:
    - Boolean variable, specifies whether or not to enable compression.
      Compression is supported only for thin filesystem.
    type: bool
  is_thin:
    description:
    - Boolean variable, specifies whether or not it is a thin filesystem.
    type: bool
  access_policy:
    description:
    - Access policy of a filesystem.
    choices: ['NATIVE', 'UNIX', 'WINDOWS']
    type: str
  locking_policy:
    description:
    - File system locking policies. These policy choices control whether the
      NFSv4 range locks must be honored.
    type: str
    choices: ['ADVISORY', 'MANDATORY']
  tiering_policy:
    description:
    - Tiering policy choices for how the storage resource data will be
      distributed among the tiers available in the pool.
    choices: ['AUTOTIER_HIGH', 'AUTOTIER', 'HIGHEST', 'LOWEST']
    type: str
  quota_config:
    description:
    - Configuration for quota management. It contains optional parameters.
    type: dict
    suboptions:
        grace_period:
            description:
            - Grace period set in quota configuration after soft limit is reached.
            - If I(grace_period) is not set during creation of filesystem,
              it will be set to C(7 days) by default.
            type: int
        grace_period_unit:
            description:
            - Unit of grace period.
            - Default unit is C(days).
            type: str
            choices: ['minutes', 'hours', 'days']
        default_hard_limit:
            description:
            - Default hard limit for user quotas and tree quotas.
            - If I(default_hard_limit) is not set while creation of filesystem,
              it will be set to C(0B) by default.
            type: int
        default_soft_limit:
            description:
            - Default soft limit for user quotas and tree quotas.
            - If I(default_soft_limit) is not set while creation of filesystem,
              it will be set to C(0B) by default.
            type: int
        is_user_quota_enabled:
            description:
            - Indicates whether the user quota is enabled.
            - If I(is_user_quota_enabled) is not set while creation of filesystem,
              it will be set to C(false) by default.
            - Parameters I(is_user_quota_enabled) and I(quota_policy) are
              mutually exclusive.
            type: bool
        quota_policy:
            description:
            - Quota policy set in quota configuration.
            - If I(quota_policy) is not set while creation of filesystem, it will
              be set to C(FILE_SIZE) by default.
            - Parameters I(is_user_quota_enabled) and I(quota_policy) are
              mutually exclusive.
            choices: ['FILE_SIZE','BLOCKS']
            type: str
        cap_unit:
            description:
            - Unit of I(default_soft_limit) and I(default_hard_limit) size.
            - Default unit is C(GB).
            choices: ['MB', 'GB', 'TB']
            type: str
  state:
    description:
    - State variable to determine whether filesystem will exist or not.
    choices: ['absent', 'present']
    required: true
    type: str
  snap_schedule_name:
    description:
    - This is the name of an existing snapshot schedule which is to be associated with the filesystem.
    - This is mutually exclusive with I(snapshot_schedule_id).
    type: str
  snap_schedule_id:
    description:
    - This is the id of an existing snapshot schedule which is to be associated with the filesystem.
    - This is mutually exclusive with I(snapshot_schedule_name).
    type: str
  replication_params:
    description:
    - Settings required for enabling or modifying replication.
    type: dict
    suboptions:
      replication_name:
        description:
        - Name of the replication session.
        type: str
      new_replication_name:
        description:
        - Replication name to rename the session to.
        type: str
      replication_mode:
        description:
        - The replication mode.
        - This is a mandatory field while creating a replication session.
        type: str
        choices: ['synchronous', 'asynchronous', 'manual']
      rpo:
        description:
        - Maximum time to wait before the system syncs the source and destination LUNs.
        - The I(rpo) option should be specified if the I(replication_mode) is C(asynchronous).
        - The value should be in range of C(5) to C(1440) for C(asynchronous),
          C(0) for C(synchronous) and C(-1) for C(manual).
        type: int
      replication_type:
        description:
        - Type of replication.
        choices: ['local', 'remote']
        type: str
      remote_system:
        description:
        - Details of remote system to which the replication is being configured.
        - The I(remote_system) option should be specified if the I(replication_type) is C(remote).
        type: dict
        suboptions:
          remote_system_host:
            required: true
            description:
            - IP or FQDN for remote Unity unisphere Host.
            type: str
          remote_system_username:
            type: str
            required: true
            description:
            - User name of remote Unity unisphere Host.
          remote_system_password:
            type: str
            required: true
            description:
            - Password of remote Unity unisphere Host.
          remote_system_verifycert:
            type: bool
            default: true
            description:
            - Boolean variable to specify whether or not to validate SSL
              certificate of remote Unity unisphere Host.
            - C(true) - Indicates that the SSL certificate should be verified.
            - C(false) - Indicates that the SSL certificate should not be
              verified.
          remote_system_port:
            description:
            - Port at which remote Unity unisphere is hosted.
            type: int
            default: 443
      destination_pool_id:
        type: str
        description:
        - ID of pool to allocate destination filesystem.
      destination_pool_name:
        type: str
        description:
        - Name of pool to allocate destination filesystem.
  replication_state:
    description:
    - State of the replication.
    choices: ['enable', 'disable']
    type: str

notes:
- SMB shares, NFS exports, and snapshots associated with filesystem need
  to be deleted prior to deleting a filesystem.
- The I(quota_config) parameter can be used to update default hard limit
  and soft limit values to limit the maximum space that can be used.
  By default they both are set to 0 during filesystem
  creation which means unlimited.
- The I(check_mode) is not supported.
a`  
- name: Create FileSystem
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_name: "ansible_test_fs"
    nas_server_name: "lglap761"
    pool_name: "pool_1"
    size: 5
    state: "present"

- name: Create FileSystem with quota configuration
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_name: "ansible_test_fs"
    nas_server_name: "lglap761"
    pool_name: "pool_1"
    size: 5
    quota_config:
      grace_period: 8
      grace_period_unit: "days"
      default_soft_limit: 10
      is_user_quota_enabled: false
    state: "present"

- name: Expand FileSystem size
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_name: "ansible_test_fs"
    nas_server_name: "lglap761"
    size: 10
    state: "present"

- name: Expand FileSystem size
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_name: "ansible_test_fs"
    nas_server_name: "lglap761"
    size: 10
    state: "present"

- name: Modify FileSystem smb_properties
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_name: "ansible_test_fs"
    nas_server_name: "lglap761"
    smb_properties:
      is_smb_op_locks_enabled: true
      smb_notify_on_change_dir_depth: 5
      is_smb_notify_on_access_enabled: true
    state: "present"

- name: Modify FileSystem Snap Schedule
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "fs_141"
    snap_schedule_id: "{{snap_schedule_id}}"
    state: "{{state_present}}"

- name: Get details of FileSystem using id
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "rs_405"
    state: "present"

- name: Delete a FileSystem using id
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "rs_405"
    state: "absent"

- name: Enable replication on the fs
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "rs_405"
    replication_params:
      replication_name: "test_repl"
      replication_type: "remote"
      replication_mode: "asynchronous"
      rpo: 60
      remote_system:
        remote_system_host: '0.1.2.3'
        remote_system_verifycert: false
        remote_system_username: 'username'
        remote_system_password: 'password'
      destination_pool_name: "pool_test_1"
    replication_state: "enable"
    state: "present"

- name: Modify replication on the fs
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "rs_405"
    replication_params:
      replication_name: "test_repl"
      new_replication_name: "test_repl_updated"
      replication_mode: "asynchronous"
      rpo: 50
    replication_state: "enable"
    state: "present"

- name: Disable replication on the fs
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "rs_405"
    replication_state: "disable"
    state: "present"

- name: Disable replication by specifying replication_name on the fs
  dellemc.unity.filesystem:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "rs_405"
    replication_params:
      replication_name: "test_replication"
    replication_state: "disable"
    state: "present"
a!  
changed:
    description: Whether or not the resource has changed.
    returned: always
    type: bool
    sample: true

filesystem_details:
    description: Details of the filesystem.
    returned: When filesystem exists
    type: dict
    contains:
        id:
            description: The system generated ID given to the filesystem.
            type: str
        name:
            description: Name of the filesystem.
            type: str
        description:
            description: Description about the filesystem.
            type: str
        is_data_reduction_enabled:
            description: Whether or not compression enabled on this
                         filesystem.
            type: bool
        size_total_with_unit:
            description: Size of the filesystem with actual unit.
            type: str
        tiering_policy:
            description: Tiering policy applied to this filesystem.
            type: str
        is_cifs_notify_on_access_enabled:
            description: Indicates whether the system generates a
                         notification when a user accesses the file system.
            type: bool
        is_cifs_notify_on_write_enabled:
            description: Indicates whether the system generates a notification
                         when the file system is written to.
            type: bool
        is_cifs_op_locks_enabled:
            description: Indicates whether opportunistic file locks are enabled
                         for the file system.
            type: bool
        is_cifs_sync_writes_enabled:
            description: Indicates whether the CIFS synchronous writes option
                         is enabled for the file system.
            type: bool
        cifs_notify_on_change_dir_depth:
            description: Indicates the lowest directory level to which the
                         enabled notifications apply, if any.
            type: int
        pool:
            description: The pool in which this filesystem is allocated.
            type: dict
            contains:
                id:
                    description: The system ID given to the pool.
                    type: str
                name:
                    description: The name of the storage pool.
                    type: str
        nas_server:
            description: The NAS Server details on which this filesystem is hosted.
            type: dict
            contains:
                id:
                    description: The system ID given to the NAS Server.
                    type: str
                name:
                    description: The name of the NAS Server.
                    type: str
        snapshots:
            description: The list of snapshots of this filesystem.
            type: list
            contains:
                id:
                    description: The system ID given to the filesystem
                                    snapshot.
                    type: str
                name:
                    description: The name of the filesystem snapshot.
                    type: str
        is_thin_enabled:
            description: Indicates whether thin provisioning is enabled for
                         this filesystem.
            type: bool
        snap_schedule_id:
            description: Indicates the id of the snap schedule associated
                         with the filesystem.
            type: str
        snap_schedule_name:
            description: Indicates the name of the snap schedule associated
                         with the filesystem.
            type: str
        quota_config:
            description: Details of quota configuration of the filesystem
                         created.
            type: dict
            contains:
                grace_period:
                    description: Grace period set in quota configuration
                                 after soft limit is reached.
                    type: str
                default_hard_limit:
                    description: Default hard limit for user quotas
                                 and tree quotas.
                    type: int
                default_soft_limit:
                    description: Default soft limit for user quotas
                                 and tree quotas.
                    type: int
                is_user_quota_enabled:
                    description: Indicates whether the user quota is enabled.
                    type: bool
                quota_policy:
                    description: Quota policy set in quota configuration.
                    type: str
        replication_sessions:
            description: List of replication sessions if replication is enabled.
            type: dict
            contains:
                id:
                    description: ID of replication session
                    type: str
                name:
                    description: Name of replication session
                    type: str
                remote_system:
                    description: Remote system
                    type: dict
                    contains:
                        id:
                            description: ID of remote system
                            type: str
    sample: {
        "access_policy": "AccessPolicyEnum.UNIX",
        "cifs_notify_on_change_dir_depth": 512,
        "cifs_share": null,
        "data_reduction_percent": 0,
        "data_reduction_ratio": 1.0,
        "data_reduction_size_saved": 0,
        "description": "",
        "existed": true,
        "folder_rename_policy": "FSRenamePolicyEnum.SMB_RENAME_FORBIDDEN",
        "format": "FSFormatEnum.UFS64",
        "hash": 8735427610152,
        "health": {
            "UnityHealth": {
                "hash": 8735427614928
            }
        },
        "host_io_size": "HostIOSizeEnum.GENERAL_8K",
        "id": "fs_65916",
        "is_advanced_dedup_enabled": false,
        "is_cifs_notify_on_access_enabled": false,
        "is_cifs_notify_on_write_enabled": false,
        "is_cifs_op_locks_enabled": false,
        "is_cifs_sync_writes_enabled": false,
        "is_data_reduction_enabled": false,
        "is_read_only": false,
        "is_smbca": false,
        "is_thin_enabled": true,
        "locking_policy": "FSLockingPolicyEnum.MANDATORY",
        "metadata_size": 11274289152,
        "metadata_size_allocated": 4294967296,
        "min_size_allocated": 0,
        "name": "test_fs",
        "nas_server": {
            "id": "nas_18",
            "name": "test_nas1"
        },
        "nfs_share": null,
        "per_tier_size_used": [
            6979321856,
            0,
            0
        ],
        "pool": {
            "id": "pool_7",
            "name": "pool 7"
        },
        "pool_full_policy": "ResourcePoolFullPolicyEnum.FAIL_WRITES",
        "quota_config": {
            "default_hard_limit": "0B",
            "default_soft_limit": "0B",
            "grace_period": "7.0 days",
            "id": "quotaconfig_171798760421_0",
            "is_user_quota_enabled": false,
            "quota_policy": "QuotaPolicyEnum.FILE_SIZE"
        },
        "replication_sessions": {
            "current_transfer_est_remain_time": 0,
            "id": "***",
            "last_sync_time": "2022-05-12 11:20:38+00:00",
            "local_role": "ReplicationSessionReplicationRoleEnum.SOURCE",
            "max_time_out_of_sync": 60,
            "members": null,
            "name": "local_repl_new",
            "network_status": "ReplicationSessionNetworkStatusEnum.OK",
            "remote_system": {
                "UnityRemoteSystem": {
                    "hash": 8735426929707
                }
            },
            "replication_resource_type": "ReplicationEndpointResourceTypeEnum.FILESYSTEM",
            "src_resource_id": "res_66444",
            "src_status": "ReplicationSessionStatusEnum.OK",
            "status": "ReplicationOpStatusEnum.AUTO_SYNC_CONFIGURED",
            "sync_progress": 0,
            "sync_state": "ReplicationSessionSyncStateEnum.IDLE"
        },
        "size_allocated": 283148288,
        "size_allocated_total": 4578148352,
        "size_preallocated": 2401173504,
        "size_total": 10737418240,
        "size_total_with_unit": "10.0 GB",
        "size_used": 1620312064,
        "snap_count": 2,
        "snaps_size": 21474869248,
        "snaps_size_allocated": 32768,
        "snapshots": [],
        "supported_protocols": "FSSupportedProtocolEnum.NFS",
        "tiering_policy": "TieringPolicyEnum.AUTOTIER_HIGH",
        "type": "FilesystemTypeEnum.FILESYSTEM"
    }
)AnsibleModule)utils
filesystemzAnsible/1.7.1c                       e Zd ZdZ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 dZd Zy)!
Filesystemz Class with FileSystem operationsc                    t        j                         | _        | j                  j                  t	                      ddgddgddgddgg}ddgg}t        | j                  d	||
      | _        t        j                  | j                         t        j                  | j                  j                  t              | _        y)z-Define all parameters required by this modulefilesystem_namefilesystem_id	pool_namepool_idnas_server_namenas_server_idsnap_schedule_namesnap_schedule_idF)argument_specsupports_check_modemutually_exclusiverequired_one_ofN)r   $get_unity_management_host_parametersmodule_paramsupdateget_filesystem_parametersr   moduleensure_required_libsget_unity_unisphere_connectionparamsapplication_type
unity_conn)selfr   r   s      l/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/unity/plugins/modules/filesystem.py__init__zFilesystem.__init__  s    "GGI!!";"=>0/B*I60/B35GHJ
 .?@ $,, %1+	-
 	""4;;/>>KK 02    Nc                    |r|n|}d}	 d}|rc|r| j                   j                  ||      }n| j                   j                  |      }|r$|j                  rt        j	                  d|       |S y|rm|s3d}t        j                  |       | j                  j                  |       | j                   j                  ||      }|rt        j	                  d|       |S yt        j	                  d	|       y# t        j                  $ r}|j                  d
k(  rJdj                  |j                        }	|j                  ||	      }
| j                  j                  |
       n<|j                  |t        |            }
| j                  j                  |
       Y d}~yY d}~yd}~wt        j                  $ r:}|j                  |t        |            }
t        j                  |
       Y d}~yd}~wt        $ rV}|j                  |t        |            }
t        j                  |
       | j                  j                  |
       Y d}~yd}~ww xY w)a&  Get the details of a FileSystem.
            :param filesystem_name: The name of the filesystem
            :param filesystem_id: The id of the filesystem
            :param obj_nas_server: NAS Server object instance
            :return: instance of the respective filesystem if exist.
        z/Failed to get the filesystem {0} with error {1}N)_id
nas_server)r'   z*Successfully got the filesystem object %s z,NAS Server is required to get the FileSystemmsg)namer(   zFailed to get the filesystem %si  z$Incorrect username or password , {0})r!   get_filesystemexistedLOGinfoerrorr   	fail_jsonr   	HttpErrorhttp_statusformatmessagestrUnityResourceNotFoundError	Exception)r"   r+   idobj_nas_server
id_or_nameerrormsgobj_fserr_msgecred_errr*   s              r#   r,   zFilesystem.get_filesystem  s    R4
D1	+F!!__;;#1 < 3F "__;;;CFfnnHH *+13!M   %LGIIg&KK))g)677- 8 / HHDfN!M  :JG 	/}}#AHHIIooj(;%%#%.ooj#a&9%%#%.. /
 // 	//*c!f5CIIcN 	+//*c!f5CIIcNKK!!c!**	+s?   A%C7 1A-C7  C7 7I
BF$$I:0G//I;AIIc                    d}|r|n|}	 | j                   j                  ||      }|r$|j                  rt        j	                  d|       |S |rt        j	                  d|       |S dj                  |      }t        j                  |       | j                  j                  |       y# t        $ rV}|j                  |t        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zGet the instance of a NAS Server.
            :param name: The NAS Server name
            :param id: The NAS Server id
            :return: instance of the respective NAS Server if exists.
        z/Failed to get the NAS Server {0} with error {1})r'   r+   z)Successfully got the nas server object %sz*Successfully got the nas server object %s z%Failed to get the nas server with {0}r)   N)r!   get_nas_serverr-   r.   r/   r4   r0   r   r1   r8   r6   )r"   r+   r9   r<   r;   obj_nasr*   r?   s           r#   rB   zFilesystem.get_nas_server  s     E!Tr
	+oo44$4GGgooD "E "=DD 		#%%#%. 	+//$A/CIIcNKK!!c!**	+&   AB* B* 'AB* *	D	3ADD	c                    |r|n|}d}	 | j                   j                  ||      }|r$|j                  rt        j	                  d|       |S |rt        j	                  d|       |S dj                  |      }t        j                  |       | j                  j                  |       y# t        $ rV}|j                  |t        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zGet the instance of a pool.
            :param pool_name: The name of the pool
            :param pool_id: The id of the pool
            :return: Dict containing pool details if exists
        z)Failed to get the pool {0} with error {1})r+   r'   z#Successfully got the pool object %szSuccessfully got pool %szFailed to get the pool with {0}r)   N)r!   get_poolr-   r.   r/   r4   r0   r   r1   r8   r6   )r"   r   r   r;   r<   obj_poolr*   r?   s           r#   rF   zFilesystem.get_pool.  s     !(WY
>	+//YG/LH8++>!#3X>7>> 		#%%#%. 	+//*c!f5CIIcNKK!!c!**	+rD   c                     |t         j                  j                  v rt         j                  |   S dj                  |      }t        j                  |       | j                  j                  |       y)zGet the tiering_policy enum.
             :param tiering_policy: The tiering_policy string
             :return: tiering_policy enum
        z%Invalid choice {0} for tiering policyr)   N)r   TieringPolicyEnum__members__r4   r.   r0   r   r1   )r"   tiering_policyr<   s      r#   get_tiering_policy_enumz"Filesystem.get_tiering_policy_enumM  s]     U44@@@**>::>EE HIIhKK!!h!/r%   c                     |dk(  rdn|}|t         j                  j                  v rt         j                  |   S dj                  |      }t        j                  |       | j                  j                  |       y)zGet the supported_protocol enum.
             :param supported_protocol: The supported_protocol string
             :return: supported_protocol enum
        MULTIPROTOCOLMULTI_PROTOCOLz)Invalid choice {0} for supported_protocolr)   N)r   FSSupportedProtocolEnumrJ   r4   r.   r0   r   r1   )r"   supported_protocolr<   s      r#   get_supported_protocol_enumz&Filesystem.get_supported_protocol_enum[  ss     /1 .7I 	!>!>!J!JJ001CDDBII"$HIIhKK!!h!/r%   c                     |t         j                  j                  v rt         j                  |   S dj                  |      }t        j                  |       | j                  j                  |       y)zGet the locking_policy enum.
             :param locking_policy: The locking_policy string
             :return: locking_policy enum
        z%Invalid choice {0} for locking_policyr)   N)r   FSLockingPolicyEnumrJ   r4   r.   r0   r   r1   )r"   locking_policyr<   s      r#   get_locking_policy_enumz"Filesystem.get_locking_policy_enumk  s]    
 U66BBB,,^<<>EE HIIhKK!!h!/r%   c                     |t         j                  j                  v rt         j                  |   S dj                  |      }t        j                  |       | j                  j                  |       y)zGet the access_policy enum.
             :param access_policy: The access_policy string
             :return: access_policy enum
        z$Invalid choice {0} for access_policyr)   N)r   AccessPolicyEnumrJ   r4   r.   r0   r   r1   )r"   access_policyr<   s      r#   get_access_policy_enumz!Filesystem.get_access_policy_enumx  s]    
 E22>>>))-88=DDHIIhKK!!h!/r%   c           
      X   	 | j                   j                  d   }|r| j                  |      nd}| j                   j                  d   }| j                   j                  d   }|r| j                  |      nd}t        j
                  j                  | j                  j                  |||||||      }t        j                  d|       |S # t        $ rV}	dj                  |t        |	            }
t        j                  |
       | j                   j                  |
       Y d}	~	yd}	~	ww xY w)	a:  Create a FileSystem.
            :param name: Name of the FileSystem
            :param obj_pool: Storage Pool obj instance
            :param obj_nas_server: NAS Server obj instance
            :param size: Total size of a filesystem in bytes
            :return: FileSystem object on successful creation
        supported_protocolsNis_thinrK   )poolr(   r+   sizeprotor]   rK   z%Successfully created file system , %sz6Create filesystem {0} operation  failed with error {1}r)   )r   r   rR   rL   r   UnityFileSystemcreater!   _clir.   r/   r8   r4   r6   r0   r1   )r"   r+   rG   r:   r_   rQ   r]   rK   r=   r?   r<   s              r#   create_filesystemzFilesystem.create_filesystem  s"   	0!%!3!34I!J'9 "&!A!A""$?C kk((3G![[//0@AN! "99.I'+  **11$$)(- 2 /F HH<fEM 	0))/c!f)= IIhKK!!h!//		0s   CC
 
	D)AD$$D)c                    	 | j                  |      }|j                         }|d   3d}t        j                  |       | j                  j                  |       |d   3d}t        j                  |       | j                  j                  |       |j                          y# t        $ rV}d	j                  |t        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)
zdDelete a FileSystem.
        :param id: The object instance of the filesystem to be deleted
        r9   
cifs_shareNzJThe Filesystem has SMB Shares. Hence deleting this filesystem is not safe.r)   	nfs_sharezKThe FileSystem has NFS Exports. Hence deleting this filesystem is not safe.Tz;Delete operation of FileSystem id:{0} failed with error {1})
r,   _get_propertiesr.   r0   r   r1   deleter8   r4   r6   )r"   r9   r=   obj_fs_dictr<   r?   s         r#   delete_filesystemzFilesystem.delete_filesystem  s    
	0((B(/F 002K<(4:		(#%%(%3;'3:		(#%%(%3MMO 	0//5vb69!f0>  IIhKK!!h!//	0s   B"B% %	D.AC??Dc                    	 i }|j                         }| j                  j                  d   }|"||j                  k7  r|j                  d|i       | j                  j                  d   }|ro|rmt	        t        j                  ||            }||j                  k  r| j                  j                  d       n"||j                  kD  r|j                  d|i       | j                  j                  d   }|r@| j                  |      |j                  k7  r"|j                  d| j                  |      i       | j                  j                  d   }|"||j                  k7  r|j                  d|i       | j                  j                  d   }	|	"|	|j                  k7  r|j                  d	|	i       | j                  j                  d
   }
|
r@| j                  |
      |j                  k7  r"|j                  d
| j                  |
      i       | j                  j                  d   }|r@| j                  |      |j                   k7  r"|j                  d| j                  |      i       |j"                  j$                  }| j&                  v| j&                  dk(  r/|re|j(                  | j&                  k7  rL|j                  ddi       n8||j(                  | j&                  k7  r|j                  d| j&                  i       | j                  j                  d   }|r|d   }|d   }|d   }|d   }|d   }|"||j*                  k7  r|j                  d|i       |"||j,                  k7  r|j                  d|i       |"||j.                  k7  r|j                  d|i       |"||j0                  k7  r|j                  d|i       |"||j2                  k7  r|j                  d|i       t5        |      dkD  r|S y# t6        $ r`}dj9                  |j(                  t;        |            }t<        j?                  |       | j                  j                  |       Y d}~yd}~ww xY w)zChecks if any modify required for filesystem attributes
        :param obj_fs: filesystem instance
        :param cap_unit: capacity unit
        :return: filesystem to update dict
        descriptionNr_   z$Filesystem size can be expanded onlyr)   rK   r]   data_reductionis_compressionrY   rU    is_snap_schedule_pausedFsnap_sch_idsmb_propertiesis_smb_sync_writes_enabledis_smb_op_locks_enabledis_smb_notify_on_write_enabledis_smb_notify_on_access_enabledsmb_notify_on_change_dir_depthis_cifs_sync_writes_enabledis_cifs_op_locks_enabledis_cifs_notify_on_write_enabled is_cifs_notify_on_access_enabledcifs_notify_on_change_dir_depthr   zNFailed to determine if FileSystem id: {0} modification required with error {1}) r   r   r   rn   intr   get_size_bytes
size_totalr1   rL   rK   is_thin_enabledis_data_reduction_enabledrZ   rY   rV   rU   storage_resourcesnap_schedulers   r9   rz   r{   r|   r}   r~   lenr8   r4   r6   r.   r0   )r"   r=   cap_unit	to_updatern   r_   	size_byterK   r]   ro   rY   rU   snap_schrt   sync_writes_enabledoplocks_enablednotify_on_writenotify_on_accessnotify_on_change_dir_depthr?   r<   s                        r#   is_modify_requiredzFilesystem.is_modify_required  s   k	0I]]_F++,,];K&;&:L:L+L  -!=>;;%%f-D 4 4T8 DE	v000KK)) />) ?!2!22$$fi%89![[//0@AN$">">"#$'-'<'<#=  "2"&">">&4#6"7 8 kk((3G"w&2H2H'H  )W!56![[//0@AN)"f&F&FF  "2N!CD KK..?M!<!<!"#&,&:&:";  /"&"="=m"L"N O "[[//0@AN$">">"#$'-'<'<#=  "2"&">">&4#6"7 8 ..<<H+##r)HKK43C3C$C!((*CU)KL%8H8H)H$$mT5E5E%FG![[//0@AN"#?@ $ ##<=   ##CD   ##DE ! ##CD + '2+v/Q/QQ$$68KLN #.'6+J+JJ$$3_EG #.'>>?$$:OLN $/(??@$$;)+, .92>>?$$:356 9~!   	0??EvfiiFI!f@N  IIhKK!!h!//	0s   O3O7 7	Q  AQQ c                 `   	 g d}i }i }|D ]+  }||j                         v s|j                  |||   i       - t        j                  d|        |j                  di |}g d}|D ]+  }	|	|j                         v s|j                  |	||	   i       - |r|j                  d|i       d|j                         v r'|j                  ddd|j                  d      iii       n'd	|j                         v r|j                  dd
dii       |j                         } |j                  di |}
t        j                  d|
       y# t        $ r`}dj                  |j                  t        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)z modifes attributes for a filesystem instance
        :param update_dict: modify dict
        :return: True on Success
        )rz   r{   r|   r}   r~   zCIFS Modify Payload: %s)r_   r]   rK   rp   rY   rU   rn   cifs_fs_parametersr   rs   snap_schedule_parameterssnapScheduler9   rr   isSnapSchedulePausedFz-Successfully modified the FS with response %sz;Failed to modify FileSystem instance id: {0} with error {1}r)   N )keysr   r.   debugprepare_cifs_fs_parametersgetmodifyr/   r8   r4   r9   r6   r0   r   r1   )r"   update_dictr=   adv_smb_paramscifs_fs_payloadfs_update_payload	smb_paramr   fs_update_paramsfs_paramrespr?   r<   s                r#   modify_filesystemzFilesystem.modify_filesystem:  s   
9	03N !O "+ P	 0 0 22#**I{97M+NOP II/A!B!B!B "#!"# & - P{//11%,,hH8M-NOP "!(()+=>@  0 0 22!((/.KOOM:;2 
 +k.>.>.@@!((/2H%1P  ]]_F 6==5#45DHHDdK 	0))/		3q6)B IIhKK!!h!//		0s%   E AE >CE 	F-AF((F-c           
         	 |j                         }|j                         }t        j                  t	        |d               |d<   |j
                  r>|j                  d|j
                  j                  |j
                  j                  di       |j                  r>|j                  d|j                  j                  |j                  j                  di       g }|j                         r;|j                  D ],  }|j                  |j                  d}|j                  |       . ||d<   |j                  j                  rF|j                  j                  j                  |d<   |j                  j                  j                  |d<   | j                  |      }|rt        j                  |j                        }t        j                  |j                         }t#        |j$                        }	|j                  d	|j                  |||j&                  |j                         d
   |	di       g |d<   | j)                  |      }
|
r|
j                         |d<   |S # t*        $ r`}dj-                  |j                  t/        |            }t0        j3                  |       | j4                  j7                  |       Y d}~yd}~ww xY w)zget display filesystem attributes
        :param obj_fs: filesystem instance
        :return: filesystem dict to display
        r   size_total_with_unitr^   r+   r9   r(   	snapshotsr   r   quota_configquota_policy)r9   default_hard_limitdefault_soft_limitis_user_quota_enabledr   grace_periodreplication_sessionsz3Failed to display the filesystem {0} with error {1}r)   N)r   ri   r   convert_size_with_unitr   r^   r+   r9   r(   has_snapr   appendr   r   get_quota_config_detailsr   r   get_time_with_unitr   r   get_replication_sessionr8   r4   r6   r.   r0   r   r1   )r"   r=   filesystem_details	snap_listsnapdquota_config_obj
hard_limit
soft_limitr   fs_repl_sessionsr?   r<   s                r#   !get_filesystem_display_attributesz,Filesystem.get_filesystem_display_attributesz  s   
8	0]]_F!'!7!7!99>&&s+=l+K'L:N56{{"))fkk&6&6$*KKNN4 56   "))!F,=,=,B,B*0*;*;*>*>$@ AB I ",, (D!%$'':A$$Q'( /8{+&&449?9P9P9^9^9a9a"#56;A;R;R;`;`;e;e"#78#<<VD"99$779
"99$779
1$11 3 #))>1A1D1DAKAK/?/U/U;K;[;[;]/=<?;G+I	+- 	. :<56#;;FC$446 ##9:%% 	0##)6&++s1v#> IIhKK!!h!//		0s   II 	K#AJ>>Kc                 |   d}	 | j                   j                  D ]o  }| j                   j                  |   }|dk(  s
|dk(  s|dk(  r,t        |t              s=||k(  sCdj	                  |      }| j                   j                  |       q | j                   j                  d   r7| j                   j                  d   | j                   j                  d
       y	y	y	# t        $ rU}dj	                  t        |            }t        j                  |       | j                   j                  |       Y d	}~y	d	}~ww xY w)z9 validates the input string checks if it is empty string rq   rn   r   r   z"Invalid input parameter "" for {0}r)   replication_paramsreplication_stateNz>Please specify replication_state along with replication_paramsz2Failed to validate the module param with error {0})	r   r   
isinstancer6   r4   r1   r8   r.   r0   )r"   invalid_stringkeyvalerrmsgr?   r<   s          r#   validate_input_stringz Filesystem.validate_input_string  s#   	0{{)) 	6kk((--'32F+F $66c3'>1AHHFKK))f)5	6 {{!!"67DKK<N<NOb<c<k%%*j%k =l7 	0##)6#a&> IIhKK!!h!//		0s&   AC C A=C 	D;&AD66D;c                     	 d}i }|d   r9t         j                  j                  | j                  j                  |d         }n=|d   r8t         j                  j                  | j                  j                  |d         }|r|j
                  d   }|sJdj                  |d         |d   f}t        j                  |       | j                  j                  |       |S # t        $ r$}d	j                  t        |            }Y d}~yd}~ww xY w)
z Get snapshot id for a give snap schedule name
        :param params: snap schedule name or id
        :return: snap schedule id after validation
        Nr+   r+   r9   rf   r   zEFailed to find the snapshot schedule id against given name or id: {0}r)   z4Failed to find the snapshot schedules with error {0})r   UnitySnapScheduleListr   r!   rc   r9   r4   r.   r0   r   r1   r8   r6   )r"   r   rs   snapshot_scheduler<   r?   s         r#   resolve_to_snapschedule_idz%Filesystem.resolve_to_snapschedule_id  s    	2K "f~$)$?$?$C$CDOODXDX_efl_m$C$n!$)$?$?$C$CDOODXDX]cdh]i$C$j! /2215((.vf~(>O		(#%%(%3 	2##)6#a&> 	2s   CC   	D)DDc                 T   	 | j                   j                  |      }|j                  }t        |      dk(  rt        j                  d       yt        t        |            D ]b  }|s||   j                  j                  |k(  s#||   j                  r3d|d||   j                  }t        j                  |       ||   c S  y# t        $ rV}dj                  t        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)	z
        Get the quota config ID mapped to the filesystem
        :param obj_fs: Filesystem instance
        :return: Quota config object if exists else None
        )r   r   z>The quota_config object for new filesystem is not updated yet.NzQuota config id for filesystem z is z?Failed to fetch quota config for filesystem {0}  with error {1}r)   )r!   get_quota_configr9   r   r.   r0   ranger   
tree_quotar/   r8   r4   r6   r   r1   )r"   r=   all_quota_configfs_idr   r*   r?   r<   s           r#   r   z#Filesystem.get_quota_config_details  s   	0#??6?RIIE#$)		 0 1 %c*:&; < :-l;FFIIUR,\:EE"$4\$B$E$EGCHHSM+L99:  	0))/s1v)> IIhKK!!h!//		0s7   AC C (C C 0C C 	D'AD""D'c                 V   |r#|d   }|d   }|d   }|d   }|d   }|d   }|d   }	rt        j                  |      }
n|j                  }
rt        j                  |      }n|j                  }rt	        |	      }n|j
                  }d}d}rt         j                  |   r8t         j                  |   }t         j                  |   j                         d	   }nBd
j                  |      }t        j                  |       | j                  j                  |       |j                  |k(  rE|j                  |
k(  r6|j
                  |k(  r'||j                  |k(  s||||j                  k(  ry	 | j                  j!                  |j"                  |||
|      }t        j%                  d|       y# t&        $ rj}dj                  |j(                  j"                  t+        |            }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)a  
        Modify default quota config settings of newly created filesystem.
        The default setting of quota config after filesystem creation is:
        default_soft_limit and default_hard_limit are 0,
        is_user_quota_enabled is false,
        grace_period is 7 days and,
        quota_policy is FILE_SIZE.
        :param quota_config_obj: Quota config instance
        :param quota_config_params: Quota config parameters to be modified
        :return: Boolean whether quota config is modified
        r   r   r   r   r   r   grace_period_unitNvaluez#Invalid choice {0} for quota policyr)   F)quota_config_idr   r   r   r   r   z7Successfully modified the quota config with response %sTz@Failed to modify quota config for filesystem {0}  with error {1})r   r   r   r   get_time_in_secondsr   QuotaPolicyEnumri   r4   r.   r0   r   r1   r   r   r!   modify_quota_configr9   r/   r8   r   r6   )r"   r   quota_config_paramsr   r   r   r   r   r   gp_unitsoft_limit_in_byteshard_limit_in_bytesgrace_period_in_secpolicy_enumpolicy_enum_valr<   r   r?   s                     r#   r   zFilesystem.modify_quota_config	  sE    ,-ABJ,-ABJ$78O$P!.~>L.~>L*:6H)*=>G"'"6"6z8"L"2"E"E"'"6"6z8"L"2"E"E"5lG"L"2"?"?$$\2#33LA)),7GGI'R   AGG "		(#%%(%3 ..2EE 337JJ --1DD*"//;>%&.'3'+;+Q+QQ	0??66 0 3 30#6#6&;, 7 .D HHNPTU 	0))/0@0K0K0N0NPSTUPV)W IIhKK!!h!//		0s   3AF5 5	H(>A H##H(c                 0   	 |d   dk(  s
|d   ~|d   ry|d   d   |d   d   |d   d   |d   d   |d   d	   d
}t        j                  |t              }|j                  |d<   |d   Z|j	                  |d         }|j
                  |d<   y|d   /| j                  j	                  |d         }|j
                  |d<   yyy# t        $ rI}dt        |      z  }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)z Update replication params replication_typeremoteNremote_systemremote_system_hostremote_system_usernameremote_system_passwordremote_system_verifycertremote_system_port)unispherehostusernamepasswordvalidate_certsportremote_system_namedestination_pool_namer   destination_pool_idz0Updating replication params failed with error %sr)   )r   r   r    r+   rF   r9   r!   r8   r6   r.   r0   r   r1   )r"   r   connection_paramsremote_system_connpool_objectr?   r<   s          r#   update_replication_paramsz$Filesystem.update_replication_paramsX  sm   	0!"45A'(:;C'8%7%HI]%^ 2? CD\ ] 2? CD\ ]&8&IJd&e.?@TU%! &+%I%I%'7&9";M;R;R"#78%&=>J*339KLc9d3e  @K&'<=%&=>J006HI`6a0b  @K&'<= K K  	0(*-a&1HIIhKK!!h!//		0s   B
C 3C 	D?DDc                 H   |d   dk(  r8|d   3d}t         j                  |       | j                  j                  |       |d   |d   }}|rV|rSd d d	 d
}|rG ||   |      s;d| d| d}t         j                  |       | j                  j                  |       yyyyy)z) Validates rpo based on replication mode replication_modeasynchronousrpoNz>rpo is required together with 'asynchronous' replication_mode.r)   c                 "    d| cxk  xr dk  S c S )N   i  r   ns    r#   <lambda>z)Filesystem.validate_rpo.<locals>.<lambda>  s    !q.D. . r%   c                     | dk(  S )Nr   r   r   s    r#   r   z)Filesystem.validate_rpo.<locals>.<lambda>  s
    a r%   c                     | dk(  S )Nr   r   s    r#   r   z)Filesystem.validate_rpo.<locals>.<lambda>  s
    AG r%   )r   synchronousmanualzInvalid rpo value - z for z replication mode.r.   r0   r   r1   )r"   r   r<   r   r   rpo_criterias         r#   validate_rpozFilesystem.validate_rpow  s    01^C"5)1WHIIhKK!!h!/ 25 9;M<  # !9/+L 9<(89#>1#e.//AC		(#%%(%3	 ?s $3r%   c                    |s3d}t         j                  |       | j                  j                  |       |d   8|d   3d}t         j                  |       | j                  j                  |       | j	                  |       |d   dk(  r:|d	   4d
}t         j                  |       | j                  j                  |       yyy) Validate replication params z8Please specify replication_params to enable replication.r)   r   Nr   zH'destination_pool_id' and 'destination_pool_name' is mutually exclusive.r   r   r   zARemote_system is required together with 'remote' replication_type)r.   r0   r   r1   r  )r"   r   r<   s      r#   validate_replication_paramsz&Filesystem.validate_replication_params  s    !QHIIhKK!!h!/34@"#:;GaHIIhKK!!h!/,-01X=BTUdBeBmZHIIhKK!!h!/ Cn=r%   c                    |d   8|d   3d}t         j                  |       | j                  j                  |       ddg}|D ]>  }||   	d|z  }t         j                  |       | j                  j                  |       @ y)	r  r   Nr   zZEither 'destination_pool_id' or 'destination_pool_name' is required to enable replication.r)   r   r   z(Please specify %s to enable replication.r  )r"   r   r<   r   r   s        r#   "validate_create_replication_paramsz-Filesystem.validate_create_replication_params  s     34<"#:;CsHIIhKK!!h!/"$67 	4C!#&.EK		(#%%(%3		4r%   c                    	 t         j                  d|j                         i }|d   r|d   dk(  rd}n|d   dk(  rd}n
|d   r|d   }|j                  }|d   r||d   k7  r|d   }|j                  |k7  r||d	<   |d   s|d   r|j                  k7  r||d
<   |r |j                  di | yy# t
        $ r@}d|z  }t         j                  |       | j                  j                  |       Y d}~yd}~ww xY w)a   Modify the replication session
            :param: obj_fs: Filesystem object
            :param: repl_session: Replication session to be modified
            :param: replication_params: Module input params
            :return: True if modification is successful
        z.Modifying replication session of filesystem %sr   r  r  r  r   r   new_replication_namer+   max_time_out_of_syncTFz2Modifying replication session failed with error %sr)   Nr   )	r.   r/   r+   r  r   r8   r0   r   r1   )	r"   r=   repl_sessionr   modify_payloadr   r+   r?   r<   s	            r#   modify_replication_sessionz%Filesystem.modify_replication_session  s*   	0HHEv{{SN!"45%&89XEC'(:;}LC#E*(/$$D!"89./EFF)*@A  D()-v&#$67;Me;T 55<9<56###5n5 	0KaOHIIhKK!!h!//	0s   B+B/ /	C886C33C8c                 
   	 | j                  |       | j                  |       | j                  ||d      }|r| j                  |||      S | j	                  |       t        |      }d|v r|d   }| j                  j                         }|D ]  }|j                  |k(  s||d<    n d|j                         vr6d|z  }t        j                  |       | j                  j                  |       t        j                  d|j                          |j                  di | y# t         $ rV}	d|j                  d	t#        |	      }t        j                  |       | j                  j                  |       Y d
}	~	y
d
}	~	ww xY w)z Enable the replication session
            :param: obj_fs: Filesystem object
            :param: replication_params: Module input params
            :return: True if enabling replication is successful
        r   r   r   zRemote system %s is not foundr)   z)Enabling replication to the filesystem %sTz'Enabling replication to the filesystem  failed with error Nr   )r	  r   !get_replication_session_on_filterr  r  get_replication_args_listr!   get_remote_systemr+   r   r.   r0   r   r1   r/   (replicate_with_dst_resource_provisioningr8   r6   )
r"   r=   r   r  replication_args_listr   remote_system_listr   r<   r?   s
             r#   enable_replicationzFilesystem.enable_replication  sz   	0,,-?@**+=> 66v?QS[\ 66v|M_``334FG$=>P$Q!#'99%78L%M"%)__%F%F%H"%7 M$))-??AN-o> #*?*D*D*FF>BTUHIIh'KK))h)7HH@&++N;F;;T>ST 	0*0++s1v?HIIhKK!!h!//		0s'   A	D# AD#  BD# #	F,AE==Fc                 ~   	 t         j                  d|j                  f       |r| j                  |       | j	                  ||d      }|r|j                          yy# t        $ rV}d|j                  dt        |      }t         j                  |       | j                  j                  |       Y d}~yd}~ww xY w)	z Remove replication from the filesystem
            :param: replication_params: Module input params
            :return: True if disabling replication is successful
        z*Disabling replication on the filesystem %srj   TFz(Disabling replication on the filesystem r  r)   N)r.   r/   r+   r   r  rj   r8   r6   r0   r   r1   )r"   r=   r   r  r?   r<   s         r#   disable_replicationzFilesystem.disable_replication   s    
	0HHBFKKPQ!../AB66v?QS[\ ##% 	0*0++s1v?HIIhKK!!h!//		0s   AA 	B<&AB77B<c                    |r|d   r| j                  |d|      }|S |r|d   r| j                  |d|d         }|S | j                  ||      }|r:|r8|r6|d   d	k(  r.|j                  j                  | j                  j                  k7  ry |S )
Nr   r   )
filter_keyr   replication_namer+   )r  r+   )actionr   local)r   r   r+   r!   )r"   r=   r   r   r  s        r#   r  z,Filesystem.get_replication_session_on_filter  s    "4_"E,,V@T@R - T    $67I$J,,V2DEW2X - Z    77v7NL+=&'9:gE ..33t7K7KKr%   c                    	 | j                   j                  |j                  j                        }|s:|r8t	        |      dkD  r%|r!d|z  }| j
                  j                  |       |S |d   S |D ]@  }|dk(  r |j                  j                  |d   k(  r|c S |dk(  s.|j                  |k(  s>|c S  y# t        $ rH}	d	t        |	      f}
t        j                  |
       | j
                  j                  |
       Y d}	~	yd}	~	ww xY w)
a   Retrieves the replication sessions configured for the filesystem
            :param: obj_fs: Filesystem object
            :param: filter_key: Key to filter replication sessions
            :param: replication_params: Module input params
            :param: name: Replication session name
            :param: action: Specifies modify or delete action on replication session
            :return: Replication session details
        )src_resource_id   zxThere are multiple replication sessions for the filesystem. Please specify replication_name in replication_params to %s.r)   r   r   r+   NzERetrieving replication session on the filesystem failed with error %s)r!   r   r   r9   r   r   r1   r   r+   r8   r6   r.   r0   )r"   r=   r  r   r+   r   r  	error_msgsessionr?   r<   s              r#   r   z"Filesystem.get_replication_session'  s   	0??BBSYSjSjSmSmBnL,|$q(%dfl%m	--)-<''#A&' #!55--226HI]6^^"N'GLLD,@"N#  	0'(+A/HIIhKK!!h!//		0s<   A&B4 )B4 .)B4 B4 B4 .B4 2B4 4	D=>D  D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   }d}t        di       }d}d}d}| j                          |!|dk(  r| j                   j	                  d       |r|sd}|	r|	d   |	d   
|	d   sd|	d<   |	d   
|	d   d|	d<   |	d   $|	d   dk  r| j                   j	                  d       |	d   4t        j                  |	d         r| j                   j	                  d       |	d   4t        j                  |	d         r| j                   j	                  d       ||s| j                   j	                  d       d}|s|r| j                  ||      }d}|s|r| j                  ||       }d}| j                  |||!      }d| _
        |s|r||d}| j                  |      | _
        n|d"k(  s|d"k(  rd"| _
        |rH|j                         }|j                         }| j                  ||      }t        j!                  d#|       |d$k(  r|s|s-d%j#                  |      }| j                   j	                  |       |s|s| j                   j	                  d&       |s| j                   j	                  d'       t        j$                  ||      }| j'                  ||||(      }t        j)                  d)|       |j*                  }|j                         }| j                  ||      }t        j)                  d*|       d+}|d$k(  r|r|r| j-                  ||,       d+}	 |d$k(  rK|rI|	rG| j/                  |      }|| j1                  ||	-      }|rd+}n| j                   j	                  d.       |d$k(  r.|r,|*|d/k(  r| j3                  ||
      }n| j5                  ||
      }|d0k(  r|r| j7                  |      }d}|d$k(  r|r| j9                  |1      }||d2<   ||d3<    | j                   j:                  d4i | y)5zs
        Perform different actions on filesystem module based on parameters
        passed in the playbook
        r   r   r   r   r   r   r_   r   r   r   r   stater   r   F)changedr   Nr   zSize can not be 0 (Zero)r)   GBr   r   r   r   daysz6Invalid grace_period provided. Must be greater than 0.zHInvalid default_soft_limit provided. Must be greater than or equal to 0.zHInvalid default_hard_limit provided. Must be greater than or equal to 0.z)cap_unit can be specified along with sizer   )r   r   )r+   r9   r:   rq   zFrom Mod Op, to_modify_dict: %spresentzbFileSystem with id {0} is not found, unable to create a FileSystem without a valid filesystem_namez9pool_id or pool_name is required to create new filesystemz'Size is required to create a filesystem)r+   rG   r:   r_   z$Successfully created filesystem , %szGot filesystem id , %sT)r   r=   )r   r   zOne or more operations related to this task failed because the new object created could not be fetched. Please rerun the task for expected result.enableabsent)r=   r)  r   r   )r   r   dictr   r1   r   is_size_negativerB   rF   r,   rs   r   ri   get_idr   r.   r/   r4   r   rd   r   r9   r   r   r   r  r  rl   r   	exit_json)r"   r   r   r   r   r   r   r_   r   r   r   r   r(  r   r   r)  resultto_modify_dictr   r   r(   rG   r=   snap_schedule_params
msg_nonameis_quota_config_modifieds                             r#   perform_module_operationz#Filesystem.perform_module_operationG  s   
 ++,,->?**?;++,,->?**?;KK&&{3	++$$Y/{{!!&);;%%j1{{)).9![[//0DE KK../BC""7+![[//0DE;;--.@A !

 !""$	KK!!&@!AH12> 45A$Z0+/Z(N+7$%89A4:01N+7$^49%% +D% E 01=..|<P/QR%% +P% Q 01=..|<P/QR%% +P% Q  $KK!! '2! 3 
m,,$ - 8J }}y'}JH$$/(54> % @  !1*&$   $>>?STD2%)9R)?!D!'!7!7!9"MMOM!44VXFNHH6GI&8"//5vm/D  %%*%5W%% +E% F%% +:% ;''h7D++5=;E15 , 7F
 II<fE"IIM!'!7!7!9!44VXFNII.>GI"4""~f"MG	 I"4#<<VD++/+C+C%5(4 ,D ,6( ,"G%% +X% Y
 I"49J9V H,11&:LM226;MNH!3,,];G!%I"4!%!G!G "H " $y'9#$''r%   )NNN)NN)NNNN)__name__
__module____qualname____doc__r$   r,   rB   rF   rL   rR   rV   rZ   rd   rl   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r  r   r8  r   r%   r#   r
   r
     s    *2.<+|+>+>00 00$0L08q0f>0@=0~0,2:0:M0^0>420(4 $0L$0L0*$0@d(r%   r
   c                 X    d}d}d}| "| dkD  r|dv r| |z  S |dv r| |z  S |dv r| |z  S | S y)zThis method get time is seconds<     Q r   minuteshoursr+  r   )time
time_units
min_in_sechour_in_sec
day_in_secs        r#   r   r     s^    JKJD1H"*$$7"+%%6!*$$Kr%   c                 j    d}d}d}| |z  dk(  r| |z  } d}n| |z  dk(  r| |z  } d}n| |z  } d}| d|S )	z3This method sets seconds in minutes, hours or days.r>  r?  r@  r   r+  rB  rA   r   )rC  
sec_in_minsec_in_hour
sec_in_dayunits        r#   r   r      se    JKJjAj 		q	 k! j D!!r%   c                     d| d   i}| d   r| d   |d<   d| v r&| d   dk(  r
| d   |d<   |S | d   dk(  rd	|d<   |S d
|d<   |S )z(Returns the replication args for payloaddst_pool_idr   r  r   r   r   r  r  r   r  r   )r   r  s     r#   r  r    s     	)*?@ ,-4FGY4Z01//01^C<Nu<U!"89 !    23}D<=!"89 !  =?!"89  r%   c                  Z   t        d?i dt        dd      dt        dd      dt        dd      dt        dd      dt        dd      d	t        dd      d
t        dd      dt        dd      dt        ddddg      dt        dd      dt        dd      dt        ddg d      dt        dt        t        d      t        d      t        d      t        d      t        d                  dt        ddg d      dt        ddddg      d t        ddg d!      d"t        dd      d#t        dd      d$t        ddt        t        dd      t        ddg d%      t        dd      t        dd      t        dd      t        ddd&d'g      t        ddg d(      )      d*d+gg,      d-t        dt        t        d      t        d      t        dd.d/g0      t        dg d10      t        d      t        dt        t        dd23      t        ddd24      t        dd23      t        dd2d25      t        ddd64      7            t        d      t        d      8            d9t        dd:d;g0      d<t        d2dd=d>g      S )@zYThis method provide parameters required for the ansible filesystem
       module on Unityr   Fr6   )requiredtyper   r   r   rn   r   r   r_   r   r   r*  TB)rQ  rR  choicesr]   boolro   r\   )NFSCIFSrN   rt   r/  )rR  )ru   rx   rv   rw   ry   )rR  optionsrY   )NATIVEUNIXWINDOWSrU   ADVISORY	MANDATORYrK   )AUTOTIER_HIGHAUTOTIERHIGHESTLOWESTr   r   r   )rA  rB  r+  	FILE_SIZEBLOCKS)MBr*  rS  )r   r   r   r   r   r   r   r   r   )rQ  rR  rX  r   r   r!  r   )rR  rT  )r  r   r  T)rR  rQ  )rR  rQ  default)rR  rQ  no_logi  )r   r   r   r   r   )r  r  r   r   r   r   r   r   r   r-  disabler(  r,  r.  r   )r/  r   r%   r#   r   r   (  s     <e%8<E6< e%8< E6	<
 %e4< E2< e%0< 5u-< u54,G< e&1< U8< !%e)IK< '+'8,0f,=$(f$5+/V+<+/U+;2
 <* E#@B+<. U%/$=?/<2 U A> ?3<6  U;7<8 u599<: 5vtu59"EGcd#U?#U?"&F"Cu5;PXBYZ5u>PQ@
 !8HIK;<L  VT!u-!%5!1!uw6IJ!u+56 % F'+7;QU7V=AvX]JN>P;?UUY;Z;?UUYbf;g7;QV`c7d(!" #'E"2 $% 0%6
 M<t EHi3HIu<v Duy(6KLw< <r%   c                  8    t               } | j                          y)zb Create Unity FileSystem object and perform action on it
        based on user input from playbookN)r
   r8  )objs    r#   mainrj  j  s     ,C  "r%   __main__N)r<  
__future__r   r   r   rR  __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Cansible_collections.dellemc.unity.plugins.module_utils.storage.dellr   
get_loggerr.   r    objectr
   r   r   r  r   rj  r9  r   r%   r#   <module>ru     s    6 @ @dL	Wra
F 5 e|$" t( t(n!$"(!(?D# zF r%   