
                            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 dZdZdZdZdZdZdZefdZefdZ G d dej6                        Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d  d!e!      Z" G d" d#e!      Z# G d$ d%e#      Z$ G d& d'e$      Z%efd(Z&y))*z=Useful commands for interacting with the Cloud Filestore API.    )
list_pager)utils)apis)waiter)util)
exceptions)log)
properties)	resourcesfilev1
v1p1alpha1v1beta1z!file.projects.locations.instanceszfile.projects.locationsz"file.projects.locations.operationsc                 6    t        j                  t        |       S )zImport and return the appropriate Cloud Filestore client.

  Args:
    version: str, the version of the API desired.

  Returns:
    Cloud Filestore client for the appropriate release track.
  )r   GetClientInstanceAPI_NAMEversions    8lib/googlecloudsdk/api_lib/filestore/filestore_client.py	GetClientr   &   s     
		'	22    c                 6    t        j                  t        |       S )z<Import and return the appropriate Filestore messages module.)r   GetMessagesModuler   r   s    r   GetMessagesr   2   s    			'	22r   c                       e Zd ZdZy)Errorz)Base class for exceptions in this module.N__name__
__module____qualname____doc__ r   r   r   r   7   s    1r   r   c                       e Zd ZdZy)InvalidArgumentErrorz;Raised when command line argument constraints are violated.Nr   r"   r   r   r$   r$   ;   s    Cr   r$   c                       e Zd ZdZy)InvalidCapacityErrorz2Raised when an invalid capacity value is provided.Nr   r"   r   r   r&   r&   ?   s    :r   r&   c                       e Zd ZdZy)InvalidNameErrorz9Raised when an invalid file share name value is provided.Nr   r"   r   r   r(   r(   C   s    Ar   r(   c                       e Zd ZdZy)InvalidDisconnectManagedADErrorz?Raised when an invalid disconnect managed AD value is provided.Nr   r"   r   r   r*   r*   G   s    Gr   r*   c                       e Zd ZdZy)InvalidDisconnectLdapErrorz.Raised when an invalid LDAP value is provided.Nr   r"   r   r   r,   r,   K   s    6r   r,   c                      e Zd ZdZefdZed        Ze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d ZddZddZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 ddZd Zed        Zed        Zed        Zy)FilestoreClientz&Wrapper for working with the file API.c                     |t         k(  rt               | _        y |t        k(  rt	               | _        y |t
        k(  rt               | _        y t        dj                  |            )Nz [{}] is not a valid API version.)	ALPHA_API_VERSIONAlphaFilestoreAdapter_adapterBETA_API_VERSIONBetaFilestoreAdapterV1_API_VERSIONFilestoreAdapter
