
                            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 e	j                    e	j"                  e	j$                  j&                         G d de	j(                                      Zy)z#Command for updating health checks.    )absolute_import)division)unicode_literals)base_classes)health_checks_utils)base)
exceptions)flags)logc                   H    e Zd ZdZdZed        Zd Zd Zd Z	d Z
d Zd	 Zy)
UpdatezUpdate a UDP health check.

  *{command}* is used to update an existing UDP health check. Only
  arguments passed in will be updated on the health check. Other
  attributes will remain unaffected.
  Nc                     t        j                  d      | _        | j                  j                  |d       t	        j
                  |d       t	        j                  |d       y )NUDPupdate)operation_typeF)request_and_response_required)r
   HealthCheckArgumentHEALTH_CHECK_ARGAddArgumentr   AddUdpRelatedArgsAddProtocolAgnosticUpdateArgs)clsparsers     /lib/surface/compute/health_checks/update/udp.pyArgszUpdate.Args*   sQ     44U;C$$VH$E))e555feD    c                     |j                   j                  d|j                  j                  |j	                         |j
                        fS )9Returns a request for fetching the existing health check.Get)healthCheckproject)apitools_clienthealthChecksmessagesComputeHealthChecksGetRequestNamer!   selfclienthealth_check_refs      r   _GetGetRequestzUpdate._GetGetRequest2   sI    ""//OO99,113(00 : 23 3r   c                     |j                   j                  d|j                  j                  |j	                         ||j
                        fS )0Returns a request for updating the health check.r   )r    healthCheckResourcer!   )r"   r#   r$    ComputeHealthChecksUpdateRequestr&   r!   r(   r)   r*   replacements       r   _GetSetRequestzUpdate._GetSetRequest9   sL    ""//OO<<,113$/(00 = 23 3r   c                     |j                   j                  d|j                  j                  |j	                         |j
                  |j                        fS )r   r   )r    r!   region)r"   regionHealthChecksr$   #ComputeRegionHealthChecksGetRequestr&   r!   r4   r'   s      r   _GetRegionalGetRequestzUpdate._GetRegionalGetRequestA   sS    ""55uOO??,113(00'.. @ 01 1r   c                     |j                   j                  d|j                  j                  |j	                         ||j
                  |j                        fS )r-   r   )r    r.   r!   r4   )r"   r5   r$   &ComputeRegionHealthChecksUpdateRequestr&   r!   r4   r0   s       r   _GetRegionalSetRequestzUpdate._GetRegionalSetRequestI   sV    ""55xOOBB,113$/(00'..	 C 01 1r   c                     |j                   |j                  j                  j                  j                  k7  r,t        j                  d|j                   j                  z         |j                  r|j                  }n|j                  |j                  }nd}|j                  r|j                  }n%|j                  |j                  j                  }nd}|j                  j                  |j                  ||j                  j                  j                  j                  |j                  j                  |j                  xs |j                  j                  |j                  xs |j                  j                  |j                  xs |j                  j                  |      |j                   xs |j"                  |j$                  xs |j&                  |j(                  xs |j*                  |j,                  xs |j.                        }|S )z'Returns a modified HealthCheck message.z<update udp subcommand applied to health check with protocol N)requestresponseportportName)namedescriptiontypeudpHealthCheckcheckIntervalSec
timeoutSechealthyThresholdunhealthyThreshold)rB   r$   HealthCheckTypeValueValuesEnumr   core_exceptionsErrorr@   rA   	port_namerC   r?   UDPHealthCheckr<   r=   r>   check_intervalrD   timeoutrE   healthy_thresholdrF   unhealthy_thresholdrG   )r(   r)   argsexisting_checkrA   rL   new_health_checks          r   ModifyzUpdate.ModifyR   s    	##77;;	<!!
H



"
"#$ $ $$k				!"..kk~~..i		 //88ii22  __((<<@@55LLIN$A$A$I$I]]Ln&C&C&L&L@n;;@@	 6  
 -- :(99<<<>#<#<00 :(99 44 >*== 3 " r   c                    t        j                  | j                               }|j                  }t	        j
                  |       |j                  xsR |j                  xsD |j                  xs6 |j                  xs( |j                  xs |j                  xs |j                   }|j                  #|j                  |rt        j                   d      |j                  !|j                  st        j                   d      |j                  !|j                  st        j                   d      | j"                  j%                  ||j&                        }t	        j(                  |      r| j+                  ||      }n| j-                  ||      }|j/                  |g      }| j1                  |||d         }|d   |k(  r=t2        j4                  j7                  dj9                  |d   j:                               |S t	        j(                  |      r| j=                  |||      }	n| j?                  |||      }	|j/                  |	g      S )z6Issues requests necessary to update UDP Health Checks.z'At least one property must be modified.z)"request" field for UDP can not be empty.z*"response" field for UDP can not be empty.r   z/No change requested; skipping update for [{0}].) r   ComputeApiHolderReleaseTrackr)   r   CheckProtocolAgnosticArgsr>   rN   rO   rP   rQ   r<   r=   rA   rL   r	   ArgumentErrorr   ResolveAsResource	resourcesIsRegionalHealthCheckRefr7   r+   MakeRequestsrU   r   statusPrintformatr@   r:   r2   )
r(   rR   holderr)   
args_unsetr*   get_requestobjects
new_objectset_requests
             r   Runz
Update.Run   s   **4+<+<+>?F]]F11$7ii 44#6#6 4$,, 4,,4040H0H4ll4&*mm5J DNN$:z$$%NOO ||$$
57 7}} $$
68 8 ,,>>f 334DE//8HIk''0@Ak!!;-0GVT71:6J
 qzZ	jjHOO
!*// n334DE//8H0:<k ''0@*Mk}--r   )__name__
__module____qualname____doc__r   classmethodr   r+   r2   r7   r:   rU   rh    r   r   r   r      sB     E E3311+Z/.r   r   N)rl   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   0googlecloudsdk.command_lib.compute.health_checksr	   r
   googlecloudsdk.corerJ   r   HiddenReleaseTracksrX   ALPHAUpdateCommandr   rn   r   r   <module>rx      sq    * &  ' 7 > ( G B = # D%%++,N.T N. - N.r   