
    j                        S r SSKJr  SSKJr  SSKJr  SSK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SKJr  SSKJr  SSKr " S S\R2                  5      r " S S\R2                  5      r " S S\R2                  5      r " S S\R2                  5      r " S S\R2                  5      rS rS r S7S jr!S r"S7S jr#S  r$S7S! jr%S7S" jr&S7S# jr'S$ r(S% r) " S& S'\*5      r+S( r,S) r-S* r.S+ r/S7S, jr0S8S- jr1S. r2S/ r3S0 r4 " S1 S2\*5      r5 " S3 S4\*5      r6 " S5 S6\65      r7g)9z(CLI Utilities for Cloud TPU VM commands.    )absolute_import)division)unicode_literalsN)base_classes)metadata_utils)apis)waiter)base)
exceptions)labels_util)map_util)log)
properties)	resourcesc                       \ rS rSrSrSrg)NoFieldsSpecifiedError(   z7Error if no fields are specified for an update request. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       :lib/googlecloudsdk/command_lib/compute/tpus/tpu_vm/util.pyr   r   (   s    ?r   r   c                       \ rS rSrSrSrg)AttachDiskError,   z<Error if the update request is invalid for attaching a disk.r   Nr   r   r   r   r   r   ,       Dr   r   c                       \ rS rSrSrSrg)DetachDiskError0   z<Error if the update request is invalid for detaching a disk.r   Nr   r   r   r   r#   r#   0   r!   r   r#   c                       \ rS rSrSrSrg)BootDiskConfigurationError4   0Error if the boot disk configuration is invalid.r   Nr   r   r   r   r&   r&   4       8r   r&   c                       \ rS rSrSrSrg)WorkerIdsError8   r(   r   Nr   r   r   r   r+   r+   8   r)   r   r+   c                     [         R                  " U 5      n[        R                  R                  R
                  R                  5       nUR                  UR                  U5      $ N)	r   ComputeApiHolderr   VALUEScoreproject	GetOrFail
