
    L                     H   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 dd
lmZ ddlmZ ddlmZ g dZg dZg dZd Zd Zd Zd Zd Z d Z!d Z"d Z#d*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$ Z0d% Z1d& Z2d' Z3d( Z4y))+z;Utilities for flags for `gcloud colab-enterprise` commands.    )runtime_templates)runtimes)arg_parsers)base)concepts)deps)
completers)flags)iam_util)concept_parsers)
properties)NVIDIA_TESLA_V100NVIDIA_TESLA_T4NVIDIA_TESLA_A100NVIDIA_A100_80GB	NVIDIA_L4)PD_STANDARDPD_SSDPD_BALANCED
PD_EXTREME)(POST_STARTUP_SCRIPT_BEHAVIOR_UNSPECIFIEDRUN_ONCERUN_EVERY_STARTDOWNLOAD_AND_RUN_EVERY_STARTc                      t        j                  ddt        j                  t        j
                  j                  j                        g      S )zkGet the attribute config for the region resource.

  Returns:
    The resource attribute for the region.
  regionz Cloud region for the {resource}.)name	help_textfallthroughs)r    ResourceParameterAttributeConfigr   PropertyFallthroughr   VALUEScolabr        8lib/googlecloudsdk/command_lib/colab_enterprise/flags.pyGetRegionAttributeConfigr'   .   s@     
	2	22,,Z->->-D-D-K-KLM
 r%   c           	          dd}|r	d}d}d}d}nd}d}ddi}dd	gi}t         j                  j                  | |       d
j                  |      d|||      j	                  |        y)a  Add a resource argument for a runtime template to the parser.

  Args:
    parser: argparse parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
    is_positional: bool, True for if arg is positional; False if flag.
  c                 b    t        j                  d| t         j                  t               d      S )Nz6aiplatform.projects.locations.notebookRuntimeTemplatesTresource_name
