
    Vh                         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)    )absolute_importdivisionprint_functiona  
---
module: nasserver
version_added: '1.1.0'
short_description:  Manage NAS servers on Unity storage system
extends_documentation_fragment:
- dellemc.unity.unity
author:
- P Srinivas Rao (@srinivas-rao5) <ansible.team@dell.com>
description:
- Managing NAS servers on Unity storage system includes get,
  modification to the NAS servers.
options:
  nas_server_id:
    description:
    - The ID of the NAS server.
    - Either I(nas_server_name) or I(nas_server_id) is required to perform the task.
    - The parameters I(nas_server_name) and I(nas_server_id) are mutually exclusive.
    type: str
  nas_server_name:
    description:
    - The Name of the NAS server.
    - Either I(nas_server_name) or I(nas_server_id)  is required to perform the task.
    - The parameters I(nas_server_name) and I(nas_server_id) are mutually exclusive.
    type: str
  nas_server_new_name:
    description:
    - The new name of the NAS server.
    - It can be mentioned during modification of the NAS server.
    type: str
  is_replication_destination:
    description:
    - It specifies whether the NAS server is a replication destination.
    - It can be mentioned during modification of the NAS server.
    type: bool
  is_backup_only:
    description:
    - It specifies whether the NAS server is used as backup only.
    - It can be mentioned during modification of the NAS server.
    type: bool
  is_multiprotocol_enabled:
    description:
    - This parameter indicates whether multiprotocol sharing mode is enabled.
    - It can be mentioned during modification of the NAS server.
    type: bool
  allow_unmapped_user:
    description:
    - This flag is used to mandatorily disable access in case of any user
      mapping failure.
    - If C(true), then enable access in case of any user mapping failure.
    - If C(false), then disable access in case of any user mapping failure.
    - It can be mentioned during modification of the NAS server.
    type: bool
  default_windows_user:
    description:
    - Default windows user name used for granting access in the case of Unix
      to Windows user mapping failure.
    - It can be mentioned during modification of the NAS server.
    type: str
  default_unix_user:
    description:
    - Default Unix user name used for granting access in the case of Windows
      to Unix user mapping failure.
    - It can be mentioned during modification of the NAS server.
    type: str
  enable_windows_to_unix_username_mapping:
    description:
    - This parameter indicates whether a Unix to/from Windows user name
      mapping is enabled.
    - It can be mentioned during modification of the NAS server.
    type: bool
  is_packet_reflect_enabled:
    description:
    - If the packet has to be reflected, then this parameter
      has to be set to C(true).
    - It can be mentioned during modification of the NAS server.
    type: bool
  current_unix_directory_service:
    description:
    - This is the directory service used for querying identity information
      for UNIX (such as UIDs, GIDs, net groups).
    - It can be mentioned during modification of the NAS server.
    type: str
    choices: ["NONE", "NIS", "LOCAL", "LDAP", "LOCAL_THEN_NIS", "LOCAL_THEN_LDAP"]
  replication_params:
    description:
    - Settings required for enabling replication.
    type: dict
    suboptions:
      destination_nas_server_name:
        description:
        - Name of the destination nas server.
        - Default value will be source nas server name prefixed by 'DR_'.
        type: str
      replication_mode:
        description:
        - The replication mode.
        - This is mandatory to enable replication.
        type: str
        choices: ['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).
        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_name:
        description:
        - Name of pool to allocate destination Luns.
        - Mutually exclusive with I(destination_pool_id).
        type: str
      destination_pool_id:
        description:
        - Id of pool to allocate destination Luns.
        - Mutually exclusive with I(destination_pool_name).
        type: str
      destination_sp:
        description:
        - Storage process of destination nas server
        choices: ['SPA', 'SPB']
        type: str
      is_backup:
        description:
        - Indicates if the destination nas server is backup.
        type: bool
      replication_name:
        description:
        - User defined name for replication session.
        type: str
      new_replication_name:
        description:
        - Replication name to rename the session to.
        type: str
  replication_state:
    description:
    - State of the replication.
    choices: ['enable', 'disable']
    type: str
  replication_reuse_resource:
    description:
    - This parameter indicates if existing NAS Server is to be used for replication.
    type: bool
  state:
    description:
    - Define the state of NAS server on the array.
    - The value present indicates that NAS server should exist on the system after
      the task is executed.
    - In this release deletion of NAS server is not supported. Hence, if state is
      set to C(absent) for any existing NAS server then error will be thrown.
    - For any non-existing NAS server, if state is set to C(absent) then it will return None.
    type: str
    required: true
    choices: ['present', 'absent']

notes:
- The I(check_mode) is not supported.
a"  

- name: Get Details of NAS Server
  dellemc.unity.nasserver:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nas_server_name: "{{nas_server_name}}"
    state: "present"

- name: Modify Details of NAS Server
  dellemc.unity.nasserver:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nas_server_name: "{{nas_server_name}}"
    nas_server_new_name: "updated_sample_nas_server"
    is_replication_destination: false
    is_backup_only: false
    is_multiprotocol_enabled: true
    allow_unmapped_user: true
    default_unix_user: "default_unix_sample_user"
    default_windows_user: "default_windows_sample_user"
    enable_windows_to_unix_username_mapping: true
    current_unix_directory_service: "LDAP"
    is_packet_reflect_enabled: true
    state: "present"

- name: Enable replication for NAS Server on Local System
  dellemc.unity.nasserver:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nas_server_id: "nas_10"
    replication_reuse_resource: false
    replication_params:
      replication_name: "test_replication"
      destination_nas_server_name: "destination_nas"
      replication_mode: "asynchronous"
      rpo: 60
      replication_type: "local"
      destination_pool_name: "Pool_Ansible_Neo_DND"
      destination_sp: "SPA"
      is_backup: true
    replication_state: "enable"
    state: "present"

- name: Enable replication for NAS Server on Remote System
  dellemc.unity.nasserver:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nas_server_name: "dummy_nas"
    replication_reuse_resource: false
    replication_params:
      replication_name: "test_replication"
      destination_nas_server_name: "destination_nas"
      replication_mode: "asynchronous"
      rpo: 60
      replication_type: "remote"
      remote_system:
        remote_system_host: '10.10.10.10'
        remote_system_verifycert: false
        remote_system_username: 'test1'
        remote_system_password: 'test1!'
      destination_pool_name: "fastVP_pool"
      destination_sp: "SPA"
      is_backup: true
    replication_state: "enable"
    state: "present"

- name: Enable replication for NAS Server on Remote System in existing NAS Server
  dellemc.unity.nasserver:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nas_server_name: "dummy_nas"
    replication_reuse_resource: true
    replication_params:
      destination_nas_server_name: "destination_nas"
      replication_mode: "asynchronous"
      rpo: 60
      replication_type: "remote"
      replication_name: "test_replication"
      remote_system:
        remote_system_host: '10.10.10.10'
        remote_system_verifycert: false
        remote_system_username: 'test1'
        remote_system_password: 'test1!'
      destination_pool_name: "fastVP_pool"
    replication_state: "enable"
    state: "present"

- name: Modify replication on the nasserver
  dellemc.unity.nasserver:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nas_server_name: "dummy_nas"
    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 nasserver
  dellemc.unity.nasserver:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nas_server_name: "dummy_nas"
    replication_state: "disable"
    state: "present"

- name: Disable replication by specifying replication_name on the nasserver
  dellemc.unity.nasserver:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nas_server_name: "dummy_nas"
    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
nas_server_details:
    description: The NAS server details.
    type: dict
    returned: When NAS server exists.
    contains:
        name:
            description: Name of the NAS server.
            type: str
        id:
            description: ID of the NAS server.
            type: str
        allow_unmapped_user:
            description: Enable/disable access status in case of any user
                         mapping failure.
            type: bool
        current_unix_directory_service:
            description: Directory service used for querying identity
                         information for UNIX (such as UIDs, GIDs, net groups).
            type: str
        default_unix_user:
            description: Default Unix user name used for granting access
                         in the case of Windows to Unix user mapping failure.
            type: str
        default_windows_user:
            description: Default windows user name used for granting
                         access in the case of Unix to Windows user mapping
                         failure.
            type: str
        is_backup_only:
            description: Whether the NAS server is used as backup only.
            type: bool
        is_multi_protocol_enabled:
            description: Indicates whether multiprotocol sharing mode is
                         enabled.
            type: bool
        is_packet_reflect_enabled:
            description: If the packet reflect has to be enabled.
            type: bool
        is_replication_destination:
            description: If the NAS server is a replication destination
                         then true.
            type: bool
        is_windows_to_unix_username_mapping_enabled:
            description: Indicates whether a Unix to/from Windows user name
                         mapping is enabled.
            type: bool
    sample: {
        "allow_unmapped_user": null,
        "cifs_server": {
            "UnityCifsServerList": [
                {
                    "UnityCifsServer": {
                        "hash": 8761756885270,
                        "id": "cifs_34"
                    }
                }
            ]
        },
        "current_sp": {
            "UnityStorageProcessor": {
                "hash": 8761756885273,
                "id": "spb"
            }
        },
        "current_unix_directory_service": "NasServerUnixDirectoryServiceEnum.NIS",
        "default_unix_user": null,
        "default_windows_user": null,
        "existed": true,
        "file_dns_server": {
            "UnityFileDnsServer": {
                "hash": 8761756885441,
                "id": "dns_12"
            }
        },
        "file_interface": {
            "UnityFileInterfaceList": [
                {
                    "UnityFileInterface": {
                        "hash": 8761756889908,
                        "id": "if_37"
                    }
                }
            ]
        },
        "filesystems": null,
        "hash": 8761757005084,
        "health": {
            "UnityHealth": {
                "hash": 8761756867588
            }
        },
        "home_sp": {
            "UnityStorageProcessor": {
                "hash": 8761756867618,
                "id": "spb"
            }
        },
        "id": "nas_10",
        "is_backup_only": false,
        "is_multi_protocol_enabled": false,
        "is_packet_reflect_enabled": false,
        "is_replication_destination": false,
        "is_replication_enabled": true,
        "is_windows_to_unix_username_mapping_enabled": null,
        "name": "dummy_nas",
        "pool": {
            "UnityPool": {
                "hash": 8761756885360,
                "id": "pool_7"
            }
        },
        "preferred_interface_settings": {
            "UnityPreferredInterfaceSettings": {
                "hash": 8761756885438,
                "id": "preferred_if_10"
            }
        },
        "replication_type": "ReplicationTypeEnum.REMOTE",
        "size_allocated": 3489660928,
        "tenant": null,
        "virus_checker": {
            "UnityVirusChecker": {
                "hash": 8761756885426,
                "id": "cava_10"
            }
        }
    }
)AnsibleModule)utils	nasserverzAnsible/1.7.1c                       e Zd ZdZd Zd Zd Zd Z	 	 	 	 	 	 ddZd Z	d	 Z
d
 Zd ZddZd Zd Zd Zd Zd Zd Zy)	NASServerz Class with NAS Server operationsc                 
   t        j                         | _        | j                  j                  t	                      ddgg}ddgg}t        | j                  d||      | _        t        j                  | j                         di d| _        t        j                  | j                  j                  t              | _        t         j                  j                  | j                        | _        t         j#                  d       y)z. Define all parameters required by this modulenas_server_namenas_server_idF)argument_specsupports_check_modemutually_exclusiverequired_one_of)changednas_server_detailsz+Connection established with the Unity ArrayN)r   $get_unity_management_host_parametersmodule_paramsupdateget_nasserver_parametersr   moduleensure_required_libsresultget_unity_unisphere_connectionparamsapplication_type
