
    Z                         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	Zd
ZdZefdZedfdZd Zd Zd ZdefdZy)zKRM API Hosting API utilities.    )absolute_import)division)unicode_literals)encoding)apis)waiter)	resourcesv1i'  i@w c                 .    t        j                  d|       S )Nkrmapihosting)r   GetMessagesModule)api_versions    0lib/googlecloudsdk/api_lib/krmapihosting/util.pyr   r   #   s    				==    Tc                 4    t        j                  d| |       S )zReturns an instance of the KRM API Hosting client.

  Args:
    api_version: The desired api version.
    use_http: bool, True to create an http object for this client.

  Returns:
    base_api.BaseApiClient, An instance of the Cloud Build client.
  r   )no_http)r   GetClientInstance)r   use_https     r   r   r   '   s      
		{\
< <r   c                     t               }|j                  }|j                  j                  |j	                  |             S )aG  Fetches a KRMApiHost instance, and returns it as a messages.KrmApiHost.

  Calls into the GetKrmApiHosts API.

  Args:
    name: the fully qualified name of the instance, e.g.
      "projects/p/locations/l/krmApiHosts/k".

  Returns:
    A messages.KrmApiHost.

  Raises:
    HttpNotFoundError: if the instance didn't exist.
  )name)r   MESSAGES_MODULEprojects_locations_krmApiHostsGet3KrmapihostingProjectsLocationsKrmApiHostsGetRequest)r   clientmessagess      r   GetKrmApiHostr   5   sC     &##(		.	.	2	2BBBM
O Or   c                     t               }|j                  }|j                  j                  |j	                  |             }|j
                  S )zCalls into the ListKrmApiHosts API.

  Args:
    parent: the fully qualified name of the parent, e.g.
      "projects/p/locations/l".

  Returns:
    A list of messages.KrmApiHost.
  )parent)r   r   r   List4KrmapihostingProjectsLocationsKrmApiHostsListRequestkrmApiHosts)r   r   r   resps       r   ListKrmApiHostsr$   J   sR     &##(		.	.	3	3CC D 
$ 
		r   c                     t               }|j                  }|j                  j                  |j	                  | ||            S )a  Creates a KRMApiHost instance, and returns the creation Operation.

  Calls into the CreateKrmApiHost API.

  Args:
    parent: the fully qualified name of the parent, e.g.
      "projects/p/locations/l".
    krm_api_host_id: the ID of the krmApiHost, e.g. "my-cluster" in
      "projects/p/locations/l/krmApiHosts/my-cluster".
    krm_api_host: a messages.KrmApiHost resource (containing properties like
      the bundle config)

  Returns:
    A messages.OperationMetadata representing the long-running operation.
  )r   
krmApiHostkrmApiHostId)r   r   r   Create6KrmapihostingProjectsLocationsKrmApiHostsCreateRequest)r   krm_api_host_idkrm_api_hostr   r   s        r   CreateKrmApiHostr,   \   sN      &##(		.	.	5	5EEL F P
Q Qr   zWaiting for cluster to createc                 d   t               }t        j                  j                  | j                  d      }t        j                  |j                        }t        j                  ||||t              }t        j                  |      }t               }t        j                  |j                  |      S )aq  Waits for the given "create" LRO to complete.

  Args:
    operation: the operation to poll.
    progress_message: the message to display while waiting for the operation.
    max_wait_ms: number of ms to wait before raising TimeoutError.

  Raises:
    apitools.base.py.HttpError: if the request returns an HTTP error.

  Returns:
    A messages.KrmApiHost resource.
  z+krmapihosting.projects.locations.operations)
collection)max_wait_mswait_ceiling_ms)r   r	   REGISTRYParseRelativeNamer   r   CloudOperationPollerNoResourcesprojects_locations_operationsWaitFor_WAIT_CEILING_MSr   MessageToJsonr   JsonToMessage
KrmApiHost)		operationprogress_messager/   r   operation_refpollerresultjsonr   s	            r    WaitForCreateKrmApiHostOperationr@   s   s    " &$$66nn!N 7 P-11**,&>>&(& 
			'$ (			 3 3T	::r   N)__doc__
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer	   _DEFAULT_API_VERSIONr6   _MAX_WAIT_TIME_MSr   r   r   r$   r,   r@    r   r   <module>rI      si    % &  ' % , . )    #  #7 > #7 <O*$Q2 5!;r   