
    <                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ  G d de      Z G d de      Z G d de      Z G d de      Zy)zSCommands for interacting with the Cloud NetApp Files Active Directory API resource.    )absolute_import)division)unicode_literals)
list_pager)	constants)util)waiter)base)log)	resourcesc                       e Zd ZdZej
                  j                  fdZed        Z	ed        Z
d Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd Zdd	Zd
 Zd Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd Zy)ActiveDirectoriesClientzQWrapper for working with Active Directories in the Cloud NetApp Files API Client.c                 f   |t         j                  j                  k(  rt               | _        y |t         j                  j
                  k(  rt               | _        y |t         j                  j                  k(  rt               | _        y t        dj                  t        j                  |               )Nz [{}] is not a valid API version.)r
   ReleaseTrackALPHAAlphaActiveDirectoriesAdapter_adapterBETABetaActiveDirectoriesAdapterGAActiveDirectoriesAdapter
ValueErrorformatnetapp_api_utilVERSION_MAP)selfrelease_tracks     >lib/googlecloudsdk/api_lib/netapp/active_directories/client.py__init__z ActiveDirectoriesClient.__init__!   s    ))///35dm	$++00	024dm	$++..	..0dm9@@

%
%m
46 7 7    c                 .    | j                   j                  S N)r   clientr   s    r   r#   zActiveDirectoriesClient.client,   s    ==r    c                 .    | j                   j                  S r"   )r   messagesr$   s    r   r&   z ActiveDirectoriesClient.messages0   s    ==!!!r    c                     t        j                  t        j                  | j                  j                        |dj                  |j                                     S )a  Waits on the long-running operation until the done field is True.

    Args:
      operation_ref: the operation reference.

    Raises:
      waiter.OperationError: if the operation contains an error.

    Returns:
      the 'response' field of the Operation.
    zWaiting for [{0}] to finish)r	   WaitForCloudOperationPollerNoResourcesr#   projects_locations_operationsr   Name)r   operation_refs     r   WaitForOperationz(ActiveDirectoriesClient.WaitForOperation4   sL     >>..KK55	78E%,,]-?-?-ABD Dr    Nc                 \   | j                   j                         }||_        ||_        ||_        ||_        ||_        ||_        ||_        ||_	        |	|_
        |
r|
ng |_        |r|ng |_        |r|ng |_        ||_        ||_        ||_        ||_        ||_        ||_        ||_        |S )a  Parses the command line arguments for Create Active Directory into a config.

    Args:
      name: the name of the Active Directory
      domain: the domain name of the Active Directory
      site: the site of the Active Directory
      dns: the DNS server IP addresses for the Active Directory domain
      net_bios_prefix: the NetBIOS prefix name of the server
      organizational_unit: The organizational unit within the AD the user
        belongs to
      aes_encryption: Bool, if enabled, AES encryption will be enabled for SMB
        communication
      username: Username of the AD domain admin
      password: Password of the AD domain admin
      backup_operators: The backup operators AD group users list
      security_operators: Security operators AD domain users list
      administrators: Built-in administrators AD group users list
      kdc_hostname: Name of the AD machine
      kdc_ip: KDC Server IP address for the AD machine
      nfs_users_with_ldap: Bool, if enabled, will allow access to local users
        and LDAP users. Disable, if only needed for LDAP users
      ldap_signing: Bool that specifies whether or not LDAP traffic needs to be
        signed
      encrypt_dc_connections: Bool, if enabled, traffic between SMB server and
        DC will be encrypted
      description: the description of the Active Directory
      labels: the labels for the Active Directory

    Returns:
      The configuration that will be used as the request body for creating a
      Cloud NetApp Active Directory.
    )r&   ActiveDirectorynamedomainsitednsnetBiosPrefixorganizationalUnitaesEncryptionusernamepasswordbackupOperatorssecurityOperatorsadministratorsnfsUsersWithLdapkdcHostnamekdcIpldapSigningencryptDcConnectionsdescriptionlabels)r   r0   r1   r2   r3   net_bios_prefixorganizational_unitaes_encryptionr7   r8   backup_operatorssecurity_operatorsr;   kdc_hostnamekdc_ipnfs_users_with_ldapldap_signingencrypt_dc_connectionsrA   rB   active_directorys                        r   ParseActiveDirectoryConfigz2ActiveDirectoriesClient.ParseActiveDirectoryConfigE   s    l }}446 $ %4"*='%3" ( (," $ 1b & )b # )<%#/ ##/ ,B)#. $r    c                 x   | j                   j                  |j                         j                         |j	                         |      }| j
                  j                  j                  |      }|r|S t        j                  j                  |j                  t        j                        }| j                  |      S )z'Create a Cloud NetApp Active Directory.)parentactiveDirectoryIdactiveDirectory
