
    (                     t    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 Zd	 Zd
 Zd Zd Zd Zy)zOUtils for cluster maintenance window and maintenance exclusion window commands.    )absolute_import)division)unicode_literals)util)
exceptions)flagsc           	         | j                   j                  |j                         | j                   _        | j                   j                  j                  g | j                   j                  _        | j                   j                  j                  j	                  |j                  |j                  |j                  |j                  |j                                     | S )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                    ~ t        j                  |d      s.t        j                  |d      st        j                  |d      s|S t        |       |j                  j	                         }|j
                  (t        j                  |      j                         |_        |j
                  j                  rd|j
                  j                  j                  D ]A  }|j                  |j                  k(  st        j                  dd|j                  z   dz          t        |t        j                  |      |      }t!        d|       |S )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''.OP''.M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                     | j                   st        j                  dd      | j                  st        j                  dd      | j                  st        j                  dd      y)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                 >   ~ t        j                  |d      s|S |j                  B|j                  j	                         }t        j                  |      j                         |_        |j                  j                  t        d|       |S t        |j                  j                  j                        D ]"  \  }}|j                  |j                  k(  s |} n t        j                  dd      |j                  j                  j                  |= t        d|       |S )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N__))668M,,];CCEGO__&&.-w7Noo''==hc3 vv999
a 
)
)/J 
 oo''==a@+W5	.r   c                    ~ t        j                  |d      s|S |j                  st        j                  dd      |j
                  B|j                  j                         }t        j                  |      j                         |_        |j
                  j                  r6|j
                  j                  j                  rt        j                  dd      d|j
                  _        t        d|       |S )a  Clears 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N		&	&

)
)')D  __))668M,,];CCEGO__&&((>>++
& 
 '+'//#+W5	.r   c                 z    |j                   s	| |_         |S | |j                   vr|j                   dz   | z   |_         |S )N,)
updateMask)fieldr)   s     r   r'   r'      sC    			G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   