
    J                        S r SSKJr  SSKJr  SSKJr  SSK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
KJr  SSKJr  SSKrSS/r/ SQrS/r/ SQrSrSr\" SS/5      r " S S\
R>                  5      r S r!S r"S r#S r$S r%S r&S r'S r(S r)      S3S jr* S4S  jr+S! r,S" r-S# r.S$ r/S% r0S& r1S' r2S( r3S) r4S* r5S+ r6S5S, jr7S- r8S. r9    S6S/ jr:S0 r;S7S1 jr<S2 r=g)8z7Flags and helpers for the compute commitments commands.    )absolute_import)division)unicode_literalsN)arg_parsers)
completers)flags)scope)resource_args)	arg_utils12-month36-month)r   24-monthr   60-month)r   r   r   z%Y-%m-%dT%H:%M:%SZz%Y-%m-%dvcpumemoryc                   (   ^  \ rS rSrU 4S jrSrU =r$ )RegionCommitmentsCompleter,   c                 4   > [         [        U ]
  " SSSS.UD6  g )Ncompute.regionCommitmentsz$alpha compute commitments list --uri)
collectionlist_command )superr   __init__)selfkwargs	__class__s     ;lib/googlecloudsdk/command_lib/compute/commitments/flags.pyr   #RegionCommitmentsCompleter.__init__.   s(    	
$d4 .;     r   )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r   r   ,   s     r!   r   c                    U R                   R                  R                  U R                   R                  R                  S.n[	        U R                   R                  S5      (       a#  U R                   R                  R
                  US'   [	        U R                   R                  S5      (       a#  U R                   R                  R                  US'   U$ )N)r   r   TWENTY_FOUR_MONTHr   SIXTY_MONTHr   )
CommitmentPlanValueValuesEnumTWELVE_MONTHTHIRTY_SIX_MONTHhasattrr)   r*   )messagesresults     r   _GetFlagToPlanMapr2   6   s    %%99FF%%99JJ& X  446IJJ//AA : X  44mDD!,,@@LLF:	-r!   c                     [        U 5      U   $ N)r2   )r0   plan_args     r   TranslatePlanArgr6   D   s    	8	$X	..r!   c                 H    U R                  S5      (       a  U R                  $ g)N
auto_renewFIsSpecifiedr8   argss    r   TranslateAutoRenewArgForCreater=   H   s     	l##??	r!   c                 H    U R                  S5      (       a  U R                  $ g )Nr8   r9   r;   s    r   TranslateAutoRenewArgForUpdater?   N   s     	l##??	r!   c                 4   U R                  S5      (       a  SnSn [        R                  R                  U R                  [        5        U R                  nU(       a   [        R                  " S5      nUR                  [        R                  R                  U R                  [        5      5      nUR                  [        R                  5      R                  [        5      nU(       d  [        S5      eU$ g! [
         a    Sn Nf = f! [
         a     N3f = f)z7Translates the custom end time arg to a RFC3339 format.custom_end_timeFNTzAmerica/Los_AngeleszLInvalid custom end time. Expected format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ)r:   datetimestrptimerA   RFC3339_FORMAT
ValueErrorpytztimezonelocalizeDATE_ONLY_FORMAT
astimezoneutcstrftime)r<   try_date_only_parsefinal_date_timetzmidnight_date_time_mtvs        r   TranslateCustomEndTimeArgrQ   T   s   	'((O!  !5!5~F,,o ]]01!#&&t';';=MN"
 1;;DHHENN
 " 
 	7  ! !!  s$   :C8 BD
 8DD

