
                            S r SSKrSSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r  SSKJ
r  SSKJr  SS	KJr  SS
KJr  SSKJr  SrSrSrSrSrSrSr\4S jr\4S jr " S S\R8                  5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r  " S S \5      r! " S! S"\"5      r# " S# S$\"5      r$ " S% S&\$5      r% " S' S(\%5      r&\4S) jr'g)*z=Useful commands for interacting with the Cloud Filestore API.    N)
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                 8    [         R                  " [        U 5      $ )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                 8    [         R                  " [        U 5      $ )z<Import and return the appropriate Filestore messages module.)r   GetMessagesModuler   r   s    r   GetMessagesr   3   s    			'	22r   c                       \ rS rSrSrSrg)Error8   z)Base class for exceptions in this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r   8   s    1r   r   c                       \ rS rSrSrSrg)InvalidArgumentError<   z;Raised when command line argument constraints are violated.r   Nr   r   r   r   r'   r'   <   s    Cr   r'   c                       \ rS rSrSrSrg)InvalidCapacityError@   z2Raised when an invalid capacity value is provided.r   Nr   r   r   r   r*   r*   @   s    :r   r*   c                       \ rS rSrSrSrg)InvalidNameErrorD   z9Raised when an invalid file share name value is provided.r   Nr   r   r   r   r-   r-   D   s    Ar   r-   c                       \ rS rSrSrSrg)InvalidDisconnectManagedADErrorH   z?Raised when an invalid disconnect managed AD value is provided.r   Nr   r   r   r   r0   r0   H   s    Gr   r0   c                       \ rS rSrSrSrg)InvalidDisconnectLdapErrorL   z.Raised when an invalid LDAP value is provided.r   Nr   r   r   r   r3   r3   L   s    6r   r3   c                   0   \ rS rSrSr\4S jr\S 5       r\S 5       r	SS jr
S rS	 rS
 rS rSS jrS rS rS rS rS rS rS rSS jrSS jr                 SS jr           S S jrS r\S 5       r\S 5       r\S 5       rSr g)!FilestoreClientP   z&Wrapper for working with the file API.c                     U[         :X  a  [        5       U l        g U[        :X  a  [	        5       U l        g U[
        :X  a  [        5       U l        g [        SR                  U5      5      e)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__FilestoreClient.__init__S   sQ    ##+-dm	$	$*,dm	N	"&(dm9@@IJJr   c                 .    U R                   R                  $ N)r;   clientrB   s    r   rG   FilestoreClient.client]   s    ==r   c                 .    U R                   R                  $ rF   )r;   messagesrH   s    r   rK   FilestoreClient.messagesa   s    ==!!!r   Nc                 F   U R                   R                  US9nU R                  R                  R	                  U5      nUR
                   H(  n[        R                  " SR                  U5      5        M*     [        R                  " U R                  R                  USUSS9$ )a[  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)rK   )FileProjectsLocationsInstancesListRequestrG   projects_locations_instancesListunreachabler	   warningrA   r   YieldFromList)rB   location_refrS   requestresponselocations         r   ListInstancesFilestoreClient.ListInstancese   s     mmEE F G {{77<<WEH((	kk3::8DE )##00' r   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ )z)Get Cloud Filestore instance information.name)rK   (FileProjectsLocationsInstancesGetRequestRelativeNamerG   rV   Get)rB   instance_refr\   s      r   GetInstanceFilestoreClient.GetInstance   E    mmDD&&( E G ;;3377@@r   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ z)Get Cloud Filestore snapshot information.rb   )rK   (FileProjectsLocationsSnapshotsGetRequestre   rG   projects_locations_snapshotsrf   rB   snapshot_refr\   s      r   GetSnapshotFilestoreClient.GetSnapshot   rj   r   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ rl   )rK   1FileProjectsLocationsInstancesSnapshotsGetRequestre   rG   &projects_locations_instances_snapshotsrf   ro   s      r   GetInstanceSnapshot#FilestoreClient.GetInstanceSnapshot   sE    mmMM&&( N G ;;==AA'JJr   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ )z'Get Cloud Filestore backup information.rb   )rK   &FileProjectsLocationsBackupsGetRequestre   rG   projects_locations_backupsrf   )rB   
backup_refr\   s      r   	GetBackupFilestoreClient.GetBackup   sE    mmBB$$& C G ;;1155g>>r   c                 t    U R                   R                  UR                  5       US9nU R                  X$5      $ )z-Deletes an existing Cloud Filestore instance.)rc   forcerK   +FileProjectsLocationsInstancesDeleteRequestre   _DeleteInstance)rB   rg   async_r   r\   s        r   DeleteInstanceFilestoreClient.DeleteInstance   s=    mmGG&&( H G 00r   c                 r    U R                   R                  UR                  5       S9nU R                  X#5      $ )z,Delete an existing Cloud Filestore instance.rb   r   )rB   rg   r   r\   s       r   DeleteInstanceAlpha#FilestoreClient.DeleteInstanceAlpha   s;    mmGG&&( H G 00r   c                     U R                   R                  R                  U5      nU(       a  U$ [        R                  R                  UR                  [        S9nU R                  U5      $ )N
collection)	rG   rV   Deleter   REGISTRYParseRelativeNamerc   OPERATIONS_COLLECTIONWaitForOperation)rB   r   r\   	delete_opoperation_refs        r   r   FilestoreClient._DeleteInstance   s]    88??HI&&88#8 9 M   //r   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ )zGets description of a long-running operation.

Args:
  operation_ref: the operation reference.

Returns:
  messages.GoogleLongrunningOperation, the operation.
rb   )rK   )FileProjectsLocationsOperationsGetRequestre   rG   projects_locations_operationsrf   rB   r   r\   s      r   GetOperationFilestoreClient.GetOperation   sG     mmEE'') F G ;;4488AAr   c                     [         R                  " [         R                  " U R                  R                  5      USR                  UR                  5       5      5      $ )zWaits 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CloudOperationPollerNoResourcesrG   r   rA   Name)rB   r   s     r   r    FilestoreClient.WaitForOperation   sL     >>..KK55	
 	%,,]-?-?-AB r   c                     U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ )zwCancels a long-running operation.

