
    I%                         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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)zYAllows you to write surfaces in terms of logical Cloud Run V2 WorkerPools API operations.    )absolute_import)division)print_function)unicode_literals)
exceptions)metric_names)base)stages)deployer)config_changes)metrics)progress_trackerworker_poolc            
           e Zd ZdZd Zd Zd Zd Zej                  j                  dddddddddf
dZd	 Zd
 Zd Zd Zy)WorkerPoolsOperationszHClient used to communicate with the actual Cloud Run V2 WorkerPools API.c                     || _         y )N)_client)selfclients     @lib/googlecloudsdk/command_lib/run/v2/worker_pools_operations.py__init__zWorkerPoolsOperations.__init__%   s	    DL    c                 ^   | j                   j                  }| j                   j                  j                  |j	                               }	 t        j                  t        j                        5  |j                  |      cddd       S # 1 sw Y   yxY w# t        j                  $ r Y yw xY w)zGet the WorkerPool.

    Args:
      worker_pool_ref: Resource, WorkerPool to get.

    Returns:
      A WorkerPool object.
    nameN)r   workertypesGetWorkerPoolRequestRelativeNamer   RecordDurationr   GET_WORKER_POOLget_worker_poolr   NotFound)r   worker_pool_refworker_poolsget_requests       r   GetWorkerPoolz#WorkerPoolsOperations.GetWorkerPool(   s     <<&&L,,$$99))+ : K!!,">">?++K8 @?? 0   #B /B
 	B 
BB B B,+B,c                 ^   | j                   j                  }| j                   j                  j                  |j	                               }	 t        j                  t        j                        5  |j                  |      cddd       S # 1 sw Y   yxY w# t        j                  $ r Y yw xY w)zDelete the WorkerPool.

    Args:
      worker_pool_ref: Resource, WorkerPool to delete.

    Returns:
      A LRO for delete operation.
    r   N)r   r   r   DeleteWorkerPoolRequestr    r   r!   r   DELETE_WORKER_POOLdelete_worker_poolr   r$   )r   r%   r&   delete_requests       r   DeleteWorkerPoolz&WorkerPoolsOperations.DeleteWorkerPool;   s     <<&&L\\''??))+ @ N!!,"A"AB..~> CBB r)   c                 *   | j                   j                  }| j                   j                  j                  |j	                               }t        j                  t        j                        5  |j                  |      cddd       S # 1 sw Y   yxY w)zList the WorkerPools in a region.

    Args:
      region_ref: Resource, Region to get the list of WorkerPools from.

    Returns:
      A list of WorkerPool objects.
    parentN)
r   r   r   ListWorkerPoolsRequestr    r   r!   r   LIST_WORKER_POOLSlist_worker_pools)r   
region_refr&   list_requests       r   ListWorkerPoolsz%WorkerPoolsOperations.ListWorkerPoolsN   so     <<&&L<<%%<<&&( = L 
		 > >	?++L9 
@	?	?   .B		BNFc                 "   |1t        j                  t        j                  |du|
du      dd      }|Wt	        j
                  |||||
|||j                  |	      \  }}}}}|y|j                  t        j                  |	d|             |d}n)|r| j                  |      }n|xs | j                  |      }t        j                  }|4t        j                  |j                               }t        j                   }t        j"                  ||      }| j$                  j&                  }| j$                  j(                  j+                  |d|      }t-        j.                  |      5  |j1                  |      cddd       S # 1 sw Y   yxY w)	a  Stubbed method for worker pool deploy surface.

    Update the WorkerPool if it exists, otherwise create it (Upsert).

    Args:
      worker_pool_ref: WorkerPool reference containing project, location,
        workerpool IDs.
      config_changes: list, objects that implement Adjust().
      release_track: ReleaseTrack, the release track of a command calling this.
      tracker: StagedProgressTracker, used to track progress.
      prefetch: the worker pool, pre-fetched for ReleaseWorkerPool. `False`
        indicates the caller did not perform a prefetch; `None` indicates a
        nonexistent worker pool.
      build_image: The build image reference to the build.
      build_pack: The build pack reference to the build.
      build_source: The build source reference to the build.
      build_from_source_container_name: The name of the container to be deployed
        from source.
      repo_to_create: Optional
        googlecloudsdk.command_lib.artifacts.docker_util.DockerRepo defining a
        repository to be created.
      already_activated_services: bool. If true, skip activation prompts for
        services
      force_new_revision: bool to force a new revision to be created.

    Returns:
      A WorkerPool object.
    N)include_buildinclude_create_repoTaborted)interruptableaborted_message)container_namenon_ingress_typeimage_digestr   )r   allow_missingforce_new_revision)r   NoOpStagedProgressTrackerr
   WorkerPoolStagesr   CreateImagelocationsIdappendconfig_changes_modAddDigestToImageChanger(   r   UPDATE_WORKER_POOLworker_pool_objects
WorkerPoolr    CREATE_WORKER_POOLWithChangesr   r   r   UpdateWorkerPoolRequestr   r!   update_worker_pool)r   r%   r   release_tracktrackerprefetchbuild_image
build_packbuild_source build_from_source_container_namerepo_to_createalready_activated_servicesrD   rB   _r   metric_namer&   upsert_requests                      r   ReleaseWorkerPoolz'WorkerPoolsOperations.ReleaseWorkerPool_   s   V  ::

