
    %                     \   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 Zd Zd Zd Zd Zd Zd Zd Zd Ze	j8                   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)scope)
exceptions)flags)logc                      dddS )N$Update a gRPC with TLS health check.z      *{command}* is used to update an existing gRPC with TLS health check. Only
      arguments passed in will be updated on the health check. Other
      attributes will remain unaffected.
      )briefDESCRIPTION r       9lib/surface/compute/health_checks/update/grpc_with_tls.py_DetailedHelpr      s    5

 r   c                     t        j                  d      }|j                  | d       t        j                  |        t        j
                  | d       |rt        j                  |        y y )NgRPC with TLSupdate)operation_type)r   HealthCheckArgumentAddArgumentr   AddGrpcRelatedUpdateArgsAddProtocolAgnosticUpdateArgs AddHealthCheckLoggingRelatedArgs)parserinclude_log_confighealth_check_args      r   _Argsr!   *   sZ    ..?vh?..v633FOL88@ r   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&   clienthealth_check_refs     r   _GetGetRequestr/   3   sI    

 
 
-
-u
//
7
7*//1&.. 8 0
1 1r   c                     | j                   j                  d| j                  j                  |j	                         ||j
                        fS )0Returns a request for updating the health check.Update)r%   healthCheckResourcer&   )r'   r(   r)    ComputeHealthChecksUpdateRequestr+   r&   r-   r.   replacements      r   _GetSetRequestr7   ;   sL    

 
 
-
-x
//
:
:*//1"-&.. ; 0
1 1r   c                     | j                   j                  d| j                  j                  |j	                         |j
                  |j                        fS )r#   r$   )r%   r&   region)r'   regionHealthChecksr)   #ComputeRegionHealthChecksGetRequestr+   r&   r9   r,   s     r   _GetRegionalGetRequestr<   D   sR    

 
 
3
3U
//
=
=*//1&..%,, > .
/ /r   c                     | j                   j                  d| j                  j                  |j	                         ||j
                  |j                        fS )r1   r2   )r%   r3   r&   r9   )r'   r:   r)   &ComputeRegionHealthChecksUpdateRequestr+   r&   r9   r5   s      r   _GetRegionalSetRequestr?   M   sV    

 
 
3
3X
//
@
@*//1"-&..%,,	 A .
/ /r   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}t        j                  ||j                        \  }}| j                  j                  |j                  || j                  j                  j                  j                  | j                  j                  |||      |j                  xs |j                   |j"                  xs |j$                  |j&                  xs |j(                  |j*                  xs |j,                        }|r&t        j.                  | ||j0                        |_        |S )z'Returns a modified HealthCheck message.zFupdate grpc-with-tls subcommand applied to health check with protocol N)portportSpecificationgrpcServiceName)namedescriptiontypegrpcTlsHealthCheckcheckIntervalSec
timeoutSechealthyThresholdunhealthyThreshold)rF   r)   HealthCheckTypeValueValuesEnumGRPC_WITH_TLScore_exceptionsErrorrD   rE   grpc_service_namerG   rC   r   #HandlePortRelatedFlagsForGRPCUpdateGRPCTLSHealthCheckcheck_intervalrH   timeoutrI   healthy_thresholdrJ   unhealthy_thresholdrK   ModifyLogConfig	logConfig)	r-   argsexisting_checkr   rE   rQ   rA   port_specificationnew_health_checks	            r   _Modifyr^   W   s   
 		$	$	8	8	F	FG 

P



"
"	#  
""K ,,KK	..%&99II ==
11 $ __00??&&::HH;;.+ < 
 ++N~/N/N:!:!:

 
 
CN$C$C 
"
"
Gn&G&G 1 & !4!D!Dn.."0	r   c                 ^   t        j                  |        | j                  xsD | j                  xs6 | j                  xs( | j
                  xs | j                  xs | j                   }|r| j                  du xr |}| j                  %| j                  |rt        j                  d      yyy)zBValidates given args and raises exception if any args are invalid.Nz'At least one property must be modified.)r   CheckProtocolAgnosticArgsrA   rT   rU   rV   rW   use_serving_portenable_loggingrE   rQ   r
   ArgumentError)rZ   r   
args_unsets      r   _ValidateArgsre      s    //5II *!4!4 * ****.2.F.F*))+* %%-<*J
4#9#9#A

"
"#L
MM  $Br   c                 x   |j                   }t        | |       t        j                  d      }|j	                  | |j
                  t        j                  j                        }t        j                  |      rt        ||      }nt        ||      }|j                  |g      }t        || |d   |      }|d   |k(  r=t        j                   j#                  dj%                  |d   j&                               |S t        j                  |      rt)        |||      }	nt+        |||      }	|j                  |	g      S )z<Issues the requests necessary for updating the health check.r   )default_scoper   z/No change requested; skipping update for [{0}].)r-   re   r   r   ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALr   IsRegionalHealthCheckRefr<   r/   MakeRequestsr^   r   statusPrintformatrD   r?   r7   )
rZ   holderr   r-   r    r.   get_requestobjects
new_objectset_requests
             r   _Runrw      s'   ==&()..?%77
FM,C,C,J,J 8 L 112BC(1ABK )9:K.'vtWQZ1CD*
 QZ:JJFMM
 N112BC(1A:NK )9:FK			k]	++r   c                   8    e Zd ZdZdZ e       Zed        Zd Z	y)UpdateAlphar   Tc                 0    t        || j                         y N)r!   _include_log_config)clsr   s     r   ArgszUpdateAlpha.Args   s    	&#))*r   c                 v    t        j                  | j                               }t        ||| j                        S r{   )r   ComputeApiHolderReleaseTrackrw   r|   )selfrZ   rr   s      r   RunzUpdateAlpha.Run   s0    **4+<+<+>?Ffd6677r   N)
__name__
__module____qualname____doc__r|   r   detailed_helpclassmethodr~   r   r   r   r   ry   ry      s+     -/-+ +8r   ry   N)"r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   rj   0googlecloudsdk.command_lib.compute.health_checksr
   r   googlecloudsdk.corerO   r   r   r!   r/   r7   r<   r?   r^   re   rw   DefaultUniverseOnlyReleaseTracksr   ALPHAUpdateCommandry   r   r   r   <module>r      s    * &  ' 7 > ( E G B = #A11//:zN  ,F D%%++,8$$$ 8 - 8r   