
                         t    d Z ddlmZ ddlmZ d Zd Zd Zd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zd Zd Zd Zy)z%colab-enterprise runtimes api helper.    )
properties)	resourcesc                 j    | j                   j                  j                         }|j                         S )zGet the parent Location resource name for the runtime.

  Args:
    args: Argparse object from Command.Run

  Returns:
    The resource name in the form projects/{project}/locations/{location}.
  )CONCEPTSregionParseRelativeName)argsr   s     7lib/googlecloudsdk/api_lib/colab_enterprise/runtimes.pyGetParentForRuntimer      s+     ==%%'&				    c                     d| v r"	 t         j                  j                  | d      S t         j                  j                  | d      S # t         j                  $ r Y 6w xY w)zParse operation relative resource name to the operation reference object.

  Args:
    operation_name: The operation resource name

  Returns:
    The operation reference object
  z/notebookRuntimes/z9aiplatform.projects.locations.notebookRuntimes.operations)
collectionz(aiplatform.projects.locations.operations)r   REGISTRYParseRelativeName WrongResourceCollectionException)operation_names    r   ParseRuntimeOperationr   #   su     ^+11
I 2   
			-	-!K 
. 
  55 
s    A AAc                 x    t         j                  j                  | j                  d      }|j	                         S )z(Transform a runtime resource into a URL.z.aiplatform.projects.locations.notebookRuntimes)relative_namer   )r   r   r   nameSelfLink)resourceruntimes     r   GetRuntimeUrir   ;   s8    00MMA 1 ' 
			r   c           
          | j                  d      r[|j                  j                  } || j                  j	                         D cg c]  \  }}|j                  ||       c}}      S yc c}}w )zConstructs the labels from command line args.

  Args:
    args: Argparse object from Command.Run
    messages: Module containing messages definition for the aiplatform API.

  Returns:
    Labels for the runtime.
  labels)keyvalue)additionalPropertiesN)IsSpecified+GoogleCloudAiplatformV1beta1NotebookRuntimeLabelsValuer   itemsAdditionalProperty)r
   messageslabels_messager   r   s        r   GetLabelsFromArgsr(   D   s}     
h<<HH   #kk//1
1
U --#U-C1
  

s   A.
c                     | j                  d      r| j                  S t        j                  j                  j
                  j                         S )zGets runtime user from command line args if provided; else default to caller.

  Args:
    args: Argparse object from Command.Run

  Returns:
    Runtime user of the runtime.
  runtime_user)r!   r*   r   VALUEScoreaccountGetr
   s    r   "GetRuntimeUserFromArgsOrPropertiesr0   [   s?     
n%!!))--//r   c                 f    | j                   j                  j                         j                         S )zGet the resource name for the notebook runtime.

  Args:
    args: Argparse object from Command.Run

  Returns:
    The resource name in the form
    projects/{project}/locations/{location}/notebookRuntimes/{runtime_id}.
  )r   r   r   r	   r/   s    r   GetRuntimeResourceNamer2   k   s&     
			$	$	&	3	3	55r   c           
          |j                  | j                  t        |       | j                  | j                  t        | |            S )a  Creates the NotebookRuntime message for the AssignNotebookRuntime request.

  Args:
    args: Argparse object from Command.Run
    messages: Module containing messages definition for the specified API.

  Returns:
    Instance of the NotebookRuntime message.
  )r   runtimeUserdisplayNamedescriptionr   )r"   
runtime_idr0   display_namer6   r(   r
   r&   s     r   CreateRuntimeMessager:   x   sG     
	=	=??4T:##""tX. 
> 
 r   c                     t        |       }t        | |      }|j                  |j                  || j                  | j
                  j                  j                         j                               |      S )zBuilds a AssignNotebookRuntimeRequest message.

  Args:
    args: Argparse object from Command.Run
    messages: Module containing messages definition for the specified API.

  Returns:
    Instance of the AssignNotebookRuntimeRequest message.
  )notebookRuntimenotebookRuntimeIdnotebookRuntimeTemplate)8googleCloudAiplatformV1beta1AssignNotebookRuntimeRequestparent)	r   r:   8AiplatformProjectsLocationsNotebookRuntimesAssignRequest8GoogleCloudAiplatformV1beta1AssignNotebookRuntimeRequestr7   r   runtime_templater   r	   )r
   r&   r@   r   s       r   !CreateRuntimeAssignRequestMessagerD      s     t$& x0'		J	J?G  @A  @A! OO"&--"@"@"F"F"H"U"U"W @A @
  
