
    )                         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 r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS r " S S\R.                  5      r\R2                  4S jrg)znotebooks runtimes api helper.    N)util)	arg_utils)log)	resourcesc                    ^ ^^ U U4S jnU U4S jnU U4S jmUU U4S jnTR                  T R                  U" 5       U" 5       U" 5       S9nU$ )zCreates the Runtime message for the create request.

Args:
  args: Argparse object from Command.Run
  messages: Module containing messages definition for the specified API.

Returns:
  Runtime of the Runtime message.
c                     > Sn TR                  S5      (       a  TR                  n TR                  U TR                  5       S9nTR	                  US9$ )Nn1-standard-4machine_type)machineTypedataDisk)virtualMachineConfig)IsSpecifiedr
   VirtualMachineConfig	LocalDiskVirtualMachine)r
   virtual_machine_configargsmessagess     0lib/googlecloudsdk/api_lib/notebooks/runtimes.py GetRuntimeVirtualMachineFromArgs7CreateRuntime.<locals>.GetRuntimeVirtualMachineFromArgs$   s^    "L''&&l%:: 8+=+=+? ; A""8N"OO    c                  
  > TR                   n S nTR                  S5      (       aN  [        R                  " SU R                  S S9R                  [        R                  " TR                  5      5      nU " UTR                  S9$ )Nruntime_access_typezruntime-access-typec                     SU ;  $ NUNSPECIFIED xs    r   <lambda>GCreateRuntime.<locals>.GetRuntimeAccessConfigFromArgs.<locals>.<lambda>3   	    =#9r   arg_namemessage_enuminclude_filter)
accessTyperuntimeOwner)	RuntimeAccessConfigr   r   ChoiceEnumMapperAccessTypeValueValuesEnumGetEnumForChoiceEnumNameToChoicer   runtime_owner)runtime_access_config	type_enumr   r   s     r   GetRuntimeAccessConfigFromArgs5CreateRuntime.<locals>.GetRuntimeAccessConfigFromArgs,   s    $88I-..,,(,FF9; <L;K(()A)AB<D 
 !4+=+=? ?r   c                     > S n TR                  S5      (       aZ  TR                  n[        R                  " SUR                  S S9R                  [        R                  " TR                  5      5      n U $ )Npost_startup_script_behaviorzpost-startup-script-behaviorc                     SU ;  $ r   r   r   s    r   r!   ECreateRuntime.<locals>.GetPostStartupScriptBehavior.<locals>.<lambda>@   r#   r   r$   )r   RuntimeSoftwareConfigr   r+   ,PostStartupScriptBehaviorTypeValueValuesEnumr-   r.   r5   )r1   runtime_software_config_messager   r   s     r   GetPostStartupScriptBehavior3CreateRuntime.<locals>.GetPostStartupScriptBehavior8   ss    I677(0(F(F%,,17EE9	; <L;K(()J)JK<M	  r   c                    > TR                  5       n TR                  S5      (       a  TR                  U l        TR                  S5      (       a  TR                  U l        TR                  S5      (       a  TR                  U l        TR                  S5      (       a  TR                  U l	        TR                  S5      (       a  T" 5       U l
        U $ )Nidle_shutdown_timeoutinstall_gpu_drivercustom_gpu_driver_pathpost_startup_scriptr5   )r8   r   r>   idleShutdownTimeoutr?   installGpuDriverr@   customGpuDriverPathrA   postStartupScriptpostStartupScriptBehavior)runtime_software_configr;   r   r   s    r    GetRuntimeSoftwareConfigFromArgs7CreateRuntime.<locals>.GetRuntimeSoftwareConfigFromArgsD   s    &<<>/00484N4N1,--151H1H.011484O4O1-..262J2J/677