GetProjectclient)release_track
ssh_helperholderproject_names       r   r4   r4   <   sI    ((7&""''//99;,			v}}l	;;r   c                     U (       + $ )z$Inverts the boolean value passed in.r   )booleans    r   InvertBooleanr<   B   s
    r   c                    ^  U 4S jnU$ )z=Request hook for merging the metadata and metadata from file.c                   > [         R                  " UR                  UR                  5      n[	        TS9nUR
                  R                  c)  UR                  R                  5       UR
                  l        [        R                  " U5       HU  u  pVUR
                  R                  R                  R                  UR                  R                  R                  XVS95        MW     U$ )zRequest hook for merging the metadata and metadata from file.

Args:
  unused_ref: ref to the service.
  args:  The args for this method.
  request: The request to be made.

Returns:
  Request with metadata field populated.
versionkeyvalue)r   ConstructMetadataDictmetadatametadata_from_fileGetMessagesModulenodeNodeMetadataValuesix	iteritemsadditionalPropertiesappendAdditionalProperty)
unused_refargsrequestmetadata_dicttpu_messagesrB   rC   api_versions          r   ProcessMergeMetadata.<locals>.ProcessJ   s     #88t..0M$[9L||$*//==?gllmmM2
ll0077



)
)
<
< = $% 3 Nr   r   rU   rV   s   ` r   MergeMetadatarY   G   s    , 
.r   c                 &   UnU R                  S5      (       a  / nU R                  S5      (       a   [        [        X R                  -   5      5      nU R                  S5      (       a*  [        [        U5      [        U R                  5      -
  5      nU$ )zGenerate the change to the tags on a resource based on the arguments.

Args:
  args: The args for this method.
  tags: The current list of tags.

Returns:
  The change to the tags after all of the arguments are applied.

clear_tagsadd_tagsremove_tags)IsKnownAndSpecifiedsortedsetr\   r]   )rQ   tagstags_updates      r   GetTagsUpdateFromArgsrc   c   s|     +	l++K	j))[==89:K	m,,[)C0@0@,AABK	r   c                    ^  U 4S jnU$ )zARequest hook for constructing the updateMask for update requests.c                   > [        5       n[        TS9nUR                  S5      (       a  UR                  S5        UR                  S5      (       a  UR                  S5        UR                  S5      (       d,  UR                  S5      (       d  UR                  S5      (       a  [        R
                  R                  U5      nUR                  5       (       aw  UR                  UR                  R                  UR                  R                  5      nUR                  (       a,  UR                  UR                  l        UR                  S5        UR                  S	5      (       d,  UR                  S
5      (       d  UR                  S5      (       al  [        XR                  R                  5      n[        U5      [        UR                  R                  5      :w  a!  XrR                  l        UR                  S5        UR                  S5      (       a  [         R"                  " SUR$                  5      nUR                  R'                  5       UR                  l        [*        R,                  " U5       HU  u  pUR                  R(                  R.                  R1                  UR                  R&                  R3                  XS95        MW     UR                  S5        GOUR                  S5      (       d-  UR                  S5      (       d  UR                  S5      (       Gap  0 nUR                  R(                  b?  UR                  R(                  R.                   H  nUR4                  XR6                  '   M     [8        R:                  " USSUR<                  SS5      n[8        R:                  " USUR>                  SSS5      n[8        R:                  " USSSUR@                  S5      nUR                  R'                  5       UR                  l        [*        R,                  " U5       HU  u  pUR                  R(                  R.                  R1                  UR                  R&                  R3                  XS95        MW     UR                  S5        UR                  S5      (       Ga  UR                  S5      (       d  S/Ul!        [E        U5      nU(       a  / Ul!        Su  pURF                  RI                  5        H=  n	U	S:X  a  URF                  S   nM  U	S:X  a  URF                  S   nM1  [K        SU	-   5      e   US:X  a!  URL                  RN                  RP                  nOvU(       a  US:X  a[  URL                  RN                  RR                  n[U        URB                  5      S:  a!  [K        S[W        URB                  5      -   5      eO[K        SU-   5      e[        URB                  5      nURM                  UUS 9nTS!:X  a0  [Y        U5      Ul-        []        UR                  R^                  U5        UR                  R^                  R1                  U5        UR                  S"5        GOUR                  S#5      (       Ga  UR                  S5      (       d  S/Ul!        [E        U5      nU(       a  / Ul!        UR                  R^                  (       d  [a        S$5      e/ nUR                  R^                   H  nUR1                  URb                  5        M      [e        U5       H  u  nnURf                  U:w  a  M  U(       a  UR                  R^                  U	   O[        UR                  R^                  U   RZ                  5      [        URB                  5      -
  nU(       d  UR                  R^                  U	   OF[Y        U5      UR                  R^                  U   l-          O   [a        S%URf                  -   S&-   5      eUR                  S"5        U(       d  [i        S'5      eS(Rk                  U5      Ul6        U$ ))a  Request hook for constructing the updateMask for update requests.

Args:
  unused_ref: ref to the service.
  args: The args for this method.
  request: The request to be made.

Returns:
  Request with updateMask field populated.

Raises:
  NoFieldsSpecifiedError: if no fields were specified.
  AttachDiskError: if the request for attaching a disk is invalid.
  DetachDiskError: if the request for detaching a disk is invalid.
r?   descriptioninternal_ipsz"network_config.enable_external_ipsupdate_labelsremove_labelsclear_labelslabelsr\   r]   r[   ra   rF   NrA   rE   update_metadataremove_metadataclear_metadataattach_diskworkerall) rr   modesourcezAargument --attach-disk: valid keys are [mode, source]; received: z	read-onlyz
read-write   z]argument --attach-disk: can only attach disks in read-write to at most one worker; received: zcargument --attach-disk: key mode: can only attach disks in read-write or read-only mode; received: )rs   
sourceDiskv2alpha1
data_disksdetach_diskzDargument --detach-disk: No data disks to detach from current TPU VM.z0argument --detach-disk: The specified data disk z) is not currently attached to the TPU VM.z]No fields would change as a result of this update; must specify at least one field to update.,)7r`   rG   r^   addr   DiffFromUpdateArgsMayHaveUpdatesApplyrI   LabelsValuerH   rk   needs_updaterc   ra   r   rD   rF   rJ   rE   rK   rL   rM   rN   rO   rC   rB   r   ApplyMapFlagsrn   rl   rm   rp   ValidateWorkerIdsFieldro   keysr   AttachedDiskModeValueValuesEnum	READ_ONLY
READ_WRITElenstrr_   	workerIdsPreprocessDiskToAttach	dataDisksr#   rv   	enumeratery   r   join
updateMask)rP   rQ   rR   update_maskrT   labels_difflabels_updaterb   rS   rB   rC   itemmetadata_updateis_all_workers_specifiedrs   rt   	mode_enumrp   disk_to_attachsource_disk_listdiskisource_diskworker_diffrU   s                           r   rV   #GenerateUpdateMask.<locals>.Processz   s   " %K$[9L
 ..oom$//oo:;  11  11  00$$33D9k		#	#	%	%#))))LL! %% - 4 4',,

