
    s                         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 Services 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)ServicesClientz.Client for Application services 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_services_app_services_clientr	   CloudOperationPollerprojects_locations_operations_pollerCloudOperationPollerNoResources_delete_poller)selfrelease_tracks     :lib/googlecloudsdk/api_lib/apphub/applications/services.py__init__zServicesClient.__init__    s    11-@DK!33MBDM<< 	 ..!!11DL !@@11D    c                 p    | j                   j                  |      }| j                  j                  |      S )zDescribe a Application Service in the Project/location.

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

    Returns:
      Described service Resource.
    name)r   5ApphubProjectsLocationsApplicationsServicesGetRequestr   Get)r   servicedescribe_reqs      r   DescribezServicesClient.Describe.   s=     	KK 	L 	
 
 $$((66r   Nc                     | j                   j                  |      }t        j                  | j                  |d||d      S )a  List application services 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 services.
    )parentservicespageSize)field
batch_sizelimitbatch_size_attribute)r   6ApphubProjectsLocationsApplicationsServicesListRequestr   YieldFromListr   )r   r)   r.   	page_sizelist_reqs        r   ListzServicesClient.List>   sQ    ( 	LL 	M 	
 
 ##!!' r   c                     | j                   j                  |      }| j                  j                  |      }|r|S t	        j
                  | j                  |t        j                  j                  t        j                  j                        }|S )a4  Delete a application service in the Project/location.

    Args:
      service: str, the name for the service 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   8ApphubProjectsLocationsApplicationsServicesDeleteRequestr   Deleter   WaitForOperationr   api_lib_constsDeleteApplicationServiceWAIT_FOR_DELETE_MESSAGEDELETE_TIMELIMIT_SEC)r   r%   
async_flag
delete_req	operationdelete_responses         r   r7   zServicesClient.Delete_   s     	NN 	O 	
 
 ))00<I#44//GG//DD	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:
      service_id: str, Service ID
      parent: parent for Application resource
      async_flag: Boolean value for async operation. If true the operation will
        be async
      discovered_service: str, Discovered service name
      display_name: str, Human-friendly display name
      description: str, Description of the Service
      attributes: Attributes, Attributes of the Service

    Returns:
      Service or Operation based on async flag value.
    )descriptiondisplayNamediscoveredService
attributes)r%   	serviceIdr)   )r   Service8ApphubProjectsLocationsApplicationsServicesCreateRequestr   Creater   r8   r   r9   CreateApplicationServiceWAIT_FOR_CREATE_MESSAGECREATE_TIMELIMIT_SEC)r   
service_idr)   r=   discovered_servicedisplay_namerB   rE   r%   
create_reqr?   create_responses               r   rI   zServicesClient.Create}   s    2 mm## ,	 $ G 	NNz& 	O 	
 
 ))00<I#44//GG//DD	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 service.N)r"   r%   
updateMask)_UpdateHelperr   statusPrintr9   UpdateApplicationServiceEMPTY_UPDATE_HELP_TEXTr   7ApphubProjectsLocationsApplicationsServicesPatchRequestr   Patchr   r8   r   WAIT_FOR_UPDATE_MESSAGEUPDATE_TIMELIMIT_SEC)
r   rM   r=   rE   argsr%   update_maskupdate_requestr?   update_responses
             r   UpdatezServicesClient.Update   s    --dJ?G[	jj

1
1
H
H  	MM" 	N 	
  ))//?I#44//GG//DD	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 )zEHelper to generate service 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ServicesClient._UpdateHelper   s   mm##%GK!11


1
1
U
Uk !--g!11


1
1
T
Tk !,,g!11


1
1
Y
Yk !11


1
1
Y
Yk   !11


1
1
]
]k !!!11


1
1
^
^k   !11


1
1
]
]k
 $GKr   )Nd   )__name__
__module____qualname____doc__r
   ReleaseTrackALPHAr   r'   r4   r7   rI   ra   rT    r   r   r   r      sA    6#'#4#4#:#: 7& 	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 V a r   