
    k*                        S r SSKJr  SSKJr  SSKJ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\R6                  5      r\R:                  4S jrg)znotebooks runtimes api helper.    )absolute_import)division)unicode_literalsN)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>6   	    =#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>C   r&   r   r'   )r   RuntimeSoftwareConfigr   r.   ,PostStartupScriptBehaviorTypeValueValuesEnumr0   r1   r8   )r4   runtime_software_config_messager   r   s     r   GetPostStartupScriptBehavior3CreateRuntime.<locals>.GetPostStartupScriptBehavior;   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_scriptr8   )r;   r   rA   idleShutdownTimeoutrB   installGpuDriverrC   customGpuDriverPathrD   postStartupScriptpostStartupScriptBehavior)runtime_software_configr>   r   r   s    r    GetRuntimeSoftwareConfigFromArgs7CreateRuntime.<locals>.GetRuntimeSoftwareConfigFromArgsG   s    &<<>/00484N4N1,--151H1H.011484O4O1-..262J2J/677
&
( 7""r   )namevirtualMachineaccessConfigsoftwareConfig)Runtimeruntime)r   r   r   r5   rK   rR   r>   s   ``    @r   CreateRuntimerS      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)parentrR   	runtimeId)r   GetParentForRuntimerS   /NotebooksProjectsLocationsRuntimesCreateRequestrR   )r   r   rU   rR   s       r   CreateRuntimeCreateRequestrY   _   s>    ##D)&$)'		A	A 
B 
> >r   c                 L    [         R                  " U 5      nUR                  US9$ )N)rU   )r   GetParentFromArgs-NotebooksProjectsLocationsRuntimesListRequest)r   r   rU   s      r   CreateRuntimeListRequestr]   f   s&    !!$'&		?	?v	?	NNr   c                 J    U R                   R                  R                  5       $ )N)CONCEPTSrR   Parser   s    r   GetRuntimeResourcerb   k   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>{   s	    a!7r   r'   )r   acceleratorConfig)r   r   RuntimeAcceleratorConfigrd   	coreCountr   r.   TypeValueValuesEnumr0   r1   re   typeSwitchRuntimeRequest)r   r   r   runtime_accelerator_configr4   s        r   GetSwitchRuntimeRequestro   o   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)rM   )rb   RelativeName/NotebooksProjectsLocationsRuntimesDeleteRequestr   r   rR   s      r   CreateRuntimeDeleteRequestru      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)rM   resetRuntimeRequest)rb   rr   ResetRuntimeRequest.NotebooksProjectsLocationsRuntimesResetRequest)r   r   rR   reset_requests       r   CreateRuntimeResetRequestr{      ?    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)rM   startRuntimeRequest)rb   rr   StartRuntimeRequest.NotebooksProjectsLocationsRuntimesStartRequest)r   r   rR   start_requests       r   CreateRuntimeStartRequestr      r|   r   c                 r    [        U 5      R                  5       nUR                  5       nUR                  X#S9$ )N)rM   stopRuntimeRequest)rb   rr   StopRuntimeRequest-NotebooksProjectsLocationsRuntimesStopRequest)r   r   rR   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)rM   switchRuntimeRequest)rb   rr   ro   /NotebooksProjectsLocationsRuntimesSwitchRequest)r   r   rR   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$ rq   )rb   rr   ,NotebooksProjectsLocationsRuntimesGetRequestrt   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)rM   diagnoseRuntimeRequest)rb   rr   DiagnosticConfig
gcs_bucketr   r   relativePathrepairFlagEnabledpacketCaptureFlagEnabledcopyHomeFilesFlagEnabledintr   1NotebooksProjectsLocationsRuntimesDiagnoseRequestDiagnoseRuntimeRequest)r   r   rR   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`   rr   ra   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`   rr   ra   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.   &PostStartupScriptOptionValueValuesEnumr0   r1   r   )r4   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)rM   migrateRuntimeRequest)rb   rr   0NotebooksProjectsLocationsRuntimesMigrateRequestr   service_account)r   r   rR   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ParseRelativeNamerM   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   GetOperationResourcerM   formatrR   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__
__future__r   r   r   enum googlecloudsdk.api_lib.notebooksr   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   r	   rS   rY   r]   rb   ro   ru   r{   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   