
    .                        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  S r " S S\5      r\
R.                  \
R0                  " \
R2                  R4                  5       " S S\
R6                  5      5       5       r\
R0                  " \
R2                  R:                  5       " S S\5      5       r\
R0                  " \
R2                  R>                  5       " S S\5      5       r g)z)Command for updating service attachments.    )absolute_import)division)unicode_literals)encoding)base_classes)base)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                   l    \ 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g)UpdateHelper8   r   Nc                 *    Xl         X l        UU l        g N)_holder_support_target_service_arg$_support_endpoint_based_security_arg)selfholdersupport_target_service_arg#support_endpoint_based_security_args       r   __init__UpdateHelper.__init__>   s     L'A$+ 	-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        U(       a  [         R                  " U5        [         R                  " USS9  [         R                  " U5        [         R                  " U5        [         R                  " U5        U(       a  [         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_target_service_arg: Whether to add arguments for producer
    forwarding rule.
  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AddConsumerAcceptListOldAddPropagatedConnectionLimit)clsparserr   r    s       r   ArgsUpdateHelper.ArgsJ   s    ( "'!@!@!BC**6(*K??O  &&v.	 !))&1	!!&D9	))&1	**62	'*!!&)$$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._GetConsumerAcceptListr   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._GetProjectOrNetworkOrEndpointBasedOnArg{   s-    0000@@$$^44r   c                 |    UR                   b  UR                   UR                  4$ UR                  UR                  4$ r   )projectIdOrNumconnectionLimit
networkUrlrG   s     r   rF   !UpdateHelper._GetProjectOrNetwork   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   )rL   rM   endpointUrlrN   rG   s     r   rE   +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)rW   rX   r>   %ComputeServiceAttachmentsPatchRequestra   rb   Name)r   r=   rZ   replacements       r   _GetPatchRequestUpdateHelper._GetPatchRequest   sV    ""55wOOAA.66-44"8"="="?*5	 B 78 8r   c                    U R                   R                  UUR                  [        R                  R
                  [        R                  " UR                  5      S9n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   rA   nat_subnetwork_refsnat_subnetwork_refnat_subnetworkss         r   _GetNatSubnetsUpdateHelper._GetNatSubnets   s    11CC#--44"88G	 D I #6"5 	##%"5   	s   !A?c                 2   [         R                  " U5      nSnU R                  (       a)  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                  S5      (       a-  UR.                  UR0                  :w  a  UR.                  Ul        SnUR                  S5      (       a-  UR2                  UR4                  :w  a  UR2                  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consumerAcceptListsreconcile_connectionspropagated_connection_limit)r   CopyProtoMessager   IsSpecifiedr{   targetServicer|   r   GetConnectionPreferencer=   r>   connectionPreferencer~   enableProxyProtocolsortedrx   
natSubnetsr   r   appendrB   rI   r   r   reconcileConnectionsr   propagatedConnectionLimit)r   r   rA   old_resourcecleared_fieldsrg   
is_updatednew_connection_preferencenew_nat_subnetsnew_reject_listr   new_accept_lists               r   _ModifyUpdateHelper._Modify   s   ++L9KJ''D,<,<=M,N,N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/00		#	#|'H'H	H+/+E+E(
566

*
*334 150P0P-
r   c                    U R                   R                  n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.)rk   N)r   r=   r)   rm   rn   ro   rp   rq   r]   r   rW   IncludeFieldsrY   rh   )r   rA   r=   rZ   r   r   rg   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   r   r   )__name__
__module____qualname____firstlineno____doc__r)   r-   r!   classmethodr9   rB   rI   rF   rE   r]   rh   rx   r   r   __static_attributes__r   r   r   r   r   8   s^    :
 %/ %/N5
G
GB8M^Pr   r   c                   D    \ rS rSrSrSrSr\" 5       r\	S 5       r
S rSrg)Updatei  r   Fc                 Z    [         R                  UU R                  U R                  5        g r   )r   r9   r   r   )r7   r8   s     r   r9   Update.Args  s%    ''00r   c                     [         R                  " U R                  5       5      n[        UU R                  U R
                  5      R                  U5      $ )r   )r   ComputeApiHolderReleaseTrackr   r   r   r   r@   s      r   r   
Update.Run  sH    **4+<+<+>?F((11 
c$i	r   r   N)r   r   r   r   r   r   r   r   detailed_helpr   r9   r   r   r   r   r   r   r     s1     ; %).&/- r   r   c                   *    \ rS rSrSrSr\" 5       rSrg)
UpdateBetai%  r   Tr   N)	r   r   r   r   r   r   r   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)UpdateAlphai,  r   Tr   N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r   ,  s    : $/-r   r   N)!r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer	   rr   r
   ro   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 \2PP6 PPf D%%(()T  * 0 D%%**+" " ," D%%++,"* " -"r   