//(
#  ,,  //  ..)$0A0ABk	[	S!2!23	3' 455$::
'')m*//==?gllm4*#2299++>> ? &	' 5 ooj!

"
"#4
5
5

"
"#4
5
5

"
"#3
4
4m				*LL))>>D$(JJ-
! ? !..}d/3T5H5H$/35o !../3/C/CT4/35o !..d/3T5I5I4Qo*//==?gllo6*#2299++>> ? &	' 7 ooj!..%%h//g!7!=	!ld!!&&(#&=!!&)$H_##H-& !  ) 
	 --AAKK	t|+ --AALL	t{{a3585EF    79=>
 	

 4;;f#00 1 n 

	"#)&> w||55~Fll##N3ool#		!	!-	0	0%%h//g!7!=	!\\##
 	
 ,,(($0 )%&67.![{*
#ll$$Q'
LL""1%//136t{{3CDll$$Q'
.4[.Aq!+ 8 >!LM
 	
 ool#"'( ( +.GNr   r   rX   s   ` r   GenerateUpdateMaskr   w   s    iV 
.r   c                 B    UR                   b  SUR                  l        U$ )zUnset acceleratorType flag when it conflicts with topology arguments.

Args:
  unused_ref: ref to the service.
  args:  The args for this method.
  request: The request to be made.

Returns:
  Request with metadata field populated.
N)topologyrH   acceleratorType)rP   rQ   rR   s      r   RemoveConflictingDefaultsr   (  s     
]]#'GLL 	.r   c                 0    [         R                  " SU 5      $ )Ntpu)r   rG   r?   s    r   rG   rG   8  s    			w	//r   c                    ^  U 4S jnU$ )z/Declarative request hook for TPU Start command.c                 F   > A A[        TS9R                  5       nX2l        U$ Nr?   )rG   StartNodeRequeststartNodeRequest)refrQ   rR   start_requestrU   s       r   rV   !StartRequestHook.<locals>.Process?  s'    %k:KKMM,Nr   r   rX   s   ` r   StartRequestHookr   <       
.r   c                    ^  U 4S jnU$ )z.Declarative request hook for TPU Stop command.c                 F   > A A[        TS9R                  5       nX2l        U$ r   )rG   StopNodeRequeststopNodeRequest)r   rQ   rR   stop_requestrU   s       r   rV    StopRequestHook.<locals>.ProcessL  s'    $[9IIKL*Nr   r   rX   s   ` r   StopRequestHookr   I  r   r   c                     [         R                  " U R                  5      R                  5       nUR	                  S5      (       + =(       a    US:g  $ )NV1API_VERSION_UNSPECIFIED)rK   	text_type
apiVersionupper
startswith)rH   rU   s     r   IsTPUVMNoder   V  sA    doo.446+$$T*
* 7668r   c                 ^    A[        [        R                  R                  [        U 5      5      $ )zRemoves Cloud TPU V1 API nodes from the 'list' output.

Used with 'compute tpus tpu-vm list'.

Args:
  response: response to ListNodes.
  args: the arguments for the list command.

Returns:
  A response with only TPU VM (non-V1 API) nodes.
)listrK   movesfilterr   responserQ   s     r   FilterTPUVMNodesr   \  s#     	cii{H5	66r   c                       \ rS rSrSrS rSrg)GuestAttributesListEntryil  z%Holder for GetGuestAttributes output.c                 4    Xl         X l        X0l        X@l        g r.   )	worker_id	namespacerB   rC   )selfr   r   rB   rC   s        r   __init__!GuestAttributesListEntry.__init__o  s    NNHJr   )rB   r   rC   r   Nr   r   r   r   r   r   r   r   r   r   r   r   l  s
    -r   r   c           
          A/ n[        U R                  5       H\  u  p4UR                  R                   H=  nUR	                  [        X5R                  UR                  UR                  5      5        M?     M^     U$ )a7  Transforms the GuestAttributes into a flatter list.

This is needed to make clearer output in the case of TPU pods, since they have
many workers.

Args:
  response: response to GetGuestAttributes.
  args: the arguments for the GetGuestAttributes command.

Returns:
  A list of GuestAttributesListEntry objects.
)	r   guestAttributes
queryValueitemsrN   r   r   rB   rC   )r   rQ   lstr   gaentrys         r   TransformGuestAttributesr   v  sc     
#112ea$$	jj
"1oouyy%++
NP % 3 
*r   c                    [        U 5       H  u  p#UR                  UR                  :w  a  M!  UR                  UR                  :w  a  [        S5      e[	        UR
                  5      [	        UR
                  5      -
  (       d  [        S5      e[        [	        UR
                  UR
                  -   5      5      Ul        X	 M     g)a  Preprocesses and validates the disk to attach.

Validates the disk to attach is not already attached to the TPU VM with
different mode or same mode and worker.
Deletes the disk from the current_data_disks_list if it is already attached
to the TPU VM with same mode but different worker.
If the disk is currently attached to the TPU VM with same mode,
joins the current worker list and the new worker list.

Args:
  current_data_disks_list: the list of data disks currently attached to the
    TPU VM.
  disk_to_attach: the disk to attach to the TPU VM.

Raises:
  AttachDiskError: if the disk is already attached to the TPU VM
    with different mode.
  AttachDiskError: if the disk is already attached to the TPU VM with same
    mode and worker.
zWargument --attach-disk: the disk is already attached to the TPU VM with different mode.zZargument --attach-disk: the disk is already attached to the same set of workers of TPU VM.N)r   rv   rs   r   r`   r   r_   )current_data_disks_listr   r   r   s       r   r   r     s    * 23ga.333		^((($  (()C,??/   &DNN^5556 8N 	 "! 4r   c                    [        U R                  5      S:X  a  U R                  S   S:X  a  gU R                   HO  nUS:X  a%  [        U R                  5      S:  a  [        SS5      eUR                  5       (       a  ME  [        SS5      e   g)	ay  Checks that the worker are numberic strings only.

The only exception is "all" which is a special value that means all
workers. If "all" is specified return True.

Args:
  args: the arguments for the update command.

Returns:
  True if only one string "all" is specified in args.worker
  False otherwise.

Raises:
  WorkerIdsError: if the worker are not numberic strings only.
ru   r   rq   Tzargument --workerz,"all" cannot be specified with other worker.zQworker must be numeric strings only or "all". e.g. --worker=0,1,2 or --worker=allF)r   rp   r+   	isnumeric)rQ   ws     r   r   r     s      	t{{1~6;;aEzc$++&*

8  ;;==
7   
r   c                     A[        U 5      (       a  U $ [        R                  R                  S5        [        R
                  " S5        g)zVerifies that the node is a TPU VM node.

If it is not a TPU VM node, exit with an error instead.

Args:
  response: response to GetNode.
  args: the arguments for the list command.

Returns:
  The response to GetNode if the node is TPU VM.
zYERROR: Please use "gcloud compute tpus describe" for Cloud TPU nodes that are not TPU VM.ru   N)r   r   errPrintsysexitr   s     r   CheckTPUVMNoder     s7     O''-- . /((1+r   c                    ^  U 4S jnU$ )z2Request hook for parsing boot disk configurations.c                   > U(       a  UR                  S5      (       d  U$ SnSnUR                  R                  5        H$  nXSU4;  d  M  [        SR	                  XC5      5      e   [        TS9nUR                  R                  US5      R                  5       S:H  nUR                  R                  US5      nU(       a:  TS	:w  a  [        R                  " S
S5      eUc  [        SR	                  Xx5      5      e0 n	U(       a  UR                  US9n
XS'   TS	:X  a  U(       a  UU	S'   U	(       a!  UR                  " S0 U	D6UR                  l        U$ )z$Parses configurations for boot disk.	boot_diskzkms-keyzconfidential-computez.--boot-disk only supports arguments: {} and {}r?   FalsetrueNrw   z--boot-diskzBconfidential-compute is only available in the alpha release track.zQargument --boot-disk: with confidential-compute={} requires kms-key; received: {})
kmsKeyNamecustomerEncryptionKeyenableConfidentialComputer   )r^   r   r   r&   formatrG   getlowerr   InvalidArgumentExceptionCustomerEncryptionKeyBootDiskConfigrH   bootDiskConfig)rP   rQ   rR   kms_key_arg_nameconfidential_compute_arg_namearg_namerT   enable_confidential_computekms_keyboot_disk_config_kwargscustomer_encryption_keyrU   s              r   rV   ,ParseBootDiskConfigurations.<locals>.Process  st   t//<<n $:!NN'')	,IJ	J(<CC-
 	
 * %[9L8'BHHJ	   nn  !148G"	
	"11P
 	
 
(--3V+.6
 	
 ! , B B !C !9P56j %@
% 9: $0$?$? %%#%%gll! Nr   r   rX   s   ` r   ParseBootDiskConfigurationsr     s    1f 
.r   c                    ^  U 4S jnU$ )z2Request hook for setting the source machine image.c                   > UR                  S5      (       ah  [        TS9nUR                  R                  (       d  UR	                  5       UR                  l        UR
                  UR                  R                  l        U$ )z9Sets the source machine image in the request if provided.imager?   )IsSpecifiedrG   rH   r   r   r   sourceImage)rP   rQ   rR   rT   rU   s       r   rV   SetImage.<locals>.Process%  s[      &{;l\\((&2&A&A&C#04

gll!!-Nr   r   rX   s   ` r   SetImager   "  s     
.r   c                     [         R                  " SS5      n[         R                  " SS5      nUR                  U S9nUR                  R                  U5      nUR                  $ )zBReturns the Cloud project number associated with the `project_id`.cloudresourcemanagerv1)	projectId)r   rG   GetClientInstance&CloudresourcemanagerProjectsGetRequestprojectsGetprojectNumber)
project_idcrm_message_moduleresource_managerreqr2   s        r   ProjectIdToProjectNumberr  1  se    --.DdK++,BDIAA 	B 	#%%))#.'			r   c                    SnSnSnUR                  S5      (       a  [        R                  " X1R                  5      (       ac  [        R
                  R                  R                  R                  5       n[        U5      nUR                  XqR                  UR                  5      nU(       a  XRR                  R                  l        U$ )zRequest hook for creating the target reservation name.

Args:
  unused_ref: ref to the service.
  args: The args for this method.
  request: The request to be made.

Returns:
  Request with reservationName field populated.
z^[a-zA-Z0-9-]+$z(projects/{}/locations/{}/reservations/{}Nreservation)r^   rematchr  r   r0   r1   r2   r3   r  r   zonerH   schedulingConfigreservationName)rP   rQ   rR   short_reservation_name_patternfull_reservation_name_patternreservation_namer
  project_numbers           r   CreateReservationNamer  ;  s     $5 "L	m,,$&6&62 2 ""''//99;J-j9N4;;		4#3#3 4DLL!!1	.r   c                    ^  U 4S jnU$ )z'Sets the provisioning model enum value.c                 |  > [        T5      nUR                  (       a;  UR                  R                  R                  UR
                  R                  l        U$ UR                  (       d;  UR                  R                  R                  UR
                  R                  l        U$  UR                  R                  SS5      R                  5       nUR                  R                  U5      nXRR
                  R                  l        U$ ! [         a*  n[        R                  " SUR                   S35      UeS nAff = f)N-_z--provisioning-modelzV is not a valid provisioning model, must be one of [standard, spot, reservation-bound])rG   spotSchedulingConfig ProvisioningModelValueValuesEnumSPOTrH   r  provisioningModelprovisioning_modelSTANDARDreplacer   	TypeErrorr   r   )r  rQ   rR   rT   normalized_candidatecandidate_enumerU   s          r   rV   %SetProvisioningModel.<locals>.ProcessX  s   $[1Lyy

'
'
H
H
M
M ll##5 n""

'
'
H
H
Q
Q ll##5 n!44<<S#FLLN

'
'
H
H"  7ELL!!3N  //
 $$% &; ; 	s   &AD 
D;%D66D;r   rX   s   ` r   SetProvisioningModelr,  V  s    6 
.r   c                   F    \ rS rSrSrS rS rS rSS jrS r	S r
S	 rS
rg)TPUNodeiv  z&Helper to create and modify TPU nodes.c                     U[         R                  R                  :X  a  SU l        OSU l        [        R
                  " SU R                  5      U l        [        R                  " SU R                  5      U l        g )Nrw   v2r   )	r
   ReleaseTrackALPHA_api_versionr   r  r5   rG   messages)r   r6   s     r   r   TPUNode.__init__y  sZ    ))///$dd((0A0ABDK**5$2C2CDDMr   c                     U R                   $ r.   )r4  )r   s    r   GetMessagesTPUNode.GetMessages  s    ==r   c                 @   [         R                  R                  R                  R	                  SS9n[
        R                  R                  UUUS.SS9nU R                  R                  UR                  5       S9nU R                  R                  R	                  U5      $ )z)Retrieves the TPU node in the given zone.TrequiredlocationsId
projectsIdtpu.projects.locations.nodesparams
collection)name)r   r0   r1   r2   r  r   REGISTRYParser4  #TpuProjectsLocationsNodesGetRequestRelativeNamer5   projects_locations_nodes)r   rC  r  r2   fully_qualified_node_name_refrR   s         r   r  TPUNode.Get  s    $$,,00$0?G$-$6$6$<$<!
 2 %= %