K 
 r   c                 8    |j                  t        |             S )zBuilds a GetNotebookRuntimeRequest message.

  Args:
    args: Argparse object from Command.Run
    messages: Module containing messages definition for the specified API.

  Returns:
    Instance of the GetNotebookRuntimeRequest message.
  r   )5AiplatformProjectsLocationsNotebookRuntimesGetRequestr2   r9   s     r   CreateRuntimeGetRequestMessagerH      s%     
	G	G!$' 
H 
 r   c                 8    |j                  t        |             S )zBuilds a ListNotebookRuntimeRequest message.

  Args:
    args: Argparse object from Command.Run
    messages: Module containing messages definition for the specified API.

  Returns:
    Instance of the ListNotebookRuntimeRequest message.
  )r@   )6AiplatformProjectsLocationsNotebookRuntimesListRequestr   r9   s     r   CreateRuntimeListRequestMessagerK      s%     
	H	H & 
I 
 r   c                 8    |j                  t        |             S )zBuilds a DeleteNotebookRuntimeRequest message.

  Args:
    args: Argparse object from Command.Run
    messages: Module containing messages definition for the specified API.

  Returns:
    Instance of the DeleteNotebookRuntimeRequest message.
  rF   )8AiplatformProjectsLocationsNotebookRuntimesDeleteRequestr2   r9   s     r   !CreateRuntimeDeleteRequestMessagerN      s%     
	J	J!$' 
K 
 r   c                 V    |j                  |j                         t        |             S )zBuilds a UpgradeNotebookRuntimeRequest message.

  Args:
    args: Argparse object from Command.Run
    messages: Module containing messages definition for the specified API.

  Returns:
    Instance of the UpgradeNotebookRuntimeRequest message.
  )9googleCloudAiplatformV1beta1UpgradeNotebookRuntimeRequestr   )9AiplatformProjectsLocationsNotebookRuntimesUpgradeRequest9GoogleCloudAiplatformV1beta1UpgradeNotebookRuntimeRequestr2   r9   s     r   "CreateRuntimeUpgradeRequestMessagerS      s=     
	K	K@H  AC  AC  AE!$' 
L 
 r   c                 V    |j                  |j                         t        |             S )zBuilds a StartNotebookRuntimeRequest message.

  Args:
    args: Argparse object from Command.Run
    messages: Module containing messages definition for the specified API.

  Returns:
    Instance of the StartNotebookRuntimeRequest message.
  )7googleCloudAiplatformV1beta1StartNotebookRuntimeRequestr   )7AiplatformProjectsLocationsNotebookRuntimesStartRequest7GoogleCloudAiplatformV1beta1StartNotebookRuntimeRequestr2   r9   s     r    CreateRuntimeStartRequestMessagerX      s4     
	I	I>F>~>~  ?A!$' 
J 
 r   c                 V    |j                  |j                         t        |             S )zBuilds a StopNotebookRuntimeRequest message.

  Args:
    args: Argparse object from Command.Run
    messages: Module containing messages definition for the specified API.

  Returns:
    Instance of the StopNotebookRuntimeRequest message.
  )6googleCloudAiplatformV1beta1StopNotebookRuntimeRequestr   )6AiplatformProjectsLocationsNotebookRuntimesStopRequest6GoogleCloudAiplatformV1beta1StopNotebookRuntimeRequestr2   r9   s     r   CreateRuntimeStopRequestMessager]      s1     
	H	H=E=|=|=~!$' 
I 
 r   N)__doc__googlecloudsdk.corer   r   r   r   r   r(   r0   r2   r:   rD   rH   rK   rN   rS   rX   r]    r   r   <module>ra      sV    , * )0.0 
6&0   ""r   