ValueErrorformat)selfr   s     r   __init__zFilestoreClient.__init__R   sQ    ##+-dm	$	$*,dm	N	"&(dm9@@IJJr   c                 .    | j                   j                  S N)r2   clientr9   s    r   r=   zFilestoreClient.client\   s    ==r   c                 .    | j                   j                  S r<   )r2   messagesr>   s    r   r@   zFilestoreClient.messages`   s    ==!!!r   Nc                 J   | j                   j                  |      }| j                  j                  j	                  |      }|j
                  D ]&  }t        j                  dj                  |             ( t        j                  | j                  j                  |d|d      S )aw  Make API calls to List active Cloud Filestore instances.

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

    Returns:
      Generator that yields the Cloud Filestore instances.
    )parentzLocation {} may be unreachable.	instancespageSizefieldlimitbatch_size_attribute)r@   )FileProjectsLocationsInstancesListRequestr=   projects_locations_instancesListunreachabler	   warningr8   r   YieldFromList)r9   location_refrG   requestresponselocations         r   ListInstanceszFilestoreClient.ListInstancesd   s     mmEE F G {{77<<WEH((	kk3::8DE )##00' r   c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z)Get Cloud Filestore instance information.name)r@   (FileProjectsLocationsInstancesGetRequestRelativeNamer=   rJ   Get)r9   instance_refrP   s      r   GetInstancezFilestoreClient.GetInstance~   E    mmDD&&( E G ;;3377@@r   c                     | j                   j                  |j                               }| j                  j                  j                  |      S z)Get Cloud Filestore snapshot information.rU   )r@   (FileProjectsLocationsSnapshotsGetRequestrX   r=   projects_locations_snapshotsrY   r9   snapshot_refrP   s      r   GetSnapshotzFilestoreClient.GetSnapshot   r\   r   c                     | j                   j                  |j                               }| j                  j                  j                  |      S r^   )r@   1FileProjectsLocationsInstancesSnapshotsGetRequestrX   r=   &projects_locations_instances_snapshotsrY   ra   s      r   GetInstanceSnapshotz#FilestoreClient.GetInstanceSnapshot   sE    mmMM&&( N G ;;==AA'JJr   c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z'Get Cloud Filestore backup information.rU   )r@   &FileProjectsLocationsBackupsGetRequestrX   r=   projects_locations_backupsrY   )r9   
backup_refrP   s      r   	GetBackupzFilestoreClient.GetBackup   sE    mmBB$$& C G ;;1155g>>r   c                 |    | j                   j                  |j                         |      }| j                  ||      S )z-Deletes an existing Cloud Filestore instance.)rV   forcer@   +FileProjectsLocationsInstancesDeleteRequestrX   _DeleteInstance)r9   rZ   async_rn   rP   s        r   DeleteInstancezFilestoreClient.DeleteInstance   s?    mmGG&&( H G 00r   c                 z    | j                   j                  |j                               }| j                  ||      S )z,Delete an existing Cloud Filestore instance.rU   ro   )r9   rZ   rr   rP   s       r   DeleteInstanceAlphaz#FilestoreClient.DeleteInstanceAlpha   s=    mmGG&&( H G 00r   c                     | j                   j                  j                  |      }|r|S t        j                  j                  |j                  t              }| j                  |      S )N
collection)	r=   rJ   Deleter   REGISTRYParseRelativeNamerV   OPERATIONS_COLLECTIONWaitForOperation)r9   rr   rP   	delete_opoperation_refs        r   rq   zFilestoreClient._DeleteInstance   s]    88??HI&&88#8 9 M   //r   c                     | j                   j                  |j                               }| j                  j                  j                  |      S )zGets description of a long-running operation.

    Args:
      operation_ref: the operation reference.

    Returns:
      messages.GoogleLongrunningOperation, the operation.
    rU   )r@   )FileProjectsLocationsOperationsGetRequestrX   r=   projects_locations_operationsrY   r9   r   rP   s      r   GetOperationzFilestoreClient.GetOperation   sG     mmEE'') F G ;;4488AAr   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=   r   r8   Name)r9   r   s     r   r}   z FilestoreClient.WaitForOperation   sL     >>..KK55	
 	%,,]-?-?-AB r   c                     | j                   j                  |j                               }| j                  j                  j                  |      S )zCancels a long-running operation.

    Args:
      operation_ref: the operation reference.

    Returns:
      Empty response message.
    rU   )r@   ,FileProjectsLocationsOperationsCancelRequestrX   r=   r   Cancelr   s      r   CancelOperationzFilestoreClient.CancelOperation   sG     mmHH'') I G ;;44;;GDDr   c                 d   | j                   j                  |j                         j                         |j	                         |      }| j
                  j                  j                  |      }|r|S t        j                  j                  |j                  t              }| j                  |      S )z"Create a Cloud Filestore instance.)rB   
