
    Vh[                       d Z ddlmZmZmZ eZdZdZdZ	ddl
Z
ddlZ	 ddlmZmZmZ d\  ZZdd
lmZmZ ddlmZ  ej2                  d      Zg dZg dZ edd	d e e        e        e        e        e        e                   ZddgZddgZ dZ! G d de"      Z#d Z$d Z%d Z&d Z'd Z(d Z)d  Z*d! Z+e,d"k(  r e+        yy# e$ r d	 ej&                         cZZY w xY w)#z/Ansible module for managing nfs export on Unity    )absolute_importdivisionprint_functiona
(  
---
module: nfs
version_added: '1.1.0'
short_description: Manage NFS export on Unity storage system
description:
- Managing NFS export on Unity storage system includes-
  Create new NFS export,
  Modify NFS export attributes,
  Display NFS export details,
  Delete NFS export.

extends_documentation_fragment:
  -  dellemc.unity.unity

author:
- Vivek Soni (@v-soni11) <ansible.team@dell.com>

options:
  nfs_export_name:
    description:
    - Name of the nfs export.
    - Mandatory for create operation.
    - Specify either I(nfs_export_name) or I(nfs_export_id) (but not both) for any
      operation.
    type: str
  nfs_export_id:
    description:
    - ID of the nfs export.
    - This is a unique ID generated by Unity storage system.
    type: str
  filesystem_name:
    description:
    - Name of the filesystem for which NFS export will be created.
    - Either filesystem or snapshot is required for creation of the NFS.
    - If I(filesystem_name) is specified, then I(nas_server) is required to uniquely
      identify the filesystem.
    - If filesystem parameter is provided, then snapshot cannot be specified.
    type: str
  filesystem_id:
    description:
    - ID of the filesystem.
    - This is a unique ID generated by Unity storage system.
    type: str
  snapshot_name:
    description:
    - Name of the snapshot for which NFS export will be created.
    - Either filesystem or snapshot is required for creation of the NFS
      export.
    - If snapshot parameter is provided, then filesystem cannot be specified.
    type: str
  snapshot_id:
    description:
    - ID of the snapshot.
    - This is a unique ID generated by Unity storage system.
    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
  path:
    description:
    - Local path to export relative to the NAS server root.
    - With NFS, each export of a file_system or file_snap must have a unique
      local path.
    - Mandatory while creating NFS export.
    type: str
  description:
    description:
    - Description of the NFS export.
    - Optional parameter when creating a NFS export.
    - To modify description, pass the new value in I(description) field.
    - To remove description, pass the empty value in I(description) field.
    type: str
  host_state:
    description:
    - Define whether the hosts can access the NFS export.
    - Required when adding or removing access of hosts from the export.
    type: str
    choices: ['present-in-export', 'absent-in-export']
  anonymous_uid:
    description:
    - Specifies the user ID of the anonymous account.
    - If not specified at the time of creation, it will be set to 4294967294.
    type: int
  anonymous_gid:
    description:
    - Specifies the group ID of the anonymous account.
    - If not specified at the time of creation, it will be set to 4294967294.
    type: int
  state:
    description:
    - State variable to determine whether NFS export will exist or not.
    required: true
    type: str
    choices: ['absent', 'present']
  default_access:
    description:
    - Default access level for all hosts that can access the NFS export.
    - For hosts that need different access than the default,
      they can be configured by adding to the list.
    - If I(default_access) is not mentioned during creation, then NFS export will
      be created with C(NO_ACCESS).
    type: str
    choices: ['NO_ACCESS', 'READ_ONLY', 'READ_WRITE', 'ROOT',
              'READ_ONLY_ROOT']
  min_security:
    description:
    - NFS enforced security type for users accessing a NFS export.
    - If not specified at the time of creation, it will be set to C(SYS).
    type: str
    choices: ['SYS', 'KERBEROS', 'KERBEROS_WITH_INTEGRITY',
              'KERBEROS_WITH_ENCRYPTION']
  adv_host_mgmt_enabled:
    description:
    - If C(false), allows you to specify hosts without first having to register them.
    - Mandatory while adding access hosts.
    type: bool
  no_access_hosts:
    description:
    - Hosts with no access to the NFS export.
    - List of dictionaries. Each dictionary will have any of the keys from
      I(host_name), I(host_id), I(subnet), I(netgroup), I(domain) and I(ip_address).
    - If I(adv_host_mgmt_enabled) is C(true) then the accepted keys are I(host_name), I(host_id) and I(ip_address).
    - If I(adv_host_mgmt_enabled) is C(false) then the accepted keys are I(host_name), I(subnet), I(netgroup), I(domain) and I(ip_address).
    type: list
    elements: dict
    suboptions:
      host_name:
        description:
        - Name of the host.
        type: str
      host_id:
        description:
        - ID of the host.
        type: str
      ip_address:
        description:
        - IP address of the host.
        type: str
      subnet:
        description:
        - Subnet can be an 'IP address/netmask' or 'IP address/prefix length'.
        type: str
      netgroup:
        description:
        - Netgroup that is defined in NIS or the local netgroup file.
        type: str
      domain:
        description:
        - DNS domain, where all NFS clients in the domain are included in the host list.
        type: str
  read_only_hosts:
    description:
    - Hosts with read-only access to the NFS export.
    - List of dictionaries. Each dictionary will have any of the keys from
      I(host_name), I(host_id), I(subnet), I(netgroup), I(domain) and I(ip_address).
    - If I(adv_host_mgmt_enabled) is C(true) then the accepted keys are I(host_name), I(host_id) and I(ip_address).
    - If I(adv_host_mgmt_enabled) is C(false) then the accepted keys are I(host_name), I(subnet), I(netgroup), I(domain) and I(ip_address).
    type: list
    elements: dict
    suboptions:
      host_name:
        description:
        - Name of the host.
        type: str
      host_id:
        description:
        - ID of the host.
        type: str
      ip_address:
        description:
        - IP address of the host.
        type: str
      subnet:
        description:
        - Subnet can be an 'IP address/netmask' or 'IP address/prefix length'.
        type: str
      netgroup:
        description:
        - Netgroup that is defined in NIS or the local netgroup file.
        type: str
      domain:
        description:
        - DNS domain, where all NFS clients in the domain are included in the host list.
        type: str
  read_only_root_hosts:
    description:
    - Hosts with read-only for root user access to the NFS export.
    - List of dictionaries. Each dictionary will have any of the keys from
      I(host_name), I(host_id), I(subnet), I(netgroup), I(domain) and I(ip_address).
    - If I(adv_host_mgmt_enabled) is C(true) then the accepted keys are I(host_name), I(host_id) and I(ip_address).
    - If I(adv_host_mgmt_enabled) is C(false) then the accepted keys are I(host_name), I(subnet), I(netgroup), I(domain) and I(ip_address).
    type: list
    elements: dict
    suboptions:
      host_name:
        description:
        - Name of the host.
        type: str
      host_id:
        description:
        - ID of the host.
        type: str
      ip_address:
        description:
        - IP address of the host.
        type: str
      subnet:
        description:
        - Subnet can be an 'IP address/netmask' or 'IP address/prefix length'.
        type: str
      netgroup:
        description:
        - Netgroup that is defined in NIS or the local netgroup file.
        type: str
      domain:
        description:
        - DNS domain, where all NFS clients in the domain are included in the host list.
        type: str
  read_write_hosts:
    description:
    - Hosts with read and write access to the NFS export.
    - List of dictionaries. Each dictionary will have any of the keys from
      I(host_name), I(host_id), I(subnet), I(netgroup), I(domain) and I(ip_address).
    - If I(adv_host_mgmt_enabled) is C(true) then the accepted keys are I(host_name), I(host_id) and I(ip_address).
    - If I(adv_host_mgmt_enabled) is C(false) then the accepted keys are I(host_name), I(subnet), I(netgroup), I(domain) and I(ip_address).
    type: list
    elements: dict
    suboptions:
      host_name:
        description:
        - Name of the host.
        type: str
      host_id:
        description:
        - ID of the host.
        type: str
      ip_address:
        description:
        - IP address of the host.
        type: str
      subnet:
        description:
        - Subnet can be an 'IP address/netmask' or 'IP address/prefix length'.
        type: str
      netgroup:
        description:
        - Netgroup that is defined in NIS or the local netgroup file.
        type: str
      domain:
        description:
        - DNS domain, where all NFS clients in the domain are included in the host list.
        type: str
  read_write_root_hosts:
    description:
    - Hosts with read and write for root user access to the NFS export.
    - List of dictionaries. Each dictionary will have any of the keys from
      I(host_name), I(host_id), I(subnet), I(netgroup), I(domain) and I(ip_address).
    - If I(adv_host_mgmt_enabled) is C(true) then the accepted keys are I(host_name), I(host_id) and I(ip_address).
    - If I(adv_host_mgmt_enabled) is C(false) then the accepted keys are I(host_name), I(subnet), I(netgroup), I(domain) and I(ip_address).
    type: list
    elements: dict
    suboptions:
      host_name:
        description:
        - Name of the host.
        type: str
      host_id:
        description:
        - ID of the host.
        type: str
      ip_address:
        description:
        - IP address of the host.
        type: str
      subnet:
        description:
        - Subnet can be an 'IP address/netmask' or 'IP address/prefix length'.
        type: str
      netgroup:
        description:
        - Netgroup that is defined in NIS or the local netgroup file.
        type: str
      domain:
        description:
        - DNS domain, where all NFS clients in the domain are included in the host list.
        type: str
notes:
- The I(check_mode) is not supported.
an  
- name: Create nfs export from filesystem
  dellemc.unity.nfs:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nfs_export_name: "ansible_nfs_from_fs"
    path: '/'
    filesystem_id: "fs_377"
    state: "present"

- name: Create nfs export from snapshot
  dellemc.unity.nfs:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nfs_export_name: "ansible_nfs_from_snap"
    path: '/'
    snapshot_name: "ansible_fs_snap"
    state: "present"

- name: Modify nfs export
  dellemc.unity.nfs:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nfs_export_name: "ansible_nfs_from_fs"
    nas_server_id: "nas_3"
    description: ""
    default_access: "READ_ONLY_ROOT"
    anonymous_gid: 4294967290
    anonymous_uid: 4294967290
    state: "present"

- name: Add host in nfs export with adv_host_mgmt_enabled as true
  dellemc.unity.nfs:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nfs_export_name: "ansible_nfs_from_fs"
    filesystem_id: "fs_377"
    adv_host_mgmt_enabled: true
    no_access_hosts:
      - host_id: "Host_1"
    read_only_hosts:
      - host_id: "Host_2"
    read_only_root_hosts:
      - host_name: "host_name1"
    read_write_hosts:
      - host_name: "host_name2"
    read_write_root_hosts:
      - ip_address: "1.1.1.1"
    host_state: "present-in-export"
    state: "present"

- name: Remove host in nfs export with adv_host_mgmt_enabled as true
  dellemc.unity.nfs:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nfs_export_name: "ansible_nfs_from_fs"
    filesystem_id: "fs_377"
    adv_host_mgmt_enabled: true
    no_access_hosts:
      - host_id: "Host_1"
    read_only_hosts:
      - host_id: "Host_2"
    read_only_root_hosts:
      - host_name: "host_name1"
    read_write_hosts:
      - host_name: "host_name2"
    read_write_root_hosts:
      - ip_address: "1.1.1.1"
    host_state: "absent-in-export"
    state: "present"

- name: Add host in nfs export with adv_host_mgmt_enabled as false
  dellemc.unity.nfs:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nfs_export_name: "ansible_nfs_from_fs"
    filesystem_id: "fs_377"
    adv_host_mgmt_enabled: false
    no_access_hosts:
      - domain: "google.com"
    read_only_hosts:
      - netgroup: "netgroup_admin"
    read_only_root_hosts:
      - host_name: "host5"
    read_write_hosts:
      - subnet: "168.159.57.4/255.255.255.0"
    read_write_root_hosts:
      - ip_address: "10.255.2.4"
    host_state: "present-in-export"
    state: "present"

- name: Remove host in nfs export with adv_host_mgmt_enabled as false
  dellemc.unity.nfs:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nfs_export_name: "ansible_nfs_from_fs"
    filesystem_id: "fs_377"
    adv_host_mgmt_enabled: false
    no_access_hosts:
      - domain: "google.com"
    read_only_hosts:
      - netgroup: "netgroup_admin"
    read_only_root_hosts:
      - host_name: "host5"
    read_write_hosts:
      - subnet: "168.159.57.4/255.255.255.0"
    read_write_root_hosts:
      - ip_address: "10.255.2.4"
    host_state: "absent-in-export"
    state: "present"

- name: Get nfs details
  dellemc.unity.nfs:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nfs_export_id: "NFSShare_291"
    state: "present"

- name: Delete nfs export by nfs name
  dellemc.unity.nfs:
    unispherehost: "{{unispherehost}}"
    username: "{{username}}"
    password: "{{password}}"
    validate_certs: "{{validate_certs}}"
    nfs_export_name: "ansible_nfs_name"
    nas_server_name: "ansible_nas_name"
    state: "absent"
a  
changed:
  description: Whether or not the resource has changed.
  returned: always
  type: bool
  sample: "false"

nfs_share_details:
  description: Details of the nfs export.
  returned: When nfs export exists.
  type: dict
  contains:
    anonymous_uid:
      description: User ID of the anonymous account
      type: int
    anonymous_gid:
      description: Group ID of the anonymous account
      type: int
    default_access:
      description: Default access level for all hosts that can access export
      type: str
    description:
      description: Description about the nfs export
      type: str
    id:
      description: ID of the nfs export
      type: str
    min_security:
      description: NFS enforced security type for users accessing an export
      type: str
    name:
      description: Name of the nfs export
      type: str
    no_access_hosts_string:
      description: Hosts with no access to the nfs export
      type: str
    read_only_hosts_string:
      description: Hosts with read-only access to the nfs export
      type: str
    read_only_root_hosts_string:
      description: Hosts with read-only for root user access to the nfs export
      type: str
    read_write_hosts_string:
      description: Hosts with read and write access to the nfs export
      type: str
    read_write_root_hosts_string:
      description: Hosts with read and write for root user access to export
      type: str
    type:
      description: NFS export type. i.e. filesystem or snapshot
      type: str
    export_paths:
      description: Export paths that can be used to mount and access export
      type: list
    filesystem:
      description: Details of the filesystem on which nfs export is present
      type: dict
      contains:
        UnityFileSystem:
          description: filesystem details
          type: dict
          contains:
            id:
              description: ID of the filesystem
              type: str
            name:
              description: Name of the filesystem
              type: str
    nas_server:
      description: Details of the nas server
      type: dict
      contains:
        UnityNasServer:
          description: NAS server details
          type: dict
          contains:
            id:
              description: ID of the nas server
              type: str
            name:
              description: Name of the nas server
              type: str
  sample: {
      'anonymous_gid': 4294967294,
      'anonymous_uid': 4294967294,
      'creation_time': '2022-03-09 15:05:34.720000+00:00',
      'default_access': 'NFSShareDefaultAccessEnum.NO_ACCESS',
      'description': '',
      'export_option': 1,
      'export_paths': [
      '**.***.**.**:/dummy-share-123'
      ],
      'filesystem': {
      'UnityFileSystem': {
          'id': 'fs_id_1',
          'name': 'fs_name_1'
      }
      },
      'host_accesses': None,
      'id': 'NFSShare_14393',
      'is_read_only': None,
      'min_security': 'NFSShareSecurityEnum.SYS',
      'modification_time': '2022-04-25 08:12:28.179000+00:00',
      'name': 'dummy-share-123',
      'nfs_owner_username': None,
      'no_access_hosts': None,
      'no_access_hosts_string': 'host1,**.***.*.*',
      'path': '/',
      'read_only_hosts': None,
      'read_only_hosts_string': '',
      'read_only_root_access_hosts': None,
      'read_only_root_hosts_string': '',
      'read_write_hosts': None,
      'read_write_hosts_string': '',
      'read_write_root_hosts_string': '',
      'role': 'NFSShareRoleEnum.PRODUCTION',
      'root_access_hosts': None,
      'snap': None,
      'type': 'NFSTypeEnum.NFS_SHARE',
      'existed': true,
      'nas_server': {
      'UnityNasServer': {
          'id': 'nas_id_1',
          'name': 'dummy_nas_server'
      }
      }
    }
N)
ip_networkIPv4NetworkIPv6Network)TNF)AnsibleModulemissing_required_lib)utilsnfs)	NO_ACCESS	READ_ONLY
READ_WRITEROOTREAD_ONLY_ROOT)SYSKERBEROSKERBEROS_WITH_INTEGRITYKERBEROS_WITH_ENCRYPTIONlistdict)	host_namehost_id
ip_addresssubnetnetgroupdomain)typerequiredelementsoptionszpresent-in-exportzabsent-in-exportpresentabsentzAnsible/1.7.1c                       e 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d Zd Zd%dZd 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 Zd Zd Zd Z d  Z!d! Z"d" Z#d# Z$y
)'NFSz Class with nfs export operationsc                 d   t        j                         | _        | j                  j                  t	                      ddgddgg dddgg}ddgg}	 t        | j                  d||      | _        t        j                  | j                         t        s*| j                  j                  t        d      t        	       t        j                  | j                  j                  t              | _        | j                  j                   | _        d
| _        | j                  j                  d   s| j                  j                  d   rd| _        n9| j                  j                  d   s| j                  j                  d   rd| _        dddddd| _        ddi| _        t*        j-                  d       y
)z. Define all parameters required by this modulenfs_export_idnas_server_idnas_server_name)filesystem_idfilesystem_namesnapshot_idsnapshot_namenfs_export_nameF)argument_specsupports_check_modemutually_exclusiverequired_one_of	ipaddress)msg	exceptionNr+   r*   Tr-   r,   no_access_hosts_stringread_only_hosts_stringread_only_root_hosts_stringread_write_hosts_stringread_write_root_hosts_string)no_access_hostsread_only_hostsread_only_root_hostsread_write_hostsread_write_root_hostsr   RO_ROOTz0Got the unity instance for provisioning on Unity)r   $get_unity_management_host_parametersmodule_paramsupdateget_nfs_parametersr	   moduleensure_required_libsHAS_IPADDRESS	fail_jsonr
   IP_ADDRESS_IMP_ERRget_unity_unisphere_connectionparamsapplication_typeunity_clicliis_given_nfs_for_fshost_param_mappingdefault_accessLOGinfo)selfr1   r2   s      e/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/dellemc/unity/plugins/modules/nfs.py__init__zNFS.__init__h  s    #GGI!!"4"67.@.0AB?.0AB	D
 ,->?@-#,,%1+- 	""4;;/KK!!&:;&G,> " @ 99$++:L:L:JL
