
     '                        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dZd Z e	j8                  e	j:                  j<                         G d de	j>                               Z  e	j8                  e	j:                  jB                         G d de              Z" e	j8                  e	j:                  jF                         G d de"             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dS )NUpdate a HTTP2 health check.z      *{command}* is used to update an existing HTTP2 health check. Only
      arguments passed in will be updated on the health check. Other
      attributes will remain unaffected.
      z          To update health check interval to 10s, run:

            $ {command} my-health-check-name --check-interval=10s
      )briefDESCRIPTIONEXAMPLES r       1lib/surface/compute/health_checks/update/http2.py_DetailedHelpr      s     )


 r   c                    t        j                  d      }|j                  | d       t        j                  | |       t        j
                  |        t        j                  | d       |rt        j                  |        yy)z Adds all the args in the parser.HTTP2update)operation_typeN)r   HealthCheckArgumentAddArgumentr   AddHttpRelatedUpdateArgsAddHttpRelatedResponseArgAddProtocolAgnosticUpdateArgs AddHealthCheckLoggingRelatedArgs)parserinclude_log_configinclude_weighted_load_balancinghealth_check_args       r   _Argsr$   2   sn    ..w7vh?..v/NP//733FGD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   _GetGetRequestr2   >   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)   r0   r1   replacements      r   _GetSetRequestr:   F   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)   r<   r/   s     r   _GetRegionalGetRequestr?   O   sR    

 
 
3
3U
//
=
=*//1&..%,, > .
/ /r   c                     | j                   j                  d| j                  j                  |j	                         ||j
                  |j                        fS )r4   r5   )r(   r6   r)   r<   )r*   r=   r,   &ComputeRegionHealthChecksUpdateRequestr.   r)   r<   r8   s      r   _GetRegionalSetRequestrB   X   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}|j                  r|j                  }n%|j                  |j                  j                  }nd}t        j                  ||j                        \  }}	}
|rV|j                  j                  }|j                  d      r/| j                  j                   j#                  |j$                        }|j                  j&                  }|j(                  /| j                  j                   j+                  |j(                        }| j                  j!                  |||	|
|j,                  xs |j                  j.                  ||      }|r|_        | j                  j                  |j                  || j                  j                  j                  j                  ||j0                  xs |j2                  |j4                  xs |j6                  |j8                  xs |j:                  |j<                  xs |j>                        }|r&t        j@                  | ||jB                        |_!        |S )z'Returns a modified HealthCheck message.z>update http2 subcommand applied to health check with protocol Nweight_report_mode)hostportportNameportSpecificationrequestPathproxyHeaderresponse)namedescriptiontypehttp2HealthCheckcheckIntervalSec
timeoutSechealthyThresholdunhealthyThreshold)"rN   r,   HealthCheckTypeValueValuesEnumr   core_exceptionsErrorrL   rM   rE   rO   rK   r   HandlePortRelatedFlagsForUpdateweightReportModeIsSpecifiedHTTP2HealthCheckWeightReportModeValueValuesEnumrD   rJ   proxy_headerProxyHeaderValueValuesEnumrequest_pathrI   check_intervalrP   timeoutrQ   healthy_thresholdrR   unhealthy_thresholdrS   ModifyLogConfig	logConfig)r0   argsexisting_checkr!   r"   rM   rE   rK   rF   	port_nameport_specificationrD   r]   http2_health_checknew_health_checks                  r   _Modifyrl   b   s   
 oo!!55;;<


H  	!" " 
""K ,,KK	YY99Dyy**//DD	]]}}H}}..77HH(;%%dN,K,K)M%$	% %'88II,-!??;;[[

!
!#  00<<,	"((CC	  77*$$ ?!22>> 8  %*<'__00??&&::@@)++N~/N/N:!:!:.. 8&7722 <(;; 1  !4!D!Dn.."0	r   c                    t        j                  |        | j                  xs` | j                  xsR | j                  xsD | j
                  xs6 | j                  xs( | j                  xs | j                  xs | j                   }|r| j                  du xr |}d}|r| j                  d      rd}| j                  B| j                  5| j                  (| j                  |s|rt!        j"                  d      yyyyyy)zBValidates given args and raises exception if any args are invalid.NFrD   Tz'At least one property must be modified.)r   CheckProtocolAgnosticArgsrF   r_   r`   ra   rb   rc   r]   use_serving_portenable_loggingrZ   rM   rE   rK   rh   r
   ArgumentError)rf   r!   r"   
args_unsetweight_report_mode_modifieds        r   _ValidateArgsrt      s    //5II *!2!2 *d6I6I *LL*$($:$:*,,*040A0A* ))+*
 %%-<*J %$)9)9:N)O"&
499#4
mm 6
%*

"
"#L
MM +5
% !7 $5r   c                 |   |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 requests necessary to update the HTTP2 Health Checks.r   )default_scoper   z/No change requested; skipping update for [{0}].)r0   rt   r   r   ResolveAsResource	resourcescompute_scope	ScopeEnumGLOBALr   IsRegionalHealthCheckRefr?   r2   MakeRequestsrl   r   statusPrintformatrL   rB   r:   )rf   holderr!   r"   r0   r#   r1   get_requestobjects
new_objectset_requests              r   _Runr      s-   ==&(*IJ..w7%77
FM,C,C,J,J 8 L112BC(1ABK )9:K.'vtWQZ1C68* QZ:JJFMM
 N112BC(1A:NK )9:FK			k]	++r   c                   <    e Zd ZdZdZdZ e       Zed        Z	d Z
y)r5   r   TFc                 F    t        || j                  | j                         y N)r$   _include_log_config _include_weighted_load_balancing)clsr    s     r   ArgszUpdate.Args   s    	&#))3+O+OPr   c                     t        j                  | j                               }t        ||| j                  | j
                        S r   )r   ComputeApiHolderReleaseTrackr   r   r   )selfrf   r   s      r   Runz
Update.Run   s=    **4+<+<+>?Ffd66557 7r   N)__name__
__module____qualname____doc__r   r   r   detailed_helpclassmethodr   r   r   r   r   r5   r5      s1    $%*"/-Q Q7r   r5   c                       e Zd ZdZy)
UpdateBetaFNr   r   r   r   r   r   r   r   r     s
     &+"r   r   c                       e Zd ZdZy)UpdateAlphaTNr   r   r   r   r   r     s
     &*"r   r   N)F)%r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   ry   0googlecloudsdk.command_lib.compute.health_checksr
   r   googlecloudsdk.corerV   r   r   r$   r2   r:   r?   rB   rl   rt   r   ReleaseTracksr   GAUpdateCommandr5   BETAr   ALPHAr   r   r   r   <module>r      s   * &  ' 7 > ( E G B = #&	A11//Oh 38N0 ,F D%%(()7T 7 *7" D%%**++ + ,+
 D%%++,** * -*r   