Args:
  operation_ref: the operation reference.

Returns:
  Empty response message.
rb   )rK   ,FileProjectsLocationsOperationsCancelRequestre   rG   r   Cancelr   s      r   CancelOperationFilestoreClient.CancelOperation   sG     mmHH'') I G ;;44;;GDDr   c                 b   U R                   R                  UR                  5       R                  5       UR	                  5       US9nU R
                  R                  R                  U5      nU(       a  U$ [        R                  R                  UR                  [        S9nU R                  U5      $ )z"Create a Cloud Filestore instance.)rN   
instanceIdinstancer   )rK   +FileProjectsLocationsInstancesCreateRequestParentre   r   rG   rV   Creater   r   r   rc   r   r   )rB   rg   r   configr\   	create_opr   s          r   CreateInstanceFilestoreClient.CreateInstance   s    mmGG""$113$$& H G
 88??HI&&88#8 9 M   //r   c                 ~    U R                   R                  US9nU R                  R                  R	                  U5      $ )Nrb   )rK   FileProjectsLocationsGetRequestrG   projects_locationsrf   )rB   r[   r\   s      r   GetLocationFilestoreClient.GetLocation   s4    mm;;;NG;;))--g66r   c                     U R                   R                  UR                  5       S9n[        R                  " U R
                  R                  USUSS9$ )Nrb   	locationsrP   rQ   )rK    FileProjectsLocationsListRequestre   r   rZ   rG   r   )rB   project_refrS   r\   s       r   ListLocationsFilestoreClient.ListLocations   sU    mm<<%%' = G ##&&' r   c                     U R                   R                  US9n[        R                  " U R                  R
                  USUSS9$ )a]  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.