::??#' ;;/0;;o.'+D$[[0""=1',D$  87$A 9%C#
  0;CD    c                    t        j                  d      }|j                  d      rct        |j                  d            }|dv rEd|j                  d      z  }t        j                  |       | j                  j                  |       |j                  d      rh|j                  d      }t        |      }|dk(  rG|j                  |      s6d|z  }t        j                  |       | j                  j                  |       |j                  d	      re|j                  d	      }|j                  d
      }t        |      dk7  r4d}t        j                  |       | j                  j                  |       yyy)zk
        Validate host access data
        :param host_dict: Host access data
        :return None
        zG(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)r   )      z.IP4/IP6: %s given in host_name instead of namer4   r   r   z%s is not a valid FQDNr   /   zMSubnet should be in format 'IP address/netmask' or 'IP address/prefix length'N)recompilegetget_ip_versionrS   errorrE   rH   matchsplitlen)rU   	host_dictfqdn_patversionr4   
ip_or_fqdnr   subnet_infos           rV   validate_host_access_datazNFS.validate_host_access_data  s>    :: A B ==%$Y]];%?@G&  )k :;		#%%#%.==&"|4J$Z0G!|HNN:$>.;		#%%#%.=="]]8,F ,,s+K;1$e		#%%#%. % #rX   c                    t        |j                               }h d}h d}||z
  }||z
  }| j                  j                  d   rD|t               k7  r7d|z  }t        j                  |       | j                  j                  |       y| j                  j                  d   sE|t               k7  r7d|z  }t        j                  |       | j                  j                  |       yyy)zv
        Validate adv_host_mgmt_enabled check
        :param host_dict: Host access data
        :return None
        >   r   r   r   >   r   r   r   r   r   adv_host_mgmt_enabledzHIf 'adv_host_mgmt_enabled' is true then host access should only have  %sr\   zIIf 'adv_host_mgmt_enabled' is false then host access should only have  %sN)setkeysrE   rK   rS   rc   rH   )rU   rg   host_dict_keys_setadv_host_mgmt_enabled_true_setadv_host_mgmt_enabled_false_setadv_host_mgmt_enabled_true_diff adv_host_mgmt_enabled_false_diffr4   s           rV   $validate_adv_host_mgmt_enabled_checkz(NFS.validate_adv_host_mgmt_enabled_check  s     !!12)O&*e'*<?]*]'+=@_+_(;;56;Z^a^c;c\_}}CIIcNKK!!c!*##$;<AaehejAj]`CIIcNKK!!c!* Bk<rX   c                 j   t        | j                  j                               D ]  }| j                  j                  |   rj| j                  j                  d   r| j                  j                  d   	 7d|z  }t
        j                  |       | j                  j                  |       | j                  j                  |   s| j                  j                  |   D ]J  }|j                         D ci c]  \  }}|s	|| }}}| j                  |       | j                  |       L 	 yc c}}w )zB
        Validate host access params
        :return None
        
