
    O                        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  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(                  R0                  5       " S S\5      5       r\
R&                  " \
R(                  R4                  5       " S S\5      5       rSS jr SS jrg)z4Command for updating a backend in a backend service.    )absolute_import)division)unicode_literals)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.Args2   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(   r:   r*   )
r+   r,   r-   r.   )ComputeRegionBackendServicesUpdateRequestr0   r)   r*   r1   #ComputeBackendServicesUpdateRequest)r3   r4   r5   replacements       r!   _GetSetRequestUpdateBackend._GetSetRequestL   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)r3   args	resourcesr4   s       r!   _GetGroupRefUpdateBackend._GetGroupRef\   s    00BB

$::6B C D D ""--/AA

$::6B B D D #r$   c           	      ~   [         R                  " U5      nU R                  XBU5      nS 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       XUR                  5       5      5      eUR                  (       a  UR                  Ul        OUR                  b  S Ul        U R                  XXR!                  5       5        Ub  UR"                  b  UR"                  Ul        UbA  UR$                  b4  UR&                  R(                  R+                  UR$                  5      Ul        U R!                  5       [,        R                   R.                  :X  d,  U R!                  5       [,        R                   R0                  :X  aD  UbA  UR2                  b4  UR&                  R(                  R5                  UR2                  5      Ul        UR8                  (       a  UR8                  Ul        UR<                  (       a  UR<                  Ul        UR>                  (       a  / Ul        U$ )Nzoner)   zMNo backend with name [{0}] in {1} [{2}] is part of the backend service [{3}].) r   CopyProtoMessagerL   backendsRelativeNameParseURLgrouphasattrrO   r)   r	   ArgumentErrorformatr0   description_ModifyBalancingModeArgsReleaseTrackfailover
preferencer.   BackendPreferenceValueValuesEnumr   ALPHABETAtraffic_durationTrafficDurationValueValuesEnumtrafficDurationcustom_metricscustomMetricscustom_metrics_fileclear_custom_metrics)r3   r4   rK   r5   rJ   existingr=   	group_refbackend_to_updatebackend
scope_type
scope_names               r!   _ModifyUpdateBackend._Modifyh   sQ   ++H5K!!$6:I'' 
			!Y%7%7
--&%
(# ( jj	F	#	#
^^
	H	%	%
%%
$$!6).."2J"5":":"<>? ?
 &*&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.   )r3   r4   rJ   rj   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_scalerr[   r\   r	   UpdatePropertyErrorr3   rJ   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.rA   r   )r   r   ComputeApiHolderrZ   r4   r
   r   rE   rK   rF   rG   r6   MakeRequestsrn   r>   )r3   rJ   holderr4   r5   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"   r6   r>   rL   rn   rY   r   r   __static_attributes__r   r$   r!   r   r   !   sI     	D 	D66 
DBJ <@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   )rq   r   Tr   )r
   r   r   r   r   r   r   rZ   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/5      (       d  ["        R$                  " S5      egz
Overrides.Nrt   )ru   rX   rv   rw   rx   ry   rz   r{   r|   r}   max_in_flight_requests#max_in_flight_requests_per_instance#max_in_flight_requests_per_endpointra   r~   r[   r\   r	   r   r   s     r!   r   UpdateBackendBeta._ValidateArgs  s    $D(T!""$.""$.D())5))5##4/00<00<T)D(T!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)UpdateBackendAlphai*  r   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5        [        R                  " USS9  g r   )r
   r   r   r   r   r   r   rZ   r   r   r   r   r   r   r   s     r!   r"   UpdateBackendAlpha.ArgsB  s    	--99&A	55fkJ  (""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   )ru   rX   rv   rw   rx   ry   rz   r{   r|   r}   r   r   r   ra   r~   r[   r\   rd   rf   rg   r	   r   r   s     r!   r    UpdateBackendAlpha._ValidateArgsO  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   *  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   rZ   r_   r`   maxInFlightRequestsmaxInFlightRequestsPerInstancemaxInFlightRequestsPerEndpoint)rk   rq   s     r!   ._ClearMutualExclusiveBackendCapacityThresholdsr   k  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balancingModerv   r]   BalancingModeValueValuesEnumRATEmaxUtilizationr   r   r   r   rZ   r_   r`   r   r   r   
CONNECTIONr   r   r   	IN_FLIGHTrw   rx   r   ry   r{   r|   rz   r}   r   r   r   r~   capacityScaler)r.   rJ   rj   rq   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   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   r
   rF   3googlecloudsdk.command_lib.compute.backend_servicesr   r   UniverseCompatibleReleaseTracksrZ   GAUpdateCommandr   r`   r   r_   r   r   rY   r   r$   r!   <module>r      s     ; &  ' % 7 ( 9 E M V E D%%(()FD&& F * FR D%%**+:5 :5 ,:5z D%%++,=5* =5 -=5@2$ 6:x<r$   