
    )                     B    S r SSKJr  SSKJr  SSKJr   " S S\5      r	g)zBackend service.    )utils)
exceptions)iam_utilc                       \ rS rSrSrSS jr\S 5       r\S 5       rS r	S r
S	 rS
 rS rS rSS jrSS jrS rS rSS jrS rS rS rS rSrg)BackendService   z"Abstracts BackendService resource.Nc                     Xl         X l        g N)ref_compute_client)selfr   compute_clients      =lib/googlecloudsdk/api_lib/compute/backend_services/client.py__init__BackendService.__init__   s    H)    c                 .    U R                   R                  $ r
   )r   apitools_clientr   s    r   _clientBackendService._client   s    ///r   c                 .    U R                   R                  $ r
   )r   messagesr   s    r   	_messagesBackendService._messages"   s    (((r   c                    [        U R                  SS 5      nUb^  U R                  R                  SU R                  R                  U R                  R                  UU R                  R                  5       S94$ U R                  R                  SU R                  R                  U R                  R                  U R                  R                  5       S94$ )NregionGetprojectr   backendServicer    r!   )
getattrr   r   regionBackendServicesr   &ComputeRegionBackendServicesGetRequestr    NamebackendServices ComputeBackendServicesGetRequestr   r   s     r   _MakeGetRequestTuple#BackendService._MakeGetRequestTuple&   s    TXXx.Fll00%nnCC((**!% D 23 3 ll**Enn==((**488==? > LM Mr   c           	         [        U R                  SS5      nUb_  U R                  R                  SU R                  R                  U R                  R                  UU R                  R                  5       US94$ U R                  R                  SU R                  R                  U R                  R                  U R                  R                  5       US94$ )z2Makes a location aware backend service patch call.r   NPatch)r    r   r!   backendServiceResource)r    r!   r.   )
r#   r   r   r$   r   (ComputeRegionBackendServicesPatchRequestr    r&   r'   "ComputeBackendServicesPatchRequest)r   replacementr   s      r   _MakeSetRequestTuple#BackendService._MakeSetRequestTuple3   s    TXXx.Fll00'nnEE((**!%)4	 F 67 7 ll**Gnn??((**!%)4 @ 67 7r   c                    [        U R                  SS 5      nUb^  U R                  R                  SU R                  R                  U R                  R                  UU R                  R                  5       S94$ U R                  R                  SU R                  R                  U R                  R                  U R                  R                  5       S94$ )Nr   Deleter   r"   )
r#   r   r   r$   r   )ComputeRegionBackendServicesDeleteRequestr    r&   r'   #ComputeBackendServicesDeleteRequestr)   s     r   _MakeDeleteRequestTuple&BackendService._MakeDeleteRequestTupleD   s    TXXx.Fll00(nnFF((**!% G 23 3 ll**Hnn@@((**488==? A LM Mr   c           	         [        U R                  SS 5      nUbv  U R                  R                  SU R                  R                  U R                  R                  US9U R                  R                  UU R                  R                  5       S94$ U R                  R                  SU R                  R                  U R                  R                  US9U R                  R                  U R                  R                  5       S94$ )Nr   	GetHealth)group)resourceGroupReferencer    r   r!   )r=   r    r!   )r#   r   r   r$   r   ,ComputeRegionBackendServicesGetHealthRequestResourceGroupReferencer    r&   r'   &ComputeBackendServicesGetHealthRequest)r   r<   r   s      r   _MakeGetHealthRequestTuple)BackendService._MakeGetHealthRequestTupleQ   s    TXXx.Fll00+nnII)-)N)N! *O *#((**!% J 23 3 ll**KnnCC)-)N)N! *O *#((**!%	 D 23 3r   c           	         [        U R                  SS5      nU(       av  U R                  R                  SU R                  R                  U R                  R                  US9UU R                  R                  U R                  R                  5       S94$ U R                  R                  SU R                  R                  U R                  R                  US9U R                  R                  U R                  R                  5       S94$ )z=Makes a call to set the security policy on a backend service.r   NSetSecurityPolicysecurityPolicy)securityPolicyReferencer   r    r!   rG   r    r!   )r#   r   r   r$   r   4ComputeRegionBackendServicesSetSecurityPolicyRequestSecurityPolicyReferencer    r&   r'   .ComputeBackendServicesSetSecurityPolicyRequestr   security_policyr   s      r   !MakeSetSecurityPolicyRequestTuple0BackendService.MakeSetSecurityPolicyRequestTuplec   s     TXXx.F
,,
,
,

