
    (                     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 rS	 rS
 rS rS rS rg)zOUtils for cluster maintenance window and maintenance exclusion window commands.    )absolute_import)division)unicode_literals)util)
exceptions)flagsc           
         U R                   R                  c  UR                  5       U R                   l        U R                   R                  R                  c  / U R                   R                  l        U R                   R                  R                  R	                  UR                  UR                  UR                  UR                  UR                  S9S95        U $ )a  Returns an update request with a new maintenance exclusion window with id, start time, and end time specified from args.

Args:
  req: API request to be issued.
  messages: message module of edgecontainer cluster.
  args: command line arguments.

Returns:
  modified request
)	startTimeendTime)idwindow)
clustermaintenancePolicyMaintenancePolicymaintenanceExclusionsappendMaintenanceExclusionWindowadd_maintenance_exclusion_name
TimeWindowadd_maintenance_exclusion_startadd_maintenance_exclusion_end)reqmessagesargss      Ilib/googlecloudsdk/command_lib/edge_cloud/container/maintenance_policy.py"RequestWithNewMaintenanceExclusionr      s     	[[""*$,$>$>$@CKK![[""88@:<CKK!!7++55<<))00$$<<88 %  *  
*    c                    A [         R                  " US5      (       d:  [         R                  " US5      (       d  [         R                  " US5      (       d  U$ [        U5        UR                  R	                  5       nUR
                  c)  [        R                  " U5      R                  5       Ul        UR
                  R                  (       ah  UR
                  R                  R                   HD  nUR                  UR                  :X  d  M  [        R                  " SSUR                  -   S-   5      e   [        U[        R                  " U5      U5      n[!        SU5        U$ )zAdds a maintenance exclusion window to the cluster if relevant flags are set.

Args:
  ref: reference to the cluster object.
  args: command line arguments.
  request: API request to be issued

Returns:
  modified request
r   r   r    --add-maintenance-exclusion-namezMaintenance exclusion name z already exists.r   )r   FlagIsExplicitlySet"_CheckAddMaintenanceExclusionFlagscalliope_commandReleaseTrackr   r   GetMessagesModuleClusterr   r   r   r   r   BadArgumentExceptionr   _AddFieldToUpdateMask)refr   requestrelease_trackmews        r   AddMaintenanceExclusionWindowr,   5   s!    
 
#
#D*J
K
K''.OPP''.MNNN %T*''446-__,,];CCEGO __&&00FF		,	,	6--.)CFF25GG
 	
 G /t%%m4d' +W5	.r   c                     U R                   (       d  [        R                  " SS5      eU R                  (       d  [        R                  " SS5      eU R                  (       d  [        R                  " SS5      eg)zConfirms all necessary flags for adding an exclusion window is set.

Args:
  args: arguments passed through gcloud command

Raises:
  BadArgumentException specifying missing flag
r   z4Every maintenance exclusion window must have a name.z!--add-maintenance-exclusion-startz:Every maintenance exclusion window must have a start time.z--add-maintenance-exclusion-endz9Every maintenance exclusion window must have an end time.N)r   r   r&   r   r   )r   s    r   r!   r!   `   ss     
	,	,

)
)*>  
	-	-

)
)+D  
	+	+

)
))C  
,r   c                 V   A [         R                  " US5      (       d  U$ UR                  cC  UR                  R	                  5       n[
        R                  " U5      R                  5       Ul        UR                  R                  c  [        SU5        U$ [        UR                  R                  R                  5       H#  u  pEUR                  UR                  :X  d  M!  Un  O   [        R                  " SS5      eUR                  R                  R                  U	 [        SU5        U$ )a  Removes the cluster.maintenance_policy.maintenance_exclusion_window if --remove-maintenance-exclusion-window flag is specified.

Args:
  ref: reference to the cluster object.
  args: command line arguments.
  request: API request to be issued

Returns:
  modified request
#remove_maintenance_exclusion_windowr   z%--remove-maintenance-exclusion-windowz@Cannot remove a maintenance exclusion window that doesn't exist.)r   r    r   r"   r#   r   r$   r%   r   r'   	enumerater   r   r/   r   r&   )r(   r   r)   r*   idxr+   is          r    RemoveMaintenanceExclusionWindowr3   z   s     
		"	"4)N	O	ON__))668M,,];CCEGO__&&.-w7Noo''==hc vv999
a 
)
)/J 
 oo''==a@+W5	.r   c                    A [         R                  " US5      (       d  U$ UR                  (       d  [        R                  " SS5      eUR
                  cC  UR                  R                  5       n[        R                  " U5      R                  5       Ul        UR
                  R                  (       a<  UR
                  R                  R                  (       a  [        R                  " SS5      eSUR
                  l        [        SU5        U$ )zClears cluster.maintenance_policy.window in the request if --clear-maintenance-window flag is specified.

Args:
  ref: reference to the cluster object.
  args: command line arguments.
  request: API request to be issued

Returns:
  modified request
clear_maintenance_windowz--no-clear-maintenance-windowzThe flag is not supportedNz--clear-maintenance-windowzFCannot clear a maintenance window if there are maintenance exclusions.r   )r   r    r5   r   r&   r   r"   r#   r   r$   r%   r   r   r'   )r(   r   r)   r*   s       r   ClearMaintenanceWindowr6      s     
		"	"4)C	D	DN		&	&

)
)')D  __))668M,,];CCEGO__&&((>>++
& 
 '+'//#+W5	.r   c                     UR                   (       d  Xl         U$ XR                   ;  a  UR                   S-   U -   Ul         U$ )N,)
updateMask)fieldr)   s     r   r'   r'      s?    			N
$$$ ++c1E9G	.r   N)__doc__
__future__r   r   r   +googlecloudsdk.api_lib.edge_cloud.containerr   googlecloudsdk.callioper   googlecloudsdk.command_lib.runr   r   r,   r!   r3   r6   r'    r   r   <module>rA      s>    V &  ' < . 08(V4(V"Jr   