
    #                     r    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ  G d	 d
e      Zy)z2Support library to handle the rollout subcommands.    )absolute_import)division)unicode_literals)
list_pager)client_util)deploy_util)logc                   j    e Zd ZdZddZddZd Z	 	 	 	 ddZ	 	 	 	 ddZ	 ddZ		 dd	Z
dd
ZddZy)RolloutClientz3Client for release service in the Cloud Deploy API.Nc                     |xs t        j                         | _        |xs t        j                  |      | _        | j                  j
                  | _        y)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__zRolloutClient.__init__   sD     ;K99;DKE = =f EDMJJ 	M    c                     |g }| j                   j                  || j                   j                  ||            }| j                  j	                  |      S )a  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   zRolloutClient.Approve,   sb      '!#mmgg"mmAA!9 B 
 h G ==  ))r   c                 p    | j                   j                  |      }| j                  j                  |      S )zpGets a rollout resource.

    Args:
      name: rollout resource name.

    Returns:
      rollout message.
    )r   )r   GClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsGetRequestr   Get)r   r   r    s      r   r#   zRolloutClient.GetC   s8     mmcc d G ==W%%r   c                     | j                   j                  |||      }t        j                  | j                  |d||d      S )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   ListzRolloutClient.ListQ   sP    * mmddJ e G ##' r   c                 v   t        j                  d|       t        j                  | j                  |t        j
                  j                  ||       |g }| j                  j                  |j                         j                         ||j                         ||      }| j                  j                  |      S )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   rA   zRolloutClient.Creater   s    4 II$k2  ((  '!#mmff!!#002""$)5 g G ==((r   c                     |g }| j                   j                  || j                   j                  |||            }| j                  j	                  |      S )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   )r6   retryJobRequest)r   LClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsRetryJobRequestRetryJobRequestr   RetryJobr   r   jobphaser   r    s         r   rN   zRolloutClient.RetryJob   sd    &  '!#mmhh55!9 6 
 i G ==!!'**r   c                     |g }| j                   j                  || j                   j                  ||            }| j                  j	                  |      S )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.
    )rJ   r   )r   advanceRolloutRequest)r   KClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsAdvanceRequestAdvanceRolloutRequestr   Advance)r   r   rQ   r   r    s        r   AdvanceRolloutzRolloutClient.AdvanceRollout   sb    "  '!#mmgg"mmAA!9 B 
 h G ==  ))r   c                     |g }| j                   j                  || j                   j                  |            }| j                  j	                  |      S )a_  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   CancelRolloutzRolloutClient.CancelRollout   s_      '!#mmff!]]??!9 @ 
 g G ==((r   c                     |g }| j                   j                  || j                   j                  |||            }| j                  j	                  |      S )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.
    rH   )r6   ignoreJobRequest)r   MClouddeployProjectsLocationsDeliveryPipelinesReleasesRolloutsIgnoreJobRequestIgnoreJobRequestr   	IgnoreJobrO   s         r   rb   zRolloutClient.IgnoreJob   sd      '!#mmii77!9 8 
 j G ==""7++r   )NN)N)NNNN)__name__
__module____qualname____doc__r   r   r#   r4   rA   rN   rW   r]   rb    r   r   r   r      s[    ;*.&" J #,)f  $+H  $	*:),,r   r   N)rf   
__future__r   r   r   apitools.base.pyr   "googlecloudsdk.api_lib.clouddeployr   !googlecloudsdk.command_lib.deployr   googlecloudsdk.corer	   objectr   rg   r   r   <module>rn      s-    9 &  ' ' : 9 #o,F o,r   