projectsIdlocationsIddisable_auto_completersr   ResourceSpec DEFAULT_PROJECT_ATTRIBUTE_CONFIGr'   r+   s    r&   GetRuntimeTemplateResourceSpeczEAddRuntimeTemplateResourceArg.<locals>.GetRuntimeTemplateResourceSpecD   s-      @#<<,. $ r%   runtime_templateFNz--runtime-templateTr    --regionzUnique name of the runtime template {}. This was optionally provided by setting --runtime-template-id in the create runtime-template command, or was system-generated if unspecified.)requiredprefixesflag_name_overridescommand_level_fallthroughs)zruntime templater   ConceptParserForResourceformatAddToParser)parserverbis_positionalr3   arg_namer8   r9   r   s           r&   AddRuntimeTemplateResourceArgrD   ;   s     !HHL#HH#R.zl+L++$&117-!- , 
 Kr%   c                     dd}t         j                  j                  d |       dj                  |      d      j	                  |        y)zAdd a resource argument for a runtime template to the parser.

  Args:
    parser: argparse parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
  runtimec                 b    t        j                  d| t         j                  t               d      S )Nz.aiplatform.projects.locations.notebookRuntimesTr*   r/   r2   s    r&   GetRuntimeResourceSpecz5AddRuntimeResourceArg.<locals>.GetRuntimeResourceSpecl   s-      8#<<,. $ r%   zUnique name of the runtime {}. This was optionally provided by setting --runtime-id in the create runtime command, or was system-generated if unspecified.Tr7   N)rF   r;   )r@   rA   rH   s      r&   AddRuntimeResourceArgrJ   d   sH     ++fTl ,  Kr%   c                     t        j                  ddt               t         j                  d      }t        j
                  j                  d|dj                  |      d      j                  |        y)	zAdd a resource argument for a Vertex AI region to the parser.

  Args:
    parser: argparse parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
  zaiplatform.projects.locationsr   T)r+   r-   r,   r.   r6   zkCloud region {}. Please see  https://cloud.google.com/colab/docs/locations for a list of supported regions.rI   N)	r   r0   r'   r1   r   r<   r=   r>   r?   )r@   rA   region_resource_specs      r&   AddRegionResourceArgrM      sk     "..%*,::" ++&, ,  Kr%   c                 z      fd}t         j                  j                  d |              j                  |       y)zAdds Resource arg for network to the parser.

  Args:
    help_text: str, the help text for the flag.
    parser: argparse parser for the command.
  c                  h    fd} t        j                  dd |        t         j                  d      S )z>Constructs and returns the Resource specification for network.c                  P    t        j                  d t        j                        S )Nnetworkr   r   	completer)r   r    compute_network_flagsNetworksCompleterr   s   r&   NetworkAttributeConfigzUAddNetworkResourceArg.<locals>.GetNetworkResourceSpec.<locals>.NetworkAttributeConfig   s%    66);; r%   zcompute.networksrQ   F)r+   rQ   projectr.   r   r0   r1   )rW   r   s    r&   GetNetworkResourceSpecz5AddNetworkResourceArg.<locals>.GetNetworkResourceSpec   s5       &(99 % r%   z	--networkNr   r<   r=   r?   )r   r@   rZ   s   `  r&   AddNetworkResourceArgr\      s3    $ ++)+YKr%   c                 z      fd}t         j                  j                  d |              j                  |       y)zAdds Resource arg for subnetwork to the parser.

  Args:
    help_text: str, the help text for the flag.
    parser: argparse parser for the command.
  c                  x    fd} d }t        j                  dd |         |       t         j                        S )z=Constructs and returns the Resource specification for Subnet.c                  P    t        j                  d t        j                        S )N
subnetworkrR   )r   r    compute_subnet_flagsSubnetworksCompleterrV   s   r&   SubnetAttributeConfigzVAddSubnetworkResourceArg.<locals>.GetSubnetResourceSpec.<locals>.SubnetAttributeConfig   s%    66(== r%   c                  N    t        j                  ddt        j                        S )Nzsubnetwork-regionzfGoogle Cloud region of this subnetwork https://cloud.google.com/compute/docs/regions-zones/#locations.rR   )r   r    r	   RegionCompleterr$   r%   r&   RegionAttributeConfigzVAddSubnetworkResourceArg.<locals>.GetSubnetResourceSpec.<locals>.RegionAttributeConfig   s)    66"P .. r%   zcompute.subnetworksr`   )r+   r`   r   rX   rY   )rc   rf   r   s     r&   GetSubnetResourceSpecz7AddSubnetworkResourceArg.<locals>.GetSubnetResourceSpec   s=       "(*$&99 r%   z--subnetworkNr[   )r   r@   rg   s   `  r&   AddSubnetworkResourceArgrh      s3    8 +++-yKr%   c                 x    d }t         j                  j                  d |       |d      j                  |        y)zAdds Resource arg for KMS key to the parser.

  Args:
    parser: argparse parser for the command.
    help_text: str, the help text for the flag.
  c            	      x    d } d }d }d }t        j                  dd |         |        |        |             S )Nc                  .    t        j                  d      S )Nzkms-key)r   r   r    r$   r%   r&   KmsKeyAttributeConfigzRAddKmsKeyResourceArg.<locals>.GetKmsKeyResourceSpec.<locals>.KmsKeyAttributeConfig   s    66IFFr%   c                  0    t        j                  dd      S )Nzkms-keyringz!KMS keyring id of the {resource}.r   r   rl   r$   r%   r&   KmsKeyringAttributeConfigzVAddKmsKeyResourceArg.<locals>.GetKmsKeyResourceSpec.<locals>.KmsKeyringAttributeConfig   s    66(K r%   c                  0    t        j                  dd      S )Nzkms-locationz"Cloud location for the {resource}.ro   rl   r$   r%   r&   KmsLocationAttributeConfigzWAddKmsKeyResourceArg.<locals>.GetKmsKeyResourceSpec.<locals>.KmsLocationAttributeConfig   s    66)M r%   c                  0    t        j                  dd      S )Nzkms-projectz$Cloud project id for the {resource}.ro   rl   r$   r%   r&   KmsProjectAttributeConfigzVAddKmsKeyResourceArg.<locals>.GetKmsKeyResourceSpec.<locals>.KmsProjectAttributeConfig   s    66(N r%   z/cloudkms.projects.locations.keyRings.cryptoKeyskey)r+   cryptoKeysId
keyRingsIdr-   r,   )r   r0   )rm   rp   rr   rt   s       r&   GetKmsKeyResourceSpecz3AddKmsKeyResourceArg.<locals>.GetKmsKeyResourceSpec   sJ    G


   9*,,..0,. r%   z	--kms-keyFrI   Nr[   )r@   r   rx   s      r&   AddKmsKeyResourceArgry      s=    < ++	 , 
 Kr%   c                 B    t         j                  j                  |        y)z+Adds the --async flags to the given parser.N)r   