collection)r&   5NetappProjectsLocationsActiveDirectoriesCreateRequestParentRelativeNamer+   r#   $projects_locations_activeDirectoriesCreater   REGISTRYParseRelativeNamer0   r   OPERATIONS_COLLECTIONr-   )r   activedirectory_refasync_configrequest	create_opr,   s          r   CreateActiveDirectoryz-ActiveDirectoriesClient.CreateActiveDirectory   s     	KK&--/<<>1668" 	L 	
  @@GGPI&&889#B#B 9 DM  //r    c                 f   | j                   j                  |      }| j                  j                  j	                  |      }|j
                  D ]&  }t        j                  dj                  |             ( t        j                  | j                  j                  |t        j                  |d      S )a  Make API calls to List active Cloud NetApp Active Directories.

    Args:
      location_ref: The parsed location of the listed NetApp Active Directories.
      limit: The number of Cloud NetApp Active Directories
        to limit the results to. This limit is passed to
        the server and the server does the limiting.

    Returns:
      Generator that yields the Cloud NetApp Active Directories.
    )rP   zLocation {} may be unreachable.pageSize)fieldlimitbatch_size_attribute)r&   3NetappProjectsLocationsActiveDirectoriesListRequestr#   rX   Listunreachabler   warningr   r   YieldFromListr   ACTIVE_DIRECTORY_RESOURCE)r   location_refrf   r`   responselocations         r   ListActiveDirectoriesz-ActiveDirectoriesClient.ListActiveDirectories   s     mmOO P G {{??DDWMH((	kk3::8DE )##8811') )r    c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z.Get Cloud NetApp Active Directory information.r0   )r&   2NetappProjectsLocationsActiveDirectoriesGetRequestrW   r#   rX   Get)r   r]   r`   s      r   GetActiveDirectoryz*ActiveDirectoriesClient.GetActiveDirectory   sC    mmNN --/ O 1G;;;;??HHr    c                 z    | j                   j                  |j                               }| j                  ||      S )z2Deletes an existing Cloud NetApp Active Directory.rs   )r&   5NetappProjectsLocationsActiveDirectoriesDeleteRequestrW   _DeleteActiveDirectory)r   r]   r^   r`   s       r   DeleteActiveDirectoryz-ActiveDirectoriesClient.DeleteActiveDirectory   sB     	KK$113 	L 	
 
 &&vw77r    c                     | j                   j                  j                  |      }|r|S t        j                  j                  |j                  t        j                        }| j                  |      S )NrS   )
r#   rX   Deleter   rZ   r[   r0   r   r\   r-   )r   r^   r`   	delete_opr,   s        r   ry   z.ActiveDirectoriesClient._DeleteActiveDirectory   sa    @@GGPI&&889#B#B 9 DM  //r    c                 ^    | j                   j                  |||||||||	|
|||||||||      S )/Parses updates into an active directory config.)r1   r2   r3   rC   rD   rE   r7   r8   rF   rG   r;   rH   rI   rJ   rK   rL   rA   rB   )r   !ParseUpdatedActiveDirectoryConfigr   activedirectory_configr1   r2   r3   rC   rD   rE   r7   r8   rF   rG   r;   rH   rI   rJ   rK   rL   rA   rB   s                       r   r   z9ActiveDirectoriesClient.ParseUpdatedActiveDirectoryConfig   sY    * ==::'/%)-%!/!5' ;  r    c                     | j                   j                  |||      }|r|S t        j                  j	                  |j
                  t        j                        }| j                  |      S )a  Updates an Active Directory.

    Args:
      activedirectory_ref: the reference to the active directory.
      activedirectory_config: Active Directory config, the updated active
        directory.
      update_mask: str, a comma-separated list of updated fields.
      async_: bool, if False, wait for the operation to complete.

    Returns:
      An Operation or Active Directory config.
    rS   )	r   UpdateActiveDirectoryr   rZ   r[   r0   r   r\   r-   )r   r]   r   update_maskr^   	update_opr,   s          r   r   z-ActiveDirectoriesClient.UpdateActiveDirectory  si     334G4J4?AI &&889#B#B 9 DM  //r    )NNNNNNNNNNNNNNNNNNNr"   NNNNNNNNNNNNNNNNNN)__name__
