
    E                         S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJr  SSK	J
r
  SS	KJr  \R                  rS
 rSS jrS rSS jr  SS jr   SS jrS r  SS jrS rS rS rS rS rSS jrS rg)zDFlags and helpers for the compute backend-services backend commands.    )absolute_import)division)unicode_literalsN)arg_parsers)base)flags)logc                 $    U R                  SSS9  g )Nz--descriptionz1An optional, textual description for the backend.)helpadd_argumentparsers    Hlib/googlecloudsdk/command_lib/compute/backend_services/backend_flags.pyAddDescriptionr   !   s    O      c                 t   U R                  SSSS9  U R                  5       n[        R                  " USSR	                  U5      S[        R
                  S9  U(       a&  [        R                  " USSR	                  U5      S	S
9  [        R                  " USSR	                  U5      S[        R                  S9  g)z(Adds arguments to define instance group.z--instance-groupTz1The name or URI of a Google Cloud Instance Group.)requiredr   zinstance groupz{0} the backend servicezinstance-group)resource_typeoperation_typeflag_prefixexplanationz3DEPRECATED, use --instance-group-zone flag instead.)r   r   r   N)r   add_mutually_exclusive_groupr   AddRegionFlagformat&REGION_PROPERTY_EXPLANATION_NO_DEFAULTAddZoneFlag$ZONE_PROPERTY_EXPLANATION_NO_DEFAULT)r   r   with_deprecated_zonescope_parsers       r   AddInstanceGroupr!   '   s    >  @
 446,$.55nE">>@ 	&077GI	K
 $.55nE"<<>r   c                 V    [        U SS 5      (       a  [        R                  " S5        g g )NzonezpThe --zone flag is deprecated, please use --instance-group-zone instead. It will be removed in a future release.)getattrr	   warning)argss    r   WarnOnDeprecatedFlagsr'   C   s'    T64  KK	<= !r   c                 `   SnSnUS-  nUS-  nSn[         R                  " S5      R                  U5      [         R                  " S5      R                  U5      [         R                  " S5      R                  U5      S	S
.nU [        R                  :X  d  U [        R
                  :X  a  SUS'   U$ )zGReturns the --balancing-modes flag value choices name:description dict.z*--max-rate-per-instance*z *--max-connections-per-instance*z/*--max-rate-per-endpoint*z*--max-max-per-endpoint*z3This is incompatible with --network-endpoint-group.a  
          Available if the backend service's load balancing scheme is either
          `INTERNAL` or `EXTERNAL`.
          Available if the backend service's protocol is one of `SSL`, `TCP`,
          or `UDP`.

          Spreads load based on how many concurrent connections the backend
          can handle.

          For backend services with --load-balancing-scheme `EXTERNAL`, you
          must specify exactly one of these additional parameters:
          `--max-connections`, `--max-connections-per-instance`, or
          `--max-connections-per-endpoint`.

          For backend services where `--load-balancing-scheme` is `INTERNAL`,
          you must omit all of these parameters.
          a  
          Available if the backend service's load balancing scheme is
          `INTERNAL_MANAGED`, `INTERNAL_SELF_MANAGED`, or `EXTERNAL`. Available
          if the backend service's protocol is one of HTTP, HTTPS, or HTTP/2.

          Spreads load based on how many HTTP requests per second (RPS) the
          backend can handle.

          You must specify exactly one of these additional parameters:
          `--max-rate`, `--max-rate-per-instance`, or `--max-rate-per-endpoint`.
          aT  
          Available if the backend service's load balancing scheme is
          `INTERNAL_MANAGED`, `INTERNAL_SELF_MANAGED`, or `EXTERNAL`. Available only
          for managed or unmanaged instance group backends.

          Spreads load based on the backend utilization of instances in a backend
          instance group.

          The following additional parameters may be specified:
          `--max-utilization`, `--max-rate`, `--max-rate-per-instance`,
          `--max-connections`, `--max-connections-per-instance`.
          For valid combinations, see `--max-utilization`.
          zP
          Spreads load based on custom defined and reported metrics.
          )
CONNECTIONRATEUTILIZATIONCUSTOM_METRICSaB  
                    Available if the backend service's load balancing scheme is
          `INTERNAL_MANAGED`, `INTERNAL_SELF_MANAGED`, or `EXTERNAL_MANAGED`. Available
          if the backend service's protocol is one of HTTP, HTTPS, or HTTP/2.

          Spreads load based on how many in-flight requests the backend can handle.

          You must specify exactly one of these additional parameters:
          `--max-in-flight-requests`, `--max-in-flight-requests-per-instance`, or
          `--max-in-flight-requests-per-endpoint`, and `--traffic-duration=LONG`.
          	IN_FLIGHT)textwrapdedentr   ReleaseTrackALPHABETA)release_trackper_rate_flagsper_connection_flagsutilization_extra_helpbalancing_modess        r   _GetBalancingModesr8   J   s    ..;00.44;  OO %   vn%oo 
 
 v,-__ &  v*+U-/\ l(((M\=N=N,N
$OK  
r   c                     Sn/ nU(       a  UR                  SS/5        U(       a  UR                  S5        U(       a  USR                  [        U5      5      -  nU R	                  S[        U5      S US9  g	)
z-Adds balancing mode argument to the argparse.z  Defines how to measure whether a backend can handle additional traffic or is
  fully loaded. For more information, see
  https://cloud.google.com/load-balancing/docs/backend-service#balancing-mode.
  INTERNET_IP_PORTINTERNET_FQDN_PORT
SERVERLESSzb
  This cannot be used when the endpoint type of an attached network endpoint
  group is {0}.
    z--balancing-modec                 "    U R                  5       $ Nupperxs    r   <lambda>"AddBalancingMode.<locals>.<lambda>   
    QWWYr   choicestyper   N)extendappendr   
_JoinTypesr   r8   )r   support_global_negsupport_region_negr3   	help_textincompatible_typess         r   AddBalancingModerP      s    )
 13GHIl+  	z,-.	/I
 	 /	  r   c                    [        U 5        U R                  SS9n/ nU(       a  UR                  SS/5        U(       a  UR                  S5        U(       a  SR	                  [        U5      5      OSnUR                  S[        S	U-   S
9  UR                  S[        SU-   S
9  UR                  S[        SU-   S
9  UR                  S[        SS
9  UR                  S[        SU-   S
9  UR                  S[        SS
9  U[        R                  :X  d  U[        R                  :X  aI  UR                  S[        SU-   S
9  UR                  S[        SU-   S
9  UR                  S[        SU-   S
9  gg)z3Adds capacity thresholds arguments to the argparse.T)mutexr:   r;   r<   z`
  This cannot be used when the endpoint type of an attached network endpoint
  group is {0}.
   z--max-rate-per-endpointa        Only valid for network endpoint group backends. Defines a maximum
      number of HTTP requests per second (RPS) per endpoint if all endpoints
      are healthy. When one or more endpoints are unhealthy, an effective
      maximum rate per healthy endpoint is calculated by multiplying
      `MAX_RATE_PER_ENDPOINT` by the number of endpoints in the network
      endpoint group, and then dividing by the number of healthy endpoints.
      rH   r   z--max-connections-per-endpointa        Only valid for network endpoint group backends. Defines a maximum
      number of connections per endpoint if all endpoints are healthy. When
      one or more endpoints are unhealthy, an effective maximum average number
      of connections per healthy endpoint is calculated by multiplying
      `MAX_CONNECTIONS_PER_ENDPOINT` by the number of endpoints in the network
      endpoint group, and then dividing by the number of healthy endpoints.
      z
--max-ratea?        Maximum number of HTTP requests per second (RPS) that the backend can
      handle. Valid for network endpoint group and instance group backends
      (except for regional managed instance groups). Must not be defined if the
      backend is a managed instance group using load balancing-based autoscaling.
      z--max-rate-per-instancea?        Only valid for instance group backends. Defines a maximum number of
      HTTP requests per second (RPS) per instance if all instances in the
      instance group are healthy. When one or more instances are unhealthy,
      an effective maximum RPS per healthy instance is calculated by
      multiplying `MAX_RATE_PER_INSTANCE` by the number of instances in the
      instance group, and then dividing by the number of healthy instances. This
      parameter is compatible with managed instance group backends that use
      autoscaling based on load balancing.
      z--max-connectionsz      Maximum concurrent connections that the backend can handle. Valid for
      network endpoint group and instance group backends (except for regional
      managed instance groups).
      z--max-connections-per-instancea        Only valid for instance group backends. Defines a maximum number
      of concurrent connections per instance if all instances in the
      instance group are healthy. When one or more instances are
      unhealthy, an effective average maximum number of connections per healthy
      instance is calculated by multiplying `MAX_CONNECTIONS_PER_INSTANCE`
      by the number of instances in the instance group, and then dividing by
      the number of healthy instances.
      z--max-in-flight-requestszR        Maximum number of in-flight requests that the backend can handle.
        z%--max-in-flight-requests-per-instancez        Only valid for instance group backends. Defines the maximum number of
        in-flight requests per instance.
        z%--max-in-flight-requests-per-endpointz        Only valid for network endpoint group backends. Defines the maximum number
        of in-flight requests per endpoint.
        N)AddMaxUtilization	add_grouprI   rJ   r   rK   r   floatintr0   r1   r2   )r   rL   rM   r3   capacity_groupcapacity_incompatible_typesappend_help_texts          r   AddCapacityLimitsr\      s   
 F##$#/. "&&	124&&|4 (C fZ!# $HJ  
   
 &
   
 

    	
   
 	   &
   l(((M\=N=N,N"    /     /    ! -Or   c                 L    U R                  S[        R                  " SSS9SS9  g)z.Adds max utilization argument to the argparse.z--max-utilization              ?lower_boundupper_bounda        Defines the maximum target for average utilization of the backend instance
      group. Supported values are `0.0` (0%) through `1.0` (100%). This is an
      optional parameter for the `UTILIZATION` balancing mode.

      You can use this parameter with other parameters for defining target
      capacity. For usage guidelines, see
      [Balancing mode combinations](https://cloud.google.com/load-balancing/docs/backend-service#balancing-mode-combos).
      rT   N)r   r   BoundedFloatr   s    r   rU   rU     s-    ##E
  r   c                     Sn/ nU(       a  UR                  SS/5        U(       a  UR                  S5        U(       a  USR                  [        U5      5      -  nU R	                  S[
        R                  " SSS	9US
9  g)z2Adds capacity thresholds argument to the argparse.a        Scales down the target capacity (max utilization, max rate, or max
      connections) without changing the target capacity. For usage guidelines
      and examples, see
      [Capacity scaler](https://cloud.google.com/load-balancing/docs/backend-service#capacity_scaler).
      r:   r;   r<   zf
    This cannot be used when the endpoint type of an attached network endpoint
    group is {0}.
    z--capacity-scalerr^   r_   r`   rT   N)rI   rJ   r   rK   r   r   rc   )r   rL   rM   rN   rO   s        r   AddCapacityScalarre   )  s    
) 13GHIl+  	z,-.	/I
 	##E  r   c                 (    U R                  SSUSS9  g)z+Adds the failover argument to the argparse.z
--failover
store_truez      Designates whether this is a failover backend. More than one
      failover backend can be configured for a given BackendService.
      Not compatible with the --global flag)actiondefaultr   Nr   )r   ri   s     r   AddFailoverrj   D  s#    /	  0r   c                  `    [         R                  " S5      [         R                  " S5      S.n U $ )zBReturns the --preference flag value choices name:description dict.a  
          This is the default setting. If the designated preferred backends
          don't have enough capacity, backends in the default category are used.
          Traffic is distributed between default backends based on the load
          balancing algorithm used.
          z
          Backends with this preference setting are used up to their capacity
          limits first, while optimizing overall network latency.
          )DEFAULT	PREFERREDr.   r/   )preferencess    r   _GetPreferencerp   P  s7      "  ?? $ + 
r   c                     Sn/ SQnUSR                  [        U5      5      -  nU R                  S[        5       S US9  g)z)Adds preference argument to the argparse.z  This parameter specifies whether a backend should be fully utilized before
  sending traffic to backends with the default preference.
  )r:   r;   r<   z  This parameter cannot be used with regional managed instance groups and when
  the endpoint type of an attached network endpoint group is {0}.
  z--preferencec                 "    U R                  5       $ r>   r?   rA   s    r   rC   AddPreference.<locals>.<lambda>o  rE   r   rF   N)r   rK   r   rp   )r   rN   rO   s      r   AddPreferencert   a  sW    ) P  fZ*+,-) 		  r   c                      [         R                  " S5      [         R                  " S5      [         R                  " S5      S.n U $ )zHReturns the --traffic-duration flag value choices name:description dict.z7
          Default value. Defaults to SHORT.
          zU
          Most requests are expected to finish with a sub-second latency.
          ze
          Most of the requests are expected to take more than multiple seconds to finish.
          )TRAFFIC_DURATION_UNSPECIFIEDSHORTLONGrn   )traffic_durationss    r   _GetTrafficDurationrz   s  sK     '/oo 7 '     oo  
 
r   c                 :    U R                  S[        5       S SS9  g)z/Adds traffic duration argument to the argparse.z--traffic-durationc                 "    U R                  5       $ r>   r?   rA   s    r   rC   $AddTrafficDuration.<locals>.<lambda>  rE   r   z<      The expected traffic duration for this service.
      rF   N)r   rz   r   s    r   AddTrafficDurationr~     s&    !#
	  r   c           
         U R                  5       nSnUR                  SS[        R                  " [        [
        [        S.S/SS9[        R                  " 5       US9  S	nUR                  S
S[        R                  " [        [
        [        S.S/SS9[        R                  " 5       US9  U(       a  UR                  SSSSSS9  gg)z1Adds a --custom-metrics flag to the given parser.a    List of custom metrics that are used for CUSTOM_METRICS balancing mode and
  WEIGHTED_ROUND_ROBIN locality load balancing policy.

  Example:

    $ {command} --custom-metrics='name=my-signal,maxUtilization=0.8,dryRun=true'
    $ {command} --custom-metrics='name=my-signal,maxUtilization=0.8,dryRun=true' --custom-metrics='name=my-signal2,maxUtilization=0.2'
    $ {command} --custom-metrics='[{"name" : "my-signal", "maxUtilization" : 0.8, "dryRun" : true}, {"name" : "my-signal2", "maxUtilization" : 0.1}]'z--custom-metricsr,   )namemaxUtilizationdryRunr   T)specrequired_keysrepeated)metavarrH   rh   r   z  File path to json file with custom metrics that are used for CUSTOM_METRICS
  balancing mode and WEIGHTED_ROUND_ROBIN locality load balancing policy.

  Example:

    $ {command} --custom-metrics-file='customMetric.json'z--custom-metrics-filez--clear-custom-metricsFrg   Nz&Clears current list of CUSTOM_METRICS.)r   rh   ri   r   )r   r   r   	ArgObjectstrrW   boolFlattenAction)r   add_clear_argumentgrouprN   help_text_files        r   AddCustomMetricsr     s    

-
-
/%Y)    %
   &&(  =.    %
   &&(   	 5   r   c                     [        U 5      S:  a(  SR                  SR                  U S S 5      U S   /5      $ SR                  U 5      $ )N   z, or z, z or )lenjoin)typess    r   rK   rK     sO    JN 
tyys,eBi  
 C06E0BCr   )Fr>   )FFN)FF)__doc__
__future__r   r   r   r.   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer   googlecloudsdk.corer	   r0   r   r!   r'   r8   rP   r\   rU   re   rj   rp   rt   rz   r~   r   rK    r   r   <module>r      s   " K &  '  / ( 4 #  >8=CN ).=A8 */).$(k\" */).6	0"$ 	8vCr   