unity_conn
nas_serverUnityNasServernas_server_conn_objLOGinfo)selfmut_ex_argsr   s      k/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/unity/plugins/modules/nasserver.py__init__zNASServer.__init__  s    "GGI!!":"<= *?;<-?@#,, %*+	
 	""4;;/ #(-/1  >>KK 02#(#3#3#B#BOO$ >?    c                     |t         j                  j                  v rt         j                  |   S dj                  |      }t        j                  |       | j                  j                  |       y)z
        Get the enum of the Offline Availability parameter.
        :param current_uds: Current Unix Directory Service string
        :return: current_uds enum
        z=Invalid value {0} for Current Unix Directory Service providedmsgN)r   !NasServerUnixDirectoryServiceEnum__members__formatr"   errorr   	fail_json)r$   current_uds	error_msgs      r&   get_current_uds_enumzNASServer.get_current_uds_enum  sb     77CCD::;GG,,2F;,? IIi KK!!i!0r(   c                 h   |r|n|}	 | j                   j                  ||      }|r%|r#|j                  st        j	                  d|       y|S # t
        j                  $ r}|j                  dk(  r8dj                  |j                        }| j                  j                  |       nQdj                  |t        |            }t        j	                  |       | j                  j                  |       Y d}~yY d}~yd}~wt
        j                  $ r:}dj                  |t        |            }t        j	                  |       Y d}~yd}~wt        $ r\}|r|n|}dj                  |t        |            }t        j	                  |       | j                  j                  |       Y d}~yd}~ww xY w)	z
        Get the NAS Server Object using NAME/ID of the NAS Server.
        :param nas_server_name: Name of the NAS Server
        :param nas_server_id: ID of the NAS Server
        :return: NAS Server object.
        )_idnamez-NAS Server object does not exist with ID: %s Ni  z$Incorrect username or password , {0}r*   z6Failed to get details of NAS Server {0} with error {1}z3Failed to get nas server details {0} with error {1})r   get_nas_serverexistedr"   r/   r   	HttpErrorhttp_statusr.   messager   r0   strUnityResourceNotFoundError	Exception)r$   r   r   r   obj_nasecred_errerr_msgs           r&   r7   zNASServer.get_nas_server  sw    )8_]
