
    ]                     n   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 	 	 	 	 	 ddZd Zd Zd Zd Zd Zd Z e
j4                  e
j6                  j8                        e
j:                   G d de
j<                                      Z e
j4                  e
j6                  j@                         G d de             Z! e
j4                  e
j6                  jD                         G d de             Z#ddie_$        ddie!_$        ddie#_$        y)z(Command for compute reservations update.    )absolute_import)division)unicode_literals)base_classes)request_helper)utils)base)
exceptions)flags)resource_args)utilc                    d}ddg}d}	|r|j                  g d       |	dz  }	|r|j                  dg       |	dz  }	|r|j                  d	d
g       |	dz  }	|r|j                  dg       |	dz  }	|r|j                  dg       |	dz  }	d}
|r| j                  d      }
| j                  d      }| j                  d      }|
s|s|rd}|
r|s|
r|s|r|rt        j                  ddd      |r8t	        | dg       D ](  }|j                         rt        j                  dd       | xr | j                  d       }|r>| j                  d      xs$ | j                  d      xs | j                  d      }|xr | }|r|xr | j                  d       }|r|xr | j                  d       }|r|xr | j                  d       }|rt        j                  ||	      y)a0  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           	         |j                   j                  }d}g }d}|r/| j                  d      rt        | dd      }|j	                  d       |r|s5| j                  d      s"| j                  d      s| j                  d      rd}| j                  d      rIt        j                  || |d      }|j                  t        | dg       D 	cg c]  }	d	|	z   	 c}	       nd}| j                  d      rGt        j                  || |d      }|j                  t        | dg       D 	cg c]  }	d	|	z   	 c}	       nW| j                  d      rFt        j                  || |d      }|j                  t        | dg       D 	cg c]  }	d	|	z   	 c}	       t        j                  ||j                         |ddd|j                        }
|j                  |j                         |
||j                  |j                  
      }|S c c}	w c c}	w c c}	w )aM  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      s7    ]]##(.+/D,,_=dOT:O01 0 0 > $ 0 01A B $ 0 01D E"o%55
D/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-=  **8_5I5I5K+94t+:+?+?A* >>!&&($%% ? ! 
Cs   G=%H=Hc                     |j                   j                  }t        j                  ||j	                         dddd|j
                  t        | dd            }|j                  |j	                         |dg|j                  |j
                        S )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                     |j                   j                  }d}| j                  d      r| j                  }|j	                  |j                         |j                  |      |j                  |j                        }|S )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                    |j                   j                  }g }| j                  d      r|j                  d       | j                  }nd}| j                  d      r|j                  d       | j
                  }nd}| j                  d      r|j                  d       t        j                  ||j                         dddd|j                  ||	      }|j                  |j                         |||j                  |j                        S )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   |j                   j                  }g }| j                  d      r|j                  d       | j                  }nd}t        j                  ||j                         dddd|j                  |      }|j                  |j                         |||j                  |j                        S )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23"&"B"B"&**



"=	* 
	2	2!&&($%% 
3 
 r1   c           
      n   |j                   j                  }g }| j                  d      r|j                  d       | j                  }nd}t        j                  ||j                         dddd|j                  |      }|j                  |j                         |||j                  |j                        S )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                   >    e Zd ZdZdZdZdZdZdZdZ	e
d        Zd Zy)Update#Update Compute Engine reservations.FTc                    t        j                         j                  |d       t        j                         j                  |       t        j                         j                  |       t        j                  d      j                  |       t        j                         j                  |       t        j                         j                  |       t        j                         j                  |       y )Nupdateoperation_typeF)r   GetReservationResourceArgAddArgumentr_flagsGetAddShareWithFlagAddToParserGetRemoveShareWithFlagGetVmCountFlagGetReservationSharingPolicyFlag GetEnableEmergentMaintenanceFlagGetSchedulingTypeFlag)clsparsers     r/   ArgszUpdate.Args  s    ++-99x : )!--f5""$0085!--f5++-99&A,,.::6B!!#//7r1   c           
      	   t        j                  | j                               }|j                  }|j                  j
                  j                  }t        || j                  | j                  | j                  | j                  | j                  | j                         t        j                         j!                  ||t#        j$                  |j                              }t'               }g }d}|j)                  d      s|j)                  d      rd}| j                  r|j)                  d      rd}|rt+        |||| j                  | j                        }	|j-                  t'        t/        j0                  |d|	fg|j                  j
                  j2                  |j                  j4                  |                   |rt7        j8                  |       | j                  r|j)                  d	      rtt;        |||      }
|j-                  t'        t/        j0                  |d|
fg|j                  j
                  j2                  |j                  j4                  |                   |j)                  d
      r;t=        |||      }|j-                  |j                  j1                  |d|fg             | j                  r|j)                  d      s"|j)                  d      s|j)                  d      rt?        |||      }	|j-                  t'        t/        j0                  |d|	fg|j                  j
                  j2                  |j                  j4                  |                   |rt7        j8                  |       | j                  r|j)                  d      rtA        |||      }	|j-                  t'        t/        j0                  |d|	fg|j                  j
                  j2                  |j                  j4                  |                   |rt7        j8                  |       | j                  r|j)                  d      rtC        |||      }	|j-                  t'        t/        j0                  |d|	fg|j                  j
                  j2                  |j                  j4                  |                   |rt7        j8                  |       |S )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   MakeRequestsrs   rt   r   RaiseToolExceptionrJ   rQ   rU   rX   r[   )selfr    rB   ry   servicerA   resultru   r   rG   r_sharing_policy_requestrP   s               r/   Runz
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#L/6$
  	++&2JKL66;;$mm55!			
 
#*4&Imm
--
$
$;K'L&M
OQ   			*	+


2
3343/6
 	++&2BCD66;;$mm55!			
 

"
"6
*))			7	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____doc__r|   r}   r~   r   r   r   classmethodro   r    r1   r/   r]   r]     sC     ,"(,%"&!8 8}r1   r]   c                   8    e Zd ZdZdZdZdZdZdZdZ	e
d        Zy)
UpdateBetar^   Tc                    t        j                         j                  |d       t        j                         j                  |       t        j                         j                  |       t        j                         j                  |       t        j                  d      j                  |       t        j                         j                  |       t        j                         j                  |       t        j                  d      j                  |       t        j                         j                  |       t        j                  ddd      }|j                  t        j                                |j                  t        j                                 |j                  t        j"                                |j                  |       y 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   z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   Nr   r   r   r   r|   r}   r~   r   r   r   r   ro   r   r1   r/   r   r   #  s;    +!(,%"&!* *r1   r   c                   8    e Zd ZdZdZdZdZdZdZdZ	e
d        Zy)UpdateAlphar^   Tc                    t        j                         j                  |d       t        j                         j                  |       t        j                         j                  |       t        j                         j                  |       t        j                  d      j                  |       t        j                         j                  |       t        j                         j                  |       t        j                  d      j                  |       t        j                         j                  |       t        j                  ddd      }|j                  t        j                                |j                  t        j                                 |j                  t        j"                                |j                  |       y r   r   r   s      r/   ro   z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   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[   ReleaseTracksrx   GAUniverseCompatibleUpdateCommandr]   BETAr   ALPHAr   detailed_helpr   r1   r/   <module>r      s\   / &  ' 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   