
    f                     T   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KJ	r  SSKJr  SS	KJr        SS
 jrS rS rS rS rS rS rS r\R.                  " \R0                  R2                  5      \R4                   " S S\R6                  5      5       5       r\R.                  " \R0                  R:                  5       " S S\5      5       r\R.                  " \R0                  R>                  5       " S S\5      5       r SS0\l!        SS0\l!        SS0\ l!        g)z(Command for compute reservations update.    )base_classes)request_helper)utils)base)
exceptions)flags)resource_args)utilc                    SnSS/n	Sn
U(       a  U	R                  / SQ5        U
S-  n
U(       a  U	R                  S/5        U
S-  n
U(       a  U	R                  S	S
/5        U
S-  n
U(       a  U	R                  S/5        U
S-  n
U(       a  U	R                  S/5        U
S-  n
U(       a  U	R                  S/5        U
S-  n
SnU(       a  U R                  S5      nU R                  S5      nU R                  S5      nU(       d  U(       d  U(       a  SnU(       a  U(       d  U(       a  U(       d  U(       a  U(       a  [        R                  " SSS5      eU(       a@  [	        U S/ 5       H/  nUR                  5       (       a  M  [        R                  " SS5      e   U(       + =(       a    U R                  S5      (       + nU(       aQ  U R                  S5      =(       d)    U R                  S5      =(       d    U R                  S5      nU=(       a    U(       + nU(       a  U=(       a    U R                  S5      (       + nU(       a  U=(       a    U R                  S5      (       + nU(       a  U=(       a    U R                  S5      (       + nU(       a  U=(       a    U R                  S 5      (       + nU(       a  [        R                  " U	U
5      eg!)"at  Validates that both share settings arguments are mentioned.

Args:
  args: The arguments given to the update command.
  support_share_with_flag: Check if share_with is supported.
  support_auto_delete: Check if auto-delete settings are supported.
  support_reservation_sharing_policy: Check if reservation sharing policy is
    supported.
  support_emergent_maintenance: Check if emergent maintenance is supported.
  support_share_type: Check if share setting is supported.
  support_scheduling_type: Check if scheduling type is supported.
  support_early_access_maintenance: Check if early access maintenance is
    supported.
Fz--share-withz
--vm-countzPlease provide one of these options: 1- Specify share-with or add-share-with or remove-share-with to update the project list. 2- Specify reservation vm-count to resize. )z--delete-at-timez--delete-after-durationz--disable-auto-deletez3- Modify auto-delete properties with specifing auto-delete-at-time or auto-delete-after-duration or disable-auto-delete flags.z--reservation-sharing-policyzU4- Modify reservation sharing policy with specifying reservation-sharing-policy flag.z--enable-emergent-maintenancez --no-enable-emergent-maintenancezP5- Modify emergent maintenance with specifying enable-emergent-maintenance flag.z--share-settingz;6- Modify share setting with specifying share-setting flag.z--scheduling-typez?7- Modify scheduling type with specifying scheduling-type flag.z--early-access-maintenancezQ8- Modify early access maintenance with specifying early-access-maintenance flag.
share_withadd_share_withremove_share_withTz--add-share-withz--remove-share-withz4Please specify project number (not project id/name).vm_countdelete_at_timedelete_after_durationdisable_auto_deletereservation_sharing_policyenable_emergent_maintenancescheduling_typeearly_access_maintenanceN)extendIsSpecifiedr   ConflictingArgumentsExceptiongetattr	isnumericInvalidArgumentExceptionMinimumArgumentException)argssupport_share_with_flagsupport_auto_delete"support_reservation_sharing_policysupport_emergent_maintenancesupport_share_typesupport_scheduling_type support_early_access_maintenancer   parameter_namesone_option_exception_messagehas_share_withhas_add_share_withhas_remove_share_withprojectminimum_argument_specifiedauto_delete_settings_updateds                    *lib/surface/compute/reservations/update.py_ValidateArgsr/      s   2 */
2    
 !	D 
 (&  !	,  "'*  !	-    !E    !I  &$  !	* 
 .%%l3N''(89**+>?)-BJ,
2
!6

2
2*,A  4!4b9  11!B
 	
 : $.~  d6F6F7 3 #'#3#34D#E $01 	312 !
 	#G+G'G  (" 	?  !=>>  "" 	@  !>??  "N4+;+;<M+N'N  &" 	=  !;<<   

-
-o.JL L      c           	      v   UR                   R                  nSn/ nSnU(       a4  U R                  S5      (       a  [        U SS5      nUR	                  S5        U(       a  U(       dD  U R                  S5      (       d,  U R                  S5      (       d  U R                  S5      (       a  SnU R                  S5      (       aF  [
        R                  " XPUSS9nUR                  [        U S/ 5       V	s/ s H  n	S	U	-   PM
     sn	5        OSnU R                  S5      (       aG  [
        R                  " XPUSS9nUR                  [        U S/ 5       V	s/ s H  n	S	U	-   PM
     sn	5        O\U R                  S5      (       aF  [
        R                  " XPUSS9nUR                  [        U S/ 5       V	s/ s H  n	S	U	-   PM
     sn	5        [
        R                  " XQR                  5       USSSUR                  5      n
UR                  UR                  5       U
UUR                  UR                  S
9nU$ s  sn	f s  sn	f s  sn	f )a;  Create Update Request for share-with.

Returns:
update request.
Args:
 args: The arguments given to the update command.
 reservation_ref: reservation refrence.
 holder: base_classes.ComputeApiHolder.
 support_share_with_flag: Check if share_with is supported.
 support_share_type: Check if share_type is supported.
Nshare_settingzshareSettings.shareTyper   r   r   projects)r   zshareSettings.projectMap.reservationreservationResourcepathsr+   zone)clientmessagesr   r   appendr
   MakeShareSettingsWithArgsr   MakeReservationMessageNamer8    ComputeReservationsUpdateRequestr+   )r   reservation_refholderr   r#   r:   share_settingsupdate_masksetting_configsr+   
r_resourcer_update_requests               r.   _GetShareSettingUpdateRequestrG      sE    ]]##(.+/D,,_==dOT:O01 0 0 > > $ 0 01A B B $ 0 01D E E"o%%55
/lDn |R88g &
/8 	
 !O	&''334DFNt%5r::G 	$g-:  +,,334GINt%8"==G 	$g-=  **85I5I5K+94t+:+?+?A* >>!&&($%% ? ! 
Cs   0H,H1,H6c                    UR                   R                  n[        R                  " UUR	                  5       SSSSUR
                  [        U SS5      S9nUR                  UR	                  5       US/UR                  UR
                  S9$ )zCreate Update Request for the reservation sharing policy.

Returns:
  UpdateRequest
Args:
  args: The arguments given to the update command.
  reservation_ref: reservation refrence.
  holder: base_classes.ComputeApiHolder.
Nr   )r   z)reservationSharingPolicy.serviceShareTyper4   )	r9   r:   r
   r=   r>   r8   r   r?   r+   )r   r@   rA   r:   rE   s        r.   )_GetReservationSharingPolicyUpdateRequestrI      s     ]]##(**



!(
,d"* 
	2	2!&&($89%% 
3 
 r0   c                     UR                   R                  nSnU R                  S5      (       a  U R                  nUR	                  UR                  5       UR                  US9UR                  UR                  S9nU$ )zCreate Update Request for vm_count.

Returns:
resize request.
Args:
 args: The arguments given to the update command.
 reservation_ref: reservation refrence.
 holder: base_classes.ComputeApiHolder.
Nr   )specificSkuCount)r5   reservationsResizeRequestr+   r8   )	r9   r:   r   r    ComputeReservationsResizeRequestr>   ReservationsResizeRequestr+   r8   )r   r@   rA   r:   r   r_resize_requests         r.   _GetResizeRequestrP     s     ]]##((	j!!}}H >>!&&( ( B B# !C !%%% ? ! 
r0   c                 .   UR                   R                  n/ nU R                  S5      (       a  UR                  S5        U R                  nOSnU R                  S5      (       a  UR                  S5        U R
                  nOSnU R                  S5      (       a  UR                  S5        [        R                  " UUR                  5       SSSSUR                  UU5	      nUR                  UR                  5       UUUR                  UR                  S9$ )z;Create Update Request for modifying auto-delete properties.r   deleteAtTimeNr   deleteAfterDurationr   r4   )r9   r:   r   r;   r   r   r
   r=   r>   r8   r?   r+   )r   r@   rA   r:   rC   r   r   rE   s           r.   _AutoDeleteUpdateRequestrT   1  s   ]]##(+	&''~&((NN	-..,- 66 	+,,~&**




* 
	2	2!&&($%% 
3 
 r0   c                 n   UR                   R                  n/ nU R                  S5      (       a  UR                  S5        U R                  nOSn[
        R                  " UUR                  5       SSSSUR                  US9nUR                  UR                  5       UUUR                  UR                  S9$ )z8Create Update Request for enabling emergent maintenance.r   enableEmergentMaintenanceN)r   r4   )r9   r:   r   r;   r   r
   r=   r>   r8   r?   r+   )r   r@   rA   r:   rC   r   rE   s          r.   '_EnableEmergentMaintenanceUpdateRequestrW   \  s    ]]##(+	34423"&"B"B"&**



"=	* 
	2	2!&&($%% 
3 
 r0   c                 n   UR                   R                  n/ nU R                  S5      (       a  UR                  S5        U R                  nOSn[
        R                  " UUR                  5       SSSSUR                  US9nUR                  UR                  5       UUUR                  UR                  S9$ )z*Create Update Request for scheduling type.r   schedulingTypeN)r   r4   )r9   r:   r   r;   r   r
   r=   r>   r8   r?   r+   )r   r@   rA   r:   rC   r   rE   s          r.   _SchedulingTypeUpdateRequestrZ   |  s    ]]##(+	'(('(**OO**



%	* 
	2	2!&&($%% 
3 
 r0   c                 n   UR                   R                  n/ nU R                  S5      (       a  UR                  S5        U R                  nOSn[
        R                  " UUR                  5       SSSSUR                  US9nUR                  UR                  5       UUUR                  UR                  S9$ )z3Create Update Request for early access maintenance.r   earlyAccessMaintenanceN)r   r4   )r9   r:   r   r;   r   r
   r=   r>   r8   r?   r+   )r   r@   rA   r:   rC   r   rE   s          r.   $_EarlyAccessMaintenanceUpdateRequestr]     s    ]]##(+	011/0#<<#**



7	* 
	2	2!&&($%% 
3 
 r0   c                   J    \ rS rSrSrSrSrSrSrSr	Sr
Sr\S 5       rS rSrg)	Updatei  #Update Compute Engine reservations.FTc                    [         R                  " 5       R                  USS9  [        R                  " 5       R                  U5        [        R                  " 5       R                  U5        [        R                  " S5      R                  U5        [        R                  " 5       R                  U5        [        R                  " 5       R                  U5        [        R                  " 5       R                  U5        g )Nupdateoperation_typeF)r	   GetReservationResourceArgAddArgumentr_flagsGetAddShareWithFlagAddToParserGetRemoveShareWithFlagGetVmCountFlagGetReservationSharingPolicyFlag GetEnableEmergentMaintenanceFlagGetSchedulingTypeFlag)clsparsers     r.   ArgsUpdate.Args  s    ++-99x : )!--f5""$0085!--f5++-99&A,,.::6B!!#//7r0   c                    [         R                  " U R                  5       5      nUR                  nUR                  R
                  R                  n[        UU R                  U R                  U R                  U R                  U R                  U R                  U R                  5        [        R                   " 5       R#                  UU[$        R&                  " UR                  5      S9n[)        5       n/ nSnUR+                  S5      (       d  UR+                  S5      (       a  SnU R                  (       a  UR+                  S5      (       a  SnU(       a  [-        XX R                  U R                  5      n	UR/                  [)        [0        R2                  " USU	4/UR                  R
                  R4                  UR                  R6                  US95      5        U(       a  [8        R:                  " U5        U R                  (       a  UR+                  S	5      (       aq  [=        XU5      n
UR/                  [)        [0        R2                  " USU
4/UR                  R
                  R4                  UR                  R6                  US95      5        UR+                  S
5      (       a:  [?        XU5      nUR/                  UR                  R3                  USU4/5      5        U R                  (       a  UR+                  S5      (       d,  UR+                  S5      (       d  UR+                  S5      (       a  [A        XU5      n	UR/                  [)        [0        R2                  " USU	4/UR                  R
                  R4                  UR                  R6                  US95      5        U(       a  [8        R:                  " U5        U R                  (       a  UR+                  S5      (       a  [C        XU5      n	UR/                  [)        [0        R2                  " USU	4/UR                  R
                  R4                  UR                  R6                  US95      5        U(       a  [8        R:                  " U5        U R                  (       a  UR+                  S5      (       a  [E        XU5      n	UR/                  [)        [0        R2                  " USU	4/UR                  R
                  R4                  UR                  R6                  US95      5        U(       a  [8        R:                  " U5        U R                  (       a  UR+                  S5      (       a  [G        XU5      n	UR/                  [)        [0        R2                  " USU	4/UR                  R
                  R4                  UR                  R6                  US95      5        U(       a  [8        R:                  " U5        U$ )z(Common routine for updating reservation.)scope_listerFr   r   Tr   r_   )requestshttp	batch_urlerrorsr   r   Resizer   r   r   r   r   r   )$r   ComputeApiHolderReleaseTrack	resourcesr9   apitools_clientreservationsr/   _support_share_with_flag_support_auto_delete#_support_reservation_sharing_policy_support_emergent_maintenance_support_share_type_support_scheduling_type!_support_early_access_maintenancer	   re   ResolveAsResourcecompute_flagsGetDefaultScopeListerlistr   rG   r;   r   MakeRequestsrv   rw   r   RaiseToolExceptionrI   rP   rT   rW   rZ   r]   )selfr   rA   r|   servicer@   resultrx   r   rF   r_sharing_policy_requestrO   s               r.   Run
Update.Run  s   **4+<+<+>?F  Imm++88G %%!!00**  %%..	 $== "88G  I  VFFJ())T-=-=. .j$$			,	'	'
6
)F)F

"
"$ mm
))$h0@AB}}4499"MM33	!"# 
  (//			6	7	7#L6$
  	++&2JKL66;;$mm55!			
 
##*4&Imm
--
$
$;K'L&M
OQ   			*	+	+


2
3
334436
 	++&2BCD66;;$mm55!			
 

"
"6
*))			7	8	8B6
 	++&2BCD66;;$mm55!		 

"
"6
*$$			+	,	,76
 	++&2BCD66;;$mm55!			
 

"
"6
*--			4	5	5?6
 	++&2BCD66;;$mm55!			
 

"
"6
*Mr0    N)__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r   classmethodrq   r   __static_attributes__r   r0   r.   r_   r_     sI     ,"(,%"&!&+#8 8Pr0   r_   c                   D    \ rS rSrSrSrSrSrSrSr	Sr
Sr\S 5       rSrg)
UpdateBetaib  r`   TFc                    [         R                  " 5       R                  USS9  [        R                  " 5       R                  U5        [        R                  " 5       R                  U5        [        R                  " 5       R                  U5        [        R                  " S5      R                  U5        [        R                  " 5       R                  U5        [        R                  " 5       R                  U5        [        R                  " SS9R                  U5        [        R                  " 5       R                  U5        [        R                  " SSSS9nUR                  [        R                  " 5       5        UR                  [        R                   " 5       5        UR                  [        R"                  " 5       5        UR                  U5        g Nrb   rc   F)support_folder_share_settingz/Manage auto-delete properties for reservations.T)requiredmutex)r	   re   rf   rg   GetShareWithFlagri   rh   rj   rk   rl   rm   GetSharedSettingFlagrn   r   ArgumentGroupGetDeleteAtTimeFlagGetDeleteAfterDurationFlagGetDisableAutoDeletero   rp   auto_delete_groups      r.   rq   UpdateBeta.Argsm  sP   ++-99x : )**62!--f5""$0085!--f5++-99&A,,.::6B  %*,,7K,?!!#//7**9
 !!'"="="?@!!'"D"D"FG!!'">">"@A!!&)r0   r   Nr   r   r   r   r   r   r   r   r   r   r   r   r   rq   r   r   r0   r.   r   r   b  sA    +!(,%"&!&+#* *r0   r   c                   D    \ rS rSrSrSrSrSrSrSr	Sr
Sr\S 5       rSrg)UpdateAlphai  r`   Tc                    [         R                  " 5       R                  USS9  [        R                  " 5       R                  U5        [        R                  " 5       R                  U5        [        R                  " 5       R                  U5        [        R                  " S5      R                  U5        [        R                  " 5       R                  U5        [        R                  " 5       R                  U5        [        R                  " SS9R                  U5        [        R                  " 5       R                  U5        [        R                  " 5       R                  U5        [        R                  " SSSS9nUR                  [        R                   " 5       5        UR                  [        R"                  " 5       5        UR                  [        R$                  " 5       5        UR                  U5        g r   )r	   re   rf   rg   r   ri   rh   rj   rk   rl   rm   r   rn   GetEarlyAccessMaintenanceFlagr   r   r   r   r   r   s      r.   rq   UpdateAlpha.Args  si   ++-99x :  **62!--f5""$0085!--f5++-99&A,,.::6B  %*,,7K,?!!#//7))+77?**9
 !!'"="="?@!!'"D"D"FG!!'">">"@A!!&)r0   r   Nr   r   r0   r.   r   r     sA    +!(,%"&!&*#* *r0   r   EXAMPLESa  
        To add `project-1,project-2,project-3` to the list of projects that are shared with a Compute Engine reservation, `my-reservation` in zone: `us-central1-a`, run:

            $ {command} my-reservation --add-share-with=project-1,project-2,project-3 --zone=us-central1-a

        To remove `project-1,project-2,project-3` from the list of projects that are shared with a Compute Engine reservation, `my-reservation` in zone: `us-central1-a`, run:

            $ {command} my-reservation --remove-share-with=project-1,project-2,project-3 --zone=us-central1-a

        To update the number of reserved VM instances to 500 for a Compute Engine reservation, `my-reservation` in zone: `us-central1-a`, run:

            $ {command} my-reservation --zone=us-central1-a --vm-count=500
        a  
        To add `project-1,project-2,project-3` to the list of projects that are shared with a Compute Engine reservation, `my-reservation` in zone: `us-central1-a`, run:

            $ {command} my-reservation --add-share-with=project-1,project-2,project-3 --zone=us-central1-a

        To remove `project-1,project-2,project-3` from the list of projects that are shared with a Compute Engine reservation, `my-reservation` in zone: `us-central1-a`, run:

            $ {command} my-reservation --remove-share-with=project-1,project-2,project-3 --zone=us-central1-a

        To update the entire list of projects that are shared with a Compute Engine reservation, `my-reservation` in zone: `us-central1-a`, run:

            $ {command} my-reservation --share-with=project-1,project-2,project-3 --zone=us-central1-a

        To update the number of reserved VM instances to 500 for a Compute Engine reservation, `my-reservation` in zone: `us-central1-a`, run:

            $ {command} my-reservation --zone=us-central1-a --vm-count=500
        N)FFFFFF)"r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer   r   /googlecloudsdk.command_lib.compute.reservationsrg   r	   r
   r/   rG   rI   rP   rT   rW   rZ   r]   ReleaseTracksr{   GAUniverseCompatibleUpdateCommandr_   BETAr   ALPHAr   detailed_helpr   r0   r.   <module>r      sW   / 8 9 0 ( . E L I @ ',!&!%*QLhAHD4(V@<< D%%(()eT e  *eP D%%**+ *  * , *F D%%++,#*& #* -#*N 	 $ 	
 , 	 r0   