
    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d	Z G d
 de      Zd Zd Zedk(  r e        yy)z/Ansible module for managing User Quota on Unity    )absolute_importdivisionprint_functionac  
---
module: user_quota
short_description: Manage user quota on the Unity storage system
description:
- Managing User Quota on the Unity storage system includes
  Create user quota,
  Get user quota,
  Modify user quota,
  Delete user quota,
  Create user quota for quota tree,
  Modify user quota for quota tree and
  Delete user quota for quota tree.
version_added: '1.2.0'
extends_documentation_fragment:
  - dellemc.unity.unity
author:
- Spandita Panigrahi (@panigs7) <ansible.team@dell.com>
options:
  filesystem_name:
    description:
    - The name of the filesystem for which the user quota is created.
    - For creation of a user quota either I(filesystem_name) or
      I(filesystem_id) is required.
    type: str
  filesystem_id:
    description:
    - The ID of the filesystem for which the user quota is created.
    - For creation of a user quota either I(filesystem_id) or
      I(filesystem_name) is required.
    type: str
  nas_server_name:
    description:
    - The name of the NAS server in which the filesystem is created.
    - For creation of a user quota either I(nas_server_name) or
      I(nas_server_id) is required.
    type: str
  nas_server_id:
    description:
    - The ID of the NAS server in which the filesystem is created.
    - For creation of a user quota either I(filesystem_id) or
      I(filesystem_name) is required.
    type: str
  hard_limit:
    description:
    - Hard limitation for a user on the total space available. If exceeded, user cannot write data.
    - Value C(0) implies no limit.
    - One of the values of I(soft_limit) and I(hard_limit) can be C(0), however, both cannot be C(0)
      during creation or modification of user quota.
    type: int
  soft_limit:
    description:
    - Soft limitation for a user on the total space available. If exceeded,
      notification will be sent to the user for the grace period mentioned, beyond
      which the user cannot use space.
    - Value C(0) implies no limit.
    - Both I(soft_limit) and I(hard_limit) cannot be C(0) during creation or modification
      of user quota.
    type: int
  cap_unit:
    description:
    - Unit of I(soft_limit) and I(hard_limit) size.
    - It defaults to C(GB) if not specified.
    choices: ['MB', 'GB', 'TB']
    type: str
  user_type:
    description:
    - Type of user creating a user quota.
    - Mandatory while creating or modifying user quota.
    choices: ['Unix', 'Windows']
    type: str
  win_domain:
    description:
    - Fully qualified or short domain name for Windows user type.
    - Mandatory when I(user_type) is C(Windows).
    type: str
  user_name:
    description:
    - User name of the user quota when I(user_type) is C(Windows) or C(Unix).
    - Option I(user_name) must be specified along with I(win_domain) when I(user_type) is C(Windows).
    type: str
  uid:
    description:
    - User ID of the user quota.
    type: str
  user_quota_id:
    description:
    - User quota ID generated after creation of a user quota.
    type: str
  tree_quota_id:
    description:
    - The ID of the quota tree.
    - Either I(tree_quota_id) or I(path) to quota tree is required to
      create/modify/delete user quota for a quota tree.
    type: str
  path:
    description:
    - The path to the quota tree.
    - Either I(tree_quota_id) or I(path) to quota tree is required to
      create/modify/delete user quota for a quota tree.
    - Path must start with a forward slash '/'.
    type: str
  state:
    description:
    - The I(state) option is used to mention the existence of the user quota.
    type: str
    required: true
    choices: ['absent', 'present']

notes:
  - The I(check_mode) is not supported.
a-  
- name: Get user quota details by user quota id
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    user_quota_id: "userquota_171798700679_0_123"
    state: "present"

- name: Get user quota details by user quota uid/user name
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_name: "fs_2171"
    nas_server_id: "nas_21"
    user_name: "test"
    state: "present"

- name: Create user quota for a filesystem with filesystem id
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "fs_2171"
    hard_limit: 6
    cap_unit: "TB"
    soft_limit: 5
    uid: "111"
    state: "present"