host_statern   NzC'host_state' and 'adv_host_mgmt_enabled' is required along with: %sr\   )r   rQ   rp   rE   rK   rS   rc   rH   itemsrv   rl   )rU   paramr4   rg   kvs         rV   !validate_host_access_input_paramsz%NFS.validate_host_access_input_params  s   
 $116689 	>E{{!!%($++2D2D 3"%)[[%7%7+&-04&5[^cc		#%%#%.##E*!%!3!3E!: >I2;//2C I$!QqA II I==iH229=>	> !Js   4
D/
?D/
c                 "   g d}|D ]  }| j                   j                  |   st        | j                   j                  |   j                               dk(  sQd|z  }t        j                  |       | j                   j                  |        y)zA
        Validate module attributes
        :return None
        )r.   r'   r+   r*   r(   r-   r,   pathr   z"Please provide valid value for: %sr\   N)rE   rK   rf   striprS   rc   rH   )rU   
param_listrz   r4   s       rV   validate_module_attributeszNFS.validate_module_attributes  s{    
>
   	/E{{!!%(4;;%%e,2245::UB		#%%#%.	/rX   c                    | j                   j                  d   r/| j                   j                  d   s| j                   j                  d   s| j                   j                  d   re| j                   j                  d   sL| j                   j                  d   s3d}t        j                  |       | j                   j	                  |       | j                   j                  d   se| j                   j                  d   sL| j                   j                  d	   s3d
}t        j                  |       | j                   j	                  |       | j                          | j                          y)z Validate input parameters r.   r-   r,   r+   r(   r)   zLPlease provide nas server id or name along with filesystem name and nfs namer\   r*   z9Please provide either nas server id/name or filesystem idN)rE   rK   rS   rc   rH   r   r}   rU   r4   s     rV   validate_inputzNFS.validate_input  s    ;;/0KK&&7KK&&}5##$56[[''8[[''(9:5		#%%#%.[[''8[[''(9:++O<&		#%%#%.'')..0rX   c                     | j                   j                  d   r| j                   j                  d   S | j                   j                  d   S )z Provide nfs_export_id or nfs_export_name user given value

        :return: value provided by user in nfs_export_id/nfs_export_name
        :rtype: str
        r'   r.   )rE   rK   )rU   s    rV   get_nfs_id_or_namezNFS.get_nfs_id_or_name  sA     ;;o.;;%%o66{{!!"344rX   c                    t         j                  d       | j                  j                  d   s| j                  j                  d   sy| j                  j                  d   r| j                  j                  d   n| j                  j                  d   }	 | j                  j                  | j                  j                  d   | j                  j                  d         }r?|j                  s3d}t         j                  |       | j                  j                  |       t         j                  d       |S # t        j                  $ rI}dt        |      z  }t         j                  |       | j                  j                  |       Y d}~d}~wt        j                  $ rn}|j                  dk(  rd	|d
t        |      }nd	|dt        |      }t         j                  |       | j                  j                  |       Y d}~.d}~wt        $ rM}d	|dt        |      }t         j                  |       | j                  j                  |       Y d}~d}~ww xY w)zb Get nas server object

        :return: nas server object
        :rtype: UnityNasServer
        zGetting nas server detailsr(   r)   N_idnamez$Given nas server not found error: %sr\     zFailed to get nas server: + due to incorrect username/password error:  error: z+Please check nas details it does not existszGot nas server details)rS   rT   rE   rK   rM   get_nas_serverr   UnityResourceNotFoundErrorstrrc   rH   HTTPClientErrorhttp_status	Exceptionexisted)rU   
