
                             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	rS
r      SS jrS rS rg)z$Utilities for the promote operation.    )rollout)
exceptions)release_util)rollout_util)target_util)log)	resourceszmRelease {} is already deployed to the last target ({}) in the promotion sequence.
- Release: {}
- Target: {}
zstate="IN_PROGRESS"Nc
           
         Un
U
(       d  [        X5      n
[        R                  " U U
UUUUUU	5      n[        R                  " X5      nU(       a0  UR
                  (       a  [        R                  R                  S5        U$ )a  Creates a rollout for the given release in the destination target.

If to_target is not specified and there is a rollout in progress, the promote
will fail. Otherwise this computes the destination target based on the
promotion sequence.

Args:
  release_ref: protorpc.messages.Message, release resource object.
  release_obj: apitools.base.protorpclite.messages.Message, release message
    object.
  to_target: str, the target to promote the release to.
  is_create: bool, if creates a rollout during release creation.
  rollout_id: str, ID to assign to the generated rollout.
  annotations: dict[str,str], a dict of annotation (key,value) pairs that
    allow clients to store small amounts of arbitrary data in cloud deploy
    resources.
  labels: dict[str,str], a dict of label (key,value) pairs that can be used to
    select cloud deploy resources and to find collections of cloud deploy
    resources that satisfy certain conditions.
  description: str, rollout description.
  starting_phase_id: str, the starting phase for the rollout.
  override_deploy_policies: List of Deploy Policies to override.

Raises:
  googlecloudsdk.command_lib.deploy.exceptions.RolloutIdExhausted
  googlecloudsdk.command_lib.deploy.exceptions.ReleaseInactiveError
Returns:
  The rollout resource created.
z The rollout is pending approval.)	GetToTargetIDr   CreateRolloutr   GetSnappedTargetrequireApprovalr   statusPrint)release_refrelease_obj	to_target	is_create
rollout_idannotationslabelsdescriptionstarting_phase_idoverride_deploy_policiesdest_targetrollout_resource
target_objs                5lib/googlecloudsdk/command_lib/deploy/promote_util.pyPromoter   "   sv    R +	7K!//	 ,,[F*J..JJ78	    c                 l   U R                   R                  R                  (       d   [        R                  " U R
                  5      e[        R                  R                  U R
                  SS9nU R                   R                  R                  S   R                  n[        [        U R                   R                  R                  5      5      nUR                  5       n[        U5       GHf  u  pg[        R                  " UR                  US   US   5      n[        R                   " U[        R                  R#                  SSUS   US   US   S	.S
95      n	U	(       d  Mx  [        R                  R#                  U	R
                  SS9n
U
R%                  5       R'                  5       UR'                  5       :X  d  M  US:  a  XFS-
     R                  nO}[(        R*                  R-                  [.        R1                  UR'                  5       UR'                  5       UR3                  5       UR3                  5       5      5        UR3                  5       n  O   UU R                   R                  R                  S   R                  :X  a  U(       d  [        R4                  " 5       e[        R6                  " U5      $ )a  Get the to_target parameter for promote API.

This checks the promotion sequence to get the next stage to promote the
release to.

Args:
  release_obj: apitools.base.protorpclite.messages.Message, release message.
  is_create: bool, if getting the target for release creation.

Returns:
  the target ID.

Raises:
  NoStagesError: if no pipeline stages exist in the release.
  ReleaseInactiveError: if this is not called during release creation and the
  specified release has no rollouts.
z9clouddeploy.projects.locations.deliveryPipelines.releases)
collectionr   
projectsIdlocationsIdNz0clouddeploy.projects.locations.deliveryPipelinesdeliveryPipelinesId)r#   r$   r%   )r"   paramszBclouddeploy.projects.locations.deliveryPipelines.releases.rollouts   )deliveryPipelineSnapshotserialPipelinestagesr   NoStagesErrornamer	   REGISTRYParseRelativeNametargetIdlistreversedAsDict	enumerater   TargetReferenceGetCurrentRolloutParseParentNamer   r   r   _LAST_TARGET_IN_SEQUENCEformatRelativeNameReleaseInactiveErrorTargetId)r   r   r   r   reversed_stagesrelease_dictistage
target_refcurrent_rolloutcurrent_rollout_refs              r   r   r   b   s^   & 
	-	-	<	<	C	C

"
";#3#3
44 ""44L 5 + 22AAHHH 
 {33BBIIJ/ ##%,O,ha,,\2L4OJ
 "33  I*<8+M:'34I'J 	! 	
O %..44


Y 5  
	#	#	%	*	*	,0@0@0B	Bq5%!e,55)
**

&--""$//#**,))+	 !--/)Q -Z 		-	-	<	<	C	CA	F	O	OP

)
)
++			i	((r    c                     [        [        R                  " 5       R                  U R	                  5       [
        SS95      nU(       a!  [        R                  " UR                  U5      eg)ae  Checks if there are any rollouts in progress for the given release.

Args:
  release_ref: protorpc.messages.Message, release resource object.
  release_obj: apitools.base.protorpclite.messages.Message, release message
    object.
  to_target_id: string, target id (e.g. 'prod')

Raises:
  googlecloudsdk.command_lib.deploy.exceptions.RolloutInProgressError
r'   )limitN)	r0   r   RolloutClientListr;   IN_PROGRESS_FILTER_TEMPLATEr   RolloutInProgressErrorr,   )r   r   to_target_idrolloutss       r   CheckIfInProgressRolloutrM      s^     ""

"
"
$&A # ( 

+
+K,<,<l
KK r    )NNNNNN)__doc__"googlecloudsdk.api_lib.clouddeployr   !googlecloudsdk.command_lib.deployr   r   r   r   googlecloudsdk.corer   r	   r9   rI   r   r   rM    r    r   <module>rS      s[    + 7 8 : : 9 # )E 
 4  !=@W)tLr    