! mm??*779 @ ;G;;//33G<<r   c                 v   [         R                  R                  R                  R	                  SS9n[
        R                  R                  UUUS.SS9nU R                  R                  U/S9nU R                  R                  UR                  5       US9nU R                  R                  R                  U5      $ )z,Retrives the Guest Attributes for the nodes.Tr:  r<  r?  r@  )r   )rC  getGuestAttributesRequest)r   r0   r1   r2   r  r   rD  rE  r4  GetGuestAttributesRequest2TpuProjectsLocationsNodesGetGuestAttributesRequestrG  r5   rH  GetGuestAttributes)r   rC  r  r   r2   rI  get_guest_attributes_requestrR   s           r   rO  TPUNode.GetGuestAttributes  s    $$,,00$0?G$-$6$6$<$<!
 2 %= %
! $(==#J#J+ $K $ mmNN*779"> O @G ;;//BB7KKr   c                    [         R                  R                  R                  R	                  SS9n[
        R                  R                  UUUS.SS9nU R                  R                  UR                  5       UUS9nU R                  R                  R                  U5      n	[
        R                  R                  U	R                  SS9n
U R!                  X5      $ )	z'Updates the TPU node in the given zone.Tr:  r<  r?  r@  )rC  rH   r   z!tpu.projects.locations.operations)rB  )r   r0   r1   r2   r  r   rD  rE  r4  %TpuProjectsLocationsNodesPatchRequestrG  r5   rH  PatchParseRelativeNamerC  WaitForOperation)r   rC  r  rH   r   poller_messager2   rI  rR   	operationoperation_refs              r   
UpdateNodeTPUNode.UpdateNode  s    $$,,00$0?G$-$6$6$<$<!
 2 %= %
! mmAA*779 B  G 44::7CI&&88#F 9 M   ??r   c                    Ub  UR                   cO  U R                  R                  R                  U R                  R                  R                  R	                  X#S9/S9$ SnUR                    H  nUR
                  U:X  d  M  Un  O   Ub  X4l        U$ UR                   R                  U R                  R                  R                  R	                  X#S95        U$ )a	  Updates a key in the TPU metadata object.

If the key does not exist, it is added.

Args:
  metadata: tpu.messages.Node.MetadataValue, the TPU's metadata.
  key: str, the key to be updated.
  value: str, the new value for the key.

Returns:
  The updated metadata.
NrA   )rM   )rM   r4  rI   rJ   rO   rB   rC   rN   )r   rE   rB   rC   r   xs         r   UpdateMetadataKeyTPUNode.UpdateMetadataKey  s     888@]]--mm  ..AA B ( ) . * *
 D**	
