
    #                     r    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
\5      rg)z2Support library to handle the rollout subcommands.    )absolute_import)division)unicode_literals)
list_pager)client_util)deploy_util)logc                       \ rS rSrSrSS jrSS jrS r    SS jr    SS jr	 SS	 jr
 SS
 jrSS jrSS jrSrg)RolloutClient   z3Client for release service in the Cloud Deploy API.Nc                     U=(       d    [         R                  " 5       U l        U=(       d    [         R                  " U5      U l        U R                  R
                  U l        g)zInitialize a release.ReleaseClient.

Args:
  client: base_api.BaseApiClient, the client class for Cloud Deploy.
  messages: module containing the definitions of messages for Cloud Deploy.
N)r   GetClientInstanceclientGetMessagesModulemessages6projects_locations_deliveryPipelines_releases_rollouts_service)selfr   r   s      1lib/googlecloudsdk/api_lib/clouddeploy/rollout.py__init__RolloutClient.__init__   sD     ;K99;DKE = =f EDMJJ 	M    c                     Uc  / nU R                   R                  UU R                   R                  UUS9S9nU R                  R	                  U5      $ )au  Calls the approve API to approve or reject a rollout..

Args:
  name: Name of the Rollout. Format is
    projects/{project}/locations/{location}/deliveryPipelines/{deliveryPipeline}/releases/{release}/rollouts/{rollout}.
  approved: True = approve; False = reject
  override_deploy_policies: List of Deploy Policies to override.

Returns:
  ApproveRolloutResponse message.
)approvedoverrideDeployPolicy)nameapproveRolloutRequest)r   KClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsApproveRequestApproveRolloutRequestr   Approve)r   r   r   override_deploy_policiesrequests        r   r    RolloutClient.Approve,   sb      '!#mmgg"mmAA!9 B 
 h G ==  ))r   c                 j    U R                   R                  US9nU R                  R                  U5      $ )z\Gets a rollout resource.

Args:
  name: rollout resource name.

Returns:
  rollout message.
)r   )r   GClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsGetRequestr   Get)r   r   r"   s      r   r&   RolloutClient.GetC   s8     mmcc d G ==W%%r   c           	      |    U R                   R                  XUS9n[        R                  " U R                  USUUSS9$ )a  Lists rollout resources that belongs to a release.

Args:
  release_name: str, name of the release.
  filter_str: optional[str], list filter.
  order_by: optional[str], field to sort by.
  limit: optional[int], the maximum number of `Rollout` objects to return.
  page_size: optional[int], the number of `Rollout` objects to return per
    request.

Returns:
  Rollout list response.
)parentfilterorderByrolloutspageSize)fieldlimit
batch_sizebatch_size_attribute)r   HClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsListRequestr   YieldFromListr   )r   release_name
filter_strorder_byr/   	page_sizer"   s          r   ListRolloutClient.ListQ   sN    * mmdd e G ##' r   c                 v   [         R                  " SU5        [        R                  " U R                  U[        R
                  R                  UU5        Uc  / nU R                  R                  UR                  5       R                  5       UUR                  5       UUS9nU R                  R                  U5      $ )a  Creates a rollout resource.

Args:
  rollout_ref: protorpc.messages.Message, rollout resource object.
  rollout_obj: apitools.base.protorpclite.messages.Message, rollout message.
  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.
  starting_phase_id: a str that specifies the rollout starting phase.
  override_deploy_policies: List of Deploy Policies to override.

Returns:
  The operation message.
zCreating rollout: %r)r)   rollout	rolloutIdstartingPhaseIdr   )r	   debugr   SetMetadatar   ResourceTypeROLLOUTJClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsCreateRequestParentRelativeNameNamer   Create)r   rollout_refrollout_objannotationslabelsstarting_phase_idr!   r"   s           r   rF   RolloutClient.Creater   s    4 II$k2  ((  '!#mmff!!#002""$)5 g G ==((r   c           	          Uc  / nU R                   R                  UU R                   R                  UUUS9S9nU R                  R	                  U5      $ )a  Calls the retryjob API to retry a job on a rollout.

