
    KA                     D   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r
  S$S jrS	 rS%S
 jrS rS rS%S jrS&S jrS&S jrS&S jrS'S jrS'S jrS&S jrS&S jrS rS rS rS rS&S jrS&S jrS&S jrS%S jrS$S jr S$S jr!S%S  jr"S! r#S" r$     S(S# jr%g))z8Flags and helpers for the compute reservations commands.    )absolute_import)division)unicode_literals)arg_parsers)base)flagsc                 `    SR                  U (       a  SOS5      n[        R                  " SUS9$ )Nz1  An optional description of the {} to create.
  zfuture reservationreservationz--descriptionhelp)formatr   Argument)is_fr	help_texts     <lib/googlecloudsdk/command_lib/compute/reservations/flags.pyGetDescriptionFlagr      s4    fU!>  

     c                  2    Sn [         R                  " SSU S9$ )Nz  Indicates whether the reservation can be consumed by VMs with "any reservation"
  defined. If enabled, then only VMs that target this reservation by name using
  `--reservation-affinity=specific` can consume from this reservation.
  z--require-specific-reservation
store_trueactionr   r   r   r   s    r   GetRequireSpecificAllocationr   $   s%    )
 
&|)
M Mr   c                 <    Sn[         R                  " SU [        US9$ )Nz  The number of VM instances that are allocated to this reservation.
  The value of this field must be an int in the range [1, 1000].
  z
--vm-count)requiredtyper   r   r   intr   r   s     r   GetVmCountFlagr!   .   s'    ) 
XCi
A Ar   c                  ,    [         R                  " SSS9$ )z!Gets the --min-cpu-platform flag.z--min-cpu-platformz;Optional minimum CPU platform of the reservation to create.r   r    r   r   GetMinCpuPlatformr$   7   s    	H
J Jr   c                  .    [         R                  " SSSS9$ )zGets the --location-hint flag.z--location-hintTzQ      Used by internal tools to control sub-zone location of the instance.
      )hiddenr   r   r#   r   r   GetLocationHintr'   >   s    	

 r   c                 0    Sn[         R                  " SXS9$ )zGets the --machine-type flag.z  The type of machine (name only) that has a fixed number of vCPUs and a fixed
  amount of memory. You can also specify a custom machine type by using the
  pattern `custom-number_of_CPUs-amount_of_memory`-for example,
  `custom-32-29440`.
  z--machine-typer   r   r   r    s     r   GetMachineTyper*   H   s    ) 
'(	KKr   Nc                 z    Sn[         R                  " U (       a  U OS[        R                  " S [        S.S9SUS9$ )Gets the --local-ssd flag.a    Manage the size and the interface of local SSD to use. See
  https://cloud.google.com/compute/docs/disks/local-ssd for more information.
  *interface*::: The kind of disk interface exposed to the VM for this SSD. Valid
  values are `scsi` and `nvme`. SCSI is the default and is supported by more
  guest operating systems. NVME may provide higher performance.
  *size*::: The size of the local SSD in base-2 GB.
  --local-ssdc                 "    U R                  5       $ Nupperxs    r   <lambda>!GetLocalSsdFlag.<locals>.<lambda>`   
    !'')r   )	interfacesizespecappendr   r   r   r   r   r   ArgDictr   custom_namer   s     r   GetLocalSsdFlagrA   S   sD    ) 
 km+% 	 
 r   c           	          Sn[         R                  " U (       a  U OS[        R                  " S [        [        S.S9SUS9$ )r,   a    Manage the size and the interface of local SSD to use. See
  https://cloud.google.com/compute/docs/disks/local-ssd for more information.
  *interface*::: The kind of disk interface exposed to the VM for this SSD. Valid
  values are `scsi` and `nvme`. SCSI is the default and is supported by more
  guest operating systems. NVME may provide higher performance.
  *size*::: The size of the local SSD in base-2 GB.
  *count*::: The number of local SSD to use per VM. If you don't specify this
  argument, then the default value is 1.
  r-   c                 "    U R                  5       $ r/   r0   r2   s    r   r4   *GetLocalSsdFlagWithCount.<locals>.<lambda>v   r6   r   )r7   r8   countr9   r;   r<   r=   r?   s     r   GetLocalSsdFlagWithCountrF   g   sG    	) 
 km+% 	
 
 r   c                     Sn[         R                  " U (       a  U OS[        R                  " [        [
        S.SS/S9SUS9$ )	zGets the --accelerator flag.a    Manage the configuration of the type and number of accelerator cards attached.
  *count*::: The number of accelerators to attach to each instance in the reservation.
  *type*::: The specific type (e.g. `nvidia-tesla-k80` for nVidia Tesla K80) of
  accelerator to attach to instances in the reservation. Use `gcloud compute accelerator-types list`
  to learn about all available accelerator types.
  z--accelerator)rE   r   rE   r   )r:   required_keysr;   r<   )r   r   r   r>   r   strr?   s     r   GetAcceleratorFlagrJ   ~   sN    ) 
 ko $V,	.
 
 r   c                     SnSSS.nU(       a  UR                  SS05        [        R                  " U (       a  U OSUUS9$ )	zGets the --share-setting flag.z/  The projects that can use the reservation.
  zEOnly your project can use the reservation. This is the default value.z          Your project and up to 100 other projects within your
          project's organization can use the reservation. If you specify
          this value, then you must also include the --share-with flag in
          the command.
        )localprojectsfolderszEAny project on the specified list of folders can use the reservation.z--share-settingchoicesr   )updater   r   )r@   support_folder_share_settingr   rP   s       r   GetSharedSettingFlagrS      sX    )"	' "NNI  ; < = 
 k&7
 r   c                 |    SnU(       a  Sn[         R                  " U (       a  U OS[        R                  " SS9SUS9$ )zGets the --share-with flag.z    If this reservation is shared (--share-setting=projects), then specify a
    comma-separated list of projects to share the reservation with. List
    projects using project IDs or project numbers.
    z    If this reservation is shared (--share-setting=projects), then specify a
    comma-separated list of projects to share the reservation with. List
    projects using project IDs, project numbers, or folder IDs.
    z--share-with   
min_length
SHARE_WITHr   metavarr   r   r   r   ArgList)r@   rR   r   s      r   GetShareWithFlagr]      sC    )
 "I
 
 kn!,	
 r   c                 j    Sn[         R                  " U (       a  U OS[        R                  " SS9SUS9$ )zGets the --add-share-with flag.z  If this reservation is shared (--share-setting is projects), then
  specify a comma-separated list of projects to share the reservation
  with. You must list the projects using project IDs or project numbers.
  z--add-share-withrU   rV   PROJECTrY   r[   r?   s     r   GetAddShareWithFlagr`      s8    )
 
 k&8!,	
 r   c                 j    Sn[         R                  " U (       a  U OS[        R                  " SS9SUS9$ )z"Gets the --remove-share-with flag.z  A list of specific projects to remove from the list of projects that this
  reservation is shared with. List must contain project IDs or project numbers.
  z--remove-share-withrU   rV   r_   rY   r[   r?   s     r   GetRemoveShareWithFlagrb      s8    ) 
 k&;!,	
 r   c                  b    Sn [         R                  " S[        R                  R                  U S9$ )zGets the --delete-at-time flag.an    Automatically deletes the reservation at a specific time from its creation.
  The specified time must be an RFC3339 timestamp, which must be
  formatted as "YYYY-MM-DDTHH:MM:SSZ" where YYYY = year, MM = month, DD = day,
  HH = hours, MM = minutes, SS = seconds, and Z = time zone in
  Coordinated Universal Time (UTC). For example, specify 2021-11-20T07:00:00Z.
  z--delete-at-timer   r   )r   r   r   DatetimeParser   s    r   GetDeleteAtTimeFlagrg      s/    ) 
{3399	
 r   c                  X    Sn [         R                  " S[        R                  " 5       U S9$ )Na    Automatically deletes the reservations after a specified number of
  days, hours, minutes, or seconds from its creation. For example,
  specify 30m for 30 minutes, or 1d2h3m4s for 1 day, 2 hours,
  3 minutes, and 4 seconds. For more information, see $ gcloud topic datetimes.
  z--delete-after-durationrd   )r   r   r   Durationr   s    r   GetDeleteAfterDurationFlagrj      s.    ) 
!
 r   c           	      4    U R                  SSS SSSS.SS	9  g
)zAdds scope flag to the parser.z--scopeSCOPEc                 "    U R                  5       $ r/   )lowerr2   s    r   r4   AddScopeFlags.<locals>.<lambda>   
    QWWYr   z4Perform maintenance on all hosts in the reservation.zOPerform maintenance only on the hosts in the reservation that have running VMs.zUPerform maintenance only on the hosts in the reservation that don't have running VMs.)allrunningunusedz1The maintenance scope to set for the reservation.)rZ   r   rP   r   N)add_argument)parsers    r   AddScopeFlagsrv      s5    G#)
 ?  r   c                  2    Sn [         R                  " SSU S9$ )z$Gets the --disable-auto-delete flag.z:  Disables the auto-delete setting for the reservation.
  z--disable-auto-deleter   r   r   r   s    r   GetDisableAutoDeleterx     s$    ) 
l
 r   c                 l    Sn[         R                  " U =(       d    SS[        R                  " 5       US9$ )z"Gets the --resource-policies flag.z  The resource policies to include in this reservation. If you omit this flag,
  no resource policies are added. You can specify any string as the key, and
  specify the name of a resource policy as the value.
  z--resource-policiesz	KEY=VALUE)rZ   r   r   )r   r   r   r>   r?   s     r   GetResourcePolicyFlagrz     s7    )
 
** 	
 r   c                 B    Sn[         R                  " U =(       d    SUS9$ )z)Gets the --source-instance-template flag.z  The url of the instance template that will be used to populate the fields of
  the reservation. Instance properties can not be defined in addition to source
  instance template.
  z--source-instance-templater   r   r?   s     r   GetSourceInstanceTemplateFlagr|   #  s'    )
 
11	
 r   c                 N    Sn[         R                  " U =(       d    SS SSS.US9$ )z+Gets the --reservation-sharing-policy flag.z@  The reservation sharing policy to use for this reservation.
  z--reservation-sharing-policyc                 "    U R                  5       $ r/   r0   r2   s    r   r4   1GetReservationSharingPolicyFlag.<locals>.<lambda>6  rp   r   z9The reservation can be shared with Google Cloud services.zThe reservation won't be shared with Google Cloud services. If you omit this flag during creation, the default value is DISALLOW_ALL.)	ALLOW_ALLDISALLOW_ALL)r   rP   r   r   r?   s     r   GetReservationSharingPolicyFlagr   /  s=    ) 
33 J	 
 r   c           	      B    Sn[         R                  " SS SSSSS.U US	9$ )
zGets the --tpu-version flag.z)  The version of Cloud TPU to reserve.
  z--tpu-versionc                 "    U R                  5       $ r/   r0   r2   s    r   r4   GetTpuVersion.<locals>.<lambda>L  rp   r   zCloud TPU v5e LitezCloud TPU v5pzCloud TPU v6ezCloud TPU v7x)V5EV5PV6ETPU7Xr   rP   r   r   r   r    s     r   GetTpuVersionr   E  s;    ) 
%  "	 
 r   c                 :    Sn[         R                  " S[        XS9$ )zGets the --chip-count flag.z$  The number of chips to reserve.
  z--chip-count)r   r   r   r   r    s     r   GetChipCountr   X  s#    ) 
3
 r   c                 >    Sn[         R                  " SS SSS.U US9$ )zGets the --workload-type flag.z.  The workload type of the TPU reservation.
  z--workload-typec                 "    U R                  5       $ r/   r0   r2   s    r   r4   !GetWorkloadType.<locals>.<lambda>i  rp   r   zPReserved resources will be optimized for SERVING workloads, such as ML inferencezNReserved resources will be optimized for BATCH workloads, such as ML training.)SERVINGBATCHr   r   r    s     r   GetWorkloadTyper   b  s9    ) 
!!	 
 r   c                 0    Sn[         R                  " SXS9$ )z!Gets the --accelerator-type flag.z6  The accelerator type to use for this reservation.
  z--accelerator-typer)   r   r    s     r   GetAcceleratorTyper   y  s    ) 
+h	OOr   c                  N    Sn [         R                  " S[        R                  U S9$ )z--emergent-maintenance flag.z  Enables the reservation to receive notifications when urgent maintenance
  for a GPU VM starts after the VM encounters a host error.
  z--enable-emergent-maintenancer   )r   r   r   StoreTrueFalseActionr   s    r    GetEnableEmergentMaintenanceFlagr     s+    ) 
%--
 r   c                  8    Sn [         R                  " SSSS.U S9$ )z--scheduling-type flag.zM  How Compute Engine schedules maintenance events for your reserved hosts.
  z--scheduling-typezAIn GROUPED mode, maintenance is synchronized across all your VMs.zSIn INDEPENDENT mode, your VMs have different, unsynchronized maintenance schedules.)GROUPEDINDEPENDENTrO   r   r   s    r   GetSchedulingTypeFlagr     s3    ) 
(	 
 r   c                 l   [        5       R                  U 5        U(       a  [        5       R                  U 5        [        R                  " SSS9nUR                  [        5       5        UR                  [        5       5        UR                  [        5       5        [        R                  " SSSS9nUR                  [        5       5        [        R                  " SSS9nUR                  [        5       5        UR                  [        5       5        U(       a  UR                  [        5       5        OUR                  [        5       5        UR                  [        5       5        UR                  [        5       5        U(       aH  UR                  [         R"                  " 5       5        UR                  [         R$                  " 5       5        UR                  U5        UR                  U5        UR                  U 5        [        R                  " SSS9n	U	R                  ['        US	95        U	R                  [)        US	95        U	R                  U 5        U(       aZ  [        R                  " S
SSS9n
U
R                  [+        5       5        U
R                  [-        5       5        U
R                  U 5        gg)z-Adds all flags needed for the create command.z.Manage the SpecificSKU reservation properties.T)r   z?Manage the instance properties for the SpecificSKU reservation.)r   mutexzJDefine the individual instance properties for the SpecificSKU reservation.Fz.Manage the properties of a shared reservation.)rR   z/Manage auto-delete properties for reservations.N)r   AddToParserr   r   ArgumentGroupAddArgumentr   r!   rz   r|   r$   r*   rF   rA   rJ   r'   instance_flagsAddMaintenanceFreezeDurationAddMaintenanceIntervalrS   r]   rg   rj   )ru   support_fleetrR   support_ssd_countsupport_auto_delete"support_reservation_sharing_policyspecific_sku_groupspecific_sku_properties_groupinstance_properties_groupshare_groupauto_delete_groups              r   AddCreateFlagsr     sE    ""6*'#%11&9))6G   !=!?@  !12  !6!89
 #'"4"4G#  ++,I,KL #00
 ''(9(;<''(89))*B*DE))/*;<''(:(<=''(9:))3357))--/1  ++,EF  !>?  (""6H+'C
 'C
 &!**9
 !!"5"78!!"<">?!!&) r   )F)Tr/   )NF)FFFFF)&__doc__
__future__r   r   r   googlecloudsdk.callioper   r   ,googlecloudsdk.command_lib.compute.instancesr   r   r   r   r!   r$   r'   r*   rA   rF   rJ   rS   r]   r`   rb   rg   rj   rv   rx   rz   r|   r   r   r   r   r   r   r   r   r#   r   r   <module>r      s    ? &  ' / ( PMAJL(.(2(
*	,&.P
. !&',M*r   