
    ;                        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 dd	lmZ dd
lmZ dZdZdZej&                  j(                  dej&                  j*                  diZej&                  j*                  fdZej&                  j*                  dfdZd Zd Zd Z	 d"dZd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%	 d#d Z&y!)$zUtilities for the Config API.    )absolute_import)division)unicode_literals)encoding)apis)waiter)base)	resources)progress_trackerconfigi'  iˤ v1alpha2v1c                 D    t        j                  t        t        |          S )zReturns the messages module for Config API.

  Args:
    release_track: The desired value of the enum
      googlecloudsdk.calliope.base.ReleaseTrack.

  Returns:
    Module containing the definitions of messages for Config API.
  )r   GetMessagesModule	_API_NAMERELEASE_TRACK_TO_API_VERSION)release_tracks    >lib/googlecloudsdk/api_lib/infra_manager/configmanager_util.pyr   r   *   s"     
		-m<
     Tc                 J    t        j                  t        t        |    |       S )a$  Returns an instance of the Config client.

  Args:
    release_track: The desired value of the enum
      googlecloudsdk.calliope.base.ReleaseTrack.
    use_http: bool, True to create an http object for this client.

  Returns:
    base_api.BaseApiClient, An instance of the Config client.
  )no_http)r   GetClientInstancer   r   )r   use_https     r   r   r   9   s'     
		"=1|
 r   c                     t               }|j                  }|j                  j                  |j	                  |             S )a   Calls into the GetDeployment API.

  Args:
    name: the fully qualified name of the deployment, e.g.
      "projects/p/locations/l/deployments/d".

  Returns:
    A messages.Deployment.

  Raises:
    HttpNotFoundError: if the deployment doesn't exist.
  name)r   MESSAGES_MODULEprojects_locations_deploymentsGet,ConfigProjectsLocationsDeploymentsGetRequest)r   clientmessagess      r   GetDeploymentr#   K   sA     &##(		.	.	2	2;;;F
 r   c                     t               }|j                  }|j                  j                  |j	                  || |            S )a  Calls into the CreateDeployment API.

  Args:
    deployment: a messages.Deployment resource (containing properties like the
      blueprint).
    deployment_id: the ID of the deployment, e.g. "my-deployment" in
      "projects/p/locations/l/deployments/my-deployment".
    location: the location in which to create the deployment.

  Returns:
    A messages.OperationMetadata representing a long-running operation.
  )parent
deploymentdeploymentId)r   r   r   Create/ConfigProjectsLocationsDeploymentsCreateRequest)r&   deployment_idlocationr!   r"   s        r   CreateDeploymentr,   _   sJ     &##(		.	.	5	5>>j} ? 
 r   c                     t               }|j                  }|j                  j                  |j	                  | |d            S )a+  Calls into the UpdateDeployment API.

  Args:
    deployment: a messages.Deployment resource (containing properties like the
      blueprint).
    deployment_full_name: the fully qualified name of the deployment.

  Returns:
    A messages.OperationMetadata representing a long-running operation.
  N)r&   r   
updateMask)r   r   r   Patch.ConfigProjectsLocationsDeploymentsPatchRequest)r&   deployment_full_namer!   r"   s       r   UpdateDeploymentr2   u   sK     &##(		.	.	4	4==&:t > 
 r   c           	        	 t               }t        j                  j                  | j                  d      }t        j                  |j                  |j                        	d	_	        	fd}	fd}dj                  |      }t        j                  |||      }t        j                  	||||t        t              }|S )	a0  Waits for the given "apply deployment" LRO to complete.

  Args:
    operation: the operation to poll.
    progress_message: string to display for default progress_tracker.

  Raises:
    apitools.base.py.HttpError: if the request returns an HTTP error.

  Returns:
    A messages.Deployment resource.
  $config.projects.locations.operations
collection c                 t   t               }t        j                  |j                        }t        j                  |j
                  |      j                  }d}d}||j                  }|j                  }||dj                  |      _
        n||dj                  ||      _
        | j                          ya   Updates the progress tracker with the result of the operation.

    Args:
      tracker: The ProgressTracker for the operation.
      result: the operation poll result.
      unused_status: map of stages with key as stage key (string) and value is
        the progress_tracker.Stage.
    r7   Nz	logs={0} zlogs={0}, step={1} )r   r   MessageToJsonmetadataJsonToMessageOperationMetadatadeploymentMetadatalogsstepformatdetailed_messageTick)	trackerresultunused_statusr"   json_valdeployment_metadatar?   r@   pollers	           r   TrackerUpdateFuncz:WaitForApplyDeploymentOperation.<locals>.TrackerUpdateFunc   s     !"H %%foo6H"00""H  DD& %%d %%dDL + 2 24 8f		d. 5 < <T4 HfLLNr   c                       j                   S zLReturns the detailed progress message to be updated on the progress tracker.rB   rI   s   r   DetailMessageCallbackz>WaitForApplyDeploymentOperation.<locals>.DetailMessageCallback        """r   !Aborting wait for operation {0}.
