
    5                        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g)z2Command for adding a backend to a backend service.    )absolute_import)division)unicode_literals)encoding)base_classes)base)
exceptions)flags)backend_flags)backend_services_utilsc                   \    \ rS rSrSrSrSrSrSr\	S 5       r
S rS rS rS	 rS
 rS rSrg)
AddBackend!   (  Add a backend to a backend service.

*{command}* adds a backend to a Google Cloud load balancer or Traffic
Director. Depending on the load balancing scheme of the backend service,
backends can be instance groups (managed or unmanaged), zonal network endpoint
groups (zonal NEGs), serverless NEGs, or an internet NEG. For more
information, see the [backend services
overview](https://cloud.google.com/load-balancing/docs/backend-service).

For most load balancers, you can define how Google Cloud measures capacity by
selecting a balancing mode. For more information, see [traffic
distribution](https://cloud.google.com/load-balancing/docs/backend-service#traffic_distribution).

To modify a backend, use the `gcloud compute backend-services update-backend`
or `gcloud compute backend-services edit` command.
TFc                    [         R                  R                  U5        [        R                  " U5        [         R
                  " USU R                  U R                  S9  [        R                  " UU R                  U R                  U R                  5       S9  [        R                  " UU R                  U R                  U R                  5       S9  [        R                  " UU R                  U R                  S9  [        R                  " U5        U R                  (       a  [        R                  " US S9  U R                  (       a  [        R                   " U5        [        R"                  " U5        g )Nzadd tosupport_global_negsupport_region_neg)r   r   release_track)default)r
   #GLOBAL_REGIONAL_BACKEND_SERVICE_ARGAddArgumentr   AddDescription+AddInstanceGroupAndNetworkEndpointGroupArgsr   r   AddBalancingModeReleaseTrackAddCapacityLimitsAddCapacityScalarAddPreferencesupport_failoverAddFailoversupport_in_flight_balancingAddTrafficDurationAddCustomMetrics)clsparsers     3lib/surface/compute/backend_services/add_backend.pyArgsAddBackend.Args:   s   	--99&A  (	551111	3
 ""1111&&(	 ##1111&&(	 ##1111
 '
5
&&&&v.""6*    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.   r0   )

Collectionapitools_clientregionBackendServicesmessages&ComputeRegionBackendServicesGetRequestNamer/   r0   backendServices ComputeBackendServicesGetRequest)selfclientbackend_service_refs      r'   _GetGetRequestAddBackend._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/   r0   )r.   r@   r0   )
r1   r2   r3   r4   )ComputeRegionBackendServicesUpdateRequestr6   r/   r0   r7   #ComputeBackendServicesUpdateRequest)r9   r:   r;   replacements       r'   _GetSetRequestAddBackend._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                 F   UR                   (       a3  [        R                  R                  UU[        R
                  " U5      S9$ UR                  (       aL  [        R                  " U R                  U R                  S9R                  UU[        R
                  " U5      S9$ g )Nscope_listerr   )
instance_groupr
   MULTISCOPE_INSTANCE_GROUP_ARGResolveAsResourcecompute_flagsGetDefaultScopeListernetwork_endpoint_groupGetNetworkEndpointGroupArgr   r   )r9   args	resourcesr:   s       r'   _GetGroupRefAddBackend._GetGroupRefy   s    00BB

$::6B C D D ""--!44!4466G6G(>>vF 7H 7HH #r*   c                    [         R                  " XU R                  5       5        UGb  UR                  UUUR                  UR
                  UUR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  S9nU R                  5       [        R                  R                  :X  d,  U R                  5       [        R                  R                   :X  a9  UR"                  Ul        UR&                  Ul        UR*                  Ul        XWl        U$ UR                  UUR                  UR
                  UUR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  S9nU R                  5       [        R                  R                  :X  d,  U R                  5       [        R                  R                   :X  a9  UR"                  Ul        UR&                  Ul        UR*                  Ul        XWl        U$ )a5  Create a backend message.

Args:
  messages: The available API proto messages.
  group_uri: String. The backend instance group uri.
  balancing_mode: Backend.BalancingModeValueValuesEnum. The backend load
    balancing mode.
  preference: Backend.PreferenceValueValuesEnum. The backend preference
  traffic_duration: Backend.TrafficDurationValueValuesEnum. The traffic
    duration for the backend.
  args: argparse Namespace. The arguments given to the add-backend command.

Returns:
  A new Backend message with its fields set according to the given
  arguments.
)balancingMode
preferencecapacityScalerdescriptiongroupmaxRatemaxRatePerInstancemaxRatePerEndpointmaxUtilizationmaxConnectionsmaxConnectionsPerInstancemaxConnectionsPerEndpointfailover)rU   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   )r   ValidateBalancingModeArgsr   Backendcapacity_scalerrX   max_ratemax_rate_per_instancemax_rate_per_endpointmax_utilizationmax_connectionsmax_connections_per_instancemax_connections_per_endpointra   r   ALPHABETAmax_in_flight_requestsmaxInFlightRequests#max_in_flight_requests_per_instancemaxInFlightRequestsPerInstance#max_in_flight_requests_per_endpointmaxInFlightRequestsPerEndpointtrafficDuration)r9   r4   	group_uribalancing_moderV   traffic_durationrP   backends           r'   _CreateBackendMessage AddBackend._CreateBackendMessage   s   2 44))+   &--&&--!77!77----$($E$E$($E$E== ! g  


!2!2!8!8
8 D$5$5$:$::&*&A&A#44 	. 44 	. #3n  &--&&--!77!77----$($E$E$($E$E== ! g 


!2!2!8!8
8 D$5$5$:$::&*&A&A#44 	. 44 	. #3nr*   c           	         [         R                  " U5      nU R                  XBU5      nUR                  5       nSn	UR                   H  n
XR
                  :X  d  M  UR                  5       S:X  d  UR                  5       S:X  a  S[        US5      -   S-   n	OQUR                  5       S:X  d  UR                  5       S:X  a  S	[        US
5      -   S-   n	OUR                  5       S:X  a  Sn	[        R                  " SR                  UR                  5       XR                  5       5      5      e   UR                  (       a0  UR                  R                  R                  UR                  5      nOS nS nUR                   (       a/  UR                  R                  R#                  UR                   5      nS nU R%                  5       [&        R$                  R(                  :X  d,  U R%                  5       [&        R$                  R*                  :X  a@  UR,                  (       a/  UR                  R                  R/                  UR,                  5      nU R1                  UR                  UUUUU5      n
UR2                  (       a  UR2                  U
l        UR6                  (       a  UR6                  U
l        UR                  R9                  U
5        U$ )N zcompute.instanceGroupszcompute.networkEndpointGroupszzone [zone]zcompute.regionInstanceGroupsz#compute.regionNetworkEndpointGroupszregion [r/   z#compute.globalNetworkEndpointGroupsglobalz:Backend [{}] in {} already exists in backend service [{}].)r   CopyProtoMessagerR   SelfLinkbackendsrY   r1   getattrr	   ArgumentErrorformatr6   rv   r4   rc   BalancingModeValueValuesEnumrV   PreferenceValueValuesEnumr   r   rl   rm   rw   TrafficDurationValueValuesEnumry   custom_metricscustomMetricscustom_metrics_fileappend)r9   r:   rQ   r;   rP   existingrC   	group_refru   scoperx   rv   rV   rw   s                 r'   _ModifyAddBackend._Modify   sU   ++H5K!!$6:I""$IE$$	mm	#  "&>>##%)HHWY77#=%  "&DD##%)NNwy(;;cA%!!#'LL%&&HOO %)A)A)C
 	
 %* ..KK


n nJ??**DD
//j t00666$"3"3"8"88


00OO


 ((G "11g"66g(r*   c                    [         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      nU R                  X2R                  UXS   5      nUR                  U R                  X4U5      /5      $ )z@Issues requests necessary to add backend to the Backend Service.rG   r   )r   ComputeApiHolderr   r:   r
   r   rK   rQ   rL   rM   r<   MakeRequestsr   rD   )r9   rP   holderr:   r;   get_requestobjects
new_objects           r'   RunAddBackend.Run  s    **4+<+<+>?F]]F 	11CC&<<VD 	D 	F 
 %%fBK!!;-0Gf&6&68K"AJ0J 			V*	EFH Hr*    N)__name__
__module____qualname____firstlineno____doc__r   r   r    r"   classmethodr(   r<   rD   rR   ry   r   r   __static_attributes__r   r*   r'   r   r   !   sW    "  %+ +@66 HVp>@Hr*   r   c                       \ rS rSrSrSrSrg)AddBackendBetai4  r   Tr   Nr   r   r   r   r   r"   r   r   r*   r'   r   r   4  s    $ !%r*   r   c                       \ rS rSrSrSrSrg)AddBackendAlphaiK  r   Tr   Nr   r   r*   r'   r   r   K  s    " !%r*   r   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   r
   rL   3googlecloudsdk.command_lib.compute.backend_servicesr   r   UniverseCompatibleReleaseTracksr   GAUpdateCommandr   rm   r   rl   r   r   r*   r'   <module>r      s     9 &  ' % 7 ( 9 E M V E D%%(()NH## NH * NHb D%%**+%Z % ,%, D%%++,%j % -%r*   