- name: Create user quota for a filesystem with filesystem name
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_name: "Test_filesystem"
    nas_server_name: "lglad068"
    hard_limit: 6
    cap_unit: "TB"
    soft_limit: 5
    uid: "111"
    state: "present"

- name: Modify user quota limit usage by user quota id
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    user_quota_id: "userquota_171798700679_0_123"
    hard_limit: 10
    cap_unit: "TB"
    soft_limit: 8
    state: "present"

- name: Modify user quota by filesystem id and user quota uid/user_name
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "fs_2171"
    user_type: "Windows"
    win_domain: "prod"
    user_name: "sample"
    hard_limit: 12
    cap_unit: "TB"
    soft_limit: 10
    state: "present"

- name: Delete user quota
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "fs_2171"
    win_domain: "prod"
    user_name: "sample"
    state: "absent"

- name: Create user quota of a quota tree
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    tree_quota_id: "treequota_171798700679_4"
    user_type: "Windows"
    win_domain: "prod"
    user_name: "sample"
    soft_limit: 9
    cap_unit: "TB"
    state: "present"

- name: Create user quota of a quota tree by quota tree path
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "fs_2171"
    path: "/sample"
    user_type: "Unix"
    user_name: "test"
    hard_limit: 2
    cap_unit: "TB"
    state: "present"

- name: Modify user quota of a quota tree
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    tree_quota_id: "treequota_171798700679_4"
    user_type: "Windows"
    win_domain: "prod"
    user_name: "sample"
    soft_limit: 10
    cap_unit: "TB"
    state: "present"

- name: Modify user quota of a quota tree by quota tree path
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "fs_2171"
    path: "/sample"
    user_type: "Windows"
    win_domain: "prod"
    user_name: "sample"
    hard_limit: 12
    cap_unit: "TB"
    state: "present"

- name: Delete user quota of a quota tree by quota tree path
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    filesystem_id: "fs_2171"
    path: "/sample"
    win_domain: "prod"
    user_name: "sample"
    state: "absent"

- name: Delete user quota of a quota tree by quota tree id
  dellemc.unity.user_quota:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    tree_quota_id: "treequota_171798700679_4"
    win_domain: "prod"
    user_name: "sample"
    state: "absent"
a  
changed:
    description: Whether or not the resource has changed.
    returned: always
    type: bool
    sample: true