__module____qualname____doc__r
   r   r   r   propertyr#   r&   r-   rN   rb   rq   rv   rz   ry   r   r    r    r   r   r      s    Y#'#4#4#:#: 	7     " "D& 
!)Pd0 )2I80 04-1,08<<@7;15159=;?7;59/3<@59?C48/3'(T0r    r   c                   H    e Zd ZdZd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZd Zy)r   z>Adapter for the Cloud NetApp Files API for Active Directories.c                     t         j                  j                  | _        t	        j
                  | j                        | _        t	        j                  | j                        | _        y N)r   )	r
   r   r   r   r   GetClientInstancer#   GetMessagesModuler&   r$   s    r   r   z!ActiveDirectoriesAdapter.__init__  sN    **--D!33((DK $55((DMr    Nc                 J   |||_         |||_        |||_        |||_        |||_        |||_        |||_        |	|	|_        |
|
|_        |||_	        |||_
        |||_        |||_        |||_        |||_        |||_        |||_        |||_        |S )r   )r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r=   r>   r<   r?   r@   rA   rB   r   s                       r   r   z:ActiveDirectoriesAdapter.ParseUpdatedActiveDirectoryConfig&  s   . &,#$(!
#& "-<*&2E/!-;*(0%(0%#/?,%1C.!.<++7(%+"&0C-+7()4J1+6(&,#!!r    c                     | j                   j                  ||j                         |      }| j                  j                  j                  |      }|S )z;Send a Patch request for the Cloud NetApp Active Directory.)rR   r0   
updateMask)r&   4NetappProjectsLocationsActiveDirectoriesPatchRequestrW   r#   rX   Patch)r   r]   r   r   update_requestr   s         r   r   z.ActiveDirectoriesAdapter.UpdateActiveDirectoryc  sX     	JJ2$113" 	K 	$ 
 @@FFIr    r   )r   r   r   r   r   r   r   r   r    r   r   r     sM    F 
!);"z
r    r   c                   "     e Zd ZdZ fdZ xZS )r   zCAdapter for the Beta Cloud NetApp Files API for Active Directories.c                     t         t        |           t        j                  j
                  | _        t        j                  | j                        | _	        t        j                  | j                        | _        y r   )superr   r   r
   r   r   r   r   r   r#   r   r&   r   	__class__s    r   r   z%BetaActiveDirectoriesAdapter.__init__s  s]    	
&68**//D!33((DK $55((DMr    r   r   r   r   r   __classcell__r   s   @r   r   r   p  s    K r    r   c                   "     e Zd ZdZ fdZ xZS )r   zDAdapter for the Alpha Cloud NetApp Files API for Active Directories.c                     t         t        |           t        j                  j
                  | _        t        j                  | j                        | _	        t        j                  | j                        | _        y r   )r   r   r   r
   r   r   r   r   r   r#   r   r&   r   s    r   r   z&AlphaActiveDirectoriesAdapter.__init__  s]    	
'79**00D!33((DK $55((DMr    r   r   s   @r   r   r   ~  s    L r    r   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.netappr   r   r   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   googlecloudsdk.corer   r   objectr   r   r   r   r   r    r   <module>r      sa    Z &  ' ' 3 A . ( # )y0f y0xSv Sl#; $@ r    