id_or_namenaser4   s        rV   get_nas_from_given_inputzNFS.get_nas_from_given_input  s    	-.{{!!/2""#45KK/ [[''859[[5G5G6 		+**++KK&&7[[''(9: , <C. s{{ @CIIcNKK!!c!*)*
9 // 	+83q6ACIIcNKK!!c!**$$ 	+}}#7A3q6K $
 A(IIcNKK!!c!** 	+CF$CIIcNKK!!c!**		+s3   AD8 8I'?FI'%A#HI'AI""I'Nc           	      X   	 |s5|s3d}t         j                  |       | j                  j                  |       |r|n|}t         j	                  d|       |r| j
                  r(| j                  j                  || j                        }n| j
                  du r(| j                  j                  || j                        }n| j                  j                  |      }n| j
                  r(| j                  j                  || j                        }nR| j
                  du r(| j                  j                  || j                  	      }n| j                  j                  |
      }t        |t        j                        rX|}t         j	                  d|       | j                  r1|D ])  }|j                  j                  | j                  k(  s'|c S  d}nd}n|r|j                   rz| j                  rV|j                  j                  | j                  k7  r3d}t         j                  |       | j                  j                  |       t         j	                  d|       |S |r|j                   sd}nd|z  }t         j                  |       | j                  j                  |       y# t        j"                  $ r9}dt%        |      dz  }t         j	                  t%        |             Y d}~yd}~wt        j&                  $ r<}|j(                  dk(  rddt%        |      }nddt%        |      }Y d}~d}~wt        j*                  $ r6}dd| j                  j,                  d   dt%        |      }Y d}~d}~wt.        $ r}ddt%        |      }Y d}~0d}~ww xY w)z~ Get the nfs export

        :return: nfs_export object if nfs exists else None
        :rtype: UnityNfsShare or None
        zPlease give nfs id/namer\   zGetting nfs export: %s)r   
filesystemF)r   snapr   )r   r   )r   r   r   z,Multiple nfs export with same name: %s foundzZMultiple nfs share with same name: %s found. Given nas server is not correct. Please checkzCMultiple nfs share with same name: %s found. Please give nas serverz,nfs found but nas details given is incorrectz"Successfully got nfs share for: %sz&Please check incorrect nfs id is givenzFailed to get nfs share: %sz2NFS share: %(id_or_name)s not found error: %(err)s)r   errNr   zFailed to get nfs share: r   r   z check unispherehost IP: r'   )rS   rc   rE   rH   rT   rP   rM   get_nfs_sharefs_objsnap_obj
isinstancer   UnityNfsShareListnas_objr   
nas_serverr   r   r   r   r   StoropsConnectTimeoutErrorrK   r   )	rU   idr   r4   r   r   nfs_listnr   s	            rV   r   zNFS.get_nfs_shareD  s   O	Ed/		#%%#%.!tJHH-z:++**224;; 3 8C--6**22r2NC**22r2:C ++**22!dkk 3 ;C--6**22! 3 7C **222=C#u667  !",.<<% %<<22dllB#$H%JC3C 3;;||(A(A||)$L		#--#-6HHA:NJ CC7*DC( 			##&) // 	#4>s1v%NOCHHSX$$ 	I}}#7A3q6K $ BLADQI// 	N!+!%!3!3O!Dc!fNC  	E=G=@VEC	EsO   GJ& J& BJ& J& &N)9/K--N)2L::N)+NN)N$$N)c                 B   	 t         j                  d| j                                |j                          t         j                  d       y# t        $ rI}dt        |      z  }t         j                  |       | j                  j                  |       Y d}~yd}~ww xY w)zt Delete nfs share

        :param nfs: NFS share obj
        :type nfs: UnityNfsShare
        :return: None
        zDeleting nfs share: %szDeleted nfs sharez%Failed to delete nfs share, error: %sr\   N)	rS   rT   r   deleter   r   rc   rE   rH   )rU   nfs_objr   r4   s       rV   delete_nfs_sharezNFS.delete_nfs_share  sw    	+HH-t/F/F/HINNHH() 	+9CFBCIIcNKK!!c!**	+s   A	A 	B?BBc                 4   | j                   j                  d   r| j                   j                  d   }nf| j                   j                  d   r| j                   j                  d   }n3d}t        j                  |       | j                   j	                  |       	 | j                   j                  d   r| j
                  s3d}t        j                  |       | j                   j	                  |       t        j                  d       | j                  j                  | j                   j                  d   | j
                        }nb| j                   j                  d   rIt        j                  d       | j                  j                  | j                   j                  d   	      }r$|j                  rt        j                  d       |S dz  }t        j                  |       | j                   j	                  |       y# t        j                  $ rL}d
