
    +E                     Z   S 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 jrS!S jrS rS rS!S jrS rS"S jrS!S jrS!S jrS!S jrS rS r S r!S r" S!S\	RF                  S\$4S jjr%  S"S\	RF                  S\$S\$4S jjr&g )#z<Utilities for flags for `gcloud notebook-executor` commands.    )
executions)	schedules)arg_parsers)base)parser_arguments)concepts)deps)flags)concept_parsers)presentation_specs)
propertiesc                     U (       a  / nO9[         R                  " [        R                  R                  R
                  5      /n[        R                  " SSUS9$ )Nregionz Cloud region for the {resource}.)name	help_textfallthroughs)r	   PropertyFallthroughr   VALUEScolabr   r    ResourceParameterAttributeConfig)for_workbenchr   s     9lib/googlecloudsdk/command_lib/notebook_executor/flags.py_GetRegionAttributeConfigr      sK    L,,Z->->-D-D-K-KLML		2	22
     c                    ^ SU4S jjn[         R                  R                  SU" 5       SR                  U5      SS9R	                  U 5        g)zAdd a resource argument for an execution to the parser.

Args:
  parser: argparse parser for the command.
  verb: str, the verb to describe the resource, such as 'to update'.
  for_workbench: bool, whether the flag is added for a workbench execution.
c                 `   > [         R                  " SU [         R                  [        T5      S9$ )Nz3aiplatform.projects.locations.notebookExecutionJobsresource_name
projectsIdlocationsIdr   ResourceSpec DEFAULT_PROJECT_ATTRIBUTE_CONFIGr   )r   r   s    r   GetExecutionResourceSpec:_AddExecutionResourceArg.<locals>.GetExecutionResourceSpec3   s-      =#<<-m<	 r   	executionz)Unique resource name of the execution {}.TrequiredN)znotebook execution jobr   ConceptParserForResourceformatAddToParser)parserverbr   r$   s     ` r   _AddExecutionResourceArgr0   *   sI     ++ 188>	 , 
 Kr   c                     SS jn[         R                  R                  SU" 5       SR                  U5      SS9R	                  U 5        g)zAdd a resource argument for a schedule to the parser.

Args:
  parser: argparse parser for the command.
  verb: str, the verb to describe the resource, such as 'to update'.
schedulec                 \    [         R                  " SU [         R                  [        5       S9$ )zAdd a resource argument for a schedule to the parser.

Args:
  resource_name: str, the name of the resource to use in attribute help
    text.

Returns:
  A concepts.ResourceSpec for a schedule.
z'aiplatform.projects.locations.schedulesr   r!   r   s    r   GetScheduleResourceSpec7AddScheduleResourceArg.<locals>.GetScheduleResourceSpecK   s,       1#<<-/	 r   z:Unique, system-generated resource name of the schedule {}.Tr'   N)r2   r)   )r.   r/   r5   s      r   AddScheduleResourceArgr7   C   sH    " ++BII$O	 , 
 Kr   c                     SS jn[         R                  " SU" 5       SSSS0S9n[        R                  " U/SS	/0S
9R	                  U 5        g)ztAdd a resource argument for a Dataform repository to the parser.

Args:
  parser: argparse parser for the command.

c                 \    [         R                  " SU [         R                  [        5       S9$ )Nz(dataform.projects.locations.repositoriesr   r!   r4   s    r   !GetDataformRepositoryResourceSpecKAddDataformRepositoryResourceArg.<locals>.GetDataformRepositoryResourceSpeck   s*      2#<<-/	 r   z--dataform-repository-namezEUnique name of the Dataform repository to source input notebook from.Tr    r(   flag_name_overridesz!--dataform-repository-name.region--regioncommand_level_fallthroughsN)zdataform repositoryr   ResourcePresentationSpecr   r*   r-   )r.   r:   dataform_repository_resources      r    AddDataformRepositoryResourceArgrE   d   sb     "4!L!L"')M $R.	" #$ .
|" Kr   c                     [         R                  " SS[        U5      [         R                  S9n[        R
                  R                  SUSR                  U5      SS9R                  U 5        g)	a  Add a resource argument for a Vertex AI region to the parser.

Args:
  parser: argparse parser for the command.
  verb: str, the verb to describe the resource, such as 'to update'.
  for_workbench: bool, whether the flag is added for a workbench execution.

zaiplatform.projects.locationsr   )r   r    r   r?   zCloud region {}.Tr'   N)	r   r"   r   r#   r   r*   r+   r,   r-   )r.   r/   r   region_resource_specs       r   _AddRegionResourceArgrH      sj     "..%+M:::	 ++%	 , 
 Kr   c                     SS jn[         R                  " SU" 5       SSSS0S9n[        R                  " U/SS	/0S
9R	                  U 5        g)zpAdd a resource argument for a runtime template to the parser.

Args:
  parser: argparse parser for the command.
c                 \    [         R                  " SU [         R                  [        5       S9$ )Nz6aiplatform.projects.locations.notebookRuntimeTemplatesr   r!   r4   s    r   GetRuntimeTemplateResourceSpecF_AddRuntimeTemplateResourceArg.<locals>.GetRuntimeTemplateResourceSpec   s*      @#<<-/	 r   z--notebook-runtime-templatezThe runtime template specifying the compute configuration for the notebook execution. The runtime template should be in the same region as the execution.Tr   r<   r=   z"--notebook-runtime-template.regionr?   r@   N)znotebook runtime templaterB   )r.   rK   runtime_template_resources      r   _AddRuntimeTemplateResourceArgrN      sf     1II#$&  $R.  ! /" Kr   c                    U R                  SSS9nU(       a  UR                  SSSS9  ON[        U SU5        UR                  SSSS9  U R                  SS	SS
9  [        R                  R                  U 5        UR                  SSSS9nU(       d*  UR                  SS9n[        U5        UR                  SSS9  UR                  SS9nUR                  SSSS9  UR                  SSS9  U(       d  UR                  SSS9  UR                  SS[        R                  " 5       SS9  U(       a_  UR                  SS9n[        R                  " U5        [        R                  " US5        UR                  SSS S!9  UR                  S"S#SS9  O=[        U5        UR                  S$SSS%9nUR                  S&S'S9  UR                  S"S(S)S9  UR                  S*S+SS9  g,)-z3Adds flags for creating an execution to the parser.z#Configuration of the execution job.Thelpr(   z--execution-display-namez"The display name of the execution.	to create--display-namez--execution-job-idzWThe id to assign to the execution job. If not specified, a random id will be generated.)rQ   hiddenz"Source of the notebook to execute.)rQ   r(   mutexa  The Dataform repository containing the notebook. Any notebook created from the Colab UI is automatically stored in a Dataform repository. The repository name can be found via the Dataform API by listing repositories in the same project and region as the notebook.)rQ   z--commit-shaz_The commit SHA to read from the Dataform repository. If unset, the file will be read from HEAD.z"The Cloud Storage notebook source.z--gcs-notebook-urizWThe Cloud Storage uri pointing to the notebook. Format: gs://bucket/notebook_file.ipynbz--generationzjThe version of the Cloud Storage object to read. If unset, the current version of the object will be used.z--direct-contentzThe direct notebook content as IPYNB. This can be a local filepath to an .ipynb file or can be set to `-` to read content from stdin.z--execution-timeoutzThe max running time of the execution job, as a duration. See '$ gcloud topic datetimes' for details on formatting the input duration.24hrQ   typedefaultz+Compute configuration of the execution job.zThe Cloud KMS encryption key (customer-managed encryption key) used to protect the execution. The key must be in the same region as the execution. If not specified, Google-managed encryption will be used.z--kernel-namez)The kernel name to use for the execution.python3)rQ   rY   z--service-accountz+The service account to run the execution asz!Identity to run the execution as.)rQ   rU   r(   z--user-emailzyThe user email to run the execution as. This requires the provided runtime template to have end user credentials enabled.z,The service account to run the execution as.Fz--gcs-output-uriz]The Cloud Storage location to upload notebook execution results to. Format: gs://bucket-name.N)	add_groupadd_argumentrH   r   
ASYNC_FLAGr-   rE   r   Durationcolab_flagsAddCustomEnvSpecFlagsAddKmsKeyResourceArgrN   )	r.   is_scheduler   execution_groupnotebook_source_groupdataform_source_groupgcs_source_groupcustom_env_spec_groupexecution_identity_groups	            r   AddCreateExecutionFlagsri      s   $$0 % /   "1 !  &+}=  1 ! 
 %    	OO')33/ 4 
 
1;; <  %%:;&&, ' 
 +44/ 5  ,     9    
&& '   !  	 +55: 6  %%&;<$$	P   8 ! 
   : !  #?3.880  9  
 ))K * 
 )); * 
 '   r   c                 \    [        U SU5        [        R                  R                  U 5        g)zAdds flags for deleting an execution to the parser.

Args:
  parser: argparse parser for the command.
  for_workbench: bool, whether the flags are for a workbench execution.

	to deleteN)r0   r   r]   r-   r.   r   s     r   AddDeleteExecutionFlagsrm   G  s"     6;>//f%r   c                     [        U SU5        g)zAdds flags for describing an execution to the parser.

Args:
  parser: argparse parser for the command.
  for_workbench: bool, whether the flag is added for a workbench execution.
to describeN)r0   rl   s     r   AddDescribeExecutionFlagsrp   S  s     6=-@r   c                 p    [        U SU5        U R                  R                  [        R                  5        g)zConstruct groups and arguments specific to listing executions.

Args:
  parser: argparse parser for the command.
  for_workbench: bool, whether the flag is added for a workbench execution.
z for which to list all executionsN)rH   display_info
AddUriFuncexecutions_utilGetExecutionUrirl   s     r   AddListExecutionsFlagsrv   ]  s0     0- 	  !@!@Ar   c                     [        U S5        g)z2Add flags for describing a schedule to the parser.ro   Nr7   r.   s    r   AddDescribeScheduleFlagsrz   j  s    /r   c                 Z    [        U S5        [        R                  R                  U 5        g)z1Adds flags for deleting a schedule to the parser.rk   N)r7   r   r]   r-   ry   s    r   AddDeleteScheduleFlagsr|   o  s    -//f%r   c                     [        U S5        g)z0Adds flags for pausing a schedule to the parser.zto pauseNrx   ry   s    r   AddPauseScheduleFlagsr~   u  s    ,r   c                 B    [        U S5        U R                  SSSSSS9  g)	z1Adds flags for resuming a schedule to the parser.z	to resumez--enable-catch-upzEnables backfilling missed runs when the schedule is resumed from PAUSED state. If enabled, all missed runs will be scheduled and new runs will be scheduled after the backfill is complete.
store_trueenable_catch_upFrQ   actiondestrY   N)r7   r\   ry   s    r   AddResumeScheduleFlagsr   z  s3    -D   
r   r.   r   c                 p    [        U SU5        U R                  R                  [        R                  5        g)zConstruct groups and arguments specific to listing schedules.

Args:
  parser: argparse parser for the command.
  for_workbench: whether the flags are for listing workbench schedules.
zfor which to list all schedulesN)rH   rr   rs   schedules_utilGetScheduleUrirl   s     r   AddListSchedulesFlagsr     s0     / 	  !>!>?r   	is_updatec                 $   U R                  SSS9nU(       d  [        U SUS9  [        USUS9  O[        U S5        UR	                  SS	U(       d  SOS
S9  UR	                  SS[
        R                  R                  S9  UR	                  SS[
        R                  R                  S9  UR	                  SS[        S9  UR	                  SSU(       d  SOS
S9  UR	                  SS[        U(       d  SOSS9  UR	                  SSSSU(       d  S
OSS9  g)zAdds flags for creating or updating a schedule to the parser.

Args:
  parser: argparse parser for the command.
  is_update: whether the flags are for updating a schedule.
  for_workbench: whether the flags are for a workbench schedule.
zConfiguration of the schedule.TrP   rR   )r   )rb   r   z	to updaterS   z!The display name of the schedule.Fz--start-timezThe timestamp after which the first run can be scheduled. Defaults to the schedule creation time. Must be in the RFC 3339 (https://www.rfc-editor.org/rfc/rfc3339.txt) format. E.g. "2026-01-01T00:00:00Z" or "2026-01-01T00:00:00-05:00")rQ   rX   z
--end-timea  Timestamp after which no new runs can be scheduled. If specified, the schedule will be completed when either end_time is reached or when scheduled_run_count >= max_run_count. If neither end time nor max_run_count is specified, new runs will keep getting scheduled until this Schedule is paused or deleted. Must be in the RFC 3339 (https://www.rfc-editor.org/rfc/rfc3339.txt) format. E.g. "2026-01-01T00:00:00Z" or "2026-01-01T00:00:00-05:00"z
--max-runszThe max runs for the schedule.z--cron-scheduleaw  Cron schedule (https://en.wikipedia.org/wiki/Cron) to launch scheduled runs. To explicitly set a timezone to the cron tab, apply a prefix in the cron tab: "CRON_TZ=${IANA_TIME_ZONE}" or "TZ=${IANA_TIME_ZONE}". The ${IANA_TIME_ZONE} may only be a valid string from IANA time zone database. For example, "CRON_TZ=America/New_York 1 * * * *", or "TZ=America/New_York 1 * * * *".z--max-concurrent-runszMaximum number of runs that can be started concurrently for this Schedule. This is the limit for starting the scheduled requests and not the execution of the notebook execution jobs created by the requests.   NrW   z--enable-queueingzEnables new scheduled runs to be queued when max_concurrent_runs limit is reached. If set to true, new runs will be queued instead of skipped.r   enable_queueingr   )	r[   rH   ri   r7   r\   r   DatetimeParseUtcTimeint)r.   r   r   schedule_groups       r   AddCreateOrUpdateScheduleFlagsr     sd    ##+ $ . 
&+]K D 6;/.$t%  
 C
 ,,  	 C ,,   +  
  %t%   
  ad  
 ( $e$  
r   N)F)FF)'__doc__(googlecloudsdk.api_lib.notebook_executorr   rt   r   r   googlecloudsdk.callioper   r   r    googlecloudsdk.calliope.conceptsr   r	   +googlecloudsdk.command_lib.colab_enterpriser
   r_   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.corer   r   r0   r7   rE   rH   rN   ri   rm   rp   rv   rz   r|   r~   r   ArgumentInterceptorboolr   r    r   r   <module>r      s    C R P / ( 4 5 1 L D G *	2BD0!HBJ	&A
B0
&-
" IN@00@AE@" \00\\ \r   