!	/oo44:I 5 KG 		 *+8:N 		3}}#AHHII%%(%3006z3q60J 		'"%%'%22 4 // 	,,2F:s1v,F IIg 	/,;" ##)6*c!f#= IIgKK!!g!..	/s8   AA A F1!BC>>F10E		F1AF,,F1c                 X   t         j                  d       |||j                  k7  ry| j                  j                  d   '| j                  j                  d   |j
                  k7  ry| j                  j                  d   3|j                  &| j                  j                  d   |j                  k7  ry| j                  j                  d   3|j                  &| j                  j                  d   |j                  k7  ry| j                  j                  d   3|j                  &| j                  j                  d   |j                  k7  ry| j                  j                  d   3|j                  &| j                  j                  d   |j                  k7  ry| j                  j                  d   3|j                  &| j                  j                  d   |j                  k7  ry|j                  }| j                  j                  d	   }||||k7  ry| j                  j                  d
   3|j                  &| j                  j                  d
   |j                  k7  ry| j                  j                  d   3|j                  &| j                  j                  d   |j                  k7  ryy)Nz4Checking Whether the parameters are modified or not.Tnas_server_new_nameis_replication_destinationis_multiprotocol_enabledis_backup_onlyis_packet_reflect_enabledallow_unmapped_user'enable_windows_to_unix_username_mappingdefault_windows_userdefault_unix_userF)r"   r#   current_unix_directory_servicer   r   r6   rE   is_multi_protocol_enabledrG   rH   rI   +is_windows_to_unix_username_mapping_enabledrK   rL   )r$   nas_server_objr1   nas_win_flaginput_win_flags        r&   	to_updatezNASServer.to_updateA  s   GH "~LLL ;;34@""#89##$ ;;:;G::B##$@A::; ;;89E99A##$>?99: ;;./;..6##$45../ ;;9:F99A##$?@99: ;;34@33;##$9:334 FF 	 KKHI 	%%)G ;;45A44<##$:;445 ;;12>119##$78112r(   Nc                     	 |j                  ||||||||	||

       y# t        $ rV}d|j                  dt        |      }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zP
        The Details of the NAS Server will be updated in the function.
        )