rb   
operationsrP   rQ   )rK   *FileProjectsLocationsOperationsListRequestr   rZ   rG   r   )rB   r   rS   r\   s       r   ListOperationsFilestoreClient.ListOperations  sO     mmFF G G ##11' r   c                    U R                   R                  5       nUUl        U(       a  UUl        U(       a  UUl        U(       a  UUl        U(       a  U R                  R                  UU5        U(       a  U R                  R                  UU5        U(       a  U R                  R                  UU5        U(       a  U R                  R                  UU5        UUl        U(       a  UUl        U(       a  UUl        U
(       a  XS'   U R                  R                  UXI5        U(       Ga  / Ul        U R                   R!                  5       nUR#                  S5      Ul        SU;   a
  US   Ul        SU;   a8  U R                   R                   R(                  R+                  US   5      /Ul        UR#                  SS5      nU R                  R/                  UU5        UR#                  S5      nU(       a  U R                  R1                  UU5        UR                  R3                  U5        Ub  UUl        Ub  UUl        U$ )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_optionsrc   zreserved-ip-rangezaddress-modezconnect-modeDIRECT_PEERINGzpsc-endpoint-project)rK   InstancetiertagsprotocolbackendTyper;   ParseManagedADIntoInstanceParseLdapIntoInstanceParseSourceInstanceIntoInstanceParsePerformanceIntoInstancelabels
kmsKeyNamedescriptionParseFileShareIntoInstancenetworksNetworkConfiggetnetworkreservedIpRangeModesValueListEntryValuesEnumlookup_by_namemodesParseConnectModeParsePscEndpointProjectappenddeletionProtectionEnableddeletionProtectionReason)rB   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   ParseFilestoreConfig$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);%&MM,,XzHh}}224n&{{62n		')01D)E&	7	"MM''EETT' 

 [[1ABl
mm$$^\B %[[)?@	-- .	
 ~.".+Fh(!-*Dh'Or   c                 N    U R                   R                  UUUUUUUUU	U
UUS9nU$ )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   )r;   ParseUpdatedInstanceConfig)rB   instance_configr   r   r   r   r   r   r   r   r   r   r   r   s                 r   r   *FilestoreClient.ParseUpdatedInstanceConfig  sI    N }}773'!9$?#= 8 H Or   c                     U R                   R                  XU5      nU(       a  U$ [        R                  R	                  UR
                  [        S9nU R                  U5      $ )a0  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.