get_user_quota_details:
    description: Details of the user quota.
    returned: When user quota exists
    type: dict
    contains:
        filesystem:
            description: Filesystem details for which the user quota is
                         created.
            type: dict
            contains:
                UnityFileSystem:
                    description: Filesystem details for which the
                                user quota is created.
                    type: dict
                    contains:
                        id:
                            description: ID of the filesystem for
                                         which the user quota is created.
                            type: str
                        name:
                            description: Name of filesystem.
                            type: str
                        nas_server:
                            description: Nasserver details where
                                         filesystem is created.
                            type: dict
                            contains:
                                name:
                                    description: Name of nasserver.
                                    type: str
                                id:
                                    description: ID of nasserver.
                                    type: str
        tree_quota:
            description: Quota tree details for which the user quota is
                         created.
            type: dict
            contains:
                UnityTreeQuota:
                    description: Quota tree details for which the user
                                 quota is created.
                    type: dict
                    contains:
                        id:
                            description: ID of the quota tree.
                            type: str
                        path:
                            description: Path to quota tree.
                            type: str
        gp_left:
            description: The grace period left after the soft limit
                         for the user quota is exceeded.
            type: int
        hard_limit:
            description: Hard limitation for a user on the total space
                         available. If exceeded, user cannot write data.
            type: int
        hard_ratio:
            description: The hard ratio is the ratio between the
                         hard limit size of the user quota
                         and the amount of storage actually consumed.
            type: str
        soft_limit:
            description: Soft limitation for a user on the total space
                         available. If exceeded, notification will be
                         sent to user for the grace period mentioned, beyond
                         which user cannot use space.
            type: int
        soft_ratio:
            description: The soft ratio is the ratio between
                         the soft limit size of the user quota
                         and the amount of storage actually consumed.
            type: str
        id:
            description: User quota ID.
            type: str
        size_used:
            description: Size of used space in the filesystem
                         by the user files.
            type: int
        state:
            description: State of the user quota.
            type: int
        uid:
            description: User ID of the user.
            type: int
        unix_name:
            description: Unix user name for this user quota's uid.
            type: str
        windows_names:
            description: Windows user name that maps to this quota's uid.
            type: str
        windows_sids:
            description: Windows SIDs that maps to this quota's uid
            type: str
    sample: {
        "existed": true,
        "filesystem": {
            "UnityFileSystem": {
                "hash": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "id": "fs_120",
                "name": "nfs-multiprotocol",
                "nas_server": {
                    "id": "nas_1",
                    "name": "lglad072"
                }
            }
        },
        "gp_left": null,
        "hard_limit": "10.0 GB",
        "hard_ratio": null,
        "hash": 8752448438089,
        "id": "userquota_171798694698_0_60000",
        "size_used": 0,
        "soft_limit": "10.0 GB",
        "soft_ratio": null,
        "state": 0,
        "tree_quota": null,
        "uid": 60000,
        "unix_name": null,
        "windows_names": null,
        "windows_sids": null
    }
)AnsibleModule)utils
user_quotazAnsible/1.7.1c                   V    e Zd ZdZd Zd Zd Zd Zd Zd Z	dd	Z
dd
Zd Zd Zd Zy)	UserQuotaz Class with User Quota operationsc                    t        j                         | _        | j                  j                  t	                      ddgddgddgddgddgddgg}d	d
ddgdfd	ddgdfg}t        | j                  d||      | _        t        j                  | j                         t        j                  | j                  j                  t              | _        y)z-Define all parameters required by this module	user_nameuid
win_domainfilesystem_namefilesystem_idnas_server_namenas_server_iduser_quota_id	user_typeWindowsFUnix)argument_specsupports_check_modemutually_exclusiverequired_ifN)r   $get_unity_management_host_parametersmodule_paramsupdateget_user_quota_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/user_quota.py__init__zUserQuota.__init__  s    "GGI!!";"=>*E2UL4I0/B0/B*O<$o6	8 $Y{0KUS#Vk]EBD $,, %1#	%
 	""4;;/>>KK 02    c                 T   | j                  |||      sy|r|n	|r|n|r|n|}| j                  j                  |||||      }t        t	        |            D ]O  }||   j
                  d|d||   j                  d|}	t        j                  |	       ||   j                  c S  y)a  
            Check if user quota is present in filesystem.
            :param fs_id: ID of filesystem where user quota is searched.
            :param uid: UID of the user quota
            :param unix: Unix user name of user quota
            :param win_name: Windows user name of user quota
            :param user_quota_id: ID of the user quota
            :return: ID of user quota if it exists else None.
        N)
filesystemid	unix_namewindows_namesr   User quota z	 with id z is present in filesystem )	check_user_type_providedr$   get_user_quotarangelen
tree_quotar+   LOGinfo)
r%   fs_idr   unixwin_namer   user_name_or_uid_or_idall_user_quotar   msgs
             r&   check_user_is_presentzUserQuota.check_user_is_present  s     ,,XsDA)-x8 NQ" 	 775]BFV^<? 8 A  N 34 	5Jj)44< 0
1K1N1NPUW %j1444	5 r(   c                 F   |r|n|}| j                   j                  |||      }t        |      dkD  r9d|d   j                  d|}t        j                  |       |d   j                  S d|z  }t        j                  |       | j                  j                  |       y)a#  
            Check if quota tree is present in filesystem.
            :param fs_id: ID of filesystem where quota tree is searched.
            :param path: Path to quota tree
            :param tree_quota_id: ID of the quota tree
            :return: ID of quota tree if it exists.
        )r*   pathr+   r   zTree quota id z present in filesystem z"The quota tree '%s' does not existr;   N)	r$   get_tree_quotar2   r+   r4   r5   errorr   	fail_json)r%   r6   r>   tree_quota_id
