
    (                     .   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 ddlZ ej.                  ej0                  j2                        ej4                   G d dej6                                      Z ej.                  ej0                  j:                         G d de             Z ej.                  ej0                  j>                         G d de             Z 	 	 ddZ!d Z"d Z#y)z9Command for adding a BGP peer to a Compute Engine router.    )absolute_import)division)unicode_literals)base_classes)routers_utils)poller)waiter)base)flags)router_utils)log)	resourcesNc                   H    e Zd ZdZdZdZed        Zed        Z	 ddZ	d Z
y)
AddBgpPeer*Add a BGP peer to a Compute Engine router.Nc                    t        j                         | _        | j                  j                  |       t	        j
                         | _        | j                  j                  |       t        j                  j                  |       t        j                  |d       t        j                  |d       t        j                  |       y )NT)for_add_bgp_peerpeer)r   RouterArgument
ROUTER_ARGAddArgumentinstance_flagsInstanceArgumentForRouterINSTANCE_ARGr
   
ASYNC_FLAGAddToParserAddBgpPeerArgs!AddReplaceCustomAdvertisementArgs!AddReplaceCustomLearnedRoutesArgsclsparsers     +lib/surface/compute/routers/add_bgp_peer.py_ArgszAddBgpPeer._Args*   s    ))+CNNNv&%??AC  (OO'	$7	++FF;	++F3    c                 &    | j                  |       y Nr$   r    s     r#   ArgszAddBgpPeer.Args5       IIfr%   c           	      2   t        j                  | j                               }|j                  j                  }|j                  j
                  j                  }| j                  j                  ||j                        }|j                  }|j                   |di |j                               }d}	|j                  E| j                  j                  ||j                  t        j                   |j                              }	t#        j$                  ||      }