instanceIdinstancerw   )r@   +FileProjectsLocationsInstancesCreateRequestParentrX   r   r=   rJ   Creater   rz   r{   rV   r|   r}   )r9   rZ   rr   configrP   	create_opr   s          r   CreateInstancezFilestoreClient.CreateInstance   s    mmGG""$113$$& H G
 88??HI&&88#8 9 M   //r   c                     | j                   j                  |      }| j                  j                  j	                  |      S )NrU   )r@   FileProjectsLocationsGetRequestr=   projects_locationsrY   )r9   rO   rP   s      r   GetLocationzFilestoreClient.GetLocation   s4    mm;;;NG;;))--g66r   c                     | j                   j                  |j                               }t        j                  | j
                  j                  |d|d      S )NrU   	locationsrD   rE   )r@    FileProjectsLocationsListRequestrX   r   rN   r=   r   )r9   project_refrG   rP   s       r   ListLocationszFilestoreClient.ListLocations   sU    mm<<%%' = G ##&&' r   c                     | j                   j                  |      }t        j                  | j                  j
                  |d|d      S )ay  Make API calls to List active Cloud Filestore operations.

    Args:
      operation_ref: The parsed location of the listed Filestore instances.
      limit: The number of Cloud Filestore instances to limit the results to.
        This limit is passed to the server and the server does the limiting.

    Returns:
      Generator that yields the Cloud Filestore instances.
    rU   
operationsrD   rE   )r@   *FileProjectsLocationsOperationsListRequestr   rN   r=   r   )r9   r   rG   rP   s       r   ListOperationszFilestoreClient.ListOperations   sO     mmFF G G ##11' r   c                    | j                   j                         }||_        |r||_        |r||_        |r||_        |r| j                  j                  ||       |r| j                  j                  ||       |r| j                  j                  ||       |r| j                  j                  ||       ||_        |r||_        |r||_        |
r|
|d<   | j                  j                  |||	       |rg |_        | j                   j!                         }|j#                  d      |_        d|v r
|d   |_        |j#                  dd      }| j                  j)                  ||       |j#                  d      }|r| j                  j+                  ||       |j                  j-                  |       |||_        |||_        |S )a  Parses the command line arguments for Create into a config.

    Args:
      tier: The tier.
      protocol: The protocol values are NFS_V3 (default) or NFS_V4_1.
      description: The description of the instance.
      file_share: The config for the file share.
      network: The network for the instance.
      performance: The performance configuration for the instance.
      labels: The parsed labels value.
      tags: The parsed tags value.
      zone: The parsed zone of the instance.
      nfs_export_options: The nfs export options for the file share.
      kms_key_name: The kms key for instance encryption.
      managed_ad: The Managed Active Directory settings of the instance.
      ldap: The LDAPS configuration of the instance.
      source_instance: The replication source of the instance.
      deletion_protection_enabled: bool, whether to enable deletion protection.
      deletion_protection_reason: The reason for enabling deletion protection.
      backend_type: The backend type of the instance (Compute or Filestore).

    Returns:
      The configuration that will be used as the request body for creating a
      Cloud Filestore instance.
    nfs_export_optionsrV   zreserved-ip-rangezconnect-modeDIRECT_PEERINGzpsc-endpoint-project)r@   InstancetiertagsprotocolbackendTyper2   ParseManagedADIntoInstanceParseLdapIntoInstanceParseSourceInstanceIntoInstanceParsePerformanceIntoInstancelabels