path_or_idtree_quota_objr;   errormsgs           r&   check_quota_tree_is_presentz%UserQuota.check_quota_tree_is_present  s     "T}
775t;H 8 J~"AOPQARAUAUW\]CHHSM!!$''';jHHIIhKK!!h!/r(   c                     | j                  |||      sy|r|n	|r|n|r|n|}| j                  j                  |||||      }t        |      dkD  r-d|d|d}t        j                  |       |d   j                  S y)a  
            Check if user quota is present in quota tree.
            :param tree_quota_id: ID of quota tree where user quota is searched.
            :param uid: UID of user quota
            :param unix: Unix name of user quota
            :param win_name: Windows name of user quota
            :param user_quota_id: ID of the user quota
            :return: ID of user quota if it exists in quota tree else None.
        N)r3   r   r-   r,   r+   r   r.   z is present in quota tree  )r/   r$   r0   r2   r4   r5   r+   )	r%   rC   r   r7   r8   r   user_quota_nameuser_quota_objr;   s	            r&   check_user_quota_in_quota_treez(UserQuota.check_user_quota_in_quota_tree  s     ,,XsDA!$#$$ =E* 	77=<?xBF;H 8 J ~"BQS`aCHHSM!!$'''r(   c	           	      J   |r|n|r|n|}	|r|n|}
|5|3d}t         j                  |       | j                  j                  |       t	        j
                  ||      }t	        j
                  ||      }	 | j                  |||      r9| j                  j                  |||||||      }t         j                  d       |S y# t        $ rW}dj                  |	|
t        |            }t         j                  |       | j                  j                  |       Y d}~yd}~ww xY w)a(  
            Create user quota of a filesystem.
            :param fs_id: ID of filesystem where user quota is to be created.
            :param soft_limit: Soft limit
            :param hard_limit: Hard limit
            :param unit: Unit of soft limit and hard limit
            :param uid: UID of the user quota
            :param unix: Unix user name of user quota
            :param win_name: Windows user name of user quota
            :param tree_quota_id: ID of tree quota
            :return: Object containing new user quota details.
        Nz`Both soft limit and hard limit cannot be empty. Please provide atleast one to create user quota.r?   )r   
hard_limit
soft_limitr   r,   r8   rC   zSuccessfully created user quotaz9Create quota for user {0} on {1} , failed with error {2} )r4   rA   r   rB   r   get_size_bytesr/   r$   create_user_quotar5   	Exceptionformatstr)r%   r6   rO   rN   unitr   r7   r8   rC   unix_or_uid_or_winfs_id_or_tree_quota_idrF   soft_limit_in_byteshard_limit_in_bytesobj_user_quotaes                   r&   rQ   zUserQuota.create_user_quota  s*    %(STTx*/]*"4JHIIhKK!!h!/#22:tD#22:tD	0,,XsDA!%!B!BQVNaNaGJVZLTQ^ "C "` :;%% B  	0R*,BCFK IIhKK!!h!//		0s   5AC 	D"ADD"c                    	 | j                   j                  |      }|j                         }|r|j                  rt	        j
                  t        |d               |d<   t	        j
                  t        |d               |d<   |j                  j                  |d   d   d<   |d   d   j                  d|j                  j                  j                  |j                  j                  j                  di       |j                  r|j                  j                  |d   d	   d
<   |S d}t        j                  |       | j                   j#                  |       y# t$        $ r`}dj'                  j                  t)        |            }t        j                  |       | j                   j#                  |       Y d}~yd}~ww xY w)zGet display user quota attributes
            :param user_quota_id: User quota ID
            :return: User quota dict to display
        rO   rN   r*   UnityFileSystemname