r6   rE   rG   rN   rL   rK   rI   rH   enable_windows_to_unix_usernamerM   z*Failed to Update parameters of NAS Server z with error r*   N)modifyr>   r6   r<   r"   r/   r   r0   )r$   rP   new_namerL   rK   is_rep_destrF   rI   rG   rH   r1   enable_win_to_unix_name_mapr@   r2   s                 r&   update_nas_serverzNASServer.update_nas_server  s    	1!!+6-*B"3%9$7*C0K/: " 
<  	1/=/B/BCFLIIIi KK!!i!00		1s    	A=AA88A=c                    	 t         j                  d|j                         i }|d   r|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|f}t         j                  |       | j                  j                  |       Y d}~yd}~ww xY w)a   Modify the replication session
            :param: nas_server_obj: NAS server 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 nas server %sreplication_modemanualrponew_replication_namer6   max_time_out_of_syncTFz2Modifying replication session failed with error %sr*   N )	r"   r#   r6   ra   rV   r>   r/   r   r0   )	r$   rP   repl_sessionreplication_paramsmodify_payloadr_   r6   r@   errormsgs	            r&   modify_replication_sessionz$NASServer.modify_replication_session  s   	0HHE~GZGZ[N!"45&'9:hF#E*(/$$D!"89./EFF)*@A  D()-v&#$67;Me;T 55<9<56###5n5 	0KQNHIIhKK!!h!//	0s   B B$ $	C,-5C''C,c                    	 | j                  |       | j                  ||       | j                  ||d      }|r| j                  |||      S | j	                  |       t        |      }d|v rW|d   dk(  rO| j                  ||       |s t        |||        |j                  di | y|d   |d<    |j                  di | yd|v r)|d   dk(  r t        |||        |j                  di | yyy# t        $ rV}d|j                  d	t        |      }t        j                  |       | j                  j!                  |
       Y d}~yd}~ww xY w)z Enable replication on NAS Server
            :param: nas_server_obj: NAS Server object.
            :param: replication: Dict which has all the replication parameter values.
            :return: True if replication is enabled else False.
        rV   replication_typeremotedestination_nas_server_iddst_nas_server_idTlocalz'Enabling replication to the nas server  failed with error r*   Nrb   )&validate_nas_server_replication_paramsupdate_replication_params!get_replication_session_on_filterrg   "validate_create_replication_paramsget_replication_args_listget_remote_systemupdate_replication_arg_list(replicate_with_dst_resource_provisioning	replicater>   r6   r<   r"   r/   r   r0   )r$   rP   replicationreplication_reuse_resourcerc   replication_args_listr@   rf   s           r&   enable_replicationzNASServer.enable_replication  s   #	077D**;8RS 66~{T\] 66~|U`aa33K@$=k$J! "[0[AS5TX`5`&&{4IJ 2/=RTbcKNKKdNcd  BMMhAi)*=>,N,,E/DE![0[AS5TX_5_+K9NP^_GGG`J_` 6`0
  	0*8*=*=s1vGHIIhKK!!h!//		0s,   A