..
M
M&*nn&L&L!0 'M '2hh&&!XX]]_ N .	 	 	$$EE$(NN$J$J. %K %0HH$$88==?	 	F 	, r   c                 V   [        U R                  SS 5      nU(       a  [        R                  " SS5      eU R                  R
                  SU R                  R                  U R                  R                  US9U R                  R                  U R                  R                  5       S94$ )Nr   z>Can only set edge security policy for global backend services.SetEdgeSecurityPolicyrE   rH   )r#   r   calliope_exceptionsInvalidArgumentExceptionr   r'   r   2ComputeBackendServicesSetEdgeSecurityPolicyRequestrJ   r    r&   rL   s      r   %MakeSetEdgeSecurityPolicyRequestTuple4BackendService.MakeSetEdgeSecurityPolicyRequestTuple}   s    TXXx.F88

JL L
 	$$II$(NN$J$J. %K %0HH$$88==?	 	J 	, r   c                 l    U R                  5       /nU(       d  U R                  R                  U5      $ U$ r
   )r8   r   MakeRequests)r   only_generate_requestrequestss      r   r5   BackendService.Delete   s2    ,,./H !!..x88Or   c                 v    U R                  5       /nU(       d   U R                  R                  U5      nUS   $ U$ )z%Fetches the backend service resource.r   )r*   r   rX   )r   rY   rZ   	responsess       r   r   BackendService.Get   s;    ))+,H &&33H=iq\Or   c                 ^    U R                  U5      /nU R                  R                  U5        g)z%Patches the backend service resource.N)r2   r   rX   )r   r1   rZ   s      r   SetBackendService.Set   s)    ))+67H%%h/r   c              #   6  #    U R                  5       n/ nUR                   HV  nU R                  R                  U R	                  UR
                  5      /U5      nU(       d  MB  UR
                  US   S.v   MX     U(       a  [        R                  " USS9  gg7f)zIssues series of gethealth requests for each backend group.

Yields:
  {'backend': backend.group, 'status': backend_service.GetHealthResponse}
r   )backendstatusz%Could not get health for some groups:)error_messageN)r   backendsr   rX   rA   r<   r   RaiseToolException)r   backend_serviceerrorsrc   	resourcess        r   r;   BackendService.GetHealth   s      hhjO F"++ &&33**7==9
:FDi 
!--9Q<@@ , 
 GI s   AB#6Bc                 n    U R                  U5      /nU(       d  U R                  R                  U5      $ U$ )z1Sets the security policy for the backend service.)rN   r   rX   )r   rM   rY   rZ   s       r   rD    BackendService.SetSecurityPolicy   s4    66GHH !!..x88Or   c                    U R                   R                  5       S:X  aq  U R                  R                  R                  nU R                  R
                  R                  U R                   R                  5       U R                   R                  S9nOU R                   R                  5       S:X  a  U R                  R                  R                  nU R                  R
                  R                  U R                   R                  5       U R                   R                  U R                   R                  S9nU R                  R                  WSW4/5      S   $ )z8Get the IAM policy for a Compute Engine backend service.compute.backendServices)resourcer    compute.regionBackendServices)rp   r   r    GetIamPolicyr   )r   
Collectionr   r   r'   r   )ComputeBackendServicesGetIamPolicyRequestr&   r    r$   /ComputeRegionBackendServicesGetIamPolicyRequestr   rX   )r   servicerequests      r   rr   BackendService.GetIamPolicy   s   xx 99$$44DDg$$--WW88==?DHH,<,< X >g				"A	A$$44JJg$$--]]88==?(("" ^ $g ,,w.P ./ 0013 3r   c           	         U R                   R                  5       S:X  a  U R                  R                  R                  nU R                  R
                  R                  U R                   R                  5       U R                   R                  U R                  R
                  R                  US9S9nOU R                   R                  5       S:X  a  U R                  R                  R                  nU R                  R
                  R                  U R                   R                  5       U R                   R                  U R                   R                  U R                  R
                  R                  US9S9nU R                  R                  WSW4/5      S   n[        R                   " U R                   R                  5       S5        U$ )	z@Set the IAM policy binding for a Compute Engine backend service.ro   )policy)rp   r    globalSetPolicyRequestrq   )rp   r   r    regionSetPolicyRequestSetIamPolicyr   zbackend service)r   rs   r   r   r'   r   )ComputeBackendServicesSetIamPolicyRequestr&   r    GlobalSetPolicyRequestr$   /ComputeRegionBackendServicesSetIamPolicyRequestr   RegionSetPolicyRequestrX   r   LogSetIamPolicy)r   rz   rv   rw   results        r   r}   BackendService.SetIamPolicy   sl   xx 99$$44DDg$$--WW88==?((""!%!5!5!>!>!!!0	 X 2g
 
			"A	A$$44JJg$$--]]88==?((""!%!5!5!>!>!!!0 ^ 2g !!...181: 0; <<=?FTXX]]_.?@Mr   c                     U R                  5       n[        R                  " U R                  R                  X1U5        U R                  U5      $ )z>Compute Engine backend service add iam policy binding request.)rr   r   AddBindingToIamPolicyr   Bindingr}   r   memberrolerz   s       r   AddIamPolicyBinding"BackendService.AddIamPolicyBinding   s=     F""4>>#9#964PV$$r   c                 r    U R                  5       n[        R                  " X1U5        U R                  U5      $ )zACompute Engine backend service remove iam policy binding request.)rr   r   RemoveBindingFromIamPolicyr}   r   s       r   RemoveIamPolicyBinding%BackendService.RemoveIamPolicyBinding   s1     F''=V$$r   )r   r   r
   )F) F)__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r*   r2   r8   rA   rN   rU   r5   r   r`   r;   rD   rr   r}   r   r   __static_attributes__ r   r   r   r      s    ** 0 0 ) )M7"M3$4"0
 ID3,%%r   r   N)
r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   rR   googlecloudsdk.command_lib.iamr   objectr   r   r   r   <module>r      s#     1 E 3b%V b%r   