Args:
  name: Name of the Rollout. Format is
    projects/{project}/locations/{location}/deliveryPipelines/{deliveryPipeline}/releases/{release}/rollouts/{rollout}.
  job: The job id on the rollout resource.
  phase: The phase id on the rollout resource.
  override_deploy_policies: List of Deploy Policies to override.

Returns:
  RetryJobResponse message.
jobIdphaseIdr   )r;   retryJobRequest)r   LClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsRetryJobRequestRetryJobRequestr   RetryJobr   r   jobphaser!   r"   s         r   rT   RolloutClient.RetryJob   sd    &  '!#mmhh55!9 6 
 i G ==!!'**r   c                     Uc  / nU R                   R                  UU R                   R                  UUS9S9nU R                  R	                  U5      $ )a  Calls the AdvanceRollout API to advance a rollout to the next phase.

Args:
  name: Name of the Rollout. Format is
    projects/{project}/locations/{location}/deliveryPipelines/{deliveryPipeline}/releases/{release}/rollouts/{rollout}.
  phase: The phase id on the rollout resource.
  override_deploy_policies: List of Deploy Policies to override.

Returns:
  AdvanceRolloutResponse message.
)rP   r   )r   advanceRolloutRequest)r   KClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsAdvanceRequestAdvanceRolloutRequestr   Advance)r   r   rW   r!   r"   s        r   AdvanceRolloutRolloutClient.AdvanceRollout   sb    "  '!#mmgg"mmAA!9 B 
 h G ==  ))r   c                     Uc  / nU R                   R                  UU R                   R                  US9S9nU R                  R	                  U5      $ )aC  Calls the CancelRollout API to cancel a rollout.

Args:
  name: Name of the Rollout. Format is
    projects/{project}/locations/{location}/deliveryPipelines/{deliveryPipeline}/releases/{release}/rollouts/{rollout}.
  override_deploy_policies: List of Deploy Policies to override.

Returns:
  CancelRolloutResponse message.
)r   )r   cancelRolloutRequest)r   JClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsCancelRequestCancelRolloutRequestr   Cancel)r   r   r!   r"   s       r   CancelRolloutRolloutClient.CancelRollout   s_      '!#mmff!]]??!9 @ 
 g G ==((r   c           	          Uc  / nU R                   R                  UU R                   R                  UUUS9S9nU R                  R	                  U5      $ )a  Calls the IgnoreJob API to ignore a job on a rollout within a specified phase.

Args:
  name: Name of the Rollout. Format is
    projects/{project}/locations/{location}/deliveryPipelines/{deliveryPipeline}/releases/{release}/rollouts/{rollout}.
  job: The job id on the rollout resource.
  phase: The phase id on the rollout resource.
  override_deploy_policies: List of Deploy Policies to override.

Returns:
  IgnoreJobResponse message.
rN   )r;   ignoreJobRequest)r   MClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsIgnoreJobRequestIgnoreJobRequestr   	IgnoreJobrU   s         r   rk   RolloutClient.IgnoreJob   sd      '!#mmii77!9 8 
 j G ==""7++r   )r   r   r   )NN)N)NNNN)__name__
__module____qualname____firstlineno____doc__r   r    r&   r8   rF   rT   r^   re   rk   __static_attributes__ r   r   r   r      s[    ;*.&" J #,)f  $+H  $	*:),,r   r   N)rq   
__future__r   r   r   apitools.base.pyr   "googlecloudsdk.api_lib.clouddeployr   !googlecloudsdk.command_lib.deployr   googlecloudsdk.corer	   objectr   rs   r   r   <module>rz      s-    9 &  ' ' : 9 #o,F o,r   