
    N                     f    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	\5      rg
)z!Apphub Application Workloads API.    )
list_pager)consts)utils)waiter)base)logc                   x    \ rS rSrSr\R                  R                  4S jrS r	  SS jr
S rS rS	 rS
 rSrg)WorkloadsClient   z/Client for Application workloads in apphub API.c                 x   [         R                  " U5      U l        [         R                  " U5      U l        U R                  R
                  U l        [        R                  " U R                  U R                  R                  5      U l
        [        R                  " U R                  R                  5      U l        g )N)api_lib_utilsGetClientInstanceclientGetMessagesModulemessages)projects_locations_applications_workloads_app_workloads_clientr   CloudOperationPollerprojects_locations_operations_pollerCloudOperationPollerNoResources_delete_poller)selfrelease_tracks     ;lib/googlecloudsdk/api_lib/apphub/applications/workloads.py__init__WorkloadsClient.__init__   s    11-@DK!33MBDM== 	 ..""11DL !@@11D    c                 j    U R                   R                  US9nU R                  R                  U5      $ )zDescribe a Application Workload in the Project/location.

Args:
  workload: str, the name for the workload being described.

Returns:
  Described workload Resource.
name)r   6ApphubProjectsLocationsApplicationsWorkloadsGetRequestr   Get)r   workloaddescribe_reqs      r   DescribeWorkloadsClient.Describe+   s=     	LL 	M 	
 
 %%)),77r   Nc           	      z    U R                   R                  US9n[        R                  " U R                  USUUSS9$ )a  List application workloads in the Projects/Location.

Args:
  parent: str,
    projects/{projectId}/locations/{location}/applications/{application}
  limit: int or None, the total number of results to return. Default value
    is None
  page_size: int, the number of entries in each batch (affects requests
    made, but not the yielded results). Default value is 100.

Returns:
  Generator of matching application workloads.
)parent	workloadspageSize)field
batch_sizelimitbatch_size_attribute)r   7ApphubProjectsLocationsApplicationsWorkloadsListRequestr   YieldFromListr   )r   r)   r.   	page_sizelist_reqs        r   ListWorkloadsClient.List;   sQ    ( 	MM 	N 	
 
 ##""' r   c                 &   U R                   R                  US9nU R                  R                  U5      nU(       a  U$ [        R
                  " U R                  U[        R                  R                  [        R                  R                  5      nU$ )a  Delete a application workload in the Project/location.

Args:
  workload: str, the name for the workload being deleted
  async_flag: Boolean value for async operation. If true the operation will
    be async

Returns:
  Empty Response Message or Operation based on async flag value.
r    )r   9ApphubProjectsLocationsApplicationsWorkloadsDeleteRequestr   Deleter   WaitForOperationr   api_lib_constsDeleteApplicationWorkloadWAIT_FOR_DELETE_MESSAGEDELETE_TIMELIMIT_SEC)r   r$   
async_flag
delete_req	operationdelete_responses         r   r8   WorkloadsClient.Delete\   s     	OO 	P 	
 
 **11*=I#4400HH00EE	O r   c                 `   U R                   R                  UUUUS9nU R                   R                  XUS9n	U R                  R	                  U	5      n
U(       a  U
$ [
        R                  " U R                  U
[        R                  R                  [        R                  R                  5      nU$ )a  Creates an application in the Project/location.

Args:
  workload_id: str, Workload ID
  parent: parent for Application resource
  async_flag: Boolean value for async operation. If true the operation will
    be async
  discovered_workload: str, Discovered workload name
  display_name: str, Human-friendly display name
  description: str, Description of the Workload
  attributes: Attributes, Attributes of the Workload

Returns:
  Workload or Operation based on async flag value.
)descriptiondisplayNamediscoveredWorkload
attributes)r$   
workloadIdr)   )r   Workload9ApphubProjectsLocationsApplicationsWorkloadsCreateRequestr   Creater   r9   r   r:   CreateApplicationWorkloadWAIT_FOR_CREATE_MESSAGECREATE_TIMELIMIT_SEC)r   workload_idr)   r>   discovered_workloaddisplay_namerD   rG   r$   
create_reqr@   create_responses               r   rK   WorkloadsClient.Createz   s    2 }}%% .	 & H 	OOf 	P 	
 
 **11*=I#4400HH00EE	O r   c                    U R                  XC5      u  pVU(       d8  [        R                  R                  [        R
                  R                  5        gU R                  R                  UUUS9nU R                  R                  U5      nU(       a  U$ [        R                  " U R                  U[        R
                  R                  [        R
                  R                  5      n	U	$ )zUpdate application workload.N)r!   r$   
updateMask)_UpdateHelperr   statusPrintr:   UpdateApplicationWorkloadEMPTY_UPDATE_HELP_TEXTr   8ApphubProjectsLocationsApplicationsWorkloadsPatchRequestr   Patchr   r9   r   WAIT_FOR_UPDATE_MESSAGEUPDATE_TIMELIMIT_SEC)
r   rO   r>   rG   argsr$   update_maskupdate_requestr@   update_responses
             r   UpdateWorkloadsClient.Update   s     ..t@H	jj

2
2
I
I  	NN" 	O 	
  **00@I#4400HH00EE	O r   c                    U R                   R                  5       nSnUR                  (       a@  [        R                  " U[
        R                  R                  5      nUR                  Ul        UR                  (       a@  [        R                  " U[
        R                  R                  5      nUR                  Ul	        UR                  (       a/  [        R                  " U[
        R                  R                  5      nUR                  (       a/  [        R                  " U[
        R                  R                  5      nUR                  (       a/  [        R                  " U[
        R                  R                   5      nUR"                  (       a/  [        R                  " U[
        R                  R$                  5      nUR&                  (       a/  [        R                  " U[
        R                  R(                  5      nX#l        X44$ )zFHelper to generate workload and update_mask fields for update_request. )r   rI   rQ   r   AddToUpdateMaskr:   rZ   #UPDATE_MASK_DISPLAY_NAME_FIELD_NAMErE   rD   "UPDATE_MASK_DESCRIPTION_FIELD_NAMEcriticality'UPDATE_MASK_ATTR_CRITICALITY_FIELD_NAMEenvironment'UPDATE_MASK_ATTR_ENVIRONMENT_FIELD_NAMEbusinessOwners+UPDATE_MASK_ATTR_BUSINESS_OWNERS_FIELD_NAMEdeveloperOwners,UPDATE_MASK_ATTR_DEVELOPER_OWNERS_FIELD_NAMEoperatorOwners+UPDATE_MASK_ATTR_OPERATOR_OWNERS_FIELD_NAMErG   )r   r`   rG   r$   ra   s        r   rW   WorkloadsClient._UpdateHelper   s   }}%%'HK!11


2
2
V
Vk "..h!11


2
2
U
Uk "--h!11


2
2
Z
Zk !11


2
2
Z
Zk   !11


2
2
^
^k !!!11


2
2
_
_k   !11


2
2
^
^k
 %  r   )r   r   r   r   r   )Nd   )__name__
__module____qualname____firstlineno____doc__r   ReleaseTrackALPHAr   r&   r4   r8   rK   rd   rW   __static_attributes__ r   r   r
   r
      sA    7#'#4#4#:#: 8& 	B<1f>/!r   r
   N)r{   apitools.base.pyr   googlecloudsdk.api_lib.apphubr   r:   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.corer   objectr
   r   r   r   <module>r      s,    ( ( B @ . ( #a!f a!r   