
    :                         S r SSKJr  SSKJr  SSKJr  SSKJr  S r	S r
S rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rg)z.colab-enterprise runtime-templates api helper.    )
exceptions)iam_util)	arg_utils)	resourcesc                 j    U R                   R                  R                  5       nUR                  5       $ )zGet the parent Location resource name for the runtime template.

Args:
  args: Argparse object from Command.Run

Returns:
  The resource name in the form projects/{project}/locations/{location}.
)CONCEPTSregionParseRelativeName)argsr	   s     @lib/googlecloudsdk/api_lib/colab_enterprise/runtime_templates.pyGetParentForRuntimeTemplater      s+     ==%%'&				    c                     SU ;   a   [         R                  R                  U SS9$ [         R                  R                  U SS9$ ! [         R                   a     N4f = f)zParse operation relative resource name to the operation reference object.

Args:
  operation_name: The operation resource name

Returns:
  The operation reference object
z/notebookRuntimeTemplates/zAaiplatform.projects.locations.notebookRuntimeTemplates.operations)
collectionz(aiplatform.projects.locations.operations)r   REGISTRYParseRelativeName WrongResourceCollectionException)operation_names    r   ParseRuntimeTemplateOperationr   %   su     "^311
X 2   
			-	-!K 
. 
  55 
s   A AAc                 r    [         R                  R                  U R                  SS9nUR	                  5       $ )z1Transform a runtime template resource into a URL.z6aiplatform.projects.locations.notebookRuntimeTemplates)relative_namer   )r   r   r   nameSelfLink)resourceruntime_templates     r   GetRuntimeTemplateUrir   ;   s9    ''99MMI :  
	"	"	$$r   c                    UR                   nSnU R                  S5      (       aN  [        R                  " SUR                  S S9R                  [        R                  " U R                  5      5      nU" U R                  UU R                  S9$ )zConstructs the machine spec from command line args.

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

Returns:
    Machine spec config for the runtime template.
Naccelerator_typezaccelerator-typec                 ,    U Ss=:g  =(       a    U ;  $ s  $ )NUNSPECIFIED xs    r   <lambda>(GetMachineSpecFromArgs.<locals>.<lambda>T   s    m!<!<1!<r   arg_namemessage_enuminclude_filter)machineTypeacceleratorTypeacceleratorCount)
'GoogleCloudAiplatformV1beta1MachineSpecIsSpecifiedr   ChoiceEnumMapperAcceleratorTypeValueValuesEnumGetEnumForChoiceEnumNameToChoicer   machine_typeaccelerator_count)r   messagesmachine_spec_configaccelerator_type_enums       r   GetMachineSpecFromArgsr9   D   s     !HH	())%66#(GG< y11$2G2GHI	 
 
##+--
 r   c                 B    U R                  5       R                  SS5      $ )aJ  Translates disk type user input to a format accepted by the API.

The command input is kept in the enum format to be consistent with other
arguments like accelerator type.

Args:
  disk_type: The disk type enum value from user (eg PD_STANDARD).

Returns:
  The disk type string value validated by AIPlatform API (eg pd-standard).
_-)lowerreplace)	disk_types    r   FormatDiskTypeForApiRequestr@   ]   s     
		"	"3	,,r   c                     UR                   nU R                  S5      (       a-  U R                  S5      (       d  [        R                  " SS5      e[	        U R
                  5      nU" X0R                  S9$ )zConstructs the persistent disk spec from command line args.

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

Returns:
  Persistent disk spec config for the runtime template.
disk_size_gbr?   z--disk-typez8Disk type must be specified when disk size is specified.)diskType
diskSizeGb).GoogleCloudAiplatformV1beta1PersistentDiskSpecr/   r   RequiredArgumentExceptionr@   r?   rB   )r   r6   persistent_disk_spec_configr?   s       r   GetPersistentDiskSpecFromArgsrH   l   st     == 
 
n%%d.>.>{.K.K

.
.B 
 ,DNN;I&'8'8 r   c                 f   UR                   nSnSnU R                  S5      (       a2  U R                  R                  R	                  5       R                  5       nU R                  S5      (       a2  U R                  R                  R	                  5       R                  5       nU" UUU R                  S9$ )zConstructs the network spec from command line args.

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

Returns:
  Network spec config for the runtime template.
Nnetwork
subnetwork)rJ   rK   enableInternetAccess)'GoogleCloudAiplatformV1beta1NetworkSpecr/   r   rJ   r
   r   rK   enable_internet_access)r   r6   network_spec_confignetwork_relative_namesubnetwork_relative_names        r   GetNetworkSpecFromArgsrR      s     !HH!	i   MM11779FFH	l###}}77==?LLN	#)66
 r   c                     U R                  S5      (       aV  UR                  R                  nU" U R                  R	                  5        VVs/ s H  u  p4UR                  X4S9PM     snnS9$ gs  snnf )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 template.
labels)keyvalue)additionalPropertiesN)r/   3GoogleCloudAiplatformV1beta1NotebookRuntimeTemplateLabelsValuerT   itemsAdditionalProperty)r   r6   labels_messagerU   rV   s        r   GetLabelsFromArgsr]      s|     
hDDPP   #kk//1
1
 --#-C1
  