r   )r;   UpdateInstancer   r   r   rc   r   r   )rB   rg   r   update_maskr   	update_opr   s          r   r   FilestoreClient.UpdateInstance  s`     ,,{I &&88#8 9 M   //r   c           	         SnSnSnSnSn/ nUc  / $ U H  nU R                   R                  R                  UR                  SU5      5      n	U R                   R                  R                  UR                  SU5      5      n
UR                  SS5      U:X  a%  UR                  SU5      nUR                  S	U5      nOSnSnU R                  UR                  S
/ 5      UUU	U
S9nUR                  U5        M     U$ )a3  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AccessModeValueValuesEnumr   r   SquashModeValueValuesEnumr   )rK   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   MakeNFSExportOptionsMsg'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                    SnSnSnSnSn/ nUc  / $ U GHD  nU R                   R                  R                  UR                  SU5      5      n	U R                   R                  R                  UR                  SU5      5      n
UR                  SS5      U:X  a%  UR                  SU5      nUR                  S	U5      nOSnSn/ nUR                  S
/ 5      nU H7  nUR                  U R                   R                  R                  U5      5        M9     U R                  UR                  S/ 5      UUU	U
UUR                  SS5      S9nUR                  U5        GMG     U$ )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)rK   r   r  r	  r
  r  r  r  r  r  r  r   r   security_flavors_listflavorsflavorr  s                    r   MakeNFSExportOptionsMsgBeta+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                     Uc  gSU;   a+  U R                  U R                  UR                  S5      S9S9$ SU;   a+  U R                  U R                  UR                  S5      S9S9$ [	        S5      e)	a)  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'   )rK   performance_configs     r   MakePerformanceConfigMsg(FilestoreClient.MakePerformanceConfigMsgF  s      !''''&&(,,Z8 '  (  
 
0	0''&&-112CD '  (   ! r   )r;   rF   )F)NNNNNNNNNNNNNNNNNNNNNNNNNFNN)!r    r!   r"   r#   r$   r>   rC   propertyrG   rK   r_   rh   rq   rv   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr  r  r%  r%   r   r   r   r6   r6   P   s.   .+ K     " "4AAK?110B(E07
0 "&!%%oh  $"&!%5n0, . .` = =~ " "r   r6   c                   b    \ rS rSrSrS r SS jrS r           SS jrS r	S	 r
S
 rSrg)r:   il  z$Adapter for the alpha filestore API.c                 L    [        [        S9U l        [        [        S9U l        g Nr   )r   r9   rG   r   rK   rH   s    r   rC   AlphaFilestoreAdapter.__init__o  s    $56DK(9:DMr   Nc                 @   UR                   c  / Ul         U(       Ga  SnSnSnUR                    Vs/ s H%  owR                  UR                  S5      :w  d  M#  UPM'     snUl         SU;   az  [        R                  R
                  R                  R                  SS9nUR                  S5      =(       d    Un[        R                  R                  XUR                  S5      5      nSU;   aq  [        R                  R
                  R                  R                  SS9nUR                  S5      n[        R                  R                  XUR                  S5      5      nSXE4;  a  [        S	5      eUb  Uc  [        S
5      e[        R                  U R                   UR                  S/ 5      5      n	U R                   R#                  UR                  S5      [$        R&                  " UR                  S5      5      UUU	S9n
UR                   R)                  U
5        ggs  snf )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.
Nrc   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)rc   
capacityGbsourceSnapshotsourceBackupnfsExportOptions)
fileSharesrc   r   r
   VALUEScoreprojectrf   snapshot_utilSNAPSHOT_NAME_TEMPLATErA   backup_utilBACKUP_NAME_TEMPLATEr'   r6   r  rK   FileShareConfigr   	BytesToGbr   )rB   r   r   instance_zonesource_snapshotsource_backupr^   fsr=  r   file_share_configs              r   r   0AlphaFilestoreAdapter.ParseFileShareIntoInstances  s    "homh  ***gg9O.O"*h 
j	(##((0044d4C>>":;L}'>>EEz~~.?@
 
J	&##((0044d4C>>"89#88??z~~o>
 
o5	5"
 	
 
	"x'7"
 	

 +BB
--(<bA --77~~f%__Z^^J%?@($- 8    !23W s   "HHc                     UR                   $ )z-Get file share configs from instance message.r:  rB   r   s     r   FileSharesFromInstance,AlphaFilestoreAdapter.FileSharesFromInstance      r   c                 F   U(       a  X!l         U(       a  X1l        U(       a  U R                  X5        / nUR                  S   (       a7  UR                  S   R                  (       a  UR                  S   R                  nU R                  X5        UR                  S   R                  (       d  XR                  S   l        U
(       a  / UR                  S   l        U(       a  U R                  X5        U(       a  U R                  X5        U(       a  U R                  X5        U	(       a.  [        UR                  SS5      (       d  [        S5      eSUl
        U(       a.  [        UR                  SS5      (       d  [        S5      eSUl
        Ub  Xl        Ub  Xl        U$ )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:  r9  r   r   r   r   getattrdirectoryServicesr3   r0   r   r   )rB   r   r   r   r   r   r   r   r   r   r   r   r   orig_nfs_export_optionss                 r   r   0AlphaFilestoreAdapter.ParseUpdatedInstanceConfig  sr     $/!%
%%oB "

$
$Q
'((+<<"1"<"<Q"?"P"P
%%oB ''*;;9P""1%6
 
"9;""1%6
''E
%%oB
  7_66EE(F
 	
 +/o'

+
+-Et  .
 	
 +/o'".2M/!-1K.r   c                     U R                  U5      nU(       d  [        S5      eUS   nUR                  UR                  S5      :w  a4  [	        SR                  UR                  UR                  S5      5      5      eg)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   rc   zfMust update an existing file share. Existing file share is named [{}]. Requested update had name [{}].N)rM  r@   rc   r   r-   rA   )rB   r   r   existingexisting_file_shares        r   rR  0AlphaFilestoreAdapter.ValidateFileShareForUpdate  sy     **?;HOPP"1+:>>&#99228&!&&
v(>3  :r   c                     U R                   R                  UUR                  5       US9nU R                  R                  R                  U5      nU$ )z6Send a Patch request for the Cloud Filestore instance.)r   rc   
updateMask)rK   *FileProjectsLocationsInstancesPatchRequestre   rG   rV   Patch)rB   rg   r   r   update_requestr   s         r   r   $AlphaFilestoreAdapter.UpdateInstance  sP    ]]MM &&( N N
 88>>~NIr   c                      U R                   R                  R                  R                  U5      nX1l        g! [
         a    [        SR                  U5      5      ef = f)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)rK   r   ConnectModeValueValuesEnumr   connectModeKeyErrorr'   rA   )rB   r   keyvalues       r   r   &AlphaFilestoreAdapter.ParseConnectMode#  sa    )
--
%
%
@
@
O
O  $)    $$*F3K s	   /8 %ArG   rK   rF   r'  )r    r!   r"   r#   r$   rC   r   rM  r   rR  r   r   r%   r   r   r   r:   r:   l  sS    ,;
 15:4x  $"&!%JX4)r   r:   c                   h   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 r SS jrS rSrU =r$ )r=   i5  z#Adapter for the beta filestore API.c                 r   > [         [        U ]  5         [        [        S9U l        [        [        S9U l        g r,  )superr=   rC   r   r<   rG   r   rK   rB   	__class__s    r   rC   BetaFilestoreAdapter.__init__8  s+    	
.0$45DK(89DMr   c                    SU;  a  g [         R                  R                  R                  R	                  SS9nUR                  S5      nUc  [        S5      e[        R                  R                  X#UR                  S5      5      $ )Nr1  Tr/  r2  r3  )
r
   r;  r<  r=  rf   r   r'   r@  rA  rA   )rB   r   r=  r^   s       r   _ParseSourceBackupFromFileshare4BetaFilestoreAdapter._ParseSourceBackupFromFileshare=  s    j($$,,00$0?G~~45H   ++22:>>/: r   c                     UR                  S5      nU(       d  gSn[        R                  " X25      (       d  [        S5      eU$ )zDParses and validates the sourceBackupdrBackup field from file_share.zsource-backupdr-backupNzR^projects/[^/]+/locations/[^/]+/backupVaults/[^/]+/dataSources/[^/]+/backups/[^/]+zInvalid 'source-backupdr-backup' format. Expected format: projects/{project_id}/locations/{location_id}/backupVaults/{backupvault_id}/dataSources/{datasource_id}/backups/{backup_id})r   rematchr'   )rB   r   source_backupdr_backuppatterns       r   !_ParseSourceBackupdrFromFileshare6BetaFilestoreAdapter._ParseSourceBackupdrFromFileshareK  sG    '^^,DE!cG88G44 H  "!r   c                     UR                  S5      nUc  [        S5      eUR                  S5      nUc  [        S5      eU R                  R                  U R                  R	                  X4S9S9Ul        g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.)r{  r|  )rQ  r   r'   rK   DirectoryServicesConfigManagedActiveDirectoryConfigrT  rB   r   r   r{  r|  s        r   r   /BetaFilestoreAdapter.ParseManagedADIntoInstanceY       ^^H%F~ !OPP~~j)H 
:  "&!F!F#}}II  J  
 "G "Hr   c           	      V   UR                  S5      nUc  [        S5      eUR                  S5      nUc  [        S5      eUR                  S5      nUR                  S5      nUR                  S5      nU R                  R	                  U R                  R                  UUUUS	9S
9Ul        g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.
r{  Nz(Domain parameter is missing in `--ldap`.serversz)Servers parameter is missing in `--ldap`.,zusers-ouz	groups-ou)r{  r  usersOugroupsOu)r   r   r'   splitrK   r~  
LdapConfigrT  rB   r   r   r{  r  usersougroupsous          r   r   *BetaFilestoreAdapter.ParseLdapIntoInstancer       XXhF~ !KLLhhy!G !LMMmmC Ghhz"Gxx$H "&!F!F]]%%	 & 
 "G "Hr   c                 @    U R                   R                  US9Ul        g)z(Parse and match the supplied PSC config.)endpointProjectN)rK   	PscConfig	pscConfig)rB   r   r   s      r   r   ,BetaFilestoreAdapter.ParsePscEndpointProject  s!    #}}66,  7  Nr   c                     U R                   R                  R                  R                  S5      n/ nUR	                  U R                   R                  US95        U R                   R                  X4S9Ul        g)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)rK   ReplicationRoleValueValuesEnumr   r   ReplicaConfigreplication)rB   r   r   r  r  s        r   r   4BetaFilestoreAdapter.ParseSourceInstanceIntoInstance  sk     ==$$88GGD HOODMM//_/MN==44 5 Hr   c                 N    [         R                  U R                  U5      Ul        g)zParses performance into performance config message and assigns to instance.

Args:
  instance: The filestore instance struct.
  performance: The performance cli param.
N)r6   r%  rK   performanceConfig)rB   r   r   s      r   r   1BetaFilestoreAdapter.ParsePerformanceIntoInstance  s      "1!I!I{"Hr   c                    AUR                   c  / Ul         U(       Gaj  SnSnUR                    Vs/ s H%  ofR                  UR                  S5      :w  d  M#  UPM'     snUl         SU;   aP  [        R                  R
                  R                  R                  SS9nUR                  S5      nUc  [        S5      eU R                  U5      nU R                  U5      nUb  Ub  [        S5      e[        R                  U R                  UR                  S	/ 5      5      n	U R                  R                  UR                  S5      [        R                   " UR                  S
5      5      UUU	S9n
UR                   R#                  U
5        ggs  snf )<Parse specified file share configs into an instance message.Nrc   r1  Tr/  r2  r3  LAt most one of ['source-backup', 'source-backupdr-backup'] can be specified.r4  r5  rc   r6  r8  sourceBackupdrBackupr9  )r:  rc   r   r
   r;  r<  r=  rf   r'   rp  rw  r6   r  rK   rB  r   rC  r   )rB   r   r   rD  rF  r^   rG  _ru  r   rH  s              r   r   /BetaFilestoreAdapter.ParseFileShareIntoInstance  s    	"hmh  ***gg9O.O"*h 
J	&""**...=>>"89$$ 
 :::Fm#EE
  
	"'='I"
 	

 +FF
--(<bA --77~~f%__Z^^J%?@$5- 8    !23M 
s   "F	F	c                     UR                   $ )z,Get fileshare configs from instance message.rK  rL  s     r   rM  +BetaFilestoreAdapter.FileSharesFromInstance  rO  r   rh  rF   )r    r!   r"   r#   r$   rC   rp  rw  r   r   r   r   r   r   rM  r%   __classcell__rm  s   @r   r=   r=   5  sC    +:
"2<"
 15-4^ r   r=   c                   D   ^  \ rS rSrSrU 4S jr SS jrS rS rSr	U =r
$ )	r?   i  z!Adapter for the filestore v1 API.c                 r   > [         [        U ]  5         [        [        S9U l        [        [        S9U l        g r,  )rk  r?   rC   r   r>   rG   r   rK   rl  s    r   rC   FilestoreAdapter.__init__  s)    	
D*,N3DK7DMr   c                 h   AUR                   c  / Ul         U(       Ga  UR                    Vs/ s H%  oDR                  UR                  S5      :w  d  M#  UPM'     snUl         U R                  U5      nU R	                  U5      nUb  Ub  [        S5      e[        R                  U R                  UR                  S/ 5      5      nU R                  R                  UR                  S5      [        R                  " UR                  S5      5      UUUS9nUR                   R                  U5        ggs  snf )r  Nrc   r  r4  r5  r  )r:  rc   r   rp  rw  r'   r6   r  rK   rB  r   rC  r   )	rB   r   r   rD  rG  rF  ru  r   rH  s	            r   r   +FilestoreAdapter.ParseFileShareIntoInstance  s*    	"h  ***gg9O.O"*h :::Fm#EE
  
	"'='I"
 	

 +BB
--(<bA --77~~f%__Z^^J%?@$5- 8    !237 s   "D/D/c                     UR                  S5      nUc  [        S5      eUR                  S5      nUc  [        S5      eU R                  R                  U R                  R	                  X4S9S9Ul        grz  r}  r  s        r   r   +FilestoreAdapter.ParseManagedADIntoInstance  r  r   c           	      V   UR                  S5      nUc  [        S5      eUR                  S5      nUc  [        S5      eUR                  S5      nUR                  S5      nUR                  S5      nU R                  R	                  U R                  R                  UUUUS	9S
9Ul        gr  r  r  s          r   r   &FilestoreAdapter.ParseLdapIntoInstance,  r  r   rh  rF   )r    r!   r"   r#   r$   rC   r   r   r   r%   r  r  s   @r   r?   r?     s%    )8 15"4H2 r   r?   c                 j    [         R                  R                  5       nUR                  [        U S9  U$ )N)api_version)r   r   CloneRegisterApiByNamer   )r  registrys     r   GetFilestoreRegistryr  J  s.    %%'(
X;?	/r   )(r$   rs  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   r>   r9   r<   INSTANCES_COLLECTIONLOCATIONS_COLLECTIONr   r   r   r   r'   r*   r-   r0   r3   objectr6   r:   r=   r?   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Yf YxF)F F)Ro0 oda+ aF &4 r   