ASYNC_FLAGr?   r@   s    r&   AddAsyncFlagr}     s    //f%r%   c           	         |rdnd}| j                  d| d      }|j                  ddd| dd	
       |j                  dd| dt        d       |j                  dt        d       | j                  d| d      }|j                  ddt        d       |j                  dd| dt        d       | j                  d| d      }t        d| d|       t        d | d|       |j                  d!d"d#d$d%| d&       y)'zConstruct args to provide a custom compute spec for notebook execution.

  Args:
    parser: argparse parser for the command.
    workbench_execution: bool, true if these flags are for creating a Workbench
      execution.
  zexecution environmentrF   z!The machine configuration of the .helpz--machine-typeFz1The Compute Engine machine type selected for the ze2-standard-4)r7   r   defaultz--accelerator-typez-The type of hardware accelerator used by the z;. If specified, --accelerator-count must also be specified.N)r   choicesr   z--accelerator-countz/The number of accelerators used by the runtime.)typer   z+The configuration for the data disk of the z--disk-typez The type of the persistent disk.r   z--disk-size-gbzThe disk size of the zr in GB. If specified, the --disk-type must also be specified. The minimum size is 10GB and the maximum is 65536GB.d   r   r   r   z"The network configuration for the zThe name of the VPC that this z is in.)r   r@   z%The name of the subnetwork that this z--enable-internet-access
store_trueenable_internet_accessTz&Enable public internet access for the )actiondestr   r   )	add_groupadd_argument_accelerator_choicesint_disk_choicesr\   rh   )r@   workbench_executionvm_namemachine_spec_groupdisk_spec_groupnetwork_spec_groups         r&   AddCustomEnvSpecFlagsr     s    "5) 
 ''.wiq9 (  !!>wiqI	 "  !!:7) D@ @" "  !!< " 
 $$7y
B % /
 -	   "7) ,     ''/y: (  0	A 1''
B	 !! #3G9A> " r%   c                     | j                  dd      }|j                  ddd       |j                  ddd	       |j                  d
ddt               |j                  dddt        j                         d       y)z5Adds Resource arg for runtime template to the parser.Tz3The software configuration of the runtime template.)hiddenr   z--post-startup-scriptFz<Post startup script in raw string to execute on the runtime.r7   r   z--post-startup-script-urlzPost startup script URL to execute on the runtime. This can be a public or private Google Cloud Storage object. In the form of gs://bucket/object or https://storage.googleapis.com/bucket/object.z--post-startup-script-behaviorzfThe behavior of the post startup script. The default if passing a post-startup-script-url is RUN_ONCE.)r7   r   r   z--set-env-varsz.Set environment variables used by the runtime.	KEY=VALUE)r7   r   r   metavarN)r   r   %_post_startup_script_behavior_choicesr   ArgDict)r@   software_config_groups     r&   %AddRuntimeTemplateSoftwareConfigFlagsr   f  s     !**@ +  $$I % 
 $$!;	 % 	 $$&2 4 %  $$;  % r%   c                 T   t        | d       | j                  ddd       | j                  ddd       | j                  d	
      }|j                  ddd       t        |       t	        |       |j                  ddt        j                         d       |j                  ddt        j                         d       |j                  ddddd       |j                  ddddd       |j                  dt        j                         dd        t        |d!       t        |        y")#zEConstruct groups and arguments specific to runtime template creation.zto create runtime templatez--runtime-template-idFzPThe id of the runtime template. If not specified, a random id will be generated.r   --display-nameTz)The display name of the runtime template.z%Configuration of the runtime templater   --descriptionz(The description of the runtime template.--labels6Add labels to identify and group the runtime template.r   r   r   r   z--idle-shutdown-timeoutzThe duration after which the runtime is automatically shut down. An input of 0s disables the idle shutdown feature, and a valid range is [10m, 24h]. See '$ gcloud topic datetimes' for details on formatting the input duration.3hr   z--enable-eucr   
enable_eucz2Enable end user credential access for the runtime.)r   r   r   r   z--enable-secure-bootenable_secure_bootz9Enables secure boot for the runtime. Disabled by default.z--network-tagsTAGSz5Applies the given Compute Engine tags to the runtime.)r   r   r   zThe Cloud KMS encryption key (customer-managed encryption key) used to protect the runtime. The key must be in the same region as the runtime. If not specified, Google-managed encryption keys will be used.N)rM   r   r   r   r   r   r   DurationArgListry   r}   )r@   runtime_template_groups     r&   AddCreateRuntimeTemplateFlagsr     s}    v;<   	6  
 "++2 ,  %%5 & 
 ./'(>?%%C 	 &  %%,
 ! & 
 %%? &  %%F &  %% B	 &  H vr%   c                 6    t        | dd       t        |        y)zEConstruct groups and arguments specific to runtime template deletion.	to deleteTrB   N)rD   r}   r|   s    r&   AddDeleteRuntimeTemplateFlagsr     s    4Hvr%   c                      t        | dd       y)zIConstruct groups and arguments specific to describing a runtime template.to describeTr   NrD   r|   s    r&   AddDescribeRuntimeTemplateFlagsr     s    TJr%   c                 n    t        | d       | j                  j                  t        j                         y)zEConstruct groups and arguments specific to listing runtime templates.z'for which to list all runtime templatesN)rM   display_info