nas_server)r^   r+   r3   UnityTreeQuotar>   zUser quota does not exist.r?   z>Failed to display the details of user quota {0} with error {1}N)r$   r0   _get_propertiesexistedr   convert_size_with_unitintr*   r^   r   r_   r+   r3   r>   r4   rA   r   rB   rR   rS   rT   )r%   r   rK   user_quota_detailsrF   r[   s         r&   ,get_filesystem_user_quota_display_attributesz6UserQuota.get_filesystem_user_quota_display_attributesF  s   
	0!__;;MJN!/!?!?!A."8"838**3/A,/O+P4R"<038**3/A,/O+P4R"<0 #--22 #<01BCFK"<01BCJJ!N,E,E,P,P,U,U*8*C*C*N*N*Q*Q$S TU ",,&1166 '|45EFvN *)7		(#%%(%3 	0##)6.*;*;SV#D IIhKK!!h!//		0s   D$E '3E 	G$AF??GNc                    |r|n|}	 d}|rx|s3d}t         j                  |       | j                  j                  |       | j                  j                  ||      }|r$|j                  rt         j                  d|       |S |rd|r| j                  j                  ||      }n| j                  j                  |      }|r%|j                  rt         j                  d|       |S yyy# t        $ rM}d|d	t        |      d
}t         j                  |       | j                  j                  |       Y d}~yd}~ww xY w)z
            Get filesystem details.
            :param nas_server: Nas server object.
            :param name: Name of filesystem.
            :param id: ID of filesystem.
            :return: Object containing filesystem details if it exists.
        Nz-NAS Server is required to get the FileSystem.r?   )r^   r_   z*Successfully got the filesystem object %s.)r+   r_   r+   zFailed to get filesystem  with error .)
r4   rA   r   rB   r$   get_filesystemrb   r5   rR   rT   )	r%   r_   r^   r+   
id_or_nameobj_fserr_msgr[   	error_msgs	            r&   rk   zUserQuota.get_filesystemk  s-    R4
	1F!MGIIg&KK))g)677TCM 8 OfnnHHI#%!M!__'2*E  "__;;r;BFfnnHHI#%!M -6   	1%s1v/IIIi KK!!i!00		1s    A;C+ A#C+ +	E4AD<<Ec                    |r|n|}d|z  }	 | j                   j                  ||      }|r$|j                  rt        j	                  d|       |S |r$|j                  rt        j	                  d|       |S t        j                  |       | j                  j                  |       y# t        $ rM}d|dt        |      d}t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)	z
            Get nas server details.
            :param name: Nas server name.
            :param id: Nas server ID.
            :return: Object containing nas server details if it exists.
        zFailed to get NAS server %s.)_idr^   z*Successfully got the NAS server object %s.r?   zFailed to get NAS server ri   rj   N)
r$   get_nas_serverrb   r4   r5   rA   r   rB   rR   rT   )r%   r^   r+   r_   ro   obj_nasr[   s          r&   get_nas_server_objzUserQuota.get_nas_server_obj  s     R4
3j@		1oo44$4GGE "E "		)$%%)%4 	1%s1v/IIIi KK!!i!00		1s%   AB( %B( 61B( (	C>1AC99C>c                    ||y| j                   j                  |      j                         }||d   }nt        j                  ||      }||d   }nt        j                  ||      }|r|d   |k(  r<|d   |k(  r4yd}t
        j                  |       | j                  j                  |       	 | j                   j                  |||      }	t
        j                  d       |	ry	y# t        $ rV}
d
j                  |t        |
            }t
        j                  |       | j                  j                  |       Y d}
~
yd}
~
ww xY w)at  
            Modify user quota of filesystem by its uid/username/user quota id.
            :param user_quota_id: ID of the user quota
            :param soft_limit: Soft limit
            :param hard_limit: Hard limit
            :param unit: Unit of soft limit and hard limit
            :return: Boolean value whether modify user quota operation is successful.
        NFrO   rN   zThe user quota does not exist.r?   )r   rN   rO   z Successfully modified user quotaTz+Modify user quota {0} failed with error {1})r$   r0   ra   r   rP   r4   rA   r   rB   modify_user_quotar5   rR   rS   rT   )r%   r   rO   rN   rU   rK   rX   rY   ro   rZ   r[   rF   s               r&   rv   zUserQuota.modify_user_quota  sN    *"477FVVX"0">"'"6"6z4"H"0">"'"6"6z4"Hl+/BB"<04GG8IIIi KK!!i!0	0!__>>]J]J] ? _N HH78  	0))/s1v)F IIhKK!!h!//		0s   25C) )	E2AEEc                     |||yy)zChecks if user type or uid is provided
           :param win_name: Windows name of user quota
           :param uid: UID of user quota
           :param unix_name: Unix name of user quotaFT )r%   r8   r   r,   s       r&   r/   z"UserQuota.check_user_type_provided  s    
 	0Ar(   c           
         | j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d	   }	| j                   j                  d
   }
| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }| j                   j                  d   }d}d}d}d}d}d}d}	 t        dddi d      }|	s|r|d}|	dk(  r8|dk(  r3d}t        j	                  |       | j                   j                  |       |	rHt        j                  |	      r3d}t        j	                  |       | j                   j                  |       |rHt        j                  |      r3d}t        j	                  |       | j                   j                  |       |
s|r9|7|5|3d}t        j	                  |       | j                   j                  |       |s|r7|5|3d}t        j	                  |       | j                   j                  |       	 |t        j                  |      r| j                   j                  d       n-|j                  d      s| j                   j                  d       ||| j                   j                  d       |
r9|7|5|3d}t        j	                  |       | j                   j                  |       	 |Dt        j                  |      r| j                   j                  d        | j                  |!      }nE|Ct        j                  |      r| j                   j                  d"       | j                  |#      }	 |Qt        j                  |      r| j                   j                  d$       | j                  ||%      }|j                  }nu|st        j                  |      r| j                   j                  d&       | j                  |#      }|r|d   }|j                  }n| j                   j                  d'       |s|r"|	s|r|
| j                   j                  d(       |r|	|}|j                  }|t        j                  d)   k(  r$|
d*k(  s|r| j                   j                  d+       n7|t        j                  d,   k(  r!|
d-k(  r| j                   j                  d.       	 |rAt        j                  |      s|j                         s| j                   j                  d/       |
r|
d*k(  r3|t        j                  |      r| j                   j                  d0       |
d-k(  rg|t        j                  |      r| j                   j                  d1       n3|t        j                  |      r| j                   j                  d0       |
d*k7  r|r|j!                  d2d      }|d3z   |z   }||r|}	 |s|r| j#                  |||      }|}	 |r| j%                  |||||      }|dn|}n| j'                  |||||      }|r|}|d4k(  r]|r| j)                  ||	||      |d5<   nCt        j+                  d6       | j-                  ||	||||||      }|r|j                  }d7|d8<   nd}	 |d9k(  r7|r5d}	d}d:|z  }t        j+                  |       | j)                  ||	||      |d;<   	 |d4k(  r|r| j/                  |      }||d<<   |d8   s
|d5   s|d;   rd7|d=<    | j                   j0                  d>i | y)?zs
        Perform different actions on user quota module based on parameters
        passed in the playbook
        r   r   r   r   cap_unitstater   rN   rO   r   r   r   r   rC   r>   N F)changedrQ   rv   get_user_quota_detailsdelete_user_quotaGBr   z2Both soft limit and hard limit cannot be unlimitedr?   z3Invalid soft_limit provided, must be greater than 0z3Invalid hard_limit provided, must be greater than 0z6Please provide either filesystem_name or filesystem_idz Please provide a valid path./zXThe path is relative to the root of the file system and must start with a forward slash.z6Please provide either filesystem_name or fileystem_id.zPlease provide either filesystem_name or filesystem_id to create user quota for afilesystem. Or provide tree_quota_id to create user quota for a quota tree.z;Invalid nas_server_name given, Please provide a valid name.)r^   z7Invalid nas_server_id given, Please provide a valid ID.rh   z;Invalid filesystem_name given, Please provide a valid name.)r_   r^   z7Invalid filesystem_id given, Please provide a valid ID.zFilesystem does not exist.z:Invalid user_type given, Please provide a valid user_type.CIFSr   zwThis filesystem supports only SMB protocol and applicable only for windows users. Please provide valid windows details.NFSr   zxThis filesystem supports only NFS protocol and applicable only for unix users. Please provide valid uid or unix details.z( UID is empty. Please provide valid UID.z6 'user_name' is empty. Please provide valid user_name.z8 'win_domain' is empty. Please provide valid win_domain.z.com\presentrv   zCreating user quotaTrQ   absentzDeleting user quota %sr   r~   r}   rx   )r   r"   dictr4   rA   rB   r   is_size_negativeis_input_empty
