
                             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  G d de      Zy)z!Apphub Application Workloads API.    )absolute_import)division)unicode_literals)
list_pager)consts)utils)waiter)base)logc                   l    e Zd ZdZej
                  j                  fdZd Z	 	 d
dZ	d Z
d Zd Zd	 Zy)WorkloadsClientz/Client for Application workloads in apphub API.c                 p   t        j                  |      | _        t        j                  |      | _        | j                  j
                  | _        t        j                  | j                  | j                  j                        | _
        t        j                  | j                  j                        | _        y )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__zWorkloadsClient.__init__    s    11-@DK!33MBDM== 	 ..""11DL !@@11D    c                 p    | j                   j                  |      }| j                  j                  |      S )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   DescribezWorkloadsClient.Describe.   s=     	LL 	M 	
 
 %%)),77r   Nc                     | j                   j                  |      }t        j                  | j                  |d||d      S )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   ListzWorkloadsClient.List>   sQ    ( 	MM 	N 	
 
 ##""' r   c                     | j                   j                  |      }| j                  j                  |      }|r|S t	        j
                  | j                  |t        j                  j                  t        j                  j                        }|S )a7  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   r7   zWorkloadsClient.Delete_   s     	OO 	P 	
 
 **11*=I#4400HH00EE	O r   c                 b   | j                   j                  ||||      }| j                   j                  |||      }	| j                  j	                  |	      }
|r|
S t        j                  | j                  |
t        j                  j                  t        j                  j                        }|S )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   r8   r   r9   CreateApplicationWorkloadWAIT_FOR_CREATE_MESSAGECREATE_TIMELIMIT_SEC)r   workload_idr)   r=   discovered_workloaddisplay_namerB   rE   r%   
create_reqr?   create_responses               r   rI   zWorkloadsClient.Create}   s    2 }}%% .	 & H 	OO+f 	P 	
 
 **11*=I#4400HH00EE	O r   c                    | j                  ||      \  }}|s8t        j                  j                  t        j
                  j                         y| j                  j                  |||      }| j                  j                  |      }|r|S t        j                  | j                  |t        j
                  j                  t        j
                  j                        }	|	S )zUpdate application workload.N)r"   r%   
updateMask)_UpdateHelperr   statusPrintr9   UpdateApplicationWorkloadEMPTY_UPDATE_HELP_TEXTr   8ApphubProjectsLocationsApplicationsWorkloadsPatchRequestr   Patchr   r8   r   WAIT_FOR_UPDATE_MESSAGEUPDATE_TIMELIMIT_SEC)
r   rM   r=   rE   argsr%   update_maskupdate_requestr?   update_responses
             r   UpdatezWorkloadsClient.Update   s     ..tZ@Hk	jj

2
2
I
I  	NN" 	O 	
  **00@I#4400HH00EE	O r   c                    | j                   j                         }d}|j                  r?t        j                  |t
        j                  j                        }|j                  |_        |j                  r?t        j                  |t
        j                  j                        }|j                  |_	        |j                  r.t        j                  |t
        j                  j                        }|j                  r.t        j                  |t
        j                  j                        }|j                  r.t        j                  |t
        j                  j                         }|j"                  r.t        j                  |t
        j                  j$                        }|j&                  r.t        j                  |t
        j                  j(                        }||_        ||fS )zFHelper to generate workload and update_mask fields for update_request. )r   rG   rO   r   AddToUpdateMaskr9   rW   #UPDATE_MASK_DISPLAY_NAME_FIELD_NAMErC   rB   "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_NAMErE   )r   r]   rE   r%   r^   s        r   rT   z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
 %H[  r   )Nd   )__name__
__module____qualname____doc__r
   ReleaseTrackALPHAr   r'   r4   r7   rI   ra   rT    r   r   r   r      sA    7#'#4#4#:#: 8& 	B<1f>/!r   r   N)ru   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.apphubr   r9   r   r   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   googlecloudsdk.corer   objectr   rx   r   r   <module>r      s3    ( &  ' ' B @ . ( #a!f a!r   