C2 AC2 )C2 +C2 2	E;AEEc                    	 t         j                  d|j                  f       |r| j                  |d       | 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 nas server
            :param: replication_params: Module input params
            :param: obj_nas: NAS Server object
            :return: True if disabling replication is successful
        z*Disabling replication on the nas server %sFdeleteTz(Disabling replication on the nas server rn   r*   N)r"   r#   r6   rp   rq   r}   r>   r<   r/   r   r0   )r$   r?   rd   rc   r@   rf   s         r&   disable_replicationzNASServer.disable_replication  s    	0HHBGLLQR!../A5I66w@RT\] ##% 	0*1,,A@HIIhKK!!h!//		0s   AA 	B='AB88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 )a   Retrieves replication session on nas server
            :param: obj_nas: NAS server object
            :param: replication_params: Module input params
            :param: action: Specifies action as modify or delete
            :return: Replication session based on filter
        remote_systemremote_system_name)
filter_keyrd   replication_namer6   )r   r6   )actionri   rm   N)get_replication_sessionr   r6   r   )r$   r?   rd   r   rc   s        r&   rq   z+NASServer.get_replication_session_on_filter  s     "4_"E,,WAU@R - T    $67I$J,,W2DEW2X - Z    777OL+=&'9:gE ..33t7K7KKr(   c                    	 | 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 nas server
            :param: obj_nas: NAS server 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 nas server. Please specify replication_name in replication_params to %s.r*   r   r   r6   NzERetrieving replication session on the nas server failed with error %s)r   r   idlenr   r0   r   r6   r>   r<   r"   r/   )r$   r?   r   rd   r6   r   rc   r2   sessionr@   rf   s              r&   r   z!NASServer.get_replication_session&  s   	0??BBSZS]S]B^L,|$q(%dfl%m	--)-<''#A&' #!55--226HI]6^^"N'GLLD,@"N#  	0'(+A/HIIhKK!!h!//		0s<   AB* B* $)B* B* B* $B* (B* *	C;3>C66C;c                    |d   }| j                   j                         }|D ]  }|j                  |k(  s||d<    n d|j                         vr7d|z  }t        j                  |       | j                  j                  |       y y )Nr   r   zRemote system %s is not foundr*   )r   rt   r6   keysr"   r/   r   r0   )r$   rx   rz   r   remote_system_listr   rf   s          r&   rt   zNASServer.get_remote_systemF  s    ()=>!__>>@/ 	M!!%779F%o6	 "7"<"<">>6:LMHIIhKK!!h!/ ?r(   c                    	 d|v r|d   dk(  r|d   d   |d   d   |d   d   |d   d   |d   d   d	}t        j                  |t              }|j                  |d
<   |d   $|j	                  |d         }|j
                  |d<   |d   v|rs|j                  |d         }|j
                  |d<   y| j                  j                  |d