messagedetail_message_callbackaborted_messagecustom_trackertracker_update_funcmax_wait_mswait_ceiling_ms)r   r
   REGISTRYParseRelativeNamer   r   CloudOperationPollerr   projects_locations_operationsrB   rA   r   ProgressTrackerWaitFor_MAX_WAIT_TIME_MS_WAIT_CEILING_MS
	operationprogress_messager!   operation_refrJ   rO   rU   rW   rE   rI   s
            @r   WaitForApplyDeploymentOperationrg      s     &$$66nn!G 7 - &&++**&
 &>#
 9??N/#333%. >>#+#&& 
-r   c                     t               }|j                  }|j                  j                  |j	                  | |            S )a  Calls ImportStateFile API.

  Args:
    import_state_file_request: a messages.ImportStateFileRequest.
    deployment_id: the ID of the deployment, e.g. "my-deployment" in
      "projects/p/locations/l/deployments/my-deployment".

  Returns:
    (Statefile) The response message.
  )importStatefileRequestr%   )r   r   r   ImportState4ConfigProjectsLocationsDeploymentsImportStateRequest)import_state_file_requestr*   r!   r"   s       r   ImportStateFilerm      sI     &##(		.	.	:	:CC!:= D 
 r   c                     t               }|j                  }|j                  j                  |j	                  | |            S )a_  Calls ExportDeploymentStateFile API.

  Args:
    export_deployment_state_file_request: A ExportDeploymentStatefileRequest
      resource to be passed as the request body.
    deployment_id: the ID of the deployment, e.g. "my-deployment" in
      "projects/p/locations/l/deployments/my-deployment".

  Returns:
    (Statefile) The response message.
  ) exportDeploymentStatefileRequestr%   )r   r   r   ExportState4ConfigProjectsLocationsDeploymentsExportStateRequest)$export_deployment_state_file_requestr*   r!   r"   s       r   ExportDeploymentStateFilers      sJ     &##(		.	.	:	:CC+O D 
 r   c                     t               }|j                  }|j                  j                  |j	                  | |            S )ad  Calls ExportDeploymentRevisionsStateFile API.

  Args:
    export_revision_state_file_request: A ExportRevisionStatefileRequest
      resource to be passed as the request body.
    deployment_id: the ID of the deployment, e.g. "my-deployment" in
      "projects/p/locations/l/deployments/my-deployment".

  Returns:
    (Statefile) The response message.
  )exportRevisionStatefileRequestr%   )r   r   (projects_locations_deployments_revisionsrp   =ConfigProjectsLocationsDeploymentsRevisionsExportStateRequest)"export_revision_state_file_requestr*   r!   r"   s       r   ExportRevisionStateFilery   	  sJ     &##(		8	8	D	DLL)K M 
 r   c                     t               }|j                  }|j                  j                  |j	                  |             S )zCalls ExportLock API.

  Args:
    deployment_full_name: string, the fully qualified name of the deployment,
      e.g. "projects/p/locations/l/deployments/d".

  Returns:
    A lock info response.
  r   )r   r   r   
