
    "                        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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  \
R:                  \
R<                  " \
R>                  R@                  \
R>                  RB                  5       " S S\
RD                  5      5       5       r#g)z;Command for updating env vars and other configuration info.    )global_methodsworker_pool)apis)messages)arg_parsers)base)util)config_changes)connection_context)
exceptions)flags)messages_util)pretty_print)serverless_operations)stages)config)
properties)	resources)progress_trackerc                   Z    \ rS rSrSrSSS.r\S 5       r\S 5       rS r	S	 r
S
 rS rSrg)Replace'   zFCreate or replace a worker-pool from a YAML worker-pool specification.z]          Creates or replaces a worker-pool from a YAML worker-pool specification.
          z          To replace the specification for a worker-pool defined in my-worker-pool.yaml

              $ {command} my-worker-pool.yaml

         )DESCRIPTIONEXAMPLESc                    [         R                  " U5        [         R                  " U5        [         R                  " U5        UR	                  SS[
        R                  " 5       SS9  UR                  R                  S5        g )NFILEstorezsThe absolute path to the YAML file with a Cloud Run worker-pool definition for the worker-pool to update or create.)actiontypehelpnone)	r   AddAsyncFlagAddClientNameAndVersionFlagsAddDryRunFlagadd_argumentr   YAMLFileContentsdisplay_info	AddFormatclsparsers     'lib/surface/run/worker_pools/replace.py
CommonArgsReplace.CommonArgs8   so     
v	&&v.	
))+B   !!&)    c                 &    U R                  U5        g )N)r.   r*   s     r-   ArgsReplace.ArgsK   s    NN6r0   c                 |    [         R                  " U[        R                  R                  U R                  5       US9$ )N)region_label)r   GetConnectionContextr   ProductRUNReleaseTrack)selfargsr5   s      r-   _ConnectionContextReplace._ConnectionContextO   s1    22emm!2!2!4< r0   c                 Z   UR                  S5      =(       d    UR                  S5      n[        R                  " U5      [        R                  " U R	                  5       5      [        R
                  " U(       a  UR                  OSU(       a  UR                  O[        R                  SS9/$ )Nclient_nameclient_versiongcloudT)set_on_template)
IsSpecifiedr   ReplaceWorkerPoolChangeSetLaunchStageAnnotationChanger9   'SetClientNameAndVersionAnnotationChanger?   r@   r   CLOUD_SDK_VERSION)r:   new_worker_poolr;   is_either_specifieds       r-   _GetBaseChangesReplace._GetBaseChangesT   s     **=9 T=M=M> 	..?55d6G6G6IJ>> 3D" )) 	

 
r0   c                 F   UR                   (       a.  [        R                  " SR                  UR                  S95        g U(       a.  [        R                  " SR                  UR                  S95        g [        R                  " SR                  UR                  S95        g )NzWNew configuration for [{{bold}}{worker_pool}{{reset}}] is being applied asynchronously.r   zVNew configuration has been validated for worker pool [{{bold}}{worker_pool}{{reset}}].zSNew configuration has been applied to worker pool [{{bold}}{worker_pool}{{reset}}].)async_r   Successformatname)r:   worker_pool_objdry_runr;   s       r-   _PrintSuccessMessageReplace._PrintSuccessMessagef   s    {{%%+V8L8LV%M 
..4f).. /5 / ..4f).. /5 /r0   c           
         [         R                  " [        R                  [        R                  5      n[        UR                  5      nSU;   a  US	 SU;  d	  SUS   ;  a  [        R                  " S5      eSUS   S   ;  a  0 US   S   S'   UR                  S0 5      R                  SS5      nUb&  [        U[        5      (       d  [        U5      US   S'   Sn [        R                  " X2R                  5      n[        R                  " Xb5      n[$        R&                  R(                  R*                  R-                  5       nUR.                  R0                  bg  Un[2        R4                  " U5      n	UR.                  R0                  nXH:w  a4  U[        U	5      :w  a%  [        R                  " S
R7                  X5      5      eXER.                  l        U R9                  XQ5      n
[:        R<                  R?                  UR.                  R@                  SUR.                  R0                  0SS9nURB                  (       a  URD                  OSnU RG                  X5      n[I        US5      (       a  URJ                  OSnU(       a  SOSn[L        RN                  " U5       nURQ                  U5      n[R        RT                  " [V        RX                  " UUUSS95        [Z        R\                  " 5       nU(       a  SOSnU(       a  Sn[^        R`                  " UUSURb                  =(       d    US9 nURe                  UU
UURb                  US9nSSS5        U Rg                  UX5        UsSSS5        $ ! [        R                    a   n[        R"                  " USS	9   SnAGNSnAff = f! , (       d  f       Nb= f! , (       d  f       g= f)z#Create or Update service from YAML.statusspectemplatezRspec.template is required but missing. Please check the content in your yaml file.metadata	namespaceNzPlease make sure that the YAML file matches the Cloud Run worker pool definition spec in https://cloud.google.com/run/docs/reference/rest/v1/namespaces.workerpools#WorkerPool)	help_textzVNamespace must be project ID [{}] or quoted number [{}] for Cloud Run (fully managed).namespacesIdzrun.namespaces.workerpools)params
collectionrR   Fz Validating new configuration forzApplying new configuration to
workerpool)	operationresource_kind_lowerzDeploying...zDeploying new worker pool...zValidating...zDeployment failed)failure_messagesuppress_output)asynrR   )4r   GetMessagesModuler   SERVERLESS_API_NAMESERVERLESS_API_VERSIONdictr   r   ConfigurationErrorget
isinstancestrr   DictToMessageWithErrorCheck
WorkerPoolr   ScalarTypeMismatchErrorMaybeRaiseCustomFieldMismatchr   VALUEScoreprojectGetrY   rZ   projects_utilGetProjectNumberrO   rJ   r   REGISTRYParserP   
is_managedregionr<   hasattrrR   r   ConnectGetWorkerPoolr   Inforun_messages_utilGetStartDeployMessager   WorkerPoolStagesr   StagedProgressTrackerrM   ReplaceWorkerPoolrS   )r:   r;   run_messagesworker_pool_dictrZ   rH   raw_worker_poolers   project_numberchangesworker_pool_refr5   conn_contextrR   r   clientrQ   deployment_stagesheadertrackers                        r-   RunReplace.Run{   s   ))**--L DII ##
8
$&&-f55))8  )&1*==9;vz*:6 !$$Z488dKIZ	3%?%?25i.z";/O%AA
33o $..Mo !!&&..224I))5g$55i@n!**44i		)s>/B"B++))/)H
 	
 *3&""?9G((..  %%O44>>
 0 / O #2"<"<$  **4>L%dI66dllEG  	+,  
	&	&|	4,,_=o

1
1".	 !113+.1O  
 11

-++0	
  22 3 
 ?A 
5	4] 00 ..
g @ % 
5	4s=   6M/ BN7,N&
N7/N#NN#&
N4	0N77
O N)__name__
__module____qualname____firstlineno____doc__detailed_helpclassmethodr.   r2   r<   rJ   rS   r   __static_attributes__r   r0   r-   r   r   '   sV     O	
- * *$  
$*rr0   r   N)$r   googlecloudsdk.api_lib.runr   r   googlecloudsdk.api_lib.utilr   r   r   googlecloudsdk.callioper   r	   #googlecloudsdk.command_lib.projectsr
   ru   googlecloudsdk.command_lib.runr   r   r   r   r   r   r   r   googlecloudsdk.corer   r   r   googlecloudsdk.core.consoler   UniverseCompatibleReleaseTracksr9   ALPHABETACommandr   r   r0   r-   <module>r      s    B 6 2 , A / ( E 9 = 5 0 M 7 @ 1 & * ) 8 D%%++T->->-C-CDDdll D E Dr0   