
                            d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ dd	lmZ dd	lmZ dd	lmZ dd
lmZ dd	lmZ ddlmZ  e
j0                  e
j2                  j4                         G d de
j6                               Z e
j0                  e
j2                  j:                         G d de             Z e
j0                  e
j2                  j>                         G d de             Z y)z=Command for updating an interface on a Compute Engine router.    )absolute_import)division)unicode_literals)encoding)base_classes)base)parser_errors)flags)router_utils)logc                   Z    e Zd ZdZdZdZdZed        Zed        Z	d Z
d Zd Zd Zd	 Zy)
UpdateInterface~Update an interface on a Compute Engine router.

  *{command}* is used to update an interface on a Compute Engine
  router.
  Nc                    t        j                         | _        | j                  j                  |d       |j	                  d      }t        j                  dd      | _        | j                  j                  |       t        j                  dd      | _
        | j                  j                  |       t        j                  |d       y )	Nupdate)operation_typeF)requiredupdated)r   r   T)
for_update)router_flagsRouterArgument
ROUTER_ARGAddArgumentadd_mutually_exclusive_groupvpn_tunnel_flagsVpnTunnelArgumentForRouterVPN_TUNNEL_ARGattachment_flags'InterconnectAttachmentArgumentForRouterINTERCONNECT_ATTACHMENT_ARGAddInterfaceArgs)clsparserlink_parsers      /lib/surface/compute/routers/update_interface.py_ArgszUpdateInterface._Args1   s    !002CNNNvh?55u5EK)DDyC "";/ 	@@9	
 #
 ##//<!!&T:    c                 $    | j                  |      S Nr&   r"   r#   s     r%   ArgszUpdateInterface.ArgsF       99Vr'   c                     |j                   j                  d|j                  j                  |j	                         |j
                  |j                        fS )NGet)routerregionproject)apitools_clientroutersmessagesComputeRoutersGetRequestNamer1   r2   )selfclient
router_refs      r%   GetGetRequestzUpdateInterface.GetGetRequestJ   sQ    &&00??$$$&& 	1 	
 r'   c                     |j                   j                  d|j                  j                  |j	                         ||j
                  |j                        fS )NPatch)r0   routerResourcer1   r2   )r3   r4   r5   ComputeRoutersPatchRequestr7   r1   r2   )r8   r9   r:   replacements       r%   GetSetRequestzUpdateInterface.GetSetRequestU   sT    &&22??$&$$&&	 	3 	
	 	r'   c                    t        j                  |      }d }|j                  D ]  }|j                  |j                  k(  s|} n |t        j                  |j                        |j                  8|j                  ,dj                  |j                  |j                        |_
        n,|j                  |j                  t        j                         |j                  4|j                  j                  j                  |j                        |_        |j"                  s|j$                  |_        |j&                  F| j(                  j+                  ||t-        j.                  |            }|j1                         |_        |j4                  s|j$                  |_        |j6                  1| j8                  j+                  ||      }	|	j1                         |_        |j2                  !|j:                  t=        j>                  d      |S )Nz{0}/{1})scope_listerzJcannot have both vpn-tunnel and interconnect-attachment for the interface.) r   CopyProtoMessage
interfacesnameinterface_namer   InterfaceNotFoundError
ip_addressmask_lengthformatipRange"RequireIpAddressAndMaskLengthError
ip_versionr5   RouterInterfaceIpVersionValueValuesEnum	ipVersionvpn_tunnel_regionr1   
vpn_tunnelr   ResolveAsResourcecompute_flagsGetDefaultScopeListerSelfLinklinkedVpnTunnelinterconnect_attachment_regioninterconnect_attachmentr    linkedInterconnectAttachmentr	   ArgumentException)
r8   r9   	resourcesargsexistingr@   ifaceivpn_refattachment_refs
             r%   ModifyzUpdateInterface.Modifya   s   ++H5KE##	
4&&	& $
 }//0C0CDD 	#$*:*:*F&&t8H8HIem
//
%4+;+;+G;;=="
//
)
)
B
Boo o !!*11d"##55

$::6B 6 g
 &..0e..,7,>,>d)##/77II
	n ,:+B+B+De( 	)..:++ 
 r'   c                    t        j                  | j                               }|j                  }| j                  j                  ||j                        }| j                  ||      }|j                  |g      }| j                  ||j                  ||d         }|d   |k(  r=t        j                  j                  dj                  |d   j                               |S |j                  | j                  |||      g      S )z=Issues requests necessary to update interfaces of the Router.r   z/No change requested; skipping update for [{0}].)r   ComputeApiHolderReleaseTrackr9   r   rT   r]   r;   MakeRequestsrd   r   statusPrintrK   rF   rA   )r8   r^   holderr9   r:   get_requestobjects
new_objects           r%   _RunzUpdateInterface._Run   s    **4+<+<+>?F]]F2249I9IJJ$$VZ8K!!;-0G
	J qzZ	jj
;
B
Bajoo
 n			FJ
	;< r'   c                 $    | j                  |      S r)   ro   r8   r^   s     r%   RunzUpdateInterface.Run       99T?r'   )__name__
__module____qualname____doc__r   r   r    classmethodr&   r,   r;   rA   rd   ro   rs    r'   r%   r   r   %   sZ     *. $; ;(  	
7r@r'   r   c                   &    e Zd ZdZd Zed        Zy)UpdateInterfaceBetar   c                 $    | j                  |      S r)   rq   rr   s     r%   rs   zUpdateInterfaceBeta.Run   rt   r'   c                 $    | j                  |      S r)   r*   r+   s     r%   r,   zUpdateInterfaceBeta.Args   r-   r'   N)ru   rv   rw   rx   rs   ry   r,   rz   r'   r%   r|   r|      s       r'   r|   c                       e Zd ZdZy)UpdateInterfaceAlphar   N)ru   rv   rw   rx   rz   r'   r%   r   r      s     r'   r   N)!rx   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r	   "googlecloudsdk.command_lib.computer
   rU   <googlecloudsdk.command_lib.compute.interconnects.attachmentsr   *googlecloudsdk.command_lib.compute.routersr   r   .googlecloudsdk.command_lib.compute.vpn_tunnelsr   googlecloudsdk.corer   ReleaseTracksrg   GAUpdateCommandr   BETAr|   ALPHAr   rz   r'   r%   <module>r      s    D &  ' % 7 ( 1 E M C $ D%%(()Ud(( U *Up D%%**+/  , D%%++,.  -r'   