kmsKeyNamedescriptionParseFileShareIntoInstancenetworksNetworkConfiggetnetworkreservedIpRangeParseConnectModeParsePscEndpointProjectappenddeletionProtectionEnableddeletionProtectionReason)r9   r   r   r   
file_sharer   performancer   r   zoner   kms_key_name
managed_adldapsource_instancedeletion_protection_enableddeletion_protection_reasonbackend_typer   network_configconnect_modepsc_endpoint_projects                         r   ParseFilestoreConfigz$FilestoreClient.ParseFilestoreConfig  s   Z }}%%'HHMhm "h )h 
mm..xD
mm))(D9
mm33HoN 
mm00;GHO(h(h);j%&MM,,Xz4Hh}}224n&{{62n		')01D)E&[[1ABl
mm$$^\B %[[)?@	-- .	
 ~.".+Fh(!-*Dh'Or   c                 T    | j                   j                  |||||||||	|
||      }|S )a	  Parses updates into an instance config.

    Args:
      instance_config: The Instance message to update.
      description: str, a new description, if any.
      labels: LabelsValue message, the new labels value, if any.
      file_share: dict representing a new file share config, if any.
      performance: The performance configuration for the instance.
      managed_ad: The Managed Active Directory settings of the instance.
      disconnect_managed_ad: Disconnect from Managed Active Directory.
      ldap: The LDAP configuration of the instance.
      disconnect_ldap: Disconnect from LDAP.
      clear_nfs_export_options: bool, whether to clear the NFS export options.
      deletion_protection_enabled: bool, whether to enable deletion protection.
      deletion_protection_reason: The reason for enabling deletion protection.

    Raises:
      InvalidCapacityError, if an invalid capacity value is provided.
      InvalidNameError, if an invalid file share name is provided.

    Returns:
      The instance message.
    )r   r   r   r   r   disconnect_managed_adr   disconnect_ldapclear_nfs_export_optionsr   r   )r2   ParseUpdatedInstanceConfig)r9   instance_configr   r   r   r   r   r   r   r   r   r   r   r   s                 r   r   z*FilestoreClient.ParseUpdatedInstanceConfig  sI    N }}773'!9$?#= 8 H Or   c                     | j                   j                  |||      }|r|S t        j                  j	                  |j
                  t              }| j                  |      S )aP  Updates an instance.

    Args:
      instance_ref: the reference to the instance.
      instance_config: Instance message, the updated instance.
      update_mask: str, a comma-separated list of updated fields.
      async_: bool, if False, wait for the operation to complete.

    Returns:
      an Operation or Instance message.
    rw   )r2   UpdateInstancer   rz   r{   rV   r|   r}   )r9   rZ   r   update_maskrr   	update_opr   s          r   r   zFilestoreClient.UpdateInstance  sb     ,,o{I &&88#8 9 M   //r   c                    d}d}d}d}d}g }|g S |D ]  }| j                   j                  j                  |j                  d|            }	| j                   j                  j                  |j                  d|            }
|j                  dd      |k(  r%|j                  d|      }|j                  d	|      }nd}d}| j                  |j                  d
g       |||	|
      }|j                  |        |S )aS  Creates an NfsExportOptions message.

    Args:
      messages: The messages module.
      nfs_export_options: list, containing NfsExportOptions dictionary.

    Returns:
      File share message populated with values, filled with defaults.
      In case no nfs export options are provided we rely on the API to apply a
      default.
    
READ_WRITEROOT_SQUASHNO_ROOT_SQUASH  Naccess-modesquash-modeanon_uidanon_gid	ip-ranges)ipRangesanonUidanonGid
accessMode
squashMode)NfsExportOptionsAccessModeValueValuesEnumlookup_by_namer   SquashModeValueValuesEnumr   )r@   r   
read_writeroot_squashno_root_squashanonimous_uidanonimous_gidnfs_export_configsnfs_export_optionaccess_modesquash_moder   r   nfs_export_configs                 r   MakeNFSExportOptionsMsgz'FilestoreClient.MakeNFSExportOptionsMsg  s)    JK%NMM!i/

#
#
=
=
L
L##M:>  
#
#
=
=
L
L##M>B 
 
		}d	3{	B$((]C$((]C"33$((b9   4   121 02 r   c                    d}d}d}d}d}g }|g S |D ]C  }| j                   j                  j                  |j                  d|            }	| j                   j                  j                  |j                  d|            }
|j                  dd      |k(  r%|j                  d|      }|j                  d	|      }nd}d}g }|j                  d
g       }|D ]6  }|j                  | j                   j                  j                  |             8 | j                  |j                  dg       |||	|
||j                  dd            }|j                  |       F |S )a  Creates an MakeNFSExportOptionsMsgBeta message.

    This function is a copy MakeNFSExportOptionsMsg with addition of handling
    the SecurityFlavors for NFSv41.

    Args:
      messages: The messages module.
      nfs_export_options: list, containing NfsExportOptions dictionary.

    Returns:
      File share message populated with values, filled with defaults.
      In case no nfs export options are provided we rely on the API to apply a
      default.
    r   r   r   r   Nr   r   r   r   zsecurity-flavorsr   r   )r   r   r   r   r   securityFlavorsr   )r   r   r   r   r   r   'SecurityFlavorsValueListEntryValuesEnum)r@   r   r   r   r   r   r   r   r   r   r   r   r   security_flavors_listflavorsflavorr   s                    r   MakeNFSExportOptionsMsgBetaz+FilestoreClient.MakeNFSExportOptionsMsgBeta  s   " JK%NMM!i/

