
    1                        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	 r " S
 S\5      r\R(                  \R*                  " \R,                  R.                  5       " S S\R0                  5      5       5       r\R*                  " \R,                  R4                  5       " S S\5      5       r\R*                  " \R,                  R8                  5       " S S\5      5       rg)z)Command for updating service attachments.    )encoding)base_classes)base)
exceptions)flags)scope)service_attachments_utilsc                      SSSS.$ )N2Update a Google Compute Engine service attachment.a        *{command}* is used to update service attachments. A service producer
      creates service attachments to make a service available to consumers.
      Service consumers use Private Service Connect endpoints to privately
      forward traffic to the service attachment.
      a        To update the connection policy of a service attachment to be ACCEPT_MANUAL, run:

        $ {command} SERVICE_ATTACHMENT_NAME --region=us-central1 --connection-preference=ACCEPT_MANUAL

      To update all supported fields of a service attachment, run:

        $ {command} SERVICE_ATTACHMENT_NAME --region=us-central1 --connection-preference=ACCEPT_AUTOMATIC --nat-subnets=MY_SUBNET1,MY_SUBNET2 --enable-proxy-protocol --consumer-reject-list=PROJECT_ID1,PROJECT_ID2 --consumer-accept-list=PROJECT_ID3=10,PROJECT_ID4=20

      )briefDESCRIPTIONEXAMPLES r       1lib/surface/compute/service_attachments/update.py_DetailedHelpr      s     ?
	

 r   c                   r    \ 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S rS rS rSrg)UpdateHelper6   r   Nc                     Xl         UU l        g N_holder$_support_endpoint_based_security_arg)selfholder#support_endpoint_based_security_args      r   __init__UpdateHelper.__init__<   s    
 L+ 	-r   c                    [         R                  " 5       U l        U R                  R                  USS9  [        R
                  " SS9U l        U R                  R                  U5        [         R                  " U5        [         R                  " U5        [         R                  " USS9  [         R                  " U5        [         R                  " U5        [         R                  " U5        U(       a-  [         R                  " U5        [         R                  " U5        O[         R                  " U5        [         R                   " U5        g)a  Create a Google Compute Engine service attachment.

Args:
  parser: the parser that parses the input from the user.
  support_endpoint_based_security_arg: Whether to support endpoint based
    security.

cls: Hold onto the definition of a complex argument so it can be used later
  to process the user's input.
flags: Define and register command-line arguments with the argument parser.
update)operation_typeF)requiredT)	is_updateN)r   ServiceAttachmentArgumentSERVICE_ATTACHMENT_ARGAddArgumentsubnetwork_flags&SubnetworkArgumentForServiceAttachmentNAT_SUBNETWORK_ARGAddDescriptionAddTargetServiceArgsForUpdateAddConnectionPreferenceAddEnableProxyProtocolForUpdate AddReconcileConnectionsForUpdateAddConsumerRejectListAddConsumerAcceptList AddRemoveObsoleteEndpointEntriesAddConsumerAcceptListOldAddPropagatedConnectionLimit)clsparserr   s      r   ArgsUpdateHelper.ArgsF   s    " "'!@!@!BC**6(*K??O  &&v.	 	''/	!!&D9	))&1	**62	'*!!&),,V4$$V,	&&v.r   c                     U R                   (       a*  [        R                  " XR                  R                  5      $ [        R
                  " XR                  R                  5      $ r   )r   r	   .GetConsumerAcceptListWithEndpointBasedSecurityclientmessagesGetConsumerAcceptListr   argsr   s      r   _GetConsumerAcceptList#UpdateHelper._GetConsumerAcceptListk   sM    00&UU
&&  %::mm$$ r   c                 h    U R                   (       a  U R                  U5      $ U R                  U5      $ r   )r   _GetProjectOrNetworkOrEndpoint_GetProjectOrNetworkr   consumer_limits     r   (_GetProjectOrNetworkOrEndpointBasedOnArg5UpdateHelper._GetProjectOrNetworkOrEndpointBasedOnArgt   s-    0000@@$$^44r   c                 |    UR                   b  UR                   UR                  4$ UR                  UR                  4$ r   )projectIdOrNumconnectionLimit
networkUrlrE   s     r   rD   !UpdateHelper._GetProjectOrNetworky   s<    $$0++^-K-KLL%%~'E'EFFr   c                     UR                   b  UR                   UR                  4$ UR                  b  UR                  UR                  4$ UR                  UR                  4$ r   )rJ   rK   endpointUrlrL   rE   s     r   rC   +UpdateHelper._GetProjectOrNetworkOrEndpoint~   s_    $$0++^-K-KLL		#	#	/((.*H*HII%%~'E'EFFr   c                     UR                   R                  " S0 UR                  5       D6nUR                  R                  nUR                  USU4/5      S   $ )z0Returns the existing ServiceAttachment resource.Getr   r   )r<   #ComputeServiceAttachmentsGetRequestAsDictapitools_clientserviceAttachmentsMakeRequests)r   r;   service_attachment_refrequest
collections        r   _GetOldResourceUpdateHelper._GetOldResource   sX    ooAA +
 
'
'
)+G''::JUG <=>qAAr   c           	          UR                   R                  SUR                  R                  UR                  UR
                  UR                  5       US94$ )z3Returns a request to update the service attachment.Patch)projectregionserviceAttachmentserviceAttachmentResource)rU   rV   r<   %ComputeServiceAttachmentsPatchRequestr_   r`   Name)r   r;   rX   replacements       r   _GetPatchRequestUpdateHelper._GetPatchRequest   sV    ""55wOOAA.66-44"8"="="?*5	 B 78 8r   c                 8   U R                   (       d   eU R                   R                  UUR                  [        R                  R
                  [        R                  " UR                  5      S9nUc  / $ U Vs/ s H  nUR                  5       PM     nnU$ s  snf )z.Returns nat subnetwork urls from the argument.)default_scopescope_lister)
r*   ResolveAsResource	resourcescompute_scope	ScopeEnumREGIONcompute_flagsGetDefaultScopeListerr;   SelfLink)r   r   r?   nat_subnetwork_refsnat_subnetwork_refnat_subnetworkss         r   _GetNatSubnetsUpdateHelper._GetNatSubnets   s    """"11CC#--44"88G	 D I "i #6"5 	##%"5   	s   9Bc                     Sn[         R                  " U5      n[         R                  " XU5      (       a  Sn[         R                  " XU5      (       a  SnU$ )z?Removes obsolete endpoint entries from accept and reject lists.FT)r	   GetConnectedEndpointIds!CleanObsoleteAcceptedEndpointUrls!CleanObsoleteRejectedEndpointUrls)r   re   cleared_fields
is_updatedconnected_endpoint_idss        r   _RemoveObsoleteEndpointEntries+UpdateHelper._RemoveObsoleteEndpointEntries   sc    J6NN !BB^  j !BB^  jr   c                    [         R                  " U5      nSnUR                  S5      (       a  SnUR                  Ul        UR                  S5      (       a-  UR
                  UR
                  :w  a  UR
                  Ul        SnUR                  S5      (       aA  [        R                  " X!R                  R                  5      nXsR                  :w  a  Xul
        SnUR                  S5      (       a-  UR                  UR                  :w  a  UR                  Ul        SnUR                  S5      (       aH  [        U R                  X5      5      nUR                  b  U[        UR                  5      :w  a  Xl        SnUR                  S	5      (       a[  [        UR                   5      n	UR"                  b  U	[        UR"                  5      :w  a   Xl        SnU	(       d  UR%                  S
5        UR                  S5      (       at  U R'                  X!5      n
[        U
U R(                  S9nUR*                  b"  U[        UR*                  U R(                  S9:w  a   Xl        SnU(       d  UR%                  S5        U R,                  (       ad  UR.                  (       aS  UR                  S5      (       d  UR                  S	5      (       a  [0        R2                  " S5      eU R5                  XT5      nUR                  S5      (       a-  UR6                  UR8                  :w  a  UR6                  Ul        SnUR                  S5      (       a-  UR:                  UR<                  :w  a  UR:                  Ul        SnU(       a  U$ g)z'Returns the updated service attachment.Ftarget_serviceTdescriptionconnection_preferenceenable_proxy_protocolnat_subnetsNconsumer_reject_listconsumerRejectListsconsumer_accept_list)keyconsumerAcceptListsz{--remove-obsolete-endpoint-accept-reject-entries cannot be specified with --consumer-accept-list or --consumer-reject-list.reconcile_connectionspropagated_connection_limit)r   CopyProtoMessageIsSpecifiedr   targetServicer   r	   GetConnectionPreferencer;   r<   connectionPreferencer   enableProxyProtocolsortedrv   
natSubnetsr   r   appendr@   rG   r   r   .remove_obsolete_endpoint_accept_reject_entriesr   ConflictingArgumentsExceptionr   r   reconcileConnectionsr   propagatedConnectionLimit)r   r   r?   old_resourcer|   re   r}   new_connection_preferencenew_nat_subnetsnew_reject_listr   new_accept_lists               r   _ModifyUpdateHelper._Modify   s&   ++L9KJ())j"&"5"5k&&			\55	5"&"2"2
/00
#
;
;MM**  
 
#&G&G	G+D(
/00		#	#|'G'G	G*.*D*D'
&&t226@Ao		 	 	(Ov

!
!@# -#!0
.//t889o		)	)	1_

*
*I, 6,*9'



 5
6.//!88F
;;o 
	)	)	1_

*
*;;I 6 +:'



 5
6 	11??			
 
 
23366O
 	
 66
j /00		#	#|'H'H	H+/+E+E(
566

*
*334 150P0P-
r   c                    U R                   R                  nU R                  (       d   eU R                  R                  UU R                   R                  [
        R                  R                  S9nU R                  X#5      n/ nU R                  U R                   XU5      nUc  U$ UR                  R                  U5         UR                  U R                  X#U5      /5      sSSS5        $ ! , (       d  f       g= f))Issue a service attachment PATCH request.)ri   N)r   r;   r&   rk   rl   rm   rn   ro   r[   r   rU   IncludeFieldsrW   rf   )r   r?   r;   rX   r   r|   re   s          r   RunUpdateHelper.Run  s    \\  F&&&&!88JJ#--44 K 
 ''GLN,,t||TPK				-	-n	=    M
NP 
>	=	=s   "C--
C;r   )__name__
__module____qualname____firstlineno____doc__r&   r*   r   classmethodr7   r@   rG   rD   rC   r[   rf   rv   r   r   r   __static_attributes__r   r   r   r   r   6   sc    : "/ "/H5
G
GB8"&\|Pr   r   c                   @    \ rS rSrSrSr\" 5       r\S 5       r	S r
Srg)Updatei+  r   Fc                 D    [         R                  UU R                  5        g r   )r   r7   r   )r5   r6   s     r   r7   Update.Args2  s    00r   c                     [         R                  " U R                  5       5      n[        UU R                  5      R                  U5      $ )r   )r   ComputeApiHolderReleaseTrackr   r   r   r>   s      r   r   
Update.Run9  s?    **4+<+<+>?F11 
c$ir   r   N)r   r   r   r   r   r   r   detailed_helpr   r7   r   r   r   r   r   r   r   +  s+     ;).&/- r   r   c                   *    \ rS rSrSrSr\" 5       rSrg)
UpdateBetaiB  r   Tr   N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r   B  s    :)-&/-r   r   c                   &    \ rS rSrSr\" 5       rSrg)UpdateAlphaiI  r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   I  s    :/-r   r   N)r   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.computer   rp   r   rm   3googlecloudsdk.command_lib.compute.networks.subnetsr(   6googlecloudsdk.command_lib.compute.service_attachmentsr	   r   objectr   UniverseCompatibleReleaseTracksr   GAUpdateCommandr   BETAr   ALPHAr   r   r   r   <module>r      s    0 & 7 ( . E E Y H \2rP6 rPj D%%(()T  * * D%%**+" " ," D%%++,"* " -"r   