
    +                         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rS	 rS
 rS rS rS r      SS jrg)z:Utilities for the cloud deploy delivery pipeline resource.    N)
exceptions)client_util)delivery_pipeline)log)	resourcesz#serialPipeline.stages.targetId:"{}"c                 H    [         R                  R                  U SUUU S.S9$ )a  Creates the delivery pipeline reference base on the parameters.

  Returns the shared delivery pipeline reference.

Args:
  name: str, delivery pipeline ID
  project: str,project number or ID.
  region: str, region ID.

Returns:
  custom target type reference.
0clouddeploy.projects.locations.deliveryPipelines)
projectsIdlocationsIddeliveryPipelinesId)
collectionparams)r   REGISTRYParse)nameprojectregions      ?lib/googlecloudsdk/command_lib/deploy/delivery_pipeline_util.pyDeliveryPipelineReferencer       s6     
			!	!
C!% 
" 
     c                     [         R                  U R                  5       5      n[        R                  " 5       R                  UR                  5       USS9n[        US SS9$ )a3  Lists the delivery pipelines associated with the specified target.

The returned list is sorted by the delivery pipeline's create time.
Args:
  target_ref: protorpc.messages.Message, target object.
  location_ref: protorpc.messages.Message, location object.

Returns:
  a sorted list of delivery pipelines.
r   )location
filter_str	page_sizec                     U R                   $ )N)
createTime)pipelines    r   <lambda>1ListDeliveryPipelinesWithTarget.<locals>.<lambda>Q   s
    h&9&9r   T)keyreverse),_PIPELINES_WITH_GIVEN_TARGET_FILTER_TEMPLATEformatNamer   DeliveryPipelinesClientListRelativeNamesorted)
target_reflocation_refr   	pipeliness       r   ListDeliveryPipelinesWithTargetr,   8   sg     <BBoo*  779>>((* ? ) 
94
 r   c                 V    [         R                  R                  U R                  SS9nU$ )Nr	   )r   )r   r   ParseRelativeNamer   )r   pipeline_refs     r   PipelineToPipelineRefr0   U   s/    ##55mmC 6 , 
r   c                 F    [         R                  " 5       R                  U 5      nU$ ! [        R                   ad  n[
        R                  " SR                  XR                  5      5        [
        R                  R                  SR                  U 5      5        UeSnAff = f)zGets the delivery pipeline and returns the value of its suspended field.

Args:
  pipeline_name: str, the canonical resource name of the delivery pipeline

Returns:
  The pipeline object
Raises:
  apitools.base.py.HttpError
zFailed to get pipeline {}: {}z"Unable to get delivery pipeline {}N)r   r%   Getapitools_exceptions	HttpErrorr   debugr#   contentstatusPrint)pipeline_namepipeline_objerrors      r   GetPipeliner<   ]   s    
$<<>BBL 		&	& II'..}mmL JJ9@@OP
Ks   %( B ABB c                 d    U R                   (       a  [        R                  " U R                  US9eg)aU  Checks if the delivery pipeline associated with the release is suspended.

Args:
  pipeline_obj: protorpc.messages.Message, delivery pipeline object.
  suspended_pipeline_msg: str, error msg to show the user if the pipeline is
    suspended.

Raises:
  googlecloudsdk.command_lib.deploy.PipelineSuspendedError if the pipeline is
  suspended
)r9   failed_activity_msgN)	suspendedcd_exceptionsPipelineSuspendedErrorr   )r:   suspended_pipeline_msgs     r   ThrowIfPipelineSuspendedrC   u   s1     

.
."''2  r   c                 0   U(       a  UO!S[         R                  " 5       R                  -   n[        R                  " 5       R                  XgS9n	[        R                  " 5       R                  U [        R                  " 5       R                  UU	UUUUS95      $ )a  Creates a rollback rollout for the target based on the given inputs.

Args:
  pipeline_rel_name: delivery_pipeline name
  target_id: the target to rollback
  validate_only: whether or not to validate only for the call
  release_id: the release_id to rollback to
  rollout_id: the rollout_id of the new rollout
  rollout_to_rollback: the rollout that is being rolled back by this rollout
  rollout_obj: the rollout resource to pass into rollbackTargetConfig
  starting_phase: starting_phase of the rollout

Returns:
  RollbackTargetResponse
z	rollback-)rolloutstartingPhaseId)	releaseIdrollbackConfig	rolloutIdrolloutToRollBacktargetIdvalidateOnly)
uuiduuid4hexr   GetMessagesModuleRollbackTargetConfigr   r%   RollbackTargetRollbackTargetRequest)
pipeline_rel_name	target_idvalidate_only
release_id
rollout_idrollout_to_rollbackrollout_objstarting_phaserollback_idrollback_target_configs
             r   CreateRollbackTargetr^      s    6 )
kDJJL<L<L.L+&88:OO P  
	2	2	4	C	C##%;;//$ < 

 
r   )FNNNNN)__doc__rM   apitools.base.pyr   r3   "googlecloudsdk.api_lib.clouddeployr   r   !googlecloudsdk.command_lib.deployr@   googlecloudsdk.corer   r   r"   r   r,   r0   r<   rC   r^    r   r   <module>re      s^    A  > : @ I # ) * -
0:0, +r   