dt        |      }t        j                  |       | j                   j	                  |       Y d}~d}~wt        j                  $ rL}|j                  dk(  rdt        |      z  }ndt        |      z  }t        j                  |       Y d}~d}~wt        $ rM}ddt        |      }t        j                  |       | j                   j	                  |       Y d}~hd}~ww xY w)z] Get filesystem obj

        :return: filesystem obj
        :rtype: UnityFileSystem
        r*   r+   z4Please provide filesystem ID/name, to get filesystemr\   z,NAS Server is required to get the filesystemzGetting filesystem by name: %s)r   r   zGetting filesystem by ID: %sr   zFilesystem:  not found error: Nr   zEFailed to get filesystem due to incorrect username/password error: %sz"Failed to get filesystem error: %szFailed to get filesystem: r   zGot the filesystem: %szFilesystem: %s does not exists)rE   rK   rS   rc   rH   r   rT   rM   get_filesystemr   r   r   r   r   r   r   )rU   r   r4   err_msgr   r   s         rV   r   zNFS.get_filesystem  sg    ;;o.++O<J[[ 12++,=>JHCIIcNKK!!c!*	+{{!!"34||LGIIg&KK))g)69:F22++,=>#|| 3 - ##O47D22**?; 3 =( fnnHH-z:M2Z?CIIcNKK!!c!*1 // 	+CF$CIIcNKK!!c!**$$ 	}}#469!f= ;SVCIIcNN 	+CF$CIIcNKK!!c!**		+s4   DH LAI!!L7AJ>>L
ALLc                 D   | j                   j                  d   r| j                   j                  d   }nf| j                   j                  d   r| j                   j                  d   }n3d}t        j                  |       | j                   j	                  |       t        j                  d       	 |rL| j                  j                  | j                   j                  d   | j                   j                  d         }n3d}t        j                  |       | j                   j	                  |       r$|j                  rt        j                  d|       |S d|z  }t        j                  |       | j                   j	                  |       y
# t        j                  $ rL}d|d	t        |      }t        j                  |       | j                   j	                  |       Y d
}~d
}~wt        j                  $ rL}|j                  dk(  rdt        |      z  }ndt        |      z  }t        j                  |       Y d
}~d
}~wt        $ rM}d|d	t        |      }t        j                  |       | j                   j	                  |       Y d
}~hd
}~ww xY w)zS Get snapshot obj

        :return: Snapshot obj
        :rtype: UnitySnap
        r,   r-   z0Please provide snapshot ID/name, to get snapshotr\   zGetting snapshot: %sr   z;Failed to get the snapshot. Please provide snapshot detailszFailed to get snapshot: r   Nr   zCFailed to get snapshot due to incorrect username/password error: %sz Failed to get snapshot error: %sz!Successfully got the snapshot: %szSnapshot: %s does not exists)rE   rK   rS   rc   rH   rT   rM   get_snapr   r   r   r   r   r   r   )rU   r   r4   r   r   s        rV   get_snapshotzNFS.get_snapshot  s    ;;m,++M:J[[0++O<JDCIIcNKK!!c!*'4	+::..**=9++O< / > 		#%%#%.& ((HH8*EO0:=CIIcNKK!!c!*1 // 	+<F<?FDCIIcNKK!!c!**$$ 	}}#469!f= 93q6AIIcNN 	+<F<?FDCIIcNKK!!c!**		+s4   1BF J"AG))J?AIJAJJc                 >   	 d}d}|r|}| j                   j                  |      }nA|r|}| j                   j                  |      }n |r|}| j                   j                  |      }|r.|j                  r"t        j	                  d|j
                         |S d| d}t        j                  |       | j                  j                  |       y# t        $ rC}d	 d
| }t        j                  |       | j                  j                  |       Y d}~yd}~ww xY w)z
        Get host object
        :param host_id: ID of the host
        :param host_name: Name of the host
        :param ip_address: Network address of the host
        :return: Host object
        :rtype: object
        Nr   r   )addresszSuccessfully got host: %szHost : z does not existsr\   zFailed to get host z	, error: )
rM   get_hostr   rS   rT   r   rc   rE   rH   r   )rU   r   r   r   host_objhostr4   r   s           rV   get_host_objzNFS.get_host_obj  s   	+HD::..7.; ::..I.>!::..z.BH,,4hmmDv%56		#%%#%. 	+'vYqc:CIIcNKK!!c!**	+s   BC 7C 	D9DDc                     |j                  d      r.| j                  |j                  d            j                  dz   S |j                  d      r|j                  d      dz   S |j                  d      r|j                  d      dz   S |j                  d      r|j                  d      dz   S |j                  d      rd|j                  d      z   dz   S |j                  d	      rd
|j                  d	      z   dz   S y)z}
        Form host access string
        :host_dict Host access type info
        :return Host access data in string
        r   r   ,r   r   r   r   z*.r   @N)ra   r   r   rU   rg   s     rV   get_host_access_string_valuez NFS.get_host_access_string_value;  s    ==#$$immI.F$HMMPSSS]];'=="# #]]<(== #$ $]]8$==   ]]8$)--    ]]:& !" " 'rX   c                 0   |j                  d      r!| j                  |j                  d            S |j                  d      r!| j                  |j                  d            S |j                  d      r!| j                  |j                  d            S y)z
        Form host access value using host object
        :host_dict Host access type info
        :return Host object
        r   r   r   )r   r   )r   N)ra   r   r   s     rV   get_host_obj_valuezNFS.get_host_obj_valueS  s     ==#$$Y]]9-E$FF]];'$$y}}[/I$JJ]]<($$	l0K$LL )rX   c                 z   i }t        | j                  j                               D ]b  }| j                  j                  |   sg ||<   | j                  j                  |   D ]%  }||   j                  | j                  |             ' d d|v r|j                  d      |d<   d|v r|j                  d      |d<   |S )z
        Form host access for advance management
        :return: Formatted Host access type info
        :rtype: dict
        r=   read_only_root_access_hostsr?   root_access_hosts)r   rQ   rp   rE   rK   appendr   pop)rU   result_hostrz   rg   s       rV   format_host_dict_for_adv_mgmtz!NFS.format_host_dict_for_adv_mgmt`  s     $116689 	RE{{!!%(%'E"!%!3!3E!: RI&--d.E.Ei.PQR	R "[09DI_9`K56"k1/:?V/WK+,rX   c                    i }t        | j                  j                               D ][  }| j                  j                  |   sd||<   | j                  j                  |   D ]  }||xx   | j                  |      z  cc<     ] |i k7  r3|j                         D ci c]  \  }}| j                  |   |dd  }}}|S c c}}w )z
        Form host access for non advance management option
        :return: Formatted Host access type info
        :rtype: dict
         N)r   rQ   rp   rE   rK   r   ry   )rU   r   rz   rg   r{   r|   s         rV   !format_host_dict_for_non_adv_mgmtz%NFS.format_host_dict_for_non_adv_mgmts  s     $116689 	WE{{!!%(%'E"!%!3!3E!: WI&$*K*KI*VV&W	W " KVJ[J[J]^$!Q42215q"v=^K^ _s   B>c                     t         j                  d       i }| j                  j                  d   r;| j                  j                  d   s| j	                         }|S | j                         }|S )a+   Traverse all given hosts params and provides with host dict,
            which has respective host str param name with its value
            required by SDK

        :return: dict with key named as respective host str param name & value
                required by SDK
        :rtype: dict
        zGetting host parametersrx   rn   )rS   rT   rE   rK   r   r   )rU   r   s     rV   get_host_dict_from_pbzNFS.get_host_dict_from_pb  sg     	*+;;l+;;%%&=>"DDF  #@@BrX   c                    i }t         j                  d       | j                         }|r|j                  |       d}|D ]8  }| j                  j
                  |   | j                  j
                  |   ||<   : | j                  j
                  d   ru| j                  j
                  d   t        j                  j                  v rBt         j                  d       t        j                  | j                  j
                  d      |d<   | j                  j
                  d   r| j                         |d<   t         j                  d|       |S )z Provide all the advance parameters named as required by SDK

        :return: all given advanced parameters
        :rtype: dict
        z#Getting all given advance parameterdescriptionanonymous_uidanonymous_gidmin_securityz5Getting min_security object from NFSShareSecurityEnumrR   z&Successfully got advance parameter: %s)
rS   rT   r   rC   rE   rK   r   NFSShareSecurityEnum__members__get_default_access)rU   rz   rg   fieldsfields        rV   get_adv_param_from_pbzNFS.get_adv_param_from_pb  s"    67..0	LL#B 	9E{{!!%(4#{{11%8e	9 ;;n-$++2D2D3 #(#=#=#I#I3JHHLM$)$>$>"">2%4E.! ;;./&*&=&=&?E"#95ArX   c                    t         j                  d       | j                  j                  | j                  j
                  d   | j                  j
                  d         }	 t        j                  |   S # t        $ rK}d|dt        |      }t         j                  |       | j                  j                  |       Y d }~y d }~ww xY w)Nz<Getting default_access object from NFSShareDefaultAccessEnumrR   zdefault_access: r   )rS   rT   rR   ra   rE   rK   r   NFSShareDefaultAccessEnumKeyErrorr   rc   rH   )rU   rR   r   r4   s       rV   r   zNFS.get_default_access  s     - 	.,,00KK/0KK/02	'22>BB 	'A(CIIcNKK!!#&&		's   !A4 4	C=ACCc                     | j                   j                         }t        |j                               t        |      z  r)|r