startswithrt   rk   r+   supported_protocolsFSSupportedProtocolEnum	isnumericreplacerG   rL   r<   rv   r5   rQ   rf   	exit_json)r%   r   r   r   r   rz   r{   r   rN   rO   r   r   r   r   rC   r>   create_user_quota_objr8   r,   nas_server_resourcer6   re   filesystem_objresulterror_messagesupported_protocolquota_tree_id_presentuser_id_presentrn   s                                r&   perform_module_operationz"UserQuota.perform_module_operation  s+   
 **?;++,,->?++,,->?**?;;;%%j1""7+**?;[[''5
[[''5
KK&&{3	kk  'KK&&{3	[[''5
**?;{{!!&) $	"	 ###%#
 *(*:H?zQPMIIm$KK!!m!4%00<5MIIm$KK!!m!4%00<5MIIm$KK!!m!4-"7'M,A?MIIm$KK!!m!4}"*/F?MIIm$KK!!m!4	 ##D)%%*I%J__S)%% +Q% R $)@%%*b%c.?3J}OdjM IIm$KK!!m!4	 &##O4%% +J% K"&###9  &##M2%% +H% I"&"9"9]"9"K	 &##O4%% +J% K!+>%4   6  #%%E&##M2%% +H% I!=1 !/!2&))%%*F%G*
%KK!! 'K! L
 z59O!/!C!C!U%B%B6%JJ"f,%% +R% S $u'D'DU'KK!Y.%% +V% W	 E((-S]]_KK!!&P!QF"$(<(<Y(GKK)).f)gI%%)=)=j)IKK)).h)i&%*>*>y*IKK)).f)g:#++FB7J!D(94H	!I	 D$($D$DUDR_$`!1M	 "AA-QTV_aiBOQO)5D5E"88YPXZghO+MI.2.D.D]T^EOQY/[*+ ./(,(>(>ujR\?GiYa?L)N% )$9$<$<M26F./$(M	 HJJ.>GHHW*.*@*@AKZYa+cF&'	 I-!%!R!RS`!a+='(%&&1D*EPcId $F9''r(   )NNN)NN)__name__
__module____qualname____doc__r'   r<   rG   rL   rQ   rf   rk   rt   rv   r/   r   rx   r(   r&   r
   r
     sB    *22B0*4'0R#0J$1L18-0^l(r(   r
   c                     t        t        dd      t        dd      t        ddddg      t        dddd	g      t        dd      t        dd      t        dd      t        dd
      t        dd
      t        ddg d      t        dd      t        dd      t        dd      t        dd      t        ddd            S )zdThis method provide parameters required for the ansible filesystem
       user quota module on UnityFrT   )requiredtypeTr   r   )r   r   choicesr   r   rd   )MBr   TB)r   r   no_log)r   r   r{   r   r   r   r   rN   rO   rz   r   r   r   rC   r>   )r   rx   r(   r&   r   r     s     E6e%8Duy(6KLE )624E2%e,U3U3U3u5:LME6e%8E6E65uT:! r(   c                  8    t               } | j                          y)zb Create Unity user quota object and perform action on it
        based on user input from playbookN)r
   r   )objs    r&   mainr     s     +C  "r(   __main__N)r   
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Cansible_collections.dellemc.unity.plugins.module_utils.storage.dellr   
get_loggerr4   r#   objectr
   r   r   r   rx   r(   r&   <module>r      s    6 @ @obeNB
H 5 e|$" a( a(H.# zF r(   