
                            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S.rSr\	R6                  " \	R8                  R:                  \	R8                  R<                  \	R8                  R>                  5      \	R@                   " S S\	RB                  5      5       5       r"S r#g)zRedeploy a rollout to a target.    )release)apis)
exceptions)base)delivery_pipeline_util)deploy_policy_util)flags)promote_util)release_util)resource_args)rollout_util)target_util)	resources)
console_ioz{description}z   To redeploy a target `prod` for delivery pipeline `test-pipeline` in region `us-central1`, run:

  $ {command} prod --delivery-pipeline=test-pipeline --region=us-central1

)DESCRIPTIONEXAMPLESrolloutc                   p    \ rS rSrSr\r\S 5       r\	R                  " \R                  5      S 5       rSrg)Redeploy0   zRedeploy the last release to a target.

Redeploy the last rollout that has a state of SUCCESSFUL or FAILED to a
target.
If rollout-id is not specified, a rollout ID will be generated.
c                 v   [         R                  " U SS9  [        R                  " U 5        [        R                  " U 5        [        R
                  " U 5        [        R                  " U [        5        [        R                  " U [        5        [        R                  " U 5        [        R                  " U 5        g )NT)
positional)r   AddTargetResourceArgr	   AddRolloutIDAddDeliveryPipelineAddDescriptionFlagAddAnnotationsFlag_ROLLOUTAddLabelsFlagAddStartingPhaseIdAddOverrideDeployPolicies)parsers    &lib/surface/deploy/targets/redeploy.pyArgsRedeploy.Args>   sx    &&v$?	v	f%	V$	VX.	)	V$	##F+    c                 :   UR                   R                  R                  5       n[        R                  " U5        UR                  5       n[        R                  R                  UR                  SUS   US   UR                  S.S9n[        R                  " UR                  5       5      nSn[        R                  " XV5        [        XB[        R                  5      n[         R"                  " 5       R%                  UR                  5       5      n[&        R(                  " US5        UR*                  (       a$  [,        R.                  " XgR                  5       5      eSR1                  UR3                  5       UR3                  5       5      n	[4        R6                  " U	S	S
9  [8        R:                  " XAR<                  5      n
[>        R@                  " UUUR3                  5       SURB                  URD                  URF                  URH                  URJ                  U
S9
  g )Nz0clouddeploy.projects.locations.deliveryPipelines
projectsIdlocationsId)r(   r)   deliveryPipelinesId)
collectionparamszCannot perform redeploy.zredeploy this releasez:Are you sure you want to redeploy release {} to target {}?T)cancel_on_noF)
rollout_idannotationslabelsdescriptionstarting_phase_idoverride_deploy_policies)&CONCEPTStargetParser   	GetTargetAsDictr   REGISTRYdelivery_pipeliner   GetPipelineRelativeNameThrowIfPipelineSuspended_GetCurrentReleaser   !ROLLOUT_IN_TARGET_FILTER_TEMPLATEr   ReleaseClientGetr   CheckReleaseSupportState	abandoneddeploy_exceptionsAbandonedReleaseErrorformatNamer   PromptContinuer   CreateDeployPolicyNamesFromIDsr3   r
   Promoter.   r/   r0   r1   r2   )selfargs
target_refref_dictpipeline_refpipeline_objfailed_redeploy_prefixcurrent_release_refrelease_objpromptpoliciess              r#   RunRedeploy.RunI   s    %%++-J*%  "H%%++E"<0#M2#'#9#9
 , L *55!!#L 833 -,"P"P '')--((*K ))+7NO 33
 "B"B"D 
 	EKK$$&
(9	
 
 f48 "@@33H ??$${{$$00!)r&    N)__name__
__module____qualname____firstlineno____doc___DETAILED_HELPdetailed_helpstaticmethodr$   gcloud_exception CatchHTTPErrorRaiseHTTPExceptionrD   HTTP_ERROR_FORMATrV   __static_attributes__rX   r&   r#   r   r   0   sH    
 !-, , 44))<<r&   r   c           
      2   [        [        R                  " UU U[        R                  SS95      n[	        U5      S:  a3  [
        R                  " SR                  UR                  5       5      5      eUS   n[        R                  " SS5      nUR                  R                  R                  UR                  R                  R                  UR                  R                  R                  /nUR                   U;  a:  ["        R$                  " UR                  5       UR&                  UR                   5      e[(        R*                  R-                  [(        R*                  R/                  UR&                  SS9R1                  5       R3                  5       S	S9nU$ )
a  Gets the current release in the target.

Args:
  pipeline_ref: pipeline_ref: protorpc.messages.Message, pipeline object.
  target_ref: target_ref: protorpc.messages.Message, target object.
  filter_str: Filter string to use when listing rollouts.

Returns:
  The most recent release with the given pipeline and target with a rollout
  that is redeployable.

Raises:
  core.Error: Target has no rollouts or rollouts in target are not
              redeployable.
   )rM   rO   
filter_strorder_bylimitz8unable to redeploy to target {}. Target has no rollouts.r   clouddeployv1zBclouddeploy.projects.locations.deliveryPipelines.releases.rollouts)r+   z9clouddeploy.projects.locations.deliveryPipelines.releases)listr   GetFilteredRolloutsENQUEUETIME_ROLLOUT_ORDERBYlencore_exceptionsErrorrF   rG   	core_apisGetMessagesModuleRolloutStateValueValuesEnum	SUCCEEDEDFAILED	CANCELLEDstaterD   RedeployRolloutErrornamer   r9   ParseRelativeNamer6   Parentr<   )rO   rM   rg   prior_rolloutsprior_rolloutmessagesredeployable_statesrR   s           r#   r>   r>      sn   ( &&#;;. 	1


BIIOO	
 
 !#-((=(++55++22++55
  33

0
0=--}/B/B  "**<<


#   vx|~L =  
r&   N)$r]   "googlecloudsdk.api_lib.clouddeployr   googlecloudsdk.api_lib.utilr   rr   r   ra   googlecloudsdk.callioper   !googlecloudsdk.command_lib.deployr   r   rD   r	   r
   r   r   r   r   googlecloudsdk.corerp   r   googlecloudsdk.core.consoler   r^   r   ReleaseTracksReleaseTrackALPHABETAGADefaultUniverseOnlyCreateCommandr   r>   rX   r&   r#   <module>r      s    & 7 9 F ( D @ M 3 : : ; : 9 = ) 2 #  T..33T5F5F5I5I Tt!! T Tn;r&   