|r|d   dk7  rd|d<   d|v r|j	                  d      |d<   |S )a   Correct payload keys as required by SDK

        :param payload: Payload used for create/modify operation
        :type payload: dict
        :param nfs_details: NFS details
        :type nfs_details: dict
        :return: Payload required by SDK
        :rtype: dict
        export_option   r:   root_access_hosts_string)rQ   valuesro   rp   r   )rU   payloadnfs_detailsouput_host_params       rV   correct_payload_as_per_sdkzNFS.correct_payload_as_per_sdk  sv      2299;w||~%5!66;;3OST3T+,(-8 7>kk27423 rX   c                    | j                   j                  d   }| j                   j                  d   }|r|s3d}t        j                  |       | j                   j	                  |       | j                         }d|v r)|j                  d      |d<   t        j                  d       | j                  |      }t        j                  d|       	 t        j                  j                  d| j                  || j                  |d	|}t        j                  d
|       |S # t        j                  $ rM}t        j                  t        |             | j                   j	                  t        |             Y d}~yd}~wt         $ rL}d|dt        |      }t        j                  |       | j                   j	                  |       Y d}~yd}~ww xY w)zq Create nfs share from given filesystem

        :return: nfs_share object
        :rtype: UnityNfsShare
        r.   r   ,Please provide name and path both for creater\   rR   share_accesszPParam name: 'share_access' is used instead of 'default_access' in SDK so changedz1Creating nfs share from filesystem with param: %s)rO   r   fsr   "Successfully created nfs share: %sNFailed to create nfs share: r    )rE   rK   rS   rc   rH   r   r   rT   r   r   UnityNfsSharecreaterO   r   UnityNfsShareNameExistedErrorr   r   rU   r   r   r4   rz   r   r   s          rV    create_nfs_share_from_filesystemz$NFS.create_nfs_share_from_filesystem  s    {{!!"34{{!!&)4@CIIcNKK!!c!***,u$$)II.>$?E.!HH : ; //6DeL	+))00 MHH4DKKdMFKMGHH97CN22 	.IIc!fKK!!c!f!-- 	+@Dc!fMCIIcNKK!!c!**	+s'   AD G2AE::GAGGc                 P   | j                   j                  d   }| j                   j                  d   }|r|s3d}t        j                  |       | j                   j	                  |       | j                         }| j                  |      }t        j                  d|       	 t        j                  j                  d| j                  || j                  |d|}t        j                  d|       |S # t        j                  $ rM}t        j                  t        |             | j                   j	                  t        |             Y d}~yd}~wt        $ rL}d	|d
t        |      }t        j                  |       | j                   j	                  |       Y d}~yd}~ww xY w)zo Create nfs share from given snapshot

        :return: nfs_share object
        :rtype: UnityNfsShare
        r.   r   r   r\   z+Creating nfs share from snap with param: %s)rO   r   r   r   r   Nr   r   r   )rE   rK   rS   rc   rH   r   r   rT   r   r   create_from_snaprO   r   r   r   r   r   s          rV   create_nfs_share_from_snapshotz"NFS.create_nfs_share_from_snapshot   sP    {{!!"34{{!!&)4@CIIcNKK!!c!***,//6>F	+)):: QHH4dmm$QJOQGHH97CN22 	.IIc!fKK!!c!f!-- 	+@Dc!fMCIIcNKK!!c!**	+s'   "AC2 2F%AEF%AF  F%c                     | j                   r| j                         S | j                   du r| j                         S d}t        j	                  |       | j
                  j                  |       y)z{ Create nfs share from either filesystem/snapshot

        :return: nfs_share object
        :rtype: UnityNfsShare
        FzEPlease provide filesystem or filesystem snapshot to create NFS exportr\   N)rP   r   r   rS   rc   rE   rH   r   s     rV   create_nfs_sharezNFS.create_nfs_share!  s^     ##88::%%.6688YCIIcNKK!!c!*rX   c                    |st         j                  d       g S g }	 |j                  d      D ]e  }t        |      }|dk(  rdj	                  |      }t        |d      }n#|dk(  rdj	                  |      }t        |d      }|j                  |       g 	 |S # t        $ rM}d|d	t        |      }t         j                  |       | j                  j                  |
       Y d}~|S d}~ww xY w)a7   Convert host_str which have comma separated hosts to host_list with
            ip4/ip6 host obj if IP4/IP6 like string found

        :param host_str: hosts str separated by comma
        :return: hosts list, which may contains IP4/IP6 object if given in
                host_str
        :rytpe: list
        zEmpty host_str givenr   rZ   {0}Fstrictr[   z!Error while converting host_str: z to list error: r\   N)rS   debugre   rb   formatr   r   r   r   r   rc   rE   rH   )rU   host_str	host_listhri   r   r4   s          rV   convert_host_str_to_listzNFS.convert_host_str_to_list2  s     II,-I		+^^C( $(+a<a(A#Ae4A\a(A#Ae4A  #$   	+#a&"CIIcNKK!!c!**	+s   A9B 	C/"AC**C/c                    i }|D ]  }t         j                  d|       ||   }|r!|   st         j                  d|       |||<   A|   d   D cg c]  }| j                  |d   d          }}|st         j                  d       t        d |D              }|D cg c]  }|j                  |vs| }	}|	st         j                  d	       |	j                  |       |	||<    |S c c}w c c}w )
a:   Compares & adds up new hosts with the existing ones and provide
            the final consolidated hosts for advance host management

        :param existing_host_dict: All hosts params details which are
            associated with existing nfs which to be modified
        :type existing_host_dict: dict
        :param new_host_dict: All hosts param details which are to be added
        :type new_host_dict: dict
        :return: consolidated hosts params details which contains newly added
            hosts along with the existing ones
        :rtype: dict
        zChecking for param: %sMExisting nfs host key: %s is empty, so lets add new host given value as it isUnityHostList	UnityHostr   r   Nothing to add as no host givenc              3   4   K   | ]  }|j                     y wNr   ).0r   s     rV   	<genexpr>z,NFS.add_host_dict_for_adv.<locals>.<genexpr>p  s     J4twwJs   +All host given to be added is already added)rS   r   r   ro   r   extend)