!
!(4"0"< #g  








$

%
%






 
	

3
3=#' k	 &&7kC 2 2? Ck11K'22++-k !33k$00nMK<<&&L\\''??- @ N
 
			,,,^< 
-	,	,s   *FFc                    | j                  |      }|.t        j                  dj                  |j                              t        j                  ||      }| j                  j                  }| j                  j                  j                  |      }t        j                  t        j                        5  |j                  |      cddd       S # 1 sw Y   yxY w)z*Update the instance split of a WorkerPool.Nz#WorkerPool [{}] could not be found.r   )r(   r   r$   formatworkerPoolsIdrJ   rP   r   r   r   rQ   r   r!   r   rL   rR   )r   r%   r   r   r&   update_requests         r   UpdateInstanceSplitz)WorkerPoolsOperations.UpdateInstanceSplit   s     $$_5K
/
6
6++ 
 %00nMK<<&&L\\''?? @ N 
		 ? ?	@,,^< 
A	@	@s   7CCc                 ^   | j                   j                  }| j                   j                  j                  |j	                               }	 t        j                  t        j                        5  |j                  |      cddd       S # 1 sw Y   yxY w# t        j                  $ r Y yw xY w)zGet the Revision.

    Args:
      worker_pool_revision_ref: Resource, Revision to get.

    Returns:
      A Revision object.
    r   N)r   	revisionsr   GetRevisionRequestr    r   r!   r   GET_WORKER_POOL_REVISIONget_revisionr   r$   )r   worker_pool_revision_refworker_pool_revisionsr'   s       r   GetRevisionz!WorkerPoolsOperations.GetRevision   s     !LL22,,$$77%224 8 K!!,"G"GH$11+> IHH r)   c                 ^   | j                   j                  }| j                   j                  j                  |j	                               }	 t        j                  t        j                        5  |j                  |      cddd       S # 1 sw Y   yxY w# t        j                  $ r Y yw xY w)zDelete the Revision.

    Args:
      worker_pool_revision_ref: Resource, Revision to delete.

    Returns:
      A LRO for delete operation.
    r   N)r   rf   r   DeleteRevisionRequestr    r   r!   r   DELETE_WORKER_POOL_REVISIONdelete_revisionr   r$   )r   rj   rk   r.   s       r   DeleteRevisionz$WorkerPoolsOperations.DeleteRevision   s     !LL22\\''==%224 > N!!,"J"JK$44^D LKK r)   c                 *   | j                   j                  }| j                   j                  j                  |j	                               }t        j                  t        j                        5  |j                  |      cddd       S # 1 sw Y   yxY w)zList the Revisions in a region under the given WorkerPool.

    Args:
      worker_pool_ref: Resource, WorkerPool to get the list of Revisions from.

    Returns:
      A list of Revision objects.
    r1   N)
r   rf   r   ListRevisionsRequestr    r   r!   r   LIST_WORKER_POOL_REVISIONSlist_revisions)r   r%   rk   r7   s       r   ListRevisionsz#WorkerPoolsOperations.ListRevisions  sp     !LL22<<%%::++- ; L 
		 G G	H"11,? 
I	H	Hr9   )__name__
__module____qualname____doc__r   r(   r/   r8   r	   ReleaseTrackALPHAr_   rd   rl   rq   rv    r   r   r   r   "   sa    P&&:* %%++'+!&k=Z=*&&@r   r   N)rz   
__future__r   r   r   r   google.api_corer   googlecloudsdk.api_lib.runr   googlecloudsdk.callioper	   googlecloudsdk.command_lib.runr
   ,googlecloudsdk.command_lib.run.sourcedeploysr   !googlecloudsdk.command_lib.run.v2r   rJ   googlecloudsdk.corer   googlecloudsdk.core.consoler   ;googlecloudsdk.generated_clients.gapic_clients.run_v2.typesr   rM   objectr   r}   r   r   <module>r      sD    ` '  % ' & 3 ( 1 A R ' 8 jt@F t@r   