&
( 7""r   )namevirtualMachineaccessConfigsoftwareConfig)Runtimeruntime)r   r   r   r2   rH   rO   r;   s   ``    @r   CreateRuntimerP      sO    P
?
# <<571357	  ' 
.r   c                 x    [         R                  " U 5      n[        X5      nUR                  X#U R                  S9$ )N)parentrO   	runtimeId)r   GetParentForRuntimerP   /NotebooksProjectsLocationsRuntimesCreateRequestrO   )r   r   rR   rO   s       r   CreateRuntimeCreateRequestrV   \   s>    ##D)&$)'		A	A 
B 
> >r   c                 L    [         R                  " U 5      nUR                  US9$ )N)rR   )r   GetParentFromArgs-NotebooksProjectsLocationsRuntimesListRequest)r   r   rR   s      r   CreateRuntimeListRequestrZ   c   s&    !!$'&		?	?v	?	NNr   c                 J    U R                   R                  R                  5       $ )N)CONCEPTSrO   Parser   s    r   GetRuntimeResourcer_   h   s    				$	$	&&r   c                    SnU R                  S5      (       a  U R                  nUR                  5       nU R                  S5      (       a  U R                  Ul        U R                  S5      (       aT  [
        R                  " SUR                  S S9R                  [
        R                  " U R                  5      5      nXCl        UR                  X#S9$ )	z)Create and return switch runtime request.r	   r
   accelerator_core_countaccelerator_typezaccelerator-typec                     SU ;  $ r   r   r   s    r   r!   )GetSwitchRuntimeRequest.<locals>.<lambda>x   s	    a!7r   r$   )r   acceleratorConfig)r   r
   RuntimeAcceleratorConfigra   	coreCountr   r+   TypeValueValuesEnumr-   r.   rb   typeSwitchRuntimeRequest)r   r   r
   runtime_accelerator_configr1   s        r   GetSwitchRuntimeRequestrl   l   s     ,	n%%$$L'@@B	.//+/+F+F(	())**#/CC79 :J9I&&t'<'<=:? 
 '0#		&	& 