rU   existing_host_dictnew_host_dictmodify_host_dicthost_access_keynew_host_obj_listexisting_host_obj_listexisting_setnew_hostactual_to_adds
             rV   add_host_dict_for_advzNFS.add_host_dict_for_advQ  s2    1 	>OII.@ -o > );O)L 		ikz{4E 1 ASSb@cds@t&v*< '+&7&7@RS^@_`d@e&7&f &v" &v %		;<J3IJJL6Gk(8;;^jKjXkMk 		GH   !780=_-5	>8  %&v ls   C+C03C0c                    i }|D ]  }t         j                  d|       ||   }| j                  |      }||   }| j                  |      }|st         j                  d       ]|r|st         j                  d|       |||<   }t        t	        |      t	        |      z
        }	|	st         j                  d       |	j                  |       dj                  d |	D              ||<    |S )a>   Compares & adds up new hosts with the existing ones and provide
            the final consolidated hosts for non advance host management

        :param existing_host_dict: All hosts params details which are
            associated with existing nfs which to be modified
        :type existing_host_dict: dict
        :param new_host_dict: All hosts param details which are to be added
        :type new_host_dict: dict
        :return: consolidated hosts params details which contains newly added
            hosts along with the existing ones
        :rtype: dict
        zChecking add host for param: %sr  r  r  r   c              3   2   K   | ]  }t        |        y wr
  r   r  r|   s     rV   r  z0NFS.add_host_dict_for_non_adv.<locals>.<genexpr>  s     8WAQ8W   )rS   r   r  r   ro   r  join)
rU   r  r  r  r  existing_host_strexisting_host_listnew_host_strnew_host_listr  s
             rV   add_host_dict_for_non_advzNFS.add_host_dict_for_non_adv}  s    1  	XOII7I 2? C!%!>!>!"# )9L 99M !		;<%7 		ikz{4@ 1 ]!3c:L6M!MNM 		GH   !34
 148W8W0W_-A 	XB  rX   c                    i }|D ]Q  }t         j                  d|       |   st         j                  d       5||   d   D cg c]  }| j                  |d   d          }}||   }|g k(  rt         j                  d       |D cg c]  }|j                   }}t	        |      t	        t        |            kD  r9d| d	| }	t         j                  |	       | j                  j                  |	
       |D 
cg c]  }
|
j                   }}
t        t        |      t        |      z        }|s/|D cg c]  }|j                  |vs| }}|||<   T |S c c}w c c}w c c}
w c c}w )a   Compares & remove new hosts from the existing ones and provide
            the remaining hosts for advance host management

        :param existing_host_dict: All hosts params details which are
            associated with existing nfs which to be modified
        :type existing_host_dict: dict
        :param new_host_dict: All hosts param details which are to be removed
        :type new_host_dict: dict
        :return: existing hosts params details from which given new hosts are
            removed
        :rtype: dict
        zChecking host for param: %s4Existing list is already empty, so nothing to remover  r  r   r   "Nothing to remove as no host givenDuplicate host given:  in host param: r\   )
rS   r   r   r   rf   ro   rc   rE   rH   r   )rU   r  r  r  r  r  r  r  unique_new_host_listr4   r   unique_existing_host_listactual_to_removeexisting_hostfinal_host_lists                  rV   remove_host_dict_for_advzNFS.remove_host_dict_for_adv  s    1 	@OII3_E%o6		PQ ASSb@cds@t&v*< '+&7&7@RS^@_`d@e&7&f &v" &v -o > B&		>?@Q#RHHKK#R #R$%C0D,E(FF./C.DDTUdTef		#%%#%.=S(TT(T%(T#C(<$=)A+ %+  ,#BX  J\i\l\l  uI  ]I}  JO  J0?_-;	@>  1&v $S )U Js   E	E!;E&8E+E+c                 r   i }|D ].  }t         j                  d|       ||   }| j                  |      }||   }| j                  |      }|st         j                  d       ^t        |      t        t	        |            kD  r9d|d|}	t         j                  |	       | j                  j                  |	       |r|st         j                  d       t        t	        |      t	        |      z        }
|
st        t	        |      t	        |
      z
        }dj                  d |D              ||<   1 |S )	a   Compares & remove new hosts from the existing ones and provide
            the remaining hosts for non advance host management

        :param existing_host_dict: All hosts params details which are
            associated with existing nfs which to be modified
        :type existing_host_dict: dict
        :param new_host_dict: All hosts param details which are to be removed
        :type new_host_dict: dict
        :return: existing hosts params details from which given new hosts are
            removed
        :rtype: dict
        z"Checking remove host for param: %sr'  r(  r)  r\   r&  r   c              3   2   K   | ]  }t        |        y wr
  r  r  s     rV   r  z3NFS.remove_host_dict_for_non_adv.<locals>.<genexpr>  s     8YAQ8Yr  )
rS   r   r  rf   ro   rc   rE   rH   r   r  )rU   r  r  r  r  r   r!  r"  r#  r4   r,  r.  s               rV   remove_host_dict_for_non_advz NFS.remove_host_dict_for_non_adv  sD    1 $	ZOII:OL 2? C!%!>!>!"# )9L 99M !		>?=!CM(:$;;!?4		#%%#%.%7		PQ#C$6":$ %$  %#"3'9#:S >" $" #O 148Y8Y0Y_-I$	ZL  rX   c                     | j                   j                  d   r| j                  ||      }|S | j                  ||      }|S )a   Compares & adds up new hosts with the existing ones and provide
            the final consolidated hosts

        :param existing_host_dict: All hosts params details which are
            associated with existing nfs which to be modified
        :type existing_host_dict: dict
        :param new_host_dict: All hosts param details which are to be added
        :type new_host_dict: dict
        :return: consolidated hosts params details which contains newly added
            hosts along with the existing ones
        :rtype: dict
        rn   )rE   rK   r  r$  rU   r  r  r  s       rV   add_hostzNFS.add_host  sP     ;;56#99:Lm\    $==>PR_`rX   c                     | j                   j                  d   r| j                  ||      }|S | j                  ||      }|S )a   Compares & remove new hosts from the existing ones and provide
            the remaining hosts

        :param existing_host_dict: All hosts params details which are
            associated with existing nfs which to be modified
        :type existing_host_dict: dict
        :param new_host_dict: All hosts param details which are to be removed
        :type new_host_dict: dict
        :return: existing hosts params details from which given new hosts are
            removed
        :rtype: dict
        rn   )rE   rK   r/  r2  r4  s       rV   remove_hostzNFS.remove_host(  sQ     ;;56#<<=OQ^_    $@@ASUbcrX   c                    i }t         j                  d       |j                         }d}|D ]X  }| j                  j                  |   | j                  j                  |   ||   k7  s=| j                  j                  |   ||<   Z | j                  j                  d   r]| j                  j                  d   |j
                  j                  k7  r-t        j                  | j                  j                  d      |d<   | j                  j                  d   r$| j                         }||j                  k7  r||d<   | j                         }|r]	 t        |      rM| j                  j                  d   s4d}t         j                  |       | j                  j                  |       nWt        |      rL| j                  j                  d   r3d	}t         j                  |       | j                  j                  |       t         j                  d
       |D 	ci c]  }	|	||	   
 }
}	| j                  j                  d   t$        d   k(  r(t         j                  d       | j'                  
|      }n't         j                  d       | j)                  
|      }|r|j+                  |       |st         j                  d       d|fS | j-                  ||      }	  |j.                  di |}|j1                          d| j5                  |j6                        fS c c}	w # t         $ rJ}dt#        |      z  }t         j                  |       | j                  j                  |       Y d}~Fd}~ww xY w# t2        $ rI}dt#        |      z  }t         j                  |       | j                  j                  |       Y d}~d}~ww xY w)a3   Modify given nfs share

        :param nfs_obj: NFS share obj
        :type nfs_obj: UnityNfsShare
        :return: tuple(bool, nfs_obj)
            - bool: indicates whether nfs_obj is modified or not
            - nfs_obj: same nfs_obj if not modified else modified nfs_obj
        :rtype: tuple
        zModifying nfs sharer   Nr   rR   rn   z|Modification of nfs host is restricted using adv_host_mgmt_enabled as false since nfs already have host added using host objr\   z}Modification of nfs host is restricted using adv_host_mgmt_enabled as true since nfs already have host added without host objz$Extracting same given param from nfsz0Failed to extract key-value from current nfs: %srx   r   zGetting host to be addedzGetting host to be removedzdExisting nfs attribute value is same as given input, so returning same nfs object - idempotency caseFzFailed to modify nfs error: %sTr  r   )rS   rT   _get_propertiesrE   rK   r   r   r   r   r   rR   r   is_nfs_have_host_with_host_objrc   rH   !is_nfs_have_host_with_host_stringr   r   HOST_STATE_LISTr5  r7  rC   r   modifyraise_if_errr   r   r   )rU   r   modify_paramr   r   r   rR   r  r4   r{   r  r   r  resps                 rV   modify_nfs_sharezNFS.modify_nfs_share<  s^    &'--/B 	@E{{!!%(4KK&&u-U1CC&*kk&8&8&?U#	@
 ;;n-$++2D2D3 #*#7#7#<#<3=+0+E+E"">2,4L( ;;./!446N!7!771?-.224/1+>t{{GYGYZqGrCCIIcNKK))c)26{CHZHZ[rHsECIIcNKK))c)2?@AN%OAaQ&7%O"%O {{!!,/?13EE34#'==1C]#S  56#'#3#34F#V ##$45HH G H'>!66+'	+!7>>1L1D T''7::'666G &P /H!f		#%%#%..	/:  	+2SV;CIIcNKK!!c!**	+sC   CL L#L "M3 L 	M0&?M++M03	O<?O  Oc                 B   d}i }| j                          d| _        | j                  j                  d   s| j                  j                  d   r| j	                         | _        d| _        d| _        | j                  r| j                         | _        n#| j                  du r| j                         | _        | j                  | j                  j                  d   | j                  j                  d         }| j                  j                  d   t        d	   k(  r|r=| j                  |      }d
}n)|s| j                         }d
}n| j                  |      \  }}| j                  j                  d   r|rt        |      }||d} | j                  j                   di | y)zY Perform different actions on nfs based on user parameter
            chosen in playbook FNr(   r)   r'   r.   )r   r   stater   T)changednfs_share_detailsr   )r   r   rE   rK   r   r   r   rP   r   r   r   