<   |d   /| j                  j	                  |d         }|j
                  |d<   yyyy# t        $ rI}dt        |      z  }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)z Update replication dict with remote system information
            :param: replication: Dict which has all the replication parameter values
            :return: Updated replication Dict
        ri   rj   r   remote_system_hostremote_system_usernameremote_system_passwordremote_system_verifycertremote_system_port)unispherehostusernamepasswordvalidate_certsportr   destination_pool_nameN)r6   destination_pool_iddestination_nas_server_namerk   z0Updating replication params failed with error %sr*   )r   r   r   r6   get_poolr   r7   r   r>   r<   r"   r/   r   r0   )	r$   rx   ry   connection_paramsremote_system_connpool_object
nas_objectr@   rf   s	            r&   rp   z#NASServer.update_replication_paramsR  s   
	0![0[AS5TX`5`%0%ABV%W +O <=U V +O <=U V&1/&BC]&^'89MN%! &+%I%I%'7&9"4F4K4K0167C"4"="=;OfCg"="hK9DK 56<=INh!3!B!BTqHr!B!sJ?I}}K ;<48OO4H4H0167C"&//":":Lc@d":"eK9DK 56 D OiI  	0ICPQFRHIIhKK!!h!//	0s   B/D 2AD 	E?EEc                 X   d|v r@|d   dk(  r8|d   3d}t         j                  |       | j                  j                  |       |d   ra|d   dk  s|d   dkD  rP|d   r|d   dk7  s|d   s=|d   d	k7  r4d
}t         j                  |       | j                  j                  |       y y y y y )Nr\   asynchronousr_   z>rpo is required together with 'asynchronous' replication_mode.r*      i  r]   r^   z)rpo value should be in range of 5 to 1440r"   r/   r   r0   )r$   rx   rf   s      r&   validate_rpozNASServer.validate_rpos  s    ,=O1PTb1b&.WHIIhKK!!h!/K$6$:k%>PSW>W !34EW9X\d9d$%78[=OSU=UBHIIhKK!!h!/ >V8 ?Xr(   c                 :   |4d}t         j                  |       | j                  j                  |       y|d   8|d   3d}t         j                  |       | j                  j                  |       | j	                  |       |d   dk(  r8|d	   3d
}t         j                  |       | j                  j                  |       d|v rS|d   Mt        |d         }|dk(  s|dkD  r4d}t         j                  |       | j                  j                  |       yyyy)z Validate NAS server replication params
            :param: replication: Dict which has all the replication parameter values
        Nz8Please specify replication_params to enable replication.r*   r   r   zH'destination_pool_id' and 'destination_pool_name' is mutually exclusive.ri   rj   r   zARemote_system is required together with 'remote' replication_typedestination_nas_namer   _   z8destination_nas_name value should be in range of 1 to 95)r"   r/   r   r0   r   r   )r$   rx   rf   dst_nas_server_name_lengths       r&   ro   z0NASServer.validate_nas_server_replication_params  s)    QHIIhKK!!h!/ 01=+NeBfBre		(#%%(%3 k*-.(:{??[?c^		(#%%(%3 &4E[9\9h-0=S1T-U*-26PSU6UYHIIh'KK))h)7 7V :i4r(   c                    |d   8|d   3d}t         j                  |       | j                  j                  |       ddg}|D ]>  }||   	d|z  }t         j                  |       | j                  j                  |       @ y)	z Validate replication params r   Nr   zDEither 'destination_pool_id' or 'destination_pool_name' is required.r*   r\   ri   z(Please specify %s to enable replication.r   )r$   rx   rf   r   keys        r&   rr   z,NASServer.validate_create_replication_params  s    ,-5+F]:^:f]HIIhKK!!h!/"$67 	4C3'EK		(#%%(%3		4r(   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   }| j                   j                  d   }|r| j                  |      }d}|r|| j                   j                  d       	 d}|s|r| j	                  ||      }|s8|dk(  r3d}t
        j                  |       | j                   j                  |       	 |r6|dk(  r1| j                  ||      }|r| j                  |||||||	||||
       d}|r!|dk(  r| j                   j                  d       |dk(  r/|r-|+|dk(  r| j                  |||      }n| j                  ||      }	 d}|r*| j	                  d|j                        j                         }|| j                  d<   || j                  d<    | j                   j                  di | j                   y)zm
        Perform different actions on NAS Server based on user parameters
        chosen in playbook
        stater   r   rD   rL   rK   rE   rF   rI   rJ   rG   rH   rM   rd   replication_statery   FNz>Please specify replication_state along with replication_paramsr*   presentzjNAS Server Resource not found. Please enter a valid Name/ID to get or modify the parameters of nas server.Tabsentz2Deletion of NAS Server is currently not supported.enabler   r   rb   )r   r   r3   r0   r7   r"   r/   rS   rZ   r{   r~   r   _get_propertiesr   	exit_json)r$   r   r   r   rD   rL   rK   rE   rF   rI   rJ   rG   rH   r1   rx   r   ry   r   rP   r+   update_flagr   s                         r&   perform_module_operationz"NASServer.perform_module_operation  s7   
 ""7+++,,->?**?;"kk001FG KK../BC#{{112HI KK;< 	# KK9: 	!"kk001FGKKHI 	0 ++,<=KK:; 	" kk(()IJkk(()=> KK../BC%)[[%7%78T%U"))+6  ,4KK!!&f!g	 m!001>@N
 %9"4KCIIcNKK!!c!*	 ey0..EK&&"$79J(*D,.A"$=!HJ  ex/KK!! 'A! B I.5F5R H,11.+Oij22>;O	 "!%!4!4n''"))8):  ")I,>(),,r(   )