AddUriFuncruntime_templates_utilGetRuntimeTemplateUrir|   s    r&   AddListRuntimeTemplatesFlagsr     s(    vHI  !7!M!MNr%   c                 J    t        | dd       t        j                  |        y)zKConstruct arguments for adding an IAM policy binding to a runtime template.zto add IAM policy binding toTr   N)rD   r   AddArgsForAddIamPolicyBindingr|   s    r&   AddFlagsToAddIamPolicyBindingr     s"    ,D ((0r%   c                      t        | dd       y)zFConstruct arguments for getting the IAM policy for a runtime template.zto get IAM policy forTr   Nr   r|   s    r&   AddGetIamPolicyFlagsr     s    %Tr%   c                 J    t        | dd       t        j                  |        y)zFConstruct arguments for setting the IAM policy for a runtime template.zto set IAM policy forTr   N)rD   r   AddArgForPolicyFiler|   s    r&   AddSetIamPolicyBindingFlagsr     s"    %T v&r%   c                 J    t        | dd       t        j                  |        y)zOConstruct arguments for removing an IAM policy binding from a runtime template.zto remove IAM policy fromTr   N)rD   r    AddArgsForRemoveIamPolicyBindingr|   s    r&   AddRemoveIamPolicyBindingFlagsr     s"    ) ++F3r%   c                 >   t        | d       t        | dd       | j                  ddd       | j                  d	d
d       | j                  ddd       | j                  ddd       | j                  ddt        j                         d       t        |        y)z+Construct arguments for creating a runtime.zto create runtimerA   zto configure the runtime withFr   z--runtime-idzQThe id of the runtime to create. If not specified, a random id will be generated.r   r   Tz*The display name of the runtime to create.r   zThe descriptionz--runtime-userzUser email for the runtime owner. Runtimes can only be used by the owner. If a user is not provided, the gcloud user will be assumed to be the owner. The user cannot be a service account.r   r   r   r   N)rM   rD   r   r   r   r}   r|   s    r&   AddCreateRuntimeFlagsr     s     v$78-U 		   	7  
 	o<MND	   	C 	   vr%   c                     t        | d       y)z5Construct arguments specific to describing a runtime.r   r   N)rJ   r|   s    r&   AddDescribeRuntimeFlagsr   .  s    ]3r%   c                 p    t        | d       | j                  j                  t        j                         y)z1Construct arguments specific to listing runtimes.zfor which to list all runtimesr   N)rM   r   r   runtimes_utilGetRuntimeUrir|   s    r&   AddListRuntimeFlagsr   3  s'    v$DE  !<!<=r%   c                 4    t        | d       t        |        y)z3Construct arguments specific to deleting a runtime.r   r   NrJ   r}   r|   s    r&   AddDeleteRuntimeFlagsr   9  s    [1vr%   c                 4    t        | d       t        |        y)z4Construct arguments specific to upgrading a runtime.z
to upgrader   Nr   r|   s    r&   AddUpgradeRuntimeFlagsr   ?  s    \2vr%   c                 4    t        | d       t        |        y)z;Construct arguments specific to starting a stopped runtime.zto startr   Nr   r|   s    r&   AddStartRuntimeFlagsr   E  s    Z0vr%   c                 4    t        | d       t        |        y)z3Construct arguments specific to stopping a runtime.zto stopr   Nr   r|   s    r&   AddStopRuntimeFlagsr   K  s    Y/vr%   N)F)5__doc__'googlecloudsdk.api_lib.colab_enterpriser   r   r   r   googlecloudsdk.callioper   r    googlecloudsdk.calliope.conceptsr   r   +googlecloudsdk.command_lib.colab_enterpriser	   +googlecloudsdk.command_lib.compute.networksr
   rT   3googlecloudsdk.command_lib.compute.networks.subnetsra   googlecloudsdk.command_lib.iamr   (googlecloudsdk.command_lib.util.conceptsr   googlecloudsdk.corer   r   r   r   r'   rD   rJ   rM   r\   rh   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$   r%   r&   <module>r      s    B _ M / ( 5 1 B V ] 3 D *  G) %
&R64>&R+\&L^%PDNK
O1'4&R4
>r%   