
                         
   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
 Ze
j                  j                   fdZe
j                  j                   fdZddZd Zd Zd Zd Zd ZddZ	 ddZy)z1A library that is used to support trace commands.    )absolute_import)division)unicode_literals)apis)waiter)base)
properties)	resourcesc                 @    | t         j                  j                  k(  ryy)zXReturns the correct API version.

  Args:
    release_track: base.ReleaseTrack object
  v1v1beta1)r   ReleaseTrackGArelease_tracks    ,lib/googlecloudsdk/api_lib/notebooks/util.pyApiVersionSelectorr      s     d''***	    c                 @    t        j                  dt        |             S )z%Returns the client for the trace API.	notebooks)	core_apisGetClientInstancer   r   s    r   	GetClientr   '   !    		$	$[%7%F
H Hr   c                 @    t        j                  dt        |             S )z'Returns the messages for the trace API.r   )r   GetMessagesModuler   r   s    r   GetMessagesr   -   r   r   Nc                     |s4t         j                  j                  j                  j	                  d      }t
        j                  j                  | d|id      S )NTrequired
projectsIdznotebooks.projects.locations)params
collection)r	   VALUEScoreprojectGetr
   REGISTRYParse)locationr&   s     r   GetLocationResourcer+   3   sV    	$$,,00$0?G				!	!G$/ 
" 
1 1r   c                     | j                  d      rR| j                  j                  j                         }t	        |j
                  |j                        j                         S y )Nruntime)IsSpecifiedCONCEPTSr-   r)   r+   locationsIdr!   RelativeName)argsr-   s     r   GetParentForRuntimer3   <   sS    	i mm##))+Gw22&1133?<>B !r   c                     | j                  d      rR| j                  j                  j                         }t	        |j
                  |j                        j                         S y )Ninstance)r.   r/   r5   r)   r+   r0   r!   r1   )r2   r5   s     r   GetParentForInstancer6   C   sS    	j!}}%%++-Hx33'2244@LNC "r   c                     | j                  d      rR| j                  j                  j                         }t	        |j
                  |j                        j                         S y )Nenvironment)r.   r/   r8   r)   r+   r0   r!   r1   )r2   r8   s     r   GetParentForEnvironmentr9   J   sS    	m$--++113K{66*5577C|~F %r   c                     t         j                  j                  | xs4 t        j                  j
                  j                  j                  d      d      S )z-Returns the resource for the current project.Tr   znotebooks.projects)r#   )r
   r(   r)   r	   r$   r%   r&   r'   )r&   s    r   GetProjectResourcer;   Q   sK    				!	!B""''//33T3B% 
" 
' 'r   c                    t         j                  j                  j                  j	                  d      }| j                  d      r$t        | j                  |      j                         S t         j                  j                  j                  j                         rLt        t         j                  j                  j                  j	                  d      |      j                         S y )NTr   r*   )r	   r$   r%   r&   r'   r.   r+   r*   r1   r   IsExplicitlySet)r2   r&   s     r   GetParentFromArgsr>   X   s    ""**...='	j!t}}g6CCEE""++;;=##,,00$0?  >r   c                 X    t         j                  j                  | dt        |            S )Nz'notebooks.projects.locations.operations)r#   api_version)r
   r(   ParseRelativeNamer   )namer   s     r   GetOperationResourcerC   b   s.    				-	-
:$]3 
. 
5 5r   c                     t        | j                  |      }t        |      }|r t        j                  |j
                        }n t        j                  ||j
                        }t        j                  |||      S )a	  Waits for the given google.longrunning.Operation to complete.

  Args:
    operation: The operation to poll.
    message: String to display for default progress_tracker.
    service: The service to get the resource after the long running operation
      completes.
    release_track: base.ReleaseTrack object.
    is_delete: Bool indicating is Poller should fetch resource post operation.

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

  Returns:
    The created Environment resource.
  )rC   rB   r   r   CloudOperationPollerNoResourcesprojects_locations_operationsCloudOperationPollerWaitFor)	operationmessageservicer   	is_deleteoperation_refclientpollers           r   WaitForOperationrP   i   sj    * 'y~~}E-]#&33,,.F ((557F	w	77r   )N)F)__doc__
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   r   googlecloudsdk.callioper   googlecloudsdk.corer	   r
   r   r   r   r   r   r+   r3   r6   r9   r;   r>   rC   rP    r   r   <module>rW      s    8 &  ' 9 . ( * ) !--00 H #//22 H1BCF' 5  %	8r   