' 
N Nr   c                 R    [        U 5      R                  5       nUR                  US9$ N)rJ   )r_   RelativeName/NotebooksProjectsLocationsRuntimesDeleteRequestr   r   rO   s      r   CreateRuntimeDeleteRequestrr      s1    t$113'		A	A 
B 
 r   c                 r    [        U 5      R                  5       nUR                  5       nUR                  X#S9$ )N)rJ   resetRuntimeRequest)r_   ro   ResetRuntimeRequest.NotebooksProjectsLocationsRuntimesResetRequest)r   r   rO   reset_requests       r   CreateRuntimeResetRequestrx      ?    t$113'..0-		@	@ 
A 
7 7r   c                 r    [        U 5      R                  5       nUR                  5       nUR                  X#S9$ )N)rJ   startRuntimeRequest)r_   ro   StartRuntimeRequest.NotebooksProjectsLocationsRuntimesStartRequest)r   r   rO   start_requests       r   CreateRuntimeStartRequestr      ry   r   c                 r    [        U 5      R                  5       nUR                  5       nUR                  X#S9$ )N)rJ   stopRuntimeRequest)r_   ro   StopRuntimeRequest-NotebooksProjectsLocationsRuntimesStopRequest)r   r   rO   stop_requests       r   CreateRuntimeStopRequestr      s?    t$113',,.,		?	? 
@ 
5 5r   c                 h    [        U 5      R                  5       n[        X5      nUR                  X#S9$ )N)rJ   switchRuntimeRequest)r_   ro   rl   /NotebooksProjectsLocationsRuntimesSwitchRequest)r   r   rO   switch_requests       r   CreateRuntimeSwitchRequestr      s;    t$113'*4:.		A	A 
B 
9 9r   c                 R    [        U 5      R                  5       nUR                  US9$ rn   )r_   ro   ,NotebooksProjectsLocationsRuntimesGetRequestrq   s      r   CreateRuntimeDescribeRequestr      s)    t$113'		>	>G	>	LLr   c                    [        U 5      R                  5       nUR                  U R                  S9nU R	                  S5      (       a  U R
                  Ul        U R	                  S5      (       a  SUl        U R	                  S5      (       a  SUl        U R	                  S5      (       a  SUl	        SnU R	                  S5      (       a  [        U R                  5      nUR                  X!R                  X4S	9S
9$ )z$"Create and return Diagnose request.)	gcsBucketrelative_pathzenable-repairTzenable-packet-capturezenable-copy-home-filesNtimeout_minutes)diagnosticConfigtimeoutMinutes)rJ   diagnoseRuntimeRequest)r_   ro   DiagnosticConfig
gcs_bucketr   r   relativePathrepairFlagEnabledpacketCaptureFlagEnabledcopyHomeFilesFlagEnabledintr   1NotebooksProjectsLocationsRuntimesDiagnoseRequestDiagnoseRuntimeRequest)r   r   rO   diagnostic_configr   s        r   CreateRuntimeDiagnoseRequestr      s    t$113'// 0  
o&&%)%7%7"	o&&*.'	-..15.	.//15./	'(($../O		C	C+J+J, ,K ,N 
D 
O Or   c           
         ^ ^ [        T 5      R                  5       nU 4S jnU 4S jnU U4S jnTR                  UTR                  U" 5       U" 5       T R                  U" 5       S9S9$ )z#"Create and return Migrate request.c                     > T R                  S5      (       a2  T R                  R                  R                  5       R	                  5       $ g )Nnetwork)r   r\   r   r]   ro   r^   s   r   GetNetworkRelativeName;CreateRuntimeMigrateRequest.<locals>.GetNetworkRelativeName   s;    	""]]""((*7799 #r   c                     > T R                  S5      (       a2  T R                  R                  R                  5       R	                  5       $ g )Nsubnet)r   r\   r   r]   ro   r^   s   r   GetSubnetRelativeName:CreateRuntimeMigrateRequest.<locals>.GetSubnetRelativeName   s;    !!]]!!'')6688 "r   c                     > S n TR                  S5      (       aZ  TR                  n[        R                  " SUR                  S S9R                  [        R                  " TR                  5      5      n U $ )Npost_startup_script_optionzpost-startup-script-optionc                     SU ;  $ r   r   r   s    r   r!   QCreateRuntimeMigrateRequest.<locals>.GetPostStartupScriptOption.<locals>.<lambda>   r#   r   r$   )r   MigrateRuntimeRequestr   r+   &PostStartupScriptOptionValueValuesEnumr-   r.   r   )r1   request_messager   r   s     r   GetPostStartupScriptOption?CreateRuntimeMigrateRequest.<locals>.GetPostStartupScriptOption   sr    I455 66o,,/&MM9; <L;K(()H)HI<K 
 r   )r   r   serviceAccountpostStartupScriptOption)rJ   migrateRuntimeRequest)r_   ro   0NotebooksProjectsLocationsRuntimesMigrateRequestr   service_account)r   r   rO   r   r   r   s   ``    r   CreateRuntimeMigrateRequestr      sq    t$113':9	 
	B	B$::(*&(--"<">	 ;  
C 
	 	r   c                 r    [         R                  R                  U R                  SS9nUR	                  5       $ )Nz%notebooks.projects.locations.runtimes)
collection)r   REGISTRYParseRelativeNamerJ   SelfLink)resourceinstances     r   GetRuntimeURIr      s7    11mm G 2 I(				r   c                       \ rS rSr\R
                  S4r\R                  S4r\R                  S4r
\R                  S4r\R                  S4rSrg)	OperationType   createddeletedupdatedresetmigratedr   N)__name__
__module____qualname____firstlineno__r   CreatedResourceCREATEDeletedResourceDELETEUpdatedResourceUPDATEResetResourceRESETMIGRATE__static_attributes__r   r   r   r   r      sR    +&+&+&g
&%  *-'r   r   c                    UR                   S   nUR                  (       aB  U" [        R                  " U R                  U5      SR                  UR                  5      SS9  U $ [        R                  " U SR                  UR                  UR                   S   U R                  5      UUUR                   S   S:H  S9nU" [        R                  " U R                  U5      SR                  UR                  5      S	S9  U$ )
a.  Handles Long Running Operations for both cases of async.

Args:
  operation: The operation to poll.
  args: ArgParse instance containing user entered arguments.
  runtime_service: The service to get the resource after the long running
    operation completes.
  release_track: base.ReleaseTrack object.
  operation_type: Enum value of type OperationType indicating the kind of
    operation to wait for.

Raises:
  apitools.base.py.HttpError: if the request returns an HTTP error

Returns:
  The Runtime resource if synchronous, else the Operation Resource.
r   znotebooks runtime {0}T)kindis_asyncz8Waiting for operation on Runtime [{}] to be {} with [{}]   r   )servicerelease_track	is_deleteF)valueasync_r   GetOperationResourcerJ   formatrO   WaitForOperation)	operationr   runtime_servicer   operation_typelogging_methodresponses          r   	HandleLROr      s    , "''*.	[[!!)..-@$++DLL9 $$BIILL...q19>>	C#!''*i7:H !!)..-@$++DLL9 Or   )__doc__enum googlecloudsdk.api_lib.notebooksr   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   r   rP   rV   rZ   r_   rl   rr   rx   r   r   r   r   r   r   r   Enumr   r   r   r   r   r   <module>r      s    %  1 : # )@F>O
'N&7759M
O0	B.DII . +11	)r   