#
#
=
=
L
L##M:>  
#
#
=
=
L
L##M>B 
 
		}d	3{	B$((]C$((]C !%%&8"=g&$$%%MM\\	
  #33$((b9  /#''	48 4   12G 0H r   c                     |yd|v r1| j                  | j                  |j                  d                  S d|v r1| j                  | j                  |j                  d                  S t	        d      )	aQ  Creates a PerformanceConfig message.

    Args:
      messages: The messages module.
      performance_config: A dictionary containing performance configuration, if
        any.

    Returns:
      The PerformanceConfig message.

    Raises:
      InvalidArgumentError: If performance_config argument constraints are
      violated.
    Nzmax-iops)maxIops)	fixedIopszmax-iops-per-tb)maxIopsPerTb)	iopsPerTbzNInvalid performance configuration. Must be one of max-iops or max-iops-per-gb.)PerformanceConfig	FixedIOPSr   	IOPSPerTBr$   )r@   performance_configs     r   MakePerformanceConfigMsgz(FilestoreClient.MakePerformanceConfigMsg?  s      !''''&&(,,Z8 '  (  
 
0	0''&&-112CD '  (   ! r   r<   )F)NNNNNNNNNNNNNNNNNNNNNNNNNFNN)r   r   r    r!   r5   r:   propertyr=   r@   rS   r[   rc   rg   rl   rs   ru   rq   r   r}   r   r   r   r   r   r   r   r   staticmethodr   r   r  r"   r   r   r.   r.   O   s.   .+ K     " "4AAK?110B(E07
0 "&!%%i\  $"&!%5n0, . .` = =~ " "r   r.   c                   V    e Zd ZdZd Z	 d
dZd Z	 	 	 	 	 	 	 	 	 	 	 ddZd Zd Z	d	 Z
y)r1   z$Adapter for the alpha filestore API.c                 X    t        t              | _        t        t              | _        y Nr   )r   r0   r=   r   r@   r>   s    r   r:   zAlphaFilestoreAdapter.__init__h  s    $56DK(9:DMr   Nc                 (   |j                   g |_         |rd}d}d}|j                   D cg c]#  }|j                  |j                  d      k7  s"|% c}|_         d|v ryt        j                  j
                  j                  j                  d      }|j                  d      xs |}t        j                  j                  |||j                  d            }d|v rut        j                  j
                  j                  j                  d      }|j                  d      }t        j                  j                  |||j                  d            }d||fvrt        d	      ||t        d
      t        j                  | j                   |j                  dg             }	| j                   j#                  |j                  d      t%        j&                  |j                  d            |||	      }
|j                   j)                  |
       yyc c}w )a)  Parse specified file share configs into an instance message.

    Args:
      instance: The Filestore instance object.
      file_share: File share configuration.
      instance_zone: The instance zone.

    Raises:
      InvalidArgumentError: If file_share argument constraints are violated.
    NrV   zsource-snapshotTrequiredzsource-snapshot-regionsource-backupsource-backup-regionzEAt most one of ['source-snapshot', 'source-backup'] can be specified.OIf 'source-backup' is specified, 'source-backup-region' must also be specified.nfs-export-optionscapacity)rV   
capacityGbsourceSnapshotsourceBackupnfsExportOptions)
fileSharesrV   r   r
   VALUEScoreprojectrY   snapshot_utilSNAPSHOT_NAME_TEMPLATEr8   backup_utilBACKUP_NAME_TEMPLATEr$   r.   r   r@   FileShareConfigr   	BytesToGbr   )r9   r   r   instance_zonesource_snapshotsource_backuprR   fsr  r   file_share_configs              r   r   z0AlphaFilestoreAdapter.ParseFileShareIntoInstancel  s    "homh  ***bgg9O.O"*h 
j	(##((0044d4C>>":;L}'>>EEXz~~.?@
 
J	&##((0044d4C>>"89#88??Xz~~o>
 
o}5	5"
 	
 
	"x'7"
 	

 +BB
--(<bA --77~~f%__Z^^J%?@($- 8    !23W s   #HHc                     |j                   S )z-Get file share configs from instance message.r  r9   r   s     r   FileSharesFromInstancez,AlphaFilestoreAdapter.FileSharesFromInstance      r   c                    |r||_         |r||_        |r| j                  ||       g }|j                  d   r2|j                  d   j                  r|j                  d   j                  }| j                  ||       |j                  d   j                  s||j                  d   _        |
rg |j                  d   _        |r| j                  ||       |r| j                  ||       |r| j                  ||       |	r)t        |j                  dd      st        d      d|_
        |r)t        |j                  dd      st        d      d|_
        |||_        |||_        |S )z:Parse update information into an updated Instance message.r   r   Nz8`--disconnect-ldap` must be used when ldap is connected.managedActiveDirectoryzD`--disconnect-managed-ad` must be used when managed-ad is connected.)r   r   ValidateFileShareForUpdater  r  r   r   r   r   getattrdirectoryServicesr,   r*   r   r   )r9   r   r   r   r   r   r   r   r   r   r   r   r   orig_nfs_export_optionss                 r   r   z0AlphaFilestoreAdapter.ParseUpdatedInstanceConfig  s~     $/o!%o
%%ozB "

$
$Q
'((+<<"1"<"<Q"?"P"P
%%ozB ''*;;9P""1%6
 
"9;""1%6
''E
%%ozB
  $7_66E(F
 	
 +/o'

+
+-Et .
 	
 +/o'".2Mo/!-1Ko.r   c                     | j                  |      }|st        d      |d   }|j                  |j                  d      k7  r4t	        dj                  |j                  |j                  d                  y)a  Validate the updated file share configuration.

    The new config must have the same name as the existing config.

    Args:
      instance_config: Instance message for existing instance.
      file_share: dict with keys 'name' and 'capacity'.

    Raises:
      InvalidNameError: If the names don't match.
      ValueError: If the instance doesn't have an existing file share.
    z6Existing instance does not have file shares configuredr   rV   zfMust update an existing file share. Existing file share is named [{}]. Requested update had name [{}].N)r(  r7   rV   r   r(   r8   )r9   r   r   existingexisting_file_shares        r   r,  z0AlphaFilestoreAdapter.ValidateFileShareForUpdate  sy     **?;HOPP"1+:>>&#99228&!&&
v(>3  :r   c                     | j                   j                  ||j                         |      }| j                  j                  j                  |      }|S )z6Send a Patch request for the Cloud Filestore instance.)r   rV   
updateMask)r@   *FileProjectsLocationsInstancesPatchRequestrX   r=   rJ   Patch)r9   rZ   r   r   update_requestr   s         r   r   z$AlphaFilestoreAdapter.UpdateInstance  sP    ]]MM &&( N N
 88>>~NIr   c                     	 | j                   j                  j                  j                  |      }||_        y# t
        $ r t        dj                  |            w xY w)z-Parse and match the supplied connection mode.zZ[{}] is not a valid connect-mode. Must be one of DIRECT_PEERING or PRIVATE_SERVICE_ACCESS.N)r@   r   ConnectModeValueValuesEnumr   connectModeKeyErrorr$   r8   )r9   r   keyvalues       r   r   z&AlphaFilestoreAdapter.ParseConnectMode  sc    )
--
%
%
@
@
O
O  $)n    $$*F3K s	   /9 $Ar<   r  )r   r   r    r!   r:   r   r(  r   r,  r   r   r"   r   r   r1   r1   e  sS    ,;
 15:4x  $"&!%JX4)r   r1   c                   V     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
	 dd	Zd
 Z xZS )r4   z#Adapter for the beta filestore API.c                 ~    t         t        |           t        t              | _        t        t              | _        y r	  )superr4   r:   r   r3   r=   r   r@   r9   	__class__s    r   r:   zBetaFilestoreAdapter.__init__1  s+    	
.0$45DK(89DMr   c                    d|vry t         j                  j                  j                  j	                  d      }|j                  d      }|t        d      t        j                  j                  |||j                  d            S )Nr  Tr  r  r  )
r
   r  r  r  rY   r   r$   r  r  r8   )r9   r   r  rR   s       r   _ParseSourceBackupFromFilesharez4BetaFilestoreAdapter._ParseSourceBackupFromFileshare6  s    j($$,,00$0?G~~45H   ++22:>>/: r   c                     |j                  d      }|t        d      |j                  d      }|t        d      | j                  j                  | j                  j	                  ||            |_        yzParses managed-ad configs into an instance message.

    Args:
      instance: The filestore instance struct.
      managed_ad: The --managed-ad flag value.

    Raises:
      InvalidArgumentError: If managed_ad argument constraints are violated.
    domainNz,Domain parameter is missing in --managed-ad.computerz.Computer parameter is missing in --managed-ad.)rG  rH  )r+  r   r$   r@   DirectoryServicesConfigManagedActiveDirectoryConfigr.  r9   r   r   rG  rH  s        r   r   z/BetaFilestoreAdapter.ParseManagedADIntoInstanceD       ^^H%F~ !OPP~~j)H 
:  "&!F!F#}}IIH  J  
 "G "Hr   c                 ^   |j                  d      }|t        d      |j                  d      }|t        d      |j                  d      }|j                  d      }|j                  d      }| j                  j	                  | j                  j                  ||||	      
      |_        yzParses ldap configs into an instance message.

    Args:
      instance: The filestore instance struct.
      ldap: The ldap cli parameters

    Raises:
      InvalidArgumentError: If ldap argument constraints are violated.
    rG  Nz(Domain parameter is missing in `--ldap`.serversz)Servers parameter is missing in `--ldap`.,zusers-ouz	groups-ou)rG  rP  usersOugroupsOu)r   r   r$   splitr@   rJ  
LdapConfigr.  r9   r   r   rG  rP  usersougroupsous          r   r   z*BetaFilestoreAdapter.ParseLdapIntoInstance]       XXhF~ !KLLhhy!G !LMMmmC Ghhz"Gxx$H "&!F!F]]%%	 & 
 "G "Hr   c                 F    | j                   j                  |      |_        y)z(Parse and match the supplied PSC config.)endpointProjectN)r@   	PscConfig	pscConfig)r9   r   r   s      r   r   z,BetaFilestoreAdapter.ParsePscEndpointProject{  s!    #}}66,  7  Nr   c                     | j                   j                  j                  j                  d      }g }|j	                  | j                   j                  |             | j                   j                  ||      |_        y)zParses source_instance into a replication config and into an instance message.

    Args:
      instance: The filestore instance struct.
      source_instance: The source_instance cli param.
    STANDBY)peerInstance)rolereplicasN)r@   ReplicationRoleValueValuesEnumr   r   ReplicaConfigreplication)r9   r   r   rb  rc  s        r   r   z4BetaFilestoreAdapter.ParseSourceInstanceIntoInstance  sm     ==$$88GGD HOODMM//_/MN==44H 5 Hr   c                 N    t         j                  | j                  |      |_        y)zParses performance into performance config message and assigns to instance.

    Args:
      instance: The filestore instance struct.
      performance: The performance cli param.
    N)r.   r  r@   performanceConfig)r9   r   r   s      r   r   z1BetaFilestoreAdapter.ParsePerformanceIntoInstance  s      "1!I!I{"Hr   c                    ~|j                   g |_         |rEd}d}|j                   D cg c]#  }|j                  |j                  d      k7  s"|% c}|_         d|v rRt        j                  j
                  j                  j                  d      }|j                  d      }|t        d      | j                  |      }t        j                  | j                  |j                  dg             }| j                  j                  |j                  d      t        j                  |j                  d	            ||
      }	|j                   j!                  |	       yyc c}w )<Parse specified file share configs into an instance message.NrV   r  Tr  r  r  r  r  rV   r  r  r  )r  rV   r   r
   r  r  r  rY   r$   rD  r.   r   r@   r  r   r  r   )
r9   r   r   r   r"  rR   r#  _r   r$  s
             r   r   z/BetaFilestoreAdapter.ParseFileShareIntoInstance  sS    	"hmh  ***bgg9O.O"*h 
J	&""**...=>>"89$$ 
 :::Fm*FF
--(<bA --77~~f%__Z^^J%?@$-	 8    !239 
s   #EEc                     |j                   S )z,Get fileshare configs from instance message.r&  r'  s     r   r(  z+BetaFilestoreAdapter.FileSharesFromInstance  r)  r   r<   )r   r   r    r!   r:   rD  r   r   r   r   r   r   r(  __classcell__rB  s   @r   r4   r4   .  s9    +:
2<"
 15#4Jr   r4   c                   8     e Zd ZdZ fdZ	 ddZd Zd Z xZS )r6   z!Adapter for the filestore v1 API.c                 ~    t         t        |           t        t              | _        t        t              | _        y r	  )r@  r6   r:   r   r5   r=   r   r@   rA  s    r   r:   zFilestoreAdapter.__init__  s)    	
D*,N3DK7DMr   c                    ~|j                   g |_         |r|j                   D cg c]#  }|j                  |j                  d      k7  s"|% c}|_         | j                  |      }t        j                  | j                  |j                  dg             }| j                  j                  |j                  d      t        j                  |j                  d            ||      }|j                   j                  |       yyc c}w )rk  NrV   r  r  rl  )r  rV   r   rD  r.   r   r@   r  r   r  r   )r9   r   r   r   r#  r"  r   r$  s           r   r   z+FilestoreAdapter.ParseFileShareIntoInstance  s     	"h  ***bgg9O.O"*h :::Fm*BB
--(<bA --77~~f%__Z^^J%?@$-	 8    !23% s   #D	Dc                     |j                  d      }|t        d      |j                  d      }|t        d      | j                  j                  | j                  j	                  ||            |_        yrF  rI  rL  s        r   r   z+FilestoreAdapter.ParseManagedADIntoInstance  rM  r   c                 ^   |j                  d      }|t        d      |j                  d      }|t        d      |j                  d      }|j                  d      }|j                  d      }| j                  j	                  | j                  j                  ||||	      
      |_        yrO  rT  rW  s          r   r   z&FilestoreAdapter.ParseLdapIntoInstance  rZ  r   r<   )	r   r   r    r!   r:   r   r   r   ro  rp  s   @r   r6   r6     s    )8 15462r   r6   c                 p    t         j                  j                         }|j                  t        |        |S )N)api_version)r   rz   CloneRegisterApiByNamer   )rw  registrys     r   GetFilestoreRegistryr{  "  s.    %%'(
X;?	/r   N)'r!   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.api_lib.utilr   r   ,googlecloudsdk.command_lib.filestore.backupsr   r  .googlecloudsdk.command_lib.filestore.snapshotsr  googlecloudsdk.corer   r	   r
   r   r   r5   r0   r3   INSTANCES_COLLECTIONLOCATIONS_COLLECTIONr|   r   r   r   r$   r&   r(   r*   r,   objectr.   r1   r4   r6   r{  r"   r   r   <module>r     s   D ' 0 , . L P * # * )   : 0 <  % 	3 ' 3
2J 2D5 D;5 ;Bu BHe H7 7Sf SlF)F F)RW0 WtX+ Xt &4 r   