# + j O ##**
--


*
*
=
= > $% Or   c                     [         R                  " U R                  R                  U R                  R                  5      n[         R
                  " X1U5      $ r.   )r	   CloudOperationPollerr5   rH  projects_locations_operationsWaitFor)r   rY  messageoperation_pollers       r   rV  TPUNode.WaitForOperation  sA    22,,113 >>*7CCr   )r3  r5   r4  N)rr   )r   r   r   r   r   r   r7  r  rO  rZ  r^  rV  r   r   r   r   r.  r.  v  s-    .E=L$@0 DDr   r.  c                       \ rS rSrSrS rSrg)SSHPreppedNodei  a  Object that has all the data needed to successfully SSH into a node.

Attributes:
  worker_ips: The IPs of the workers of the node.
  ssh_helper: The ssh_helper used to SSH into the node.
  id: The id of the node.
  tpu_name: The unqualified TPU VM name.
  instance_names: The name of the instances of the workers of the node.
  project: The project associated with the node.
  command_list: The list of the commands passed into ssh.
  remainder: The remainder list of ssh_args used to pass into the SSH command.
  host_key_suffixes: The host key suffixes associated with the node.
  user: The user executing the SSH command.
  release_track: The release track for the SSH protos (Alpha, Beta, etc.).
  enable_batching: A bool indicating if the user enabled batching for the
    node.
c                     Xl         X l        X0l        X@l        / U l        S U l        S U l        / U l        S U l        / U l	        S U l
        / U l        g r.   )tpu_nameuserr6   enable_batching