t'        |||
||	      }t#        j(                  |      rYt#        j*                  ||j,                  |      \  }}}|||d}t/        j0                  |      D ]  \  }}|	t3        |||        |j4                  &t7        j8                  ||j4                        |_        |j<                  j?                  |       |j@                  8|jC                  |
|j@                        }|jD                  j?                  |       |jG                  |jI                  |jJ                  |jL                  |jO                         |            }t        jP                  jS                  |jT                  d	|jJ                  |jL                  d
      }|jV                  rCtY        jZ                  |dj]                  |jO                         |jT                        dd       |S |j                  jS                  |jO                         d|jJ                  |jL                  d
      }t_        j`                  ||      }tc        jd                  ||dj]                  |jT                  |jO                                     S )a"  Runs the command.

    Args:
      args: contains arguments passed to the command
      support_bfd_mode: The flag to indicate whether bfd mode is supported.

    Returns:
      The result of patching the router adding the bgp peer with the
      information provided in the arguments.
    N)scope_lister)md5_authentication_key_namesupport_bfd_modeinstance_ref)messagesresource_classargs)advertiseModeadvertisedGroupsadvertisedIpRanges)r0   	ip_ranges)namekey)projectregionrouterrouterResourcezcompute.regionOperations)r9   r:   )
collectionparamszrouter [{0}] to add peer [{1}]Tz[Run the [gcloud compute operations describe] command to check the status of this operation.)kindis_asyncdetailszcompute.routersz#Creating peer [{0}] in router [{1}] )3r   ComputeApiHolderReleaseTrackclientr0   apitools_clientroutersr   ResolveAsResourcer   ComputeRoutersGetRequestGetAsDictinstancer   r   GetInstanceZoneScopeListerr    GenerateMd5AuthenticationKeyName_CreateBgpPeerMessageHasReplaceAdvertisementFlagsParseAdvertisementsRouterBgpPeersix	iteritemssetattrset_custom_learned_route_rangesr   ParseCustomLearnedIpRangescustomLearnedIpRangesbgpPeersappendmd5_authentication_keyRouterMd5AuthenticationKeymd5AuthenticationKeysPatchComputeRoutersPatchRequestr9   r:   NameREGISTRYParser7   async_r   UpdatedResourceformatr   Pollerr	   WaitFor)selfr2   r.   holderr0   service
router_refrequest_typereplacementr/   r-   r   modegroupsrangesattrsattrvaluer[   resultoperation_reftarget_router_refoperation_pollers                          r#   _RunzAddBgpPeer._Run9   sJ    **4+<+<+>?F}}%%Hmm++33G2249I9IJJ44L++lAZ->->-@ABKL}} &&88



%@@O 9 l #/"O"OT# !$?)!D 006)==H,B,BdFF
  $ &e u-+$
$e
$ . ++7#0#K#Kt'K'K$d  %"".'BB*0K0K  C   ''../EF]]++&&$$??$&	 	, 	
F &&,,-!)) ''
 - M {{	
/66oo 7
 m((..$!)) ''
 /  }}W.?@>>-44IIz(	
 r%   c                 $    | j                  |      S )See base.UpdateCommand.rx   rh   r2   s     r#   RunzAddBgpPeer.Run   s    99T?r%   )F)__name__
__module____qualname____doc__r   r   classmethodr$   r)   rx   r}   rB   r%   r#   r   r   "   sH     3*,4 4   xtr%   r   c                   .    e Zd ZdZdZdZed        Zd Zy)AddBgpPeerBetar   Nc                 &    | j                  |       y r'   r(   r    s     r#   r)   zAddBgpPeerBeta.Args   r*   r%   c                 (    | j                  |d      S )rz   Fr.   r{   r|   s     r#   r}   zAddBgpPeerBeta.Run   s    99TE922r%   	r~   r   r   r   r   r   r   r)   r}   rB   r%   r#   r   r      s&    2*, 3r%   r   c                   .    e Zd ZdZdZdZed        Zd Zy)AddBgpPeerAlphar   Nc                 &    | j                  |       y r'   r(   r    s     r#   r)   zAddBgpPeerAlpha.Args   r*   r%   c                 (    | j                  |d      S )rz   Tr   r{   r|   s     r#   r}   zAddBgpPeerAlpha.Run   s    99   r%   r   rB   r%   r#   r   r      s&    2*, r%   r   c                    |rt        | |      }nt        | |      }d}|j                  M|j                  r!| j                  j                  j
                  }n | j                  j                  j                  }| j                  |j                  |j                  |j                  |j                  |j                  |||j                  |j                  |j                  |j                  |j                   |j"                        }|j$                  |_        ||j)                         |_        |j,                  ||_        |j0                  |j0                  |_        |j4                  |j4                  |_        |S )az  Creates a BGP peer with base attributes based on flag arguments.

  Args:
    messages: API messages holder.
    args: contains arguments passed to the command.
    md5_authentication_key_name: The md5 authentication key name.
    support_bfd_mode: The flag to indicate whether bfd mode is supported.
    instance_ref: An instance reference.

  Returns:
    the RouterBgpPeer
  N)r7   interfaceNamepeerIpAddresspeerAsnadvertisedRoutePriorityenablebfd
enableIpv6ipv6NexthopAddresspeerIpv6NexthopAddress
enableIpv4ipv4NexthopAddresspeerIpv4NexthopAddress)_CreateBgpPeerBfdMessageMode_CreateBgpPeerBfdMessageenabledrR   EnableValueValuesEnumTRUEFALSE	peer_name	interfacepeer_ip_addresspeer_asnadvertised_route_priorityenable_ipv6ipv6_nexthop_addresspeer_ipv6_nexthop_addressenable_ipv4ipv4_nexthop_addresspeer_ipv4_nexthop_addresscustom_learned_route_prioritycustomLearnedRoutePrioritySelfLinkrouterApplianceInstancer[   md5AuthenticationKeyNameexport_policiesexportPoliciesimport_policiesimportPolicies)r0   r2   r-   r.   r/   r   r   rt   s           r#   rO   rO      sO   & 
&x
6C
"8T
2C&	\\||%%;;@@f%%;;AAf!!>>NN((mm"<<
!!22!;;!!22!;; " &  '+&H&H&#%1%:%:%<F"	  ,&AF#	% 00F	% 00F	-r%   c                 X   |j                  d      s4|j                  d      s#|j                  d      s|j                  d      syd}|j                  %| j                  j                  |j                        }| j                  |j                  |j
                  ||j                        S )@Creates a BGP peer with base attributes based on flag arguments.bfd_min_receive_intervalbfd_min_transmit_intervalbfd_session_initialization_modebfd_multiplierN)minReceiveIntervalminTransmitIntervalsessionInitializationMode
multiplier)IsSpecifiedr   RouterBgpPeerBfd(SessionInitializationModeValueValuesEnumr   r   r   )r0   r2   r   s      r#   r   r     s     12			5	6			;	<			*	+$(!	))5!!JJ00	
 $
 
	"	"6688 ?$$	 
# 
 r%   c                    |j                  d      s4|j                  d      s#|j                  d      s|j                  d      syd}d}|j                  J| j                  j                  |j                        }| j                  j	                  |j                        }| j                  |j
                  |j                  |||j                        S )r   r   r   r   r   N)r   r   rn   r   r   )r   r   r   ModeValueValuesEnumr   r   r   r   )r0   r2   rn   r   s       r#   r   r   .  s     12			5	6			;	<			*	+	$$(!	))5$$88,,D 	!!JJ00	
 $
 
	"	"6688 ?$$ 
# 
 r%   )FN)$r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   ,googlecloudsdk.command_lib.compute.instancesr   r   *googlecloudsdk.command_lib.compute.routersr   googlecloudsdk.corer   r   rS   ReleaseTracksrD   GAUniverseCompatibleUpdateCommandr   BETAr   ALPHAr   rO   r   r   rB   r%   r#   <module>r      s   @ &  ' 7 8 < . ( P < C # ) 
 D%%(()Q## Q  *Qh D%%**+3Z 3 ,3 D%%++,n  -, 8v0r%   