
    N$                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ	 ddlm
Z dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZej<                  j>                  fdZ ejB                   ejD                  ej<                  j>                         G d dejF                                      Z$ ejD                  ej<                  jJ                         G d de$             Z& ejD                  ej<                  jN                         G d de&             Z(y)z<Deploy a container to Cloud Run that will run to completion.    )absolute_import)division)print_function)unicode_literals)base)
exceptions)parser_errors)config_changes)connection_context)container_parser)flags)messages_util)pretty_print)resource_args)serverless_operations)stages)concept_parsers)presentation_specs)log)progress_trackerz/us-docker.pkg.dev/cloudrun/container/job:latestc                 B   d}t        j                  |      }|j                  t        j                  t
        d             |j                  t        j                  |              |j                  t        j                                |j                  t        j                                | t         j                  j                  t         j                  j                  fv r#|j                  t        j                                |j                  t        j                                |j                  t        j                                |j                  t        j                                |j                  t        j                                 |j                  t        j"                                |j                  t        j$                                |j                  t        j&                                |j                  t        j(                                |S )z=Returns an argument group with all per-container deploy args.z|
Container Flags

  If the --container is specified the following arguments may only be specified after a --container flag.
helpF)imagerequiredrelease_track)r   ArgumentGroupAddArgumentr   ImageArgEXAMPLE_JOB_IMAGEMutexEnvVarsFlags
MemoryFlagCpuFlagReleaseTrackALPHABETAGpuFlagArgsFlagSecretsFlagsCommandFlagDependsOnFlagAddVolumeMountFlagRemoveVolumeMountFlagClearVolumeMountsFlagStartupProbeFlag)r   	help_textgroups      lib/surface/run/jobs/create.pyContainerArgGroupr4   ,   sm   )
 

)
,%ENN):UKLE++-HIE$$&'EMMO$t((..0A0A0F0FGG	emmo&ENN$%E&&()E%%'(E'')*E,,./E//12E//12E**,-	,    c                   @    e Zd ZdZdddZed        Zed        Zd Z	y)	CreateCreate a Cloud Run job.z1          Creates a new Cloud Run job.
          aa            To deploy a new job `my-data-transformation` on Cloud Run:

              $ {command} my-data-transformation --image=us-docker.pkg.dev/project/image

          You may also omit the job name. Then a prompt will be displayed
          with a suggested default value:

              $ {command} --image=us-docker.pkg.dev/project/image
          )DESCRIPTIONEXAMPLESc                    t        j                  dt        j                  d      ddd      }t	        j
                  |       t	        j                  |       t	        j                  |       t	        j                  |       t	        j                  |       t	        j                  |       t	        j                  |       t	        j                  |       t	        j                  |d       t	        j                  |       t	        j                  |       t	        j                   |d	       t	        j"                  |       t	        j$                  |d	       t	        j&                  |d
       t	        j(                  |       t	        j*                  || j-                                |j/                         }t	        j0                  |       |j3                  d      }t	        j4                  |d       t	        j6                  |       t9        j:                  |g      j=                  |       |j>                  jA                  d       y )NJOBT)promptzJob to create.F)r   prefixesjob)resource_kind)
with_clear)hiddenz=--async cannot be used if executing the job after the update.r   )implies_execute_nownone)!r   ResourcePresentationSpecr   GetJobResourceSpecr   AddLabelsFlagAddParallelismFlagAddTasksFlagAddMaxRetriesFlagAddTaskTimeoutFlagsAddServiceAccountFlagAddSetCloudSQLFlagAddVpcConnectorArg AddVpcNetworkGroupFlagsForCreateAddEgressSettingsFlagAddClientNameAndVersionFlagsAddBinAuthzPolicyFlagsAddBinAuthzBreakglassFlagAddCmekKeyFlagAddSandboxArgAddGeneralAnnotationFlagsAddVolumesFlagsr%   add_mutually_exclusive_groupAddAsyncFlagadd_argument_groupAddWaitForCompletionFlagAddExecuteNowFlagr   ConceptParserAddToParserdisplay_info	AddFormat)clsparserjob_presentationpolling_groupexecute_groups        r3   
CommonArgszCreate.CommonArgs]   s    *BB((5 
	V$	v	F#	f%	'	V$	V$	**6G	'	&&v.	  E:	##F+	E2	t,	##F+	&#"2"2"45779M	}%!44L 5 M 
""=dK	M*!!#3"45AA&I
!!&)r5   c                 n    t         j                  |        t               }t        j                  | |       y )N)r7   rf   r4   r   AddContainerFlags)rb   container_argss     r3   ArgszCreate.Args   s(    
f&(N&&v~>r5   c           
      *   t        j                  |d      r{|j                  }t        |      dkD  rt	        j
                  dd      |j                         D ci c]  \  }}|j                  d      s|| }}}|rAt        j                  |      t        j                  |d      st        j                  d      |j                  j                  j                         }t        j                  |       t!        j"                  |t         j$                  j&                  | j)                               }t        j*                  || j)                               }|j-                  t/        j0                  | j)                                      |j2                  xs |j4                  }	d	}
