
    x                         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	KJr  SS
KJr  SSKJr   " S S\5      rg)z1Support library to handle the deploy subcommands.    )absolute_import)division)unicode_literals)client_util)automation_util)custom_target_type_util)deploy_policy_util)manifest_util)target_util)logc                   :    \ rS rSrSrS
S jrS rS rS rS r	S	r
g)DeployClient   zHClient for managing Cloud Deploy delivery pipeline and target resources.Nc                     U=(       d    [         R                  " 5       U l        [         R                  " 5       U l        U=(       d    [         R
                  " U5      U l        U R                  R                  U l        g)zInitialize a deploy.DeployClient.

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OperationsClientoperation_clientGetMessagesModulemessages$projects_locations_deliveryPipelines_pipeline_service)selfr   r   s      0lib/googlecloudsdk/api_lib/clouddeploy/deploy.py__init__DeployClient.__init__!   sS     ;K99;DK'88:DE = =f EDM![[MMD    c                 x   [         R                  " U R                  X5      nSnU[         R                  R                      Vs0 s H  nUR
                  U R                  U5      _M!     nnU R                  R                  Xd5        U[         R                  R                      Vs0 s H$  nUR
                  [        R                  " U5      _M&     nnU R                  R                  Xd5        U[         R                  R                      Vs0 s H$  nUR
                  [        R                  " U5      _M&     nnU R                  R                  Xd5        U[         R                  R                      Vs0 s H$  nUR
                  [         R"                  " U5      _M&     nnU R                  R                  Xd5        U[         R                  R$                      Vs0 s H$  nUR
                  [&        R(                  " U5      _M&     nnU R                  R                  Xd5        gs  snf s  snf s  snf s  snf s  snf )zCreates Cloud Deploy resources.

Asynchronously calls the API then iterate the operations
to check the status.

Args:
 manifests: the list of parsed resource yaml definitions.
 region: location ID.
z"Created Cloud Deploy resource: {}.N)r
   ParseDeployConfigr   ResourceKindDELIVERY_PIPELINEnameCreateDeliveryPipeliner   CheckOperationStatusTARGETr   PatchTarget
AUTOMATIONr   PatchAutomationCUSTOM_TARGET_TYPEr   PatchCustomTargetTypeDEPLOY_POLICYr	   PatchDeployPolicy)r   	manifestsregionresource_dictmsg_templateresourceoperation_dicts          r   CreateResourcesDeployClient.CreateResources-   s    "33yM 8L &&&88

H 	t228<<
   	..~L &m&@&@&G&GHHH 	{..x88H   	..~L
 &m&@&@&K&KLLH 	66x@@L   	..~L
 &&&99

H 	.DDXNN
   	..~L
 &m&@&@&N&NOOH 	);;HEEO   	..~LGs   &H#%+H(+H-3+H2+H7c                    [         R                  " U R                  X5      nSnU[         R                  R                      Vs0 s H.  nUR
                  [        R                  " UR
                  5      _M0     nnU R                  R                  Xu5        U[         R                  R                      Vs0 s H.  nUR
                  [        R                  " UR
                  5      _M0     nnU R                  R                  Xu5        U[         R                  R                      Vs0 s H.  nUR
                  [        R                  " UR
                  5      _M0     nnU R                  R                  Xu5        U[         R                  R                       Vs0 s H  nUR
                  U R#                  Xc5      _M!     nnU R                  R                  Xu5        U[         R                  R$                      Vs0 s H.  nUR
                  [&        R(                  " UR
                  5      _M0     nnU R                  R                  Xu5        gs  snf s  snf s  snf s  snf s  snf )aP  Delete Cloud Deploy resources.

Asynchronously calls the API then iterate the operations
to check the status.

Args:
 manifests: [str], the list of parsed resource yaml definitions.
 region: str, location ID.
 force: bool, if true, the delivery pipeline with sub-resources will be
   deleted and its sub-resources will also be deleted.
z"Deleted Cloud Deploy resource: {}.N)r
   r   r   r    r%   r"   r   DeleteTargetr   r$   r)   r   DeleteCustomTargetTyper'   r   DeleteAutomationr!   DeleteDeliveryPipeliner+   r	   DeleteDeployPolicy)r   r-   r.   forcer/   r0   r1   r2   s           r   DeleteResourcesDeployClient.DeleteResources`   s4    "33yM 8L &m&@&@&G&GHHH 	{//>>H   	..~L &&&99
	
H 	.EEMM
 	

	   	..~L &m&@&@&K&KLLH 	77FFL   	..~L &&&88

H 	t228CC
   	..~L &m&@&@&N&NOOH 	)<<X]]KKO   	..~LEs   5I45I%5I&I85Ic           	          [         R                  " S[        U5      -   5        U R                  R	                  U R
                  R                  USUR                  [        R                  S95      $ )zCreates a delivery pipeline resource.

Args:
  pipeline_config: apitools.base.protorpclite.messages.Message, delivery
    pipeline message.

Returns:
  The operation message.
zCreating delivery pipeline: T)deliveryPipelineallowMissingr"   
updateMask)
r   debugreprr   Patchr   9ClouddeployProjectsLocationsDeliveryPipelinesPatchRequestr"   r
   PIPELINE_UPDATE_MASK)r   pipeline_configs     r   r#   #DeployClient.CreateDeliveryPipeline   sd     II,tO/DDE!!''OO, %%$99	 	P 	
 r   c                     [         R                  " S[        U5      -   5        U R                  R	                  U R
                  R                  SUR                  US95      $ )aZ  Deletes a delivery pipeline resource.

Args:
  pipeline_config: apitools.base.protorpclite.messages.Message, delivery
    pipeline message.
  force: if true, the delivery pipeline with sub-resources will be deleted
    and its sub-resources will also be deleted.

Returns:
  The operation message. It could be none if the resource doesn't exist.
zDeleting delivery pipeline: T)r@   r"   r;   )r   rB   rC   r   Deleter   :ClouddeployProjectsLocationsDeliveryPipelinesDeleteRequestr"   )r   rG   r;   s      r   r9   #DeployClient.DeleteDeliveryPipeline   sY     II,tO/DDE!!((PPO$8$8 	Q 	
 r   )r   r   r   r   )NN)__name__
__module____qualname____firstlineno____doc__r   r3   r<   r#   r9   __static_attributes__ r   r   r   r      s#    P
N1Mf2Mh(r   r   N)rQ   
__future__r   r   r   "googlecloudsdk.api_lib.clouddeployr   !googlecloudsdk.command_lib.deployr   r   r	   r
   r   googlecloudsdk.corer   objectr   rS   r   r   <module>rY      s6    8 &  ' : = E @ ; 9 #[6 [r   