
    q7                     ^   S 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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\R>                  " \R@                  RB                  \R@                  RD                  5      \RF                   " S S\RH                  5      5       5       r%\R>                  " \R@                  RL                  5      \RF                   " S S\%5      5       5       r'S r(g)z2Rollback a Cloud Deploy target to a prior rollout.    N)
exceptions)client_util)release)base)delivery_pipeline_util)deploy_policy_util)deploy_util)flags)promote_util)release_util)resource_args)rollout_util)target_util)log)	resources)
console_ioz{description}z   To rollback a target 'prod' for delivery pipeline 'test-pipeline' in region 'us-central1', run:

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


)DESCRIPTIONEXAMPLESrollbackc                   p    \ rS rSrSr\r\S 5       r\	R                  " \R                  5      S 5       rSrg)Rollback6   Rollbacks a target to a prior rollout.

If release is not specified, the command rollbacks the target with the last
successful deployed release. If optional rollout-id parameter is not
specified, a generated rollout ID will be used.
c                    [         R                  " U SS9  [        R                  " U S5        [        R                  " U 5        [        R
                  " U 5        [        R                  " U 5        [        R                  " U [        5        [        R                  " U [        5        [        R                  " U 5        [        R                  " U 5        g )NT)
positionalz#Name of the release to rollback to.)r   AddTargetResourceArgr
   
AddReleaseAddRolloutIDAddDeliveryPipelineAddDescriptionFlagAddAnnotationsFlag	_ROLLBACKAddLabelsFlagAddStartingPhaseIdAddOverrideDeployPoliciesparsers    &lib/surface/deploy/targets/rollback.pyArgsRollback.ArgsB   s    &&v$?	VBC	v	f%	V$	VY/		*	V$	##F+    c                    UR                   R                  R                  5       n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        [        R                  " U5        [        UR                  XB5      u  px[        R                  " 5       R!                  UR                  5       5      n	["        R$                  " U	S5        U	R&                  (       a&  Sn
[(        R*                  " XR                  5       5      eSR-                  UR/                  5       UR/                  5       5      n["        R0                  " XUR/                  5       U5        [2        R4                  " S	S
9  UR6                  =(       d    SR-                  UR/                  5       5      n[8        R:                  " XAR<                  5      n[>        R@                  " UU	UR/                  5       SURB                  URD                  URF                  UURH                  =(       d    SUS9
nU(       a5   [        RJ                  " UR                  5       UR/                  5       S	S9  U$ U$ ! [L        RN                   a:  nURP                  S:X  a  [R        RT                  RW                  S5         S nAU$ S nAff = f)N0clouddeploy.projects.locations.deliveryPipelines
projectsIdlocationsIdr.   r/   deliveryPipelinesId
collectionparamsCannot perform rollback.roll back this target'Rolling back target {} to release {}.

Tcancel_on_noRollback from {}Fstable)
rollout_idannotationslabelsdescriptionstarting_phase_idoverride_deploy_policies)validate_onlyi  zStarting on September 14, 2026, the rollback feature will require a new permission: clouddeploy.rollouts.rollback. For more information, see https://docs.cloud.google.com/deploy/docs/rollout-perms-notice),CONCEPTStargetParseAsDictr   REGISTRYdelivery_pipeliner   GetPipelineRelativeNameThrowIfPipelineSuspendedr   	GetTarget_GetCurrentAndRollbackReleaser   ReleaseClientGetr   CheckReleaseSupportState	abandoneddeploy_exceptionsAbandonedReleaseErrorformatName	PrintDiffr   PromptContinuer?   r   CreateDeployPolicyNamesFromIDsrA   r   Promoter<   r=   r>   r@   CreateRollbackTargetapitools_exceptions	HttpErrorstatus_coder   statusPrint)selfargs
target_refref_dictpipeline_refpipeline_obj'failed_activity_error_annotation_prefixcurrent_release_refrollback_release_refrelease_objerror_msg_annotation_prefixpromptrollout_descriptionpoliciesrollout_resourcees                   r(   RunRollback.RunN   s    %%++-J  "H%%++E"<0#M2#'#9#9
 , L *55!!#L /I+33 *%0Ml1- '')--))+K ))+7NO$>!33
%'H'H'J  9??/446F :??+<f 40** .@.G.G  "/
 "@@33H $++??$${{'00<H!)  	33%%'OO	
  !** ==C
**

P s   :2J0 0K>/K99K> N)__name__
__module____qualname____firstlineno____doc___DETAILED_HELPdetailed_helpstaticmethodr)   gcloud_exception CatchHTTPErrorRaiseHTTPExceptionrR   HTTP_ERROR_FORMATrp   __static_attributes__rr   r+   r(   r   r   6   sJ     !-	, 	, 44))VVr+   r   c                   .    \ rS rSrSr\S 5       rS rSrg)RollbackAlpha   r   c                 Z    [         R                  U 5        [        R                  " U 5        g )N)r   r)   r
   AddRollbackOfRolloutr&   s    r(   r)   RollbackAlpha.Args   s     MM&	v&r+   c                 l
   UR                   R                  R                  5       n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        [        R                  " 5       R                  UR                  S9n[        R                   " [        R                  " 5       U[        R"                  R$                  UR&                  UR(                  5        [*        R,                  " [        R.                  " UR                  5       UR1                  5       SUR2                  UR4                  UR6                  UUR8                  S	95      nUR2                  n	[        R
                  R;                  [        R
                  R                  UR<                  R>                  R@                  S
S9RC                  5       R                  5       SS9n
UR2                  (       d  [D        RF                  " UR1                  5       U
5      n	U
R                  5       n[        R
                  R                  U	S
URI                  S5      URI                  S5      URI                  S5      U
R1                  5       S.S9nUR                  5       UR<                  R>                  l         UR                  (       d  [        R
                  R;                  [        R
                  R                  UR<                  R>                  RJ                  S
S9RC                  5       R                  5       SS9nSRM                  UR1                  5       5      UR<                  R>                  l         [6        RN                  " 5       RQ                  U
R                  5       5      n[Z        R\                  " US5        SRM                  UR1                  5       U
R1                  5       5      n[Z        R^                  " XUR1                  5       U5        [`        Rb                  " SS9  [        R.                  " UR                  5       UR1                  5       SU	U
R1                  5       UR<                  R>                  RJ                  UR<                  R>                  UR<                  Rd                  S9nUR<                  R>                  $ ! [R        RT                   a  n[V        RX                  " U5      eS nAff = f)Nr-   r.   r/   r0   r2   r5   )r?   T)rB   r<   rollout_to_rollback
release_idrollout_objstarting_phaseBclouddeploy.projects.locations.deliveryPipelines.releases.rolloutsr3   9clouddeploy.projects.locations.deliveryPipelines.releasesr1   r.   r/   r1   
releasesIdr:   r6   r7   r8   F)rB   r<   r   r   r   r   )3rC   rD   rE   rF   r   rG   rH   r   rI   rJ   rK   r   GetMessagesModuleRolloutr?   r	   SetMetadataResourceTypeROLLOUTr=   r>   copydeepcopyrZ   rU   r<   rollback_of_rolloutr   r@   ParseRelativeNamerollbackConfigrolloutnameParentr   GenerateRolloutIdgetrollbackOfRolloutrT   rN   rO   r[   r\   r   HttpExceptionr   rP   rV   r   rW   startingPhaseId)r`   ra   rb   rc   rd   re   rf   r   validate_responsefinal_rollout_idrh   resource_dictnew_rollout_refrg   ri   errorrk   create_responses                     r(   rp   RollbackAlpha.Run   s_   %%++-J  "H%%++E"<0#M2#'#9#9
 , L *55!!#L /I+33 //199$$ : K %%'  (( 33%%'OO $ 8 8||#11		
 $--??  ,,4499[ 	! 	
 
	N @   ??%77
//
1 +113m!**00
Y)--l;*..}=%2%6%67L%M0557	 1 	o 
&
&
( &&..3
 %..@@



"
"..66HH] #  68<>I A 
 
#
#$7$<$<$>
? &&..:,))+//

+
+
-k ))+7NO 9??/446F :??+<f 40,AA!!##',,.-<<DDVV%44<<(77GGO ))1119 (( ,$$U++,s   22T T3T..T3rr   N)	rs   rt   ru   rv   rw   rz   r)   rp   r~   rr   r+   r(   r   r      s!     ' '
C2r+   r   c           	         U (       a  UR                  5       n[        R                  " X!5      n[        R                  R                  [        R                  R                  UR                  SS9R                  5       R                  5       SS9n[        R                  R                  U SUS   US   UR                  5       U S.S9nXV4$ [        R                  " X!5      n[        U5      S:  a3  [        R                  " S	R!                  UR                  5       5      5      eUu  p[        R                  R                  [        R                  R                  UR                  SS9R                  5       R                  5       SS9n[        R                  R                  [        R                  R                  U	R                  SS9R                  5       R                  5       SS9nXV4$ )
zrGets the current deployed release and the release that will be used by promote API to create the rollback rollout.r   r   r   r.   r/   r   r2      z>unable to rollback target {}. Target has less than 2 rollouts.)rF   r   GetCurrentRolloutr   rG   r   rE   r   r   rJ   rU   r   GetValidRollBackCandidatelencore_exceptionsErrorrT   )
r   rd   rb   rc   current_rolloutrg   rh   prior_rolloutscurrent_deployed_rolloutprevious_deployed_rollouts
             r(   rM   rM   @  s     "H!33JMO#,,>>    [ 	! 	
 
	N ?  %--33N"<0#M2#/#4#4#6$	
 4 	 44!;;N >Q!!
J6*//#$  ;I7#,,>>  $))[ 	! 	
 
	N ?  %--??  %**[ 	! 	
 
	N @  44r+   ))rw   r   apitools.base.pyr   r[   "googlecloudsdk.api_lib.clouddeployr   r   googlecloudsdk.api_lib.utilr{   googlecloudsdk.callioper   !googlecloudsdk.command_lib.deployr   r   r	   rR   r
   r   r   r   r   r   googlecloudsdk.corer   r   r   googlecloudsdk.core.consoler   rx   r"   ReleaseTracksReleaseTrackBETAGADefaultUniverseOnlyCreateCommandr   ALPHAr   rM   rr   r+   r(   <module>r      s   9  > : 6 F ( . D @ 9 M 3 : : ; : 9 = # ) 2 #	 	 D%%**D,=,=,@,@Aot!! o  Bod D%%++,Q2H Q2  -Q2h65r+   