s   A.
c                     UR                   nU R                  S5      (       a-  U R                  nUS:X  a  U" SS9$ [        U5      S-   nU" SUS9$ g)	zConstructs the idle shutdown config from command line args.

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

Returns:
  Idle shutdown config for the runtime template.
idle_shutdown_timeoutr   T)idleShutdownDisabledsF)r`   idleTimeoutN)6GoogleCloudAiplatformV1beta1NotebookIdleShutdownConfigr/   r_   str)r   r6   idle_shutdown_configduration_secondsduration_serializeds        r   GetIdleShutdownConfigFromArgsrh      sn     EE  
-..111!t<<./#5"0C  
r   c                 >    UR                  U R                  (       + S9$ )zConstructs the euc config from command line args.

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

Returns:
  Euc config for the runtime template.
)eucDisabled)-GoogleCloudAiplatformV1beta1NotebookEucConfig
enable_eucr   r6   s     r   GetEucConfigFromArgsrn      s'     
	?	?' 
@ 
 r   c                 4    UR                  U R                  S9$ )zConstructs the shielded vm config from command line args.

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

Returns:
  Shielded vm config for the runtime template.
)enableSecureBoot),GoogleCloudAiplatformV1beta1ShieldedVmConfigenable_secure_bootrm   s     r   GetShieldedVmConfigFromArgsrs      s%     
	>	>.. 
? 
 r   c                 J    U R                  S5      (       a  U R                  $ / $ )Nnetwork_tags)r/   ru   r   s    r   GetNetworkTagsFromArgsrw      s#    "..~>>		FBFr   c           	         UR                   nUR                  nUR                  nSnU R                  S5      (       aN  [        R
                  " SUR                  S S9R                  [        R                  " U R                  5      5      n/ nU R                  S5      (       a,  U R                   Vs/ s H  or" XpR                  U   S9PM     nnU" UU" UU R                  U R                  S9S	9$ s  snf )
z6Constructs the software config from command line args.Npost_startup_script_behaviorzpost-startup-script-behaviorc                     U S:g  $ )N(POST_STARTUP_SCRIPT_BEHAVIOR_UNSPECIFIEDr"   r#   s    r   r%   +GetSoftwareConfigFromArgs.<locals>.<lambda>   s    5"6r   r'   set_env_vars)r   rV   )postStartupScriptBehaviorpostStartupScriptpostStartupScriptUrl)envpostStartupScriptConfig)"GoogleCloudAiplatformV1beta1EnvVar3GoogleCloudAiplatformV1beta1PostStartupScriptConfig2GoogleCloudAiplatformV1beta1NotebookSoftwareConfigr/   r   r0   (PostStartupScriptBehaviorValueValuesEnumr2   r3   ry   r}   post_startup_scriptpost_startup_script_url)r   r6   env_varpost_startup_script_configsoftware_config!post_startup_script_behavior_enumenv_varsks           r   GetSoftwareConfigFromArgsr      s   77'BB  OO/&*#	455(1(B(B//XX6)
 ""4#D#DE & (	n%%=A=N=N=NQ//23=N   

8$E 44#;;
 s   1C0c                     UR                   nU R                  S5      (       a6  U" U R                  R                  R	                  5       R                  5       S9$ g)zConstructs the encryption spec from the kms key resource arg.

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

Returns:
  Encryption spec for the notebook resource.
kms_key)
kmsKeyNameN)*GoogleCloudAiplatformV1beta1EncryptionSpecr/   r   r   r
   r   )r   r6   encryption_specs      r   CreateEncryptionSpecConfigr     sQ     GG/	i  ==((..0==?  
r   c                 f    U R                   R                  R                  5       R                  5       $ )zGet the resource name for the runtime template.

Args:
  args: Argparse object from Command.Run

Returns:
  The resource name in the form
  projects/{project}/locations/{location}/notebookRuntimeTemplates/{runtime_template_id}.
)r   r   r
   r   rv   s    r   GetRuntimeTemplateResourceNamer   &  s&     
	'	'	-	-	/	<	<	>>r   c                 (   UR                  U R                  U R                  U R                  [	        X5      [        X5      [        X5      [        X5      [        X5      [        X5      [        X5      [        U 5      [        X5      [        X5      S9$ )zCreates the RuntimeTemplate message for the create request.

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

Returns:
  Instance of the RuntimeTemplate message.
)r   displayNamedescriptionmachineSpecdataPersistentDiskSpecnetworkSpecrT   idleShutdownConfig	eucConfigshieldedVmConfignetworkTagsencryptionSpecsoftwareConfig)rX   runtime_template_iddisplay_namer   r9   rH   rR   r]   rh   rn   rs   rw   r   r   rm   s     r   CreateRuntimeTemplater   3  s     
	E	E####""(8:4J(8t.6tF$T424B(./?.t> 
F 
 r   c                 d    [        U 5      n[        X5      nUR                  UU R                  US9$ )zBuilds a CreateNotebookRuntimeTemplateRequest message.

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

Returns:
  Instance of the CreateNotebookRuntimeTemplateRequest message.
)3googleCloudAiplatformV1beta1NotebookRuntimeTemplatenotebookRuntimeTemplateIdparent)r   r   @AiplatformProjectsLocationsNotebookRuntimeTemplatesCreateRequestr   )r   r6   r   r   s       r   "CreateRuntimeTemplateCreateRequestr   N  sA     't,&*4:OO>N$($<$< P r   c                 2    UR                  [        U 5      S9$ )zBuilds a DeleteNotebookRuntimeTemplateRequest message.

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

Returns:
  Instance of the DeleteNotebookRuntimeTemplateRequest message.
r   )@AiplatformProjectsLocationsNotebookRuntimeTemplatesDeleteRequestr   rm   s     r   "CreateRuntimeTemplateDeleteRequestr   d  s%     OO-d3 P r   c                 2    UR                  [        U 5      S9$ )zBuilds a GetNotebookRuntimeTemplateRequest message.

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

Returns:
  Instance of the GetNotebookRuntimeTemplateRequest message.
r   )=AiplatformProjectsLocationsNotebookRuntimeTemplatesGetRequestr   rm   s     r   CreateRuntimeTemplateGetRequestr   v  s%     LL-d3 M r   c                 2    UR                  [        U 5      S9$ )zBuilds a ListNotebookRuntimeTemplatesRequest message.

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

Returns:
  Instance of the ListNotebookRuntimeTemplatesRequest message.
)r   )>AiplatformProjectsLocationsNotebookRuntimeTemplatesListRequestr   rm   s     r    CreateRuntimeTemplateListRequestr     s%     MM,T2 N r   c                 2    UR                  [        U 5      S9$ )zBuilds a RuntimeTemplatesGetIamPolicyRequest message.

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

Returns:
  Instance of the RuntimeTemplatesGetIamPolicyRequest message.
)r   )FAiplatformProjectsLocationsNotebookRuntimeTemplatesGetIamPolicyRequestr   rm   s     r   (CreateRuntimeTemplateGetIamPolicyRequestr     s%     
	X	X-d3 
Y 
5 5r   c                 R    UR                  U S9nUR                  U[        U5      S9$ )a  Builds a RuntimeTemplatesSetIamPolicyRequest message.

Args:
  iam_policy: The IAM policy to set.
  args: Argparse object from Command.Run
  messages: Module containing messages definition for the specified API.

Returns:
  Instance of the RuntimeTemplatesSetIamPolicyRequest message.
)policy)googleIamV1SetIamPolicyRequestr   )GoogleIamV1SetIamPolicyRequestFAiplatformProjectsLocationsNotebookRuntimeTemplatesSetIamPolicyRequestr   )
iam_policyr   r6   google_iam_set_policy_requests       r   (CreateRuntimeTemplateSetIamPolicyRequestr     sB     #+"I"I #J #		X	X%B-d3 
Y 
 r   c                 p    [         R                  " U R                  UR                  5      n[	        X U5      $ )a  Reads policy file from args to build a RuntimeTemplatesSetIamPolicyRequest.

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

Returns:
  Instance of the RuntimeTemplatesSetIamPolicyRequest message.
)r   ParsePolicyFilepolicy_fileGoogleIamV1Policyr   )r   r6   r   s      r   0CreateRuntimeTemplateSetIamPolicyRequestFromFiler     s2     ##
224&	1&	IIr   N) __doc__googlecloudsdk.callioper   googlecloudsdk.command_lib.iamr   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   r   r   r   r9   r@   rH   rR   r]   rh   rn   rs   rw   r   r   r   r   r   r   r   r   r   r   r   r"   r   r   <module>r      s    5 . 3 : ),%2-82.2G@&
?6,$$$5&Jr   