DDc                     U R                  US   U R                   R                  R                  S9U R                  US   S-  U R                   R                  R                  S9/$ )Nr   amounttyper   i   )ResourceCommitmentTypeValueValuesEnumVCPUMEMORY)r0   resources_args     r   TranslateResourcesArgr[   {   ss    !!v&**>>CC " 
 !!x([9**>>EE " 

 
r!   c                    UR                   n[        X5      nSUR                  5       ;   a@  UR                  U R	                  US   U R                  R
                  R                  S95        UR                  S5      (       aP  UR                  nUR                  U R	                  US   US   U R                  R
                  R                  S95        U$ )z,Util functions to parse ResourceCommitments.	local-ssdrS   resources_acceleratorcountrU   )rT   acceleratorTyperU   )
	resourcesr[   keysappendrV   rW   	LOCAL_SSDr:   r^   ACCELERATOR)r0   r<   rZ   ra   accelerator_args        r   TranslateResourcesArgGrouprg      s    ..-#H<)M&&((## -,,@@JJ 	$ 	
 
-..00O##"7++F3,,@@LL 	$ 	
 
r!   c                 6    U (       a  U R                  S5      $ / $ )z)List arguments are delineated by a comma.,)split)args    r   TranslateMergeArgrl      s    3&B&r!   c           	      X    [         R                  " S[        U SS[         R                  S9$ )N
commitmentr   )resource_name	completerpluralnameregional_collectionregion_explanation)compute_flagsResourceArgumentr   REGION_PROPERTY_EXPLANATION)rq   s    r   MakeCommitmentArgrx      s-    		'	' *5&BB
 r!   c                     [        XU5        [        U UUUU5        [        U 5        [        U 5        [	        U 5        [        U 5        g)z4Add general arguments for `commitments create` flag.N)AddPlanForCreateAddReservationArgGroupAddResourcesArgGroupAddSplitSourceCommitmentAddMergeSourceCommitmentsAddCustomEndTime)parsersupport_share_settingsupport_stable_fleetsupport_existing_reservation"support_reservation_sharing_policysupport_60_month_plansupport_24_month_plans          r   AddCreateFlagsr      sH     62GH"( v6"F#6r!   c                 2    [        U 5        [        XU5        g)z4Add general arguments for `commitments update` flag.N)AddAutoRenewAddPlanForUpdater   r   r   s      r   AddUpdateFlagsr      s     v62GHr!   c                 \    U R                  SSU(       d  U(       a	  [        SS9$ [        SS9$ )N--planTDuration of the commitment.requiredchoiceshelp)add_argumentEXTENDED_VALID_PLANSVALID_PLANSr   s      r   rz   rz      sG    				"7 # ) 
 
 
 ( 
 
 r!   c                 \    U R                  SSU(       d  U(       a	  [        SS9$ [        SS9$ )Nr   Fr   r   )r   EXTENDED_VALID_UPDATE_PLANSVALID_UPDATE_PLANSr   s      r   r   r      sG    				"7 * ) 
 
 
 ( 
 
 r!   c                 &    U R                  SSSSS9$ )Nz--auto-renew
store_trueFz'Enable auto renewal for the commitment.)actiondefaultr   r   r   s    r   r   r      s&    			4	 
 
 r!   c                     U R                  SSSS9  U R                  SS[        SS9  U R                  S	S[        S
S9  [        U SSS9  g)z6Add license based flags for `commitments create` flag.z	--licenseTzApplicable license URI. For example: `https://www.googleapis.com/compute/v1/projects/suse-sap-cloud/global/licenses/sles-sap-12`r   r   z--cores-per-licenseFzZCore range of the instance. Must be one of: `1-2`, `3-4`, `5+`. Required for SAP licenses.r   rU   r   z--amountzNumber of licenses purchased.)r   r   N)r   strintrz   r   s    r   AddLicenceBasedFlagsr      st    h	   	5   	4c0O   Er!   c                 $    U R                  SSSS9$ )Nz--split-source-commitmentFzsCreates the new commitment by splitting the specified source commitment and redistributing the specified resources.r   r   r   s    r   r}   r}     s&    			!J	 
 
 r!   c                 $    U R                  SSSS9$ )Nz--merge-source-commitmentsFzeCreates the new commitment by merging the specified source commitments and combining their resources.r   r   r   s    r   r~   r~     s%    			">	 
 
 r!   c                 .    U R                  SS[        SS9$ )Nz--custom-end-timeFzMSpecifies a custom future end date and extends the commitment's ongoing term.r   )r   r   r   s    r   r   r   #  s(    			 
 
 r!   c           
         U R                  SSS9nSnUR                  SU[        R                  " [        [        [        R
                  " 5       S.S9S9  S	nUR                  S
U[        R                  " [        [        S.S9S9  g)zDAdd the argument group for ResourceCommitment support in commitment.z/Manage the commitment for particular resources.Tr   a  Resources to be included in the commitment. For details and examples of valid
specifications, refer to the
[custom machine type guide](https://cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type#specifications).
*memory*::: The size of the memory, should include units (e.g. 3072MB or 9GB). If no units are specified, GB is assumed.
*vcpu*::: The number of the vCPU cores.
*local-ssd*::: The size of local SSD.
z--resources)r   r]   r   spec)r   rU   aN  Manage the configuration of the type and number of accelerator cards to include in the commitment.
*count*::: The number of accelerators to include.
*type*::: The specific type (e.g. nvidia-tesla-k80 for NVIDIA Tesla K80) of the accelerator. Use `gcloud compute accelerator-types list` to learn about all available accelerator types.
z--resources-accelerator)r_   rU   N)	add_groupr   r   ArgDictr   
BinarySizer   )r   resources_groupresources_helpaccelerator_helps       r   r|   r|   /  s    $$7$ % /. #..0  

 c3$?@  r!   c                 \    [         R                  " SU R                  R                  SSS S9$ )z:Helper to get a choice flag from the commitment type enum.z--typezaType of commitment. `memory-optimized` indicates that the commitment is for memory-optimized VMs.zgeneral-purposec                     U S:g  $ )NTYPE_UNSPECIFIEDr   )xs    r   <lambda>#GetTypeMapperFlag.<locals>.<lambda>_  s
    q$66r!   )help_strr   include_filter)r   ChoiceEnumMapperr+   rW   )r0   s    r   GetTypeMapperFlagr   U  s4    		#	#--4  6	
 	r!   c                    U R                  SSS9n[        USS9  UR                  S5      n[        U5        [        R                  " S5      R                  U5        [        R                  " S5      R                  U5        [        R                  " S	5      R                  U5        [        R                  " S
5      R                  U5        [        R                  " S5      R                  U5        [        R                  " S5      R                  U5        [        R                  " S5      R                  U5        [        R                  " S5      R                  U5        U $ )z=Add reservation arguments to the update-reservations command.z8Manage reservations that are attached to the commitment.Tmutexz7Path to a YAML file of two reservations' configuration.)custom_textz:Specify source and destination reservations configuration.z--source-acceleratorz--dest-acceleratorz--source-local-ssdz--dest-local-ssdz--source-share-settingz--source-share-withz--dest-share-settingz--dest-share-with)	r   AddReservationsFromFileFlagAddReservationArgumentsreservation_flagsGetAcceleratorFlagAddToParserGetLocalSsdFlagGetSharedSettingFlagGetShareWithFlag)r   parent_reservations_groupreservations_groups      r   AddUpdateReservationGroupr   c  sK   $..@ /  K 1::B ,-&&'=>JJ &&';<HH ##$89EE ##$67CC
 (()ABNN $$%:;GG (()?@LL $$%89EE 
-r!   c                    Sn[         [         [        [         [         [        S.nU R                  S[        R
                  " US9UR                  S5      SS9  U R                  S[        R
                  " US9UR                  S	5      SS9  U $ )
zDAdd --source-reservation and --dest-reservation arguments to parser.a~  
{0} reservation configuration.
*reservation*::: Name of the {0} reservation to operate on.
*reservation-zone*:::  Zone of the {0} reservation to operate on.
*vm-count*::: 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].
*machine-type*:::  The type of machine (name only) which has a fixed number of
vCPUs and a fixed amount of memory. This also includes specifying custom machine
type following `custom-number_of_CPUs-amount_of_memory` pattern, e.g. `custom-32-29440`.
*min-cpu-platform*::: Optional minimum CPU platform of the reservation to create.
*require-specific-reservation*::: 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.
)reservationzreservation-zonezvm-countzmachine-typezmin-cpu-platformzrequire-specific-reservationz--source-reservationr   sourceT)rU   r   r   z--dest-reservationdestination)r   r   boolr   r   r   format)r   	help_textreservation_specs      r   r   r     s    ) &* 	$45H%	   	$45M*	   
-r!   c                 `    U(       a  UOSnU R                  S[        R                  " 5       US9$ )Nz<Path to a YAML file of multiple reservations' configuration.z--reservations-from-file)rU   r   )r   r   FileContents)r   r   r   s      r   r   r     s@     
 I 
 
		 ##% 
 
 r!   c                 j    SnU R                  S[        R                  " [        [        S.SS/S9SUS9$ )	z.Add --existing-reservation argument to parser.a:  
  Details of the existing on-demand reservation or auto-created future
  reservation that you want to attach to your commitment. Specify a new instance
  of this flag for every existing reservation that you want to attach. The
  reservations must be in the same region as the commitment.
  *name*::: The name of the reservation.
  *zone*::: The zone of the reservation.
  For example, to attach an existing reservation named reservation-name in the
  zone reservation-zone, use the following text:
  --existing-reservation=name=reservation-name,zone=reservation-zone
  z--existing-reservation)rr   zonerr   r   )r   required_keysrc   )rU   r   r   )r   r   r   r   )r   r   s     r   AddExistingReservationFlagr     sK    
) 
		S)&&9I  
 
 r!   c                 ^   [         R                  R                  S[        R                  R
                  S05      n[        U SS5      nUc  / $ / nU HX  nUR                  US   /[        R                  R
                  US   U5      S   nUR                  UR                  5       5        MZ     U$ )z9Method to translate existing-reservations args into URLs.r   zcompute.reservationsexisting_reservationNrr   r   r   )
ru   ResourceResolverFromMapcompute_scope	ScopeEnumZONEgetattrResolveResourcesrc   SelfLink)r<   ra   resolverexisting_reservationsreservation_urlsr   reservation_refs          r   ResolveExistingReservationArgsr     s    ++33m--224JK( "$(>E"I*k//	V	$$F	
 	O O4467 + 
r!   c                    U R                  SSS9n[        U5        U(       a  [        U5        UR                  SS9n[        R
                  " SS9R                  U5        UR                  SSS	/S	S
S9  UR                  SS9n[        Xr5        U(       a  UR                  SSS9n[        U5        U(       a  UR                  SSS9n	[        U	5        gg)z0Adds all flags needed for reservations creation.z:Manage the reservations to be created with the commitment.Tr   z9Manage the reservation to be created with the commitment.)r   F)
positionalz--reservation-typespecificz*The type of the reservation to be created.)hiddenr   r   r   z9Manage the specific SKU reservation properties to create.z7Manage the properties of a shared reservation to create)r   r   z?Manage the properties of a reservation sharing policy to createN)r   r   r   add_argument_groupr
   GetReservationResourceArgAddArgumentr   AddFlagsToSpecificSkuGroupAddFlagsToShareSettingGroup'AddFlagsToReservationSharingPolicyGroup)
r   r   r   support_existing_reservationsr   reservations_manage_groupsingle_reservation_groupspecific_sku_reservation_groupshare_setting_reservation_group reservation_sharing_policy_groups
             r   r{   r{     s    %..B$ /  78"896IIF J  ))U;GG ''l7 (  $<#N#NF $O $  $  33J 	4 	
 $   ?@''?'R'RN (S ($ ,,LM (r!   c                 d    [         R                  " 5       /nU H  nUR                  U 5        M     g)z3Adds flags needed for a reservation sharing policy.N)r   GetReservationSharingPolicyFlagr   groupr<   rk   s      r   r   r   #  s/     779
$ cOOE r!   c                    [         R                  " 5       [         R                  " SS9[         R                  " 5       [         R                  " SS9[         R
                  " 5       [         R                  " 5       [         R                  " 5       /nU(       a$  UR                  [        R                  " 5       5        U H  nUR                  U 5        M     g)z6Adds flags needed for a specific sku zonal allocation.Fr   N)r   GetRequireSpecificAllocationGetVmCountFlagGetMinCpuPlatformGetMachineTyper   r   GetResourcePolicyFlagrc   instance_flagsAddMaintenanceIntervalr   )r   r   r<   rk   s       r   r   r   ,  s     446&&6))+&&6'')**,--/
$ KK5578cOOE r!   c                     [         R                  " 5       [         R                  " 5       /nU H  nUR                  U 5        M     g)z7Adds flags needed for an allocation with share setting.N)r   r   r   r   r   s      r   r   r   ?  s;     ,,.((*
$
 cOOE r!   )FFFFFF)FFr4   )FFFF)F)>__doc__
__future__r   r   r   rB   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   compute_completersr   ru   r	   r   ,googlecloudsdk.command_lib.compute.instancesr  /googlecloudsdk.command_lib.compute.reservationsr   r
   $googlecloudsdk.command_lib.util.apisr   rF   r   r   r   r   rD   rI   sorted_REQUIRED_RESOURCESListCommandCompleterr   r2   r6   r=   r?   rQ   r[   rg   rl   rx   r   r   rz   r   r   r   r}   r~   r   r|   r   r   r   r   r   r   r{   r   r   r   r   r!   r   <module>r     s@    > &  '  / O E E P V I :  :&G  \ B % fh/0 !3!H!H /$N4'
  !&',2 @EI6	#L'T%P
.,  "'',3Nl&r!   