STATE_LISTr   r   rA  get_nfs_share_display_attrs	exit_json)rU   rD  rE  r   results        rV   perform_module_operationzNFS.perform_module_operation  s    ;;o.$++2D2D!3#88:DL##--/DK%%. --/DM $${{!!/2##$56 % 
 ;;g&*Q-7 //8++-GG  $44W=GW ;;g&7 ;G D$'8:''rX   )NN)NNNr
  )%__name__
__module____qualname____doc__rW   rl   rv   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r$  r/  r2  r5  r7  rA  rJ  r   rX   rV   r%   r%   e  s    *1Ef /D+(>$/ 105-^W'r+ 5+n2+h!+F"0M&($:',$+L+B+">* X/ b- ^5 n ( (O7b1(rX   r%   c                    t         j                  d       | j                         }t         j                  d       | j                  j                  |d   d   d<   d|d   d   vr| j                  j
                  |d   d   d<   t         j                  d       | j                  j                         d   }| j                  j                  j                  |d	   d<   ||d<   t        |       rSt         j                  d
       | j                  j
                  |d   d   d<   | j                  j                  |d   d   d<   t         j                  d       |S )z Provide nfs share attributes for display

    :param nfs: NFS share obj
    :type nfs: UnityNfsShare
    :return: nfs_share_details
    :rtype: dict
    z/Getting nfs share details from nfs share objectzUpdating filesystem detailsr   UnityFileSystemr   r   zUpdating nas server detailsr   UnityNasServerzUpdating snap detailsr   	UnitySnapz&Successfully updated nfs share details)	rS   rT   r9  r   r   r   r   is_nfs_obj_for_snapr   )r   rE  nas_detailss      rV   rG  rG    sI    HH>?//1 HH*+ l#$56v>$\23DEE!! 	,'(9:4@ HH*+$$446|DK%%**  !&)&1l# 7#()7>||&!+.t49@9J9J&!+.v6HH56rX   c                 <    d}|D ]  }| j                  |      s y y)z Check whether nfs host is already added using host obj

    :param nfs_details: nfs details
    :return: True if nfs have host already added with host obj else False
    :rtype: bool
    )r;   r<   r   r>   r   TFra   r   host_obj_paramshost_obj_params      rV   r:  r:    s.    ,O * ??>* rX   c                 <    d}|D ]  }| j                  |      s y y)z Check whether nfs host is already added using host by string method

    :param nfs_details: nfs details
    :return: True if nfs have host already added with host string method else False
    :rtype: bool
    )r6   r7   r8   r9   r:   TFrV  rW  s      rV   r;  r;    s.    O * ??>* rX   c                 v    	 dj                  |       } t        | d      }|j                  S # t        $ r Y yw xY w)Nr   Fr   r   )r   r   ri   
ValueError)valips     rV   rb   rb   	  s=    mmC E*zz s   ), 	88c                 T    | j                   t        j                  j                  k(  ryy)z Check whether the nfs_obj if for filesystem

    :param nfs_obj: NFS share object
    :return: True if nfs_obj is of filesystem type
    :rtype: bool
    TF)r   r   NFSTypeEnum	NFS_SHAREr   s    rV   is_nfs_obj_for_fsrc    s"     ||u((222rX   c                 T    | j                   t        j                  j                  k(  ryy)z Check whether the nfs_obj if for snapshot

    :param nfs_obj: NFS share object
    :return: True if nfs_obj is of snapshot type
    :rtype: bool
    TF)r   r   r`  NFS_SNAPSHOTrb  s    rV   rS  rS    s"     ||u((555rX   c            
      b   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t        dd      dt        ddt              dt        ddt              dt        ddd      dt        dt        dt        dt        dt        dt        ddt              dt        dd      dt        dd      d t        ddt
              S )"z@ Provides parameters required for the NFS share module on Unity r.   Fr   )r   r   r'   r*   r+   r,   r-   r(   r)   r   T)r   r   no_logr   rR   )r   r   choicesr   rn   boolN)r   r   defaultr;   r<   r=   r>   r?   rx   r   intr   rC  r   )r   DEFAULT_ACCESS_LISTMIN_SECURITY_LIST	HOST_DICTr<  rF  r   rX   rV   rD   rD   *  sr     e%8E6 E6 e%8	
 %e4 E6 E6 e%8 5uT: %e4 U$79 5u"35 #EM  "!" "#$ '%& #'( ()* UOL+, E6-. E6/0 DujA1 rX   c                  8    t               } | j                          y)zZ Create UnityNFS object and perform action on it
        based on user input from playbookN)r%   rJ  )objs    rV   mainrq  I  s     %C  "rX   __main__)-rN  
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNr_   	tracebackr3   r   r   r   rG   rI   ImportError
format_excansible.module_utils.basicr	   r
   Cansible_collections.dellemc.unity.plugins.module_utils.storage.dellr   
get_loggerrS   rl  rm  r   rn  r<  rF  rL   objectr%   rG  r:  r;  rb   rc  rS  rD   rq  rK  r   rX   rV   <module>r     sI   6 @ @fP	Ob
B 
 F>>(2%M% K eu) 1 fuv&*f)-%)V'+v%)V-.	 '(:;"
" Y(& Y(x"!H (		># zF K(  F(-/Cy/C/C/E%M%Fs   C C"!C"