ExportLock3ConfigProjectsLocationsDeploymentsExportLockRequestr1   r!   r"   s      r   r{   r{   #  sG     &##(		.	.	9	9BB# C 
 r   c                     t               }|j                  }|j                  j                  |j	                  | |            S )a;  Calls deployment Lock API.

  Args:
    lock_deployment_request: A LockDeploymentRequest resource to be passed as
      the request body
    deployment_full_name: the ID of the deployment, e.g. "my-deployment" in
      "projects/p/locations/l/deployments/my-deployment".

  Returns:
    A long running operation.
  )lockDeploymentRequestr   )r   r   r   Lock-ConfigProjectsLocationsDeploymentsLockRequest)lock_deployment_requestr1   r!   r"   s       r   LockDeploymentr   7  sI     &##(		.	.	3	3<< 7# = 
 r   c                     t               }|j                  }|j                  j                  |j	                  | |            S )aH  Calls deployment Unlock API.

  Args:
    unlock_deployment_request: A UnlockDeploymentRequest resource to be passed
      as the request body
    deployment_full_name: the ID of the deployment, e.g. "my-deployment" in
      format "projects/p/locations/l/deployments/my-deployment".

  Returns:
    A long running operation.
  )unlockDeploymentRequestr   )r   r   r   Unlock/ConfigProjectsLocationsDeploymentsUnlockRequest)unlock_deployment_requestr1   r!   r"   s       r   UnlockDeploymentr   Q  sI     &##(		.	.	5	5>>";# ? 
 r   c                     t               }|j                  }|j                  j                  |j	                  |             S )a+  Lists all revisions for a deployment.

  Args:
    deployment_full_name: the fully qualified name of the deployment, e.g.
      "projects/p/locations/l/deployments/d".

  Returns:
    (ListRevisionsResponse) The response message.

  Raises:
    HttpNotFoundError: if the deployment doesn't exist.
  )r%   )r   r   rv   List6ConfigProjectsLocationsDeploymentsRevisionsListRequestr}   s      r   ListRevisionsr   k  sG     &##(		8	8	=	=EE% F 
 r   c                     t               }|j                  }|j                  j                  |j	                  | |            S )a=  Calls ExportPreviewResult API.

  Args:
    export_preview_result_request: A ExportPreviewResultRequest
      resource to be passed as the request body.
    preview_id: the ID of the preview, e.g. "my-preview" in
      "projects/p/locations/l/previews/my-preview".

  Returns:
    (Statefile) The response message.
  )exportPreviewResultRequestr%   )r   r   projects_locations_previewsExport,ConfigProjectsLocationsPreviewsExportRequest)export_preview_result_request
preview_idr!   r"   s       r   ExportPreviewResultr     sI     &##(		+	+	2	2;;%B < 
 r   c                     t               }|j                  }|j                  j                  |j	                  || |            S )a  Calls into the CreatePreview API.

  Args:
    preview: a messages.Preview resource (containing properties like the
      blueprint).
    preview_id: the ID of the preview, e.g. "my-preview" in
      "projects/p/locations/l/previews/my-preview".
    location: the location in which to create the preview.

  Returns:
    A messages.OperationMetadata representing a long-running operation.
  )r%   preview	previewId)r   r   r   r(   ,ConfigProjectsLocationsPreviewsCreateRequest)r   r   r+   r!   r"   s        r   CreatePreviewr     sJ     &##(		+	+	2	2;;7j < 
 r   c           	        	 t               }t        j                  j                  | j                  d      }t        j                  |j                  |j                        	d	_	        	fd}	fd}dj                  |      }t        j                  |||      }t        j                  	||||t        t              }|S )	a+  Waits for the given "create preview" LRO to complete.

  Args:
    operation: the operation to poll.
    progress_message: string to display for default progress_tracker.

  Raises:
    apitools.base.py.HttpError: if the request returns an HTTP error.

  Returns:
    A messages.Preview resource.
  r4   r5   r7   c                 t   t               }t        j                  |j                        }t        j                  |j
                  |      j                  }d}d}||j                  }|j                  }||dj                  |      _
        n||dj                  ||      _
        | j                          yr9   )r   r   r:   r;   r<   r=   previewMetadatar?   r@   rA   rB   rC   )	rD   rE   rF   r"   rG   preview_metadatar?   r@   rI   s	           r   rJ   z8WaitForCreatePreviewOperation.<locals>.TrackerUpdateFunc  s     !"H %%foo6H--""Ho  DD#""d""dDL + 2 24 8f		d. 5 < <T4 HfLLNr   c                       j                   S rL   rM   rN   s   r   rO   z<WaitForCreatePreviewOperation.<locals>.DetailMessageCallback  rP   r   rQ   rR   rV   )r   r
   r[   r\   r   r   r]   r   r^   rB   rA   r   r_   r`   ra   rb   rc   s
            @r   WaitForCreatePreviewOperationr     s     &$$66nn!G 7 - &&((**&
 &>#
 9??N/#333%. >>#+#&& 
-r   N)zApplying the deployment)zCreating the preview)'__doc__
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper	   googlecloudsdk.corer
   googlecloudsdk.core.consoler   r   rb   ra   ReleaseTrackALPHAGAr   r   r   r#   r,   r2   rg   rm   rs   ry   r{   r   r   r   r   r   r    r   r   <module>r      s    $ &  ' % , . ( ) 8	   '  	Z$   %)$5$5$8$8  %)$5$5$8$84 $(,* !:Nb*44(44,4. !7Nr   