t7        j8                  |d	
       t;        j<                  |      5 }t?        j@                  t7        jB                  ||dd             |	rd}nd}tE        jF                  |tI        jJ                  |	|j4                        d|jL                        5 }|jO                  ||||jL                  xr |	       }|	r7|jQ                  |||j4                  |jL                  | j)                               }
d	d	d	       |jL                  r2|	s0t?        jR                  djU                  jV                               n}d}|j4                  r|djU                  |
jV                        z  }n |	r|djU                  |
jV                        z  }t?        jR                  djU                  jV                  |             d}|	r,|t7        jX                  | j)                         |
      z  }|dz  }|t7        jZ                  | j)                         |jV                  |	      z  }t\        j^                  ja                  |       |cd	d	d	       S c c}}w # 1 sw Y   XxY w# 1 sw Y   y	xY w)zDeploy a Job to Cloud Run.
containers
   z--containerz&Jobs may include at most 10 containersr   z--image)argumentr   N)resourceCreatingr?   zCreating and running job...zCreating job...)execute_nowinclude_completionzJob failed to deploy)failure_messagesuppress_output)asynz=Job [{{bold}}{job}{{reset}}] is being created asynchronously.)r?   zbeen createdz and completed execution [{}]z# and started running execution [{}]z:Job [{{bold}}{job}{{reset}}] has successfully {operation}.)r?   	operation 
)repeat)1r   FlagIsExplicitlySetrl   lenc_exceptionsInvalidArgumentExceptionitemsIsSpecifiedr   RequiredImageArgumentExceptionc_parser_errorsRequiredErrorCONCEPTSr?   ParseValidateResourcer   GetConnectionContextProductRUNr%   GetJobConfigurationChangesappendr
   SetLaunchStageAnnotationChangerq   waitr   MaybeLogDefaultGpuTypeMessager   Connectr   InfoGetStartDeployMessager   StagedProgressTrackerr   	JobStagesasync_	CreateJobRunJobSuccessformatnameGetExecutionCreatedMessageGetRunJobMessager   statusPrint)selfargsrl   r   	containerneeds_imagejob_refconn_contextchangesrq   	execution
operations
header_msgtrackerr?   rv   msgs                    r3   Runz
Create.Run   s     |4??j	Z2	33C
 	

 ",!1!1!3!3odI&&w/ 	/!3  
 
77DD&&tW5))9==mm%%'G	7#%::emm!2!2!4L ..'')+G NN55d6G6G6IJ ""/diiKI//tD		&	&|	4


-
-GZ
 
2
&
11



%$)) 1++ ""WgT[[-L_ # 
  ''w		4;;8I8I8K)  
[$ff2	

 #	99
6==innM
M)
<CCnn ) 	HOOHH	 P 	
 c	}77
 	
 	t	]++



sxx c 
jjsq 
5	47J  
5	4s-   O6A5P	AO<&EP	<P	P		PN)
__name__
__module____qualname____doc__detailed_helpclassmethodrf   staticmethodrj   r    r5   r3   r7   r7   H   sG      		-  '* '*R ? ?
[r5   r7   c                        e Zd ZdZed        Zy)
BetaCreater8   c                     | j                  |       t        j                  |       t        j                  |       t	        t
        j                  j                        }t        j                  ||       y Nr   )
rf   r   AddGpuTypeFlagGpuZonalRedundancyFlagr4   r   r%   r'   r   rh   ra   rb   ri   s      r3   rj   zBetaCreate.Args   sP    NN6	 	  (&T5F5F5K5KLN&&v~>r5   Nr   r   r   r   r   rj   r   r5   r3   r   r      s    ? ?r5   r   c                        e Zd ZdZed        Zy)AlphaCreater8   c                    | j                  |       t        j                  |       t        j                  |       t        j                  |       t        t        j                  j                        }t        j                  ||       y r   )rf   r   AddRuntimeFlagr   r   r4   r   r%   r&   r   rh   r   s      r3   rj   zAlphaCreate.Args   s^    NN6	 	 	  (&T5F5F5L5LMN&&v~>r5   Nr   r   r5   r3   r   r      s    ? ?r5   r   N))r   
__future__r   r   r   r   googlecloudsdk.callioper   r   r|   r	   r   googlecloudsdk.command_lib.runr
   r   r   r   r   r   r   r   r   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.corer   googlecloudsdk.core.consoler   r!   r%   GAr4   UniverseCompatibleReleaseTracksCommandr7   r'   r   r&   r   r   r5   r3   <module>r      s   C &  % ' ( > D 9 = ; 5 0 8 7 8 @ 1 D G # 8 F  %)$5$5$8$8 8 D%%(()^T\\ ^ * ^B D%%**+	? 	? ,	? D%%++,
?* 
? -
?r5   