
    R                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  SSKJr  SSKJ	r	  \R                  \R                  " \R                   R"                  5       " S	 S
\R$                  5      5       5       r\R                  " \R                   R(                  5       " S S\5      5       r\R                  " \R                   R,                  5       " S S\5      5       rSS jr SS jrg)z4Command for updating a backend in a backend service.    )encoding)base_classes)base)
exceptions)flags)backend_flags)backend_services_utilsc                   X    \ rS rSrSr\S 5       rS rS rS r	S r
 SS	 jrS
 rS rSrg)UpdateBackend   a  Update an existing backend of a load balancer or Traffic Director.

*{command}* updates attributes of a backend that is already associated with a
backend service. Configurable attributes depend on the load balancing scheme
and the type of backend (instance group, zonal NEG, serverless NEG, or
internet NEG). For more information, see [traffic
distribution](https://cloud.google.com/load-balancing/docs/backend-service#traffic_distribution).
and the [Failover for Internal TCP/UDP Load Balancing
overview](https://cloud.google.com/load-balancing/docs/internal/failover-overview).

To add, remove, or swap backends, use the `gcloud compute backend-services
remove-backend` and `gcloud compute backend-services add-backend` commands.
c                    [         R                  R                  U 5        [        R                  " U 5        [         R
                  " U S5        [        R                  " U 5        [        R                  " U 5        [        R                  " U 5        [        R                  " U S S9  [        R                  " U 5        [        R                  " U SS9  g )N	update indefaultTadd_clear_argument)r   #GLOBAL_REGIONAL_BACKEND_SERVICE_ARGAddArgumentr   AddDescription+AddInstanceGroupAndNetworkEndpointGroupArgsAddBalancingModeAddCapacityLimitsAddCapacityScalarAddFailoverAddPreferenceAddCustomMetrics)parsers    6lib/surface/compute/backend_services/update_backend.pyArgsUpdateBackend.Args/   s    	--99&A  (	55fkJ""6*##F+##F+fd3'""6dC    c                 d   UR                  5       S:X  aT  UR                  R                  SUR                  R	                  UR                  5       UR                  UR                  S94$ UR                  R                  SUR                  R                  UR                  5       UR                  S94$ )Ncompute.regionBackendServicesGet)backendServiceregionproject)r%   r'   )

Collectionapitools_clientregionBackendServicesmessages&ComputeRegionBackendServicesGetRequestNamer&   r'   backendServices ComputeBackendServicesGetRequest)selfclientbackend_service_refs      r   _GetGetRequestUpdateBackend._GetGetRequest;   s    %%'+JJ$$::ooDD!4!9!9!;,33-55 E 78 8 ""22OO<<2779+33 = 56 6r!   c           	      h   UR                  5       S:X  aU  UR                  R                  SUR                  R	                  UR                  5       UUR                  UR                  S94$ UR                  R                  SUR                  R                  UR                  5       UUR                  S94$ )Nr#   Update)r%   backendServiceResourcer&   r'   )r%   r7   r'   )
r(   r)   r*   r+   )ComputeRegionBackendServicesUpdateRequestr-   r&   r'   r.   #ComputeBackendServicesUpdateRequest)r0   r1   r2   replacements       r   _GetSetRequestUpdateBackend._GetSetRequestI   s    %%'+JJ$$::ooGG!4!9!9!;)4,33-55	 H 78 8 ""22OO??2779'2+33 @ 56 6r!   c                    UR                   (       a3  [        R                  R                  UU[        R
                  " U5      S9$ UR                  (       a8  [        R                  " 5       R                  UU[        R
                  " U5      S9$ g )Nscope_lister)instance_groupr   MULTISCOPE_INSTANCE_GROUP_ARGResolveAsResourcecompute_flagsGetDefaultScopeListernetwork_endpoint_groupGetNetworkEndpointGroupArg)r0   args	resourcesr1   s       r   _GetGroupRefUpdateBackend._GetGroupRefY   s    00BB

$::6B C D D ""--/AA

$::6B B D D #r!   c           	         [         R                  " U5      nS nU R                  5       [        R                  R                  :X  a  UR
                  (       aw  UR                   H!  nUR
                  UR
                  :X  d  M  Un  O   U(       d>  [        R                  " SR                  UR
                  UR                  5       5      5      eOU R                  XBU5      n	UR                   HB  nU	R                  5       UR                  UR                  5      R                  5       :X  d  M@  Un  O   U(       d  S n
S n[        U	S5      (       a  Sn
U	R                   n[        U	S5      (       a  Sn
U	R"                  n[        R                  " SR                  U	R                  5       U
UUR                  5       5      5      eUR$                  (       a  UR$                  Ul        OUR$                  b  S Ul        U R'                  XXpR                  5       5        Ub  UR(                  b  UR(                  Ul        UbA  UR*                  b4  UR,                  R.                  R1                  UR*                  5      Ul        U R                  5       [        R                  R                  :X  d,  U R                  5       [        R                  R2                  :X  aD  UbA  UR4                  b4  UR,                  R.                  R7                  UR4                  5      Ul        UR:                  (       a  UR:                  Ul        UR>                  (       a  UR>                  Ul        UR@                  (       a  / Ul        U$ )Nz@No backend with name [{0}] is part of the backend service [{1}].zoner&   zMNo backend with name [{0}] in {1} [{2}] is part of the backend service [{3}].)!r   CopyProtoMessageReleaseTrackr   ALPHAservicebackendsr   ArgumentErrorformatr-   rI   RelativeNameParseURLgrouphasattrrL   r&   description_ModifyBalancingModeArgsfailover
preferencer+   BackendPreferenceValueValuesEnumBETAtraffic_durationTrafficDurationValueValuesEnumtrafficDurationcustom_metricscustomMetricscustom_metrics_fileclear_custom_metrics)r0   r1   rH   r2   rG   existingr:   backend_to_updatebackend	group_ref
scope_type
scope_names               r   _ModifyUpdateBackend._Modifye   s   ++H5Kd//555$,, ))'??dll*%

 * &&#VDLL2E2J2J2LM
 	
  ##DV<i ))' ""$!!'--0==?@ &

 * 

9f%%* ~~*9h''* ''*&&#V #((*	
 	
 &*&6&6#				%&*#!!'):):)< $)B#'== $)D
//
!
!
;
;DOO
L " 4#4#4#:#::  "d&7&7&<&<<)!!- //
!
!
@
@## ' (,(;(;%(,(@(@%  (*%r!   Nc                 2    [        UR                  X#U5        g)a  Update balancing mode fields in backend_to_update according to args.

Args:
  client: The compute client.
  args: The arguments given to the update-backend command.
  backend_to_update: The backend message to modify.
  release_track: The release track of the command.
N)rY   r+   )r0   r1   rG   rg   release_tracks        r   rY   &UpdateBackend._ModifyBalancingModeArgs   s     -r!   c                    [        UR                  SLUR                  UR                  SLUR                  SLUR
                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SL/5      (       d  [        R                  " S5      eg)z}Validatest that at least one field to update is specified.

Args:
  args: The arguments given to the update-backend command.
N'At least one property must be modified.)anyrX   balancing_modemax_utilizationmax_ratemax_rate_per_instancemax_rate_per_endpointmax_connectionsmax_connections_per_instancemax_connections_per_endpointcapacity_scalerrZ   r[   r   UpdatePropertyErrorr0   rG   s     r   _ValidateArgsUpdateBackend._ValidateArgs   s     $D(T!""$.""$.D())5))5D(T!t#   **
35 5r!   c                    U R                  U5        [        R                  " U R                  5       5      nUR                  n[
        R                  R                  UUR                  [        R                  " U5      S9nU R                  X45      nUR                  U/5      S   nU R                  X2R                  XAU5      nUR                  U R                  X4U5      /5      $ )zCIssues requests necessary to update backend of the Backend Service.r>   r   )r   r   ComputeApiHolderrN   r1   r   r   rB   rH   rC   rD   r3   MakeRequestsrl   r;   )r0   rG   holderr1   r2   get_requestbackend_servicemodified_backend_services           r   RunUpdateBackend.Run   s    t**4+<+<+>?F]]F 	11CC&<<VD 	D 	F 
 %%fBK));-8;O#||  "5_ N F4	6   r!    N)__name__
__module____qualname____firstlineno____doc__staticmethodr   r3   r;   rI   rl   rY   r   r   __static_attributes__r   r!   r   r   r      sI     	D 	D66 
DSl <@50r!   r   c                   .    \ rS rSrSr\S 5       rS rSrg)UpdateBackendBeta     Update an existing backend in a backend service.

*{command}* updates a backend that is part of a backend
service. This is useful for changing the way a backend
behaves. Example changes that can be made include changing the
load balancing policy and draining a backend by setting
its capacity scaler to zero.

Backends are instance groups or network endpoint groups. One
of the `--network-endpoint-group` or `--instance-group` flags is required to
identify the backend that you are modifying. You cannot change
the instance group or network endpoint group associated with a backend, but
you can remove a backend and add a new one with `backend-services
remove-backend` and `backend-services add-backend`.

The `gcloud compute backend-services edit` command can also
update a backend if the use of a text editor is desired.

For more information about the available settings, see
https://cloud.google.com/load-balancing/docs/backend-service.
c                    [         R                  R                  U5        [         R                  " US5        [        R
                  " U5        [        R                  " XR                  5       S9  [        R                  " XR                  5       S9  [        R                  " U5        [        R                  " US S9  [        R                  " U5        [        R                  " USS9  [        R                  " U5        g )Nr   ro   r   Tr   )r   r   r   r   r   r   r   rN   r   r   r   r   r   AddTrafficDurationclsr   s     r   r   UpdateBackendBeta.Args  s    	--99&A	55fkJ  (""69I9I9KL##F:J:J:LM##F+fd3'""6dC$$V,r!   c                 ,   [        UR                  SLUR                  UR                  SLUR                  SLUR
                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                   SL[#        US5      =(       a    UR$                  SL/5      (       d  [&        R(                  " S5      eg)
Overrides.NrP   rr   )rs   rX   rt   ru   rv   rw   rx   ry   rz   r{   max_in_flight_requests#max_in_flight_requests_per_instance#max_in_flight_requests_per_endpointr_   r|   rZ   r[   rW   rP   r   r}   r~   s     r   r   UpdateBackendBeta._ValidateArgs  s     $D(T!""$.""$.D())5))5##4/00<00<T)D(T!t#i =T\\%=#  & **
35 5'r!   r   N	r   r   r   r   r   classmethodr   r   r   r   r!   r   r   r      s     , 
- 
-5r!   r   c                   .    \ rS rSrSr\S 5       rS rSrg)UpdateBackendAlphai9  r   c                    [         R                  R                  U5        [         R                  " USSS9  [        R
                  " U5        [        R                  " XR                  5       S9  [        R                  " XR                  5       S9  [        R                  " U5        [        R                  " US S9  [        R                  " U5        [        R                  " U5        [        R                  " USS9  g )Nr   T)support_inline_servicer   r   r   )r   r   r   r   r   r   r   rN   r   r   r   r   r   r   r   s     r   r   UpdateBackendAlpha.ArgsQ  s    	--99&A	55D   (""69I9I9KL##F:J:J:LM##F+fd3'$$V,""6dCr!   c                 :   [        UR                  SLUR                  UR                  SLUR                  SLUR
                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                  SLUR                   SLUR"                  SLUR$                  SLUR&                  SL/5      (       d  [(        R*                  " S5      eg)r   Nrr   )rs   rX   rt   ru   rv   rw   rx   ry   rz   r{   r   r   r   r_   r|   rZ   r[   rb   rd   re   r   r}   r~   s     r   r    UpdateBackendAlpha._ValidateArgs`  s2    $D(T!""$.""$.D())5))5##4/00<00<T)D(T!t#4'  ,!!-'  * **
35 5+r!   r   Nr   r   r!   r   r   r   9  s"    , D D5r!   r   Nc                     SU l         SU l        SU l        SU l        SU l        SU l        U[        R                  R                  :X  d  U[        R                  R                  :X  a  SU l
        SU l        SU l        gg)z@Initialize the backend's mutually exclusive capacity thresholds.N)maxRatemaxRatePerInstancemaxConnectionsmaxConnectionsPerInstancemaxRatePerEndpointmaxConnectionsPerEndpointr   rN   rO   r^   maxInFlightRequestsmaxInFlightRequestsPerInstancemaxInFlightRequestsPerEndpoint)rh   ro   s     r   ._ClearMutualExclusiveBackendCapacityThresholdsr   |  sv    '/#''&*'##'&*'#t((...	$++00	0"&G-1G*-1G*	 
1r!   c                 F   [         R                  " XUR                  U5        UR                  (       Ga  U R                  R                  UR                  5      Ul        UR                  U R                  R
                  R                  :X  ao  SUl        SUl        SUl	        SUl
        U[        R                  R                  :X  d  U[        R                  R                  :X  a  SUl        SUl        SUl        GO0UR                  U R                  R
                  R$                  :X  an  SUl        SUl        SUl        SUl        U[        R                  R                  :X  d  U[        R                  R                  :X  a  SUl        SUl        SUl        OU[        R                  R                  :X  d  U[        R                  R                  :X  aX  UR                  U R                  R
                  R,                  :X  a*  SUl        SUl        SUl        SUl        SUl	        SUl
        UR.                  b  UR.                  Ul        UR0                  b  [3        U5        UR0                  Ul        GOUR4                  b  [3        U5        UR4                  Ul        GOcUR6                  b  [3        U5        UR6                  Ul        GO8UR8                  b  [3        U5        UR8                  Ul	        GOUR:                  b  [3        U5        UR:                  Ul        OUR<                  b  [3        U5        UR<                  Ul
        OU[        R                  R                  :X  d  U[        R                  R                  :X  a}  UR>                  b  [3        X#5        UR>                  Ul        OSUR@                  b  [3        X#5        UR@                  Ul        O)URB                  b  [3        X#5        URB                  Ul        URD                  b  URD                  Ul#        gg)a/  Update balancing mode fields in backend_to_update according to args.

Args:
  messages: API messages class, determined by the release track.
  args: The arguments given to the update-backend command.
  backend_to_update: The backend message to modify.
  release_track: The release track of the command.
N)$r	   ValidateBalancingModeArgsbalancingModert   r\   BalancingModeValueValuesEnumRATEmaxUtilizationr   r   r   r   rN   rO   r^   r   r   r   
CONNECTIONr   r   r   	IN_FLIGHTru   rv   r   rw   ry   rz   rx   r{   r   r   r   r|   capacityScaler)r+   rG   rg   ro   s       r   rY   rY     s    22'55}F 
55	! # 	''55::	;)-&)-&481481
4,,22
2d//44404-;?8;?8

)
)



7
7
B
BC)-&"&-1*-1*
4,,22
2d//44404-;?8;?8 T..444 1 1 6 66++88BBC #'-1*-1*)-&481481
 
%'+';';$
 
]]23DE $!!-23DE+/+E+E('23DE'+';';$((423DE)) /!!-23DE+/+E+E(((423DE)) / t((...	$++00	0"".4
 /3.I.I+		1	1	=4
 
2
2 6 
	1	1	=4
 
2
2 6 
%'+';';$ &r!   r   )r   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   r   rC   3googlecloudsdk.command_lib.compute.backend_servicesr   r	   UniverseCompatibleReleaseTracksrN   GAUpdateCommandr   r^   r   rO   r   r   rY   r   r!   r   <module>r      s     ; & 7 ( 9 E M V E D%%(()WD&& W * Wt D%%**+;5 ;5 ,;5| D%%++,?5* ?5 -?5D2$ 6:x<r!   