NNNNNNNNNN)NNNN)__name__
__module____qualname____doc__r'   r3   r7   rS   rZ   rg   r{   r~   rq   r   rt   rp   r   ro   rr   r   rb   r(   r&   r
   r
     ss    *@81)/VKZ :>GKEICGFJ6:18"0H)0V0,.0@
00B08B4Z-r(   r
   c                  `   t        d.i dt               dt               dt               dt               dt               dt        g d      d	t        d
      dt        d
      dt        d
      dt        d
      dt        d
      dt        d
      dt        dt        t        d      t        dddg      t        d      t        dddg      t        dt        t        ddd      t        d
dd      t        dd      t        ddd      t        dddd       !      "      t        d      t        d      t        dd#d$g      t        d
      t        d      t        d      %      "      d&t        d
      d't        dd(d)g      d*t        dd+d,gd-      S )/zb
    This method provides parameters required for the ansible NAS Server
    modules on Unity
    r   r   rD   rL   rK   rM   )NISLDAPLOCAL_THEN_NISLOCAL_THEN_LDAPNONELOCAL)choicesrE   bool)typerG   rF   rI   rJ   rH   rd   dictr<   r   r]   )r   r   intrm   rj   T)r   requiredno_logF)r   r   default)r   r   i  )r   r   r   r   )r   r   r   r   r   )r   optionsSPASPB)r   r\   r_   ri   r   r   r   destination_sp	is_backupr   r`   ry   r   r   disabler   r   r   )r   r   r   rb   )r   rb   r(   r&   r   r     s     &&.2f& F& && "V	&
 (,9(:& $(V#4& (& "&6!2& !f-& 15&0A& #'F"3&  VT(,%(8!u~x6PQ% !uw6IJF'+7;QU^b7c=AvX]JN>P;?UUY;Z;?UUYbf;g7;QV`clp7q(!" #'E"2 $% 0UUENC'!u-!%5!1'6
 &F $(V#4G&H EHi3HII&J D9h*?eLK& &r(   c                 T    t         j                  |    rt         j                  |    }|S y)zGetting correct enum values for Storage Processor
            :param: destination_sp: Storage Processor to be used in Destination NAS Server.
            :return: enum value for Storage Processor.
        N)r   NodeEnum)r   destination_sp_enums     r&   get_sp_enumr   <  s*    
 ~~n%#nn^<"" &r(   c                 Z    i }| d   r| d   |d<   d| v r| d   dk(  r
| d   |d<   |S d|d<   |S )z(Returns the replication args for payloadr   r\   r   r_   ra   r^   rb   )rd   rz   s     r&   rs   rs   F  sg    ,-4FGY4Z01//12nD8J58Q45 !  9;45  r(   c                     d| v r| d   rt        | d         }||d<   | d   |d<   d| v r| d   r| d   |d<   | d   dk(  r&d	|j                  z   |d
<   d| v r| d   	| d   |d
<   yyy| d   |j                  |d
<   yy)aJ   Update replication arg list
        :param: replication: Dict which has all the replication parameter values
        :param: replication_args_list: the existing list which should be updated
        :param: nas_server_obj: NAS Server object on which replication is to be enabled
        :return: Updated replication_args_list
    r   dst_spr   dst_pool_idr   rG   ri   rm   DR_dst_nas_server_namer   N)r   r6   )rx   rz   rP   dst_sp_enums       r&   ru   ru   U  s     ;&;7G+H!+.>"?@*5h'+67L+M-(k!k+&>2=k2J./%&'17<~?R?R7R34(K7KHe<f<r;FGd;e!"78 =s7 45=;I;N;N!"78 >r(   c                  8    t               } | j                          y)zb Create Unity NAS Server object and perform action on it
        based on user input from playbookN)r
   r   )objs    r&   mainr   n  s     +C  "r(   __main__N)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Cansible_collections.dellemc.unity.plugins.module_utils.storage.dellr   
get_loggerr"   r   objectr
   r   r   rs   ru   r   r   rb   r(   r&   <module>r      s    C BENFPE
N 5e{#" b- b-J,^#!O2# zF r(   