worker_ipsr7   idinstance_namesr2   command_list	remainderhost_key_suffixes)r   rj  rk  r6   rl  s        r   r   SSHPreppedNode.__init__  sS    MI&*DODODGDDLDDNDr   )rp  rl  rr  rn  ro  r2   r6   rq  r7   rj  rk  rm  Nr   r   r   r   rh  rh    s    $ r   rh  c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )SCPPreppedNodei	  zObject that has all the data needed to successfully SCP into a node.

Attributes:
  srcs: The sources for SCP.
  dst: The destination for SCP.
c                 F   > [         [        U ]  XX45        XPl        X`l        g r.   )superru  r   srcsdst)r   rj  rk  r6   rl  rx  ry  	__class__s          r   r   SCPPreppedNode.__init__  s#    	.$( IHr   )ry  rx  )r   r   r   r   r   r   r   __classcell__)rz  s   @r   ru  ru  	  s     r   ru  )r0  )rw   )8r   
__future__r   r   r   r  r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.api_lib.utilr   r	   googlecloudsdk.callioper
   r   $googlecloudsdk.command_lib.util.argsr   r   googlecloudsdk.coresdk_core_exceptionsr   r   r   rK   Errorr   r   r#   r&   r+   r4   r<   rY   rc   r   r   rG   r   r   r   r   objectr   r   r   r   r   r   r   r  r  r,  r.  rh  ru  r   r   r   <module>r     sE   / &  ' 	 
 7 9 , . ( . < 9 A # * ) 
@066 @E)// EE)// E9!4!:!: 99(.. 9<
8(nb 0

87 v ,%#PB(6r6@mDf mD`  V   F^ r   