
    }                        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  e
j.                  e
j0                  j2                         G d
 de
j4                               Z e
j.                  e
j0                  j8                         G d de             Z e
j.                  e
j0                  j<                         G d de             Zy)z;Command for adding an interface to a Compute Engine router.    )absolute_import)division)unicode_literals)encoding)base_classes)base)parser_errors)flagsc                   ^    e Zd 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)
AddInterfacexAdd an interface to a Compute Engine router.

  *{command}* is used to add an interface to a Compute Engine
  router.
  Nc                 `   t        j                         | _        | j                  j                  |d       |j	                  d      }|j                  d      }t        j                  d      | _        | j                  j                  |       |j                  d      }t        j                         | _        | j                  j                  |       |j                  d      }t        j                         | _        | j                  j                  |       t        j                  |       y )	Nupdate)operation_typeT)requiredz
VPN TunnelFzInterconnect Attachment
Subnetwork)router_flagsRouterArgument
ROUTER_ARGAddArgumentadd_mutually_exclusive_groupadd_argument_groupvpn_tunnel_flagsVpnTunnelArgumentForRouterVPN_TUNNEL_ARGattachment_flags'InterconnectAttachmentArgumentForRouterINTERCONNECT_ATTACHMENT_ARGsubnet_flagsSubnetworkArgumentForRouterSUBNETWORK_ARGAddInterfaceArgs)clsparserlink_parservpn_tunnel_groupinterconnect_attachment_groupsubnetwork_groups         ,lib/surface/compute/routers/add_interface.py_ArgszAddInterface._Args1   s    !002CNNNvh?55t5DK"55lC)DDC ""#34$/$B$B!%! 	@@B # ##//0MN"55lC%AACC""#34!!&)    c                 &    | j                  |       y N)r*   )r#   r$   s     r)   ArgszAddInterface.ArgsL   s    IIfr+   c                     |j                   j                  d|j                  j                  |j	                         |j
                  |j                        fS )NGet)routerregionproject)apitools_clientroutersmessagesComputeRoutersGetRequestNamer2   r3   )selfclient
router_refs      r)   _GetGetRequestzAddInterface._GetGetRequestP   sQ    &&00??$$$&& 	1 	
 r+   c                     |j                   j                  d|j                  j                  |j	                         ||j
                  |j                        fS )NPatch)r1   routerResourcer2   r3   )r4   r5   r6   ComputeRoutersPatchRequestr8   r2   r3   )r9   r:   r;   replacements       r)   _GetSetRequestzAddInterface._GetSetRequest[   sT    &&22??$&$$&&	 	3 	
	 	r+   c           	         t        j                  |      }d }|j                  }|j                  |j                  3|j
                  'dj                  |j                  |j
                        }nB|j                  t        j                  d      |j
                  t        j                  d      d }|j                  /|j                  j                  j                  |j                        }|j                  s|j                  |_        d }	|j                  1| j                   j#                  ||t%        j&                  |            }	|j(                  s|j                  |_        d }
|j*                  | j,                  j#                  ||      }
d }d }d }|j                  4| j.                  j#                  ||      }|j                  }|j0                  }|j                  j                  ||	r|	j3                         nd |
r|
j3                         nd |r|j3                         nd |||      }|||_        |j6                  j9                  |       |S )Nz{0}/{1}z0--mask-length must be set if --ip-address is setz2--mask-length cannot be set if --subnetwork is set)scope_lister)namelinkedVpnTunnellinkedInterconnectAttachment
subnetworkipRangeprivateIpAddressredundantInterface)r   CopyProtoMessageinterface_name
ip_addressrH   mask_lengthformatr	   ArgumentException
ip_versionr6   RouterInterfaceIpVersionValueValuesEnumvpn_tunnel_regionr2   
vpn_tunnelr   ResolveAsResourcecompute_flagsGetDefaultScopeListerinterconnect_attachment_regioninterconnect_attachmentr   r!   redundant_interfaceSelfLink	ipVersion
interfacesappend)r9   r:   	resourcesargsexistingrA   maskrM   rR   vpn_refattachment_refsubnetwork_refprivate_ip_addressr\   	interfaces                  r)   ModifyzAddInterface.Modifyg   s9   ++H5KD((N"		 T%5%5%A1A1AB??"-->
 	
 '--@
 	
 J"??22KK
//j !!*11dG"##55

$::6B 6 g ..,7,>,>d)N##/77II
	n N"**<<T9Mn?? 44///6))+D)7N##%T1?N++-T+. 0 
I &i!!),r+   c                 |   t        j                  | j                               }|j                  }| j                  j                  ||j                        }| j                  ||      }|j                  |g      }| j                  ||j                  ||d         }|j                  | j                  |||      g      S )Nr   )r   ComputeApiHolderReleaseTrackr:   r   rW   ra   r<   MakeRequestsrj   rB   )r9   rb   holderr:   r;   get_requestobjects
new_objects           r)   _RunzAddInterface._Run   s    **4+<+<+>?F]]F2249I9IJJ%%fj9K!!;-0G
	J 			VZ	<= r+   c                 $    | j                  |      S r-   )rs   )r9   rb   s     r)   RunzAddInterface.Run   s    99T?r+   )__name__
__module____qualname____doc__r   r   r   r!   classmethodr*   r.   r<   rB   rj   rs   ru    r+   r)   r   r   $   s_     *. $.* *4  	
AF(r+   r   c                       e Zd ZdZy)AddInterfaceBetar   Nrv   rw   rx   ry   r{   r+   r)   r}   r}          
 r+   r}   c                       e Zd ZdZy)AddInterfaceAlphar   Nr~   r{   r+   r)   r   r      r   r+   r   N) ry   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r	   "googlecloudsdk.command_lib.computer
   rX   <googlecloudsdk.command_lib.compute.interconnects.attachmentsr   3googlecloudsdk.command_lib.compute.networks.subnetsr   *googlecloudsdk.command_lib.compute.routersr   .googlecloudsdk.command_lib.compute.vpn_tunnelsr   ReleaseTracksrm   GAUpdateCommandr   BETAr}   ALPHAr   r{   r+   r)   <module>r      s    B &  ' % 7 ( 1 E V L
 D%%(()Z4%% Z *Zz D%%**+|  , D%%++,(  -r+   