
    ]                     p   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
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\
R4                  " \
R6                  R8                  5      \
R:                   " S S\
R<                  5      5       5       r\
R4                  " \
R6                  R@                  5       " S S\5      5       r!\
R4                  " \
R6                  RD                  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.    )absolute_import)division)unicode_literals)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	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  [        R                  " UU	5      eg)a  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.
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.
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_typeN)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_typer   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_ValidateArgsr0       s   , */
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Namer9    ComputeReservationsUpdateRequestr,   )r    reservation_refholderr!   r%   r;   share_settingsupdate_masksetting_configsr,   
r_resourcer_update_requests               r/   _GetShareSettingUpdateRequestrH      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.serviceShareTyper5   )	r:   r;   r   r>   r?   r9   r   r@   r,   )r    rA   rB   r;   rF   s        r/   )_GetReservationSharingPolicyUpdateRequestrJ      s     ]]##(**



!(
,d"* 
	2	2!&&($89%% 
3 
 r1   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)r6   reservationsResizeRequestr,   r9   )	r:   r;   r   r    ComputeReservationsResizeRequestr?   ReservationsResizeRequestr,   r9   )r    rA   rB   r;   r   r_resize_requests         r/   _GetResizeRequestrQ   
  s     ]]##((	j!!}}H >>!&&( ( B B# !C !%%% ? ! 
r1   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   r5   )r:   r;   r   r<   r   r   r   r>   r?   r9   r@   r,   )r    rA   rB   r;   rD   r   r   rF   s           r/   _AutoDeleteUpdateRequestrU   $  s   ]]##(+	&''~&((NN	-..,- 66 	+,,~&**




* 
	2	2!&&($%% 
3 
 r1   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   r5   )r:   r;   r   r<   r   r   r>   r?   r9   r@   r,   )r    rA   rB   r;   rD   r   rF   s          r/   '_EnableEmergentMaintenanceUpdateRequestrX   O  s    ]]##(+	34423"&"B"B"&**



"=	* 
	2	2!&&($%% 
3 
 r1   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   r5   )r:   r;   r   r<   r   r   r>   r?   r9   r@   r,   )r    rA   rB   r;   rD   r   rF   s          r/   _SchedulingTypeUpdateRequestr[   o  s    ]]##(+	'(('(**OO**



%	* 
	2	2!&&($%% 
3 
 r1   c                   F    \ 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!!#//7r1   c                 H
   [         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                  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-                  ['        [.        R0                  " USU	4/UR                  R
                  R2                  UR                  R4                  US95      5        U(       a  [6        R8                  " U5        U R                  (       a  UR)                  S	5      (       aq  [;        XU5      n
UR-                  ['        [.        R0                  " USU
4/UR                  R
                  R2                  UR                  R4                  US95      5        UR)                  S
5      (       a:  [=        XU5      nUR-                  UR                  R1                  USU4/5      5        U R                  (       a  UR)                  S5      (       d,  UR)                  S5      (       d  UR)                  S5      (       a  [?        XU5      n	UR-                  ['        [.        R0                  " USU	4/UR                  R
                  R2                  UR                  R4                  US95      5        U(       a  [6        R8                  " U5        U R                  (       a  UR)                  S5      (       a  [A        XU5      n	UR-                  ['        [.        R0                  " USU	4/UR                  R
                  R2                  UR                  R4                  US95      5        U(       a  [6        R8                  " U5        U R                  (       a  UR)                  S5      (       a  [C        XU5      n	UR-                  ['        [.        R0                  " USU	4/UR                  R
                  R2                  UR                  R4                  US95      5        U(       a  [6        R8                  " 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   ComputeApiHolderReleaseTrack	resourcesr:   apitools_clientreservationsr0   _support_share_with_flag_support_auto_delete#_support_reservation_sharing_policy_support_emergent_maintenance_support_share_type_support_scheduling_typer   rc   ResolveAsResourcecompute_flagsGetDefaultScopeListerlistr   rH   r<   r   MakeRequestsrt   ru   r   RaiseToolExceptionrJ   rQ   rU   rX   r[   )selfr    rB   rz   servicerA   resultrv   r   rG   r_sharing_policy_requestrP   s               r/   Run
Update.Run  sR   **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
*Mr1    N)__name__
__module____qualname____firstlineno____doc__r}   r~   r   r   r   r   classmethodro   r   __static_attributes__r   r1   r/   r]   r]     sC     ,"(,%"&!8 8}r1   r]   c                   @    \ 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)
UpdateBetai#  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                  " 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 Nr`   ra   F)support_folder_share_settingz/Manage auto-delete properties for reservations.T)requiredmutexr   rc   rd   re   GetShareWithFlagrg   rf   rh   ri   rj   rk   GetSharedSettingFlagrl   r	   ArgumentGroupGetDeleteAtTimeFlagGetDeleteAfterDurationFlagGetDisableAutoDeleterm   rn   auto_delete_groups      r/   ro   UpdateBeta.Args-  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!!&)r1   r   Nr   r   r   r   r   r}   r~   r   r   r   r   r   ro   r   r   r1   r/   r   r   #  s;    +!(,%"&!* *r1   r   c                   @    \ 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)UpdateAlphaiF  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                  " 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   r   s      r/   ro   UpdateAlpha.ArgsQ  sR   ++-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!!&)r1   r   Nr   r   r1   r/   r   r   F  s;    +!(,%"&!* *r1   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)FFFFF)%r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   googlecloudsdk.callioper	   r
   "googlecloudsdk.command_lib.computer   r   /googlecloudsdk.command_lib.compute.reservationsre   r   r   r0   rH   rJ   rQ   rU   rX   r[   ReleaseTracksry   GAUniverseCompatibleUpdateCommandr]   BETAr   ALPHAr   detailed_helpr   r1   r/   <module>r      sV   / &  ' 7 9 0 ( . E L I @ ',!&!ALHAHD4(V@< D%%(()QT Q  *Qh D%%**+* * ,*D D%%++,!*& !* -!*J 	 $ 	
 , 	 r1   