
    7                     *   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j*                  j,                        ej.                   G d dej0                                      Z ej(                  ej*                  j4                         G d de             Z ej(                  ej*                  j8                         G d de             Z	 ddZd Zd Z ddie_!        y)z;Command for updating a BGP peer on a Compute Engine router.    )absolute_import)division)unicode_literals)base_classes)routers_utils)poller)waiter)base)flags)router_utils)log)	resourcesc                   B    e Zd ZdZdZed        Zed        ZddZd Z	y)UpdateBgpPeer-Update a BGP peer on a Compute Engine router.Nc                 0   t        j                         | _        | j                  j                  |       t        j
                  j                  |       t        j                  |dd       t        j                  |d       t        j                  |       y )NFT)for_add_bgp_peer	is_updatepeer)
r   RouterArgument
ROUTER_ARGAddArgumentr
   
ASYNC_FLAGAddToParserAddBgpPeerArgs AddUpdateCustomAdvertisementArgs AddUpdateCustomLearnedRoutesArgsclsparsers     .lib/surface/compute/routers/update_bgp_peer.py_ArgszUpdateBgpPeer._Args'   sm    ))+CNNNv&OO'	
 
**66:	**62    c                 &    | j                  |       y Nr"   r   s     r!   ArgszUpdateBgpPeer.Args4       IIfr#   c           	         t        j                  |       t        j                  | j	                               }|j
                  j                  }|j
                  j                  j                  }| j                  j                  ||j                        }|j                  }|j                   |di |j                               }t        j                  ||j                         }	d}
g }|j"                  rb|	j$                  V|j&                  D cg c]  }|j(                  |	j$                  k7  r| c}|_        |j&                  s|j+                  d       n|j,                  |	j$                  @|	j$                  }
|j&                  D ]$  }|j(                  |
k(  s|j,                  |_         nP nNt        j0                  ||      }
|j3                  |
|j,                        }|j&                  j+                  |       t5        |	|||
|       t        j6                  |      rt        j8                  ||j:                  |      \  }}}t        j<                  ||j:                  |	j>                  |       |||d}|jA                         D ]  \  }}|	tC        |	||        t        jD                  |      rOt        jF                  ||j:                  |	       |jH                  rFtK        jL                  |j:                  |jH                  	      }|	jN                  jQ                  |       |jR                  rNtK        jL                  |j:                  |jR                  	      }t        jT                  ||j:                  |	|
       |jV                  r<tK        jX                  ||jV                        }|	jZ                  jQ                  |       |j\                  r-t        j^                  ||j:                  |	|j\                         |j`                  &tK        jb                  ||j`                        |	_2        |jf                  r<tK        jb                  ||jf                        }|	jd                  jQ                  |       |jh                  r"t        jj                  ||	|jh                         |jl                  }|j
                  j                  jo                  |      5  |jq                   ||jr                  |jt                  |jw                         |            }ddd       t        jx                  j{                  j(                  d|jr                  |jt                  d      }|j|                  rCt        j                  |dj                  |	j(                  |jw                               dd       |S |j                  j{                  |jw                         d|jr                  |jt                  d      }t        j                  ||      }t        j                  ||dj                  |	j(                  |jw                                     S c c}w # 1 sw Y   9xY w)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 updating the bgp peer with the
      information provided in the arguments.
    Nmd5AuthenticationKeys)namekey)md5_authentication_key_namesupport_bfd_mode)messagesresource_classargs)r/   r0   existing_modenew_mode)advertiseModeadvertisedGroupsadvertisedIpRanges)r/   r0   resource)r0   groups)r/   r0   r7   r8   )r/   	ip_ranges)r/   r0   r7   r9   )r/   r   r9   )projectregionrouterrouterResourcezcompute.regionOperations)r:   r;   )
collectionparamszpeer [{0}] in router [{1}]Tz[Run the [gcloud compute operations describe] command to check the status of this operation.)kindis_asyncdetailszcompute.routersz#Updating peer [{0}] in router [{1}] )Fr   CheckIncompatibleFlagsOrRaiser   ComputeApiHolderReleaseTrackclientr/   apitools_clientroutersr   ResolveAsResourcer   ComputeRoutersGetRequestGetAsDictFindBgpPeerOrRaise	peer_nameclear_md5_authentication_keymd5AuthenticationKeyNamer*   r+   appendmd5_authentication_keyr,    GenerateMd5AuthenticationKeyNameRouterMd5AuthenticationKey_UpdateBgpPeerMessageHasReplaceAdvertisementFlagsParseAdvertisementsRouterBgpPeerPromptIfSwitchToDefaultModer4   itemssetattr HasIncrementalAdvertisementFlagsValidateCustomModeadd_advertisement_groupsr   ParseGroupsr5   extendremove_advertisement_groupsRemoveGroupsFromAdvertisementsadd_advertisement_rangesParseIpRangesr6   remove_advertisement_ranges RemoveIpRangesFromAdvertisementsset_custom_learned_route_rangesParseCustomLearnedIpRangescustomLearnedIpRangesadd_custom_learned_route_ranges"remove_custom_learned_route_ranges%RemoveIpRangesFromCustomLearnedRoutesComputeRoutersPatchRequestIncludeFieldsPatchr:   r;   NameREGISTRYParseasync_r   UpdatedResourceformatr   Pollerr	   WaitFor)selfr1   r.   holderr/   service
router_refrequest_typereplacementr   r-   cleared_fieldsrS   moder8   rangesattrsattrvaluegroups_to_addgroups_to_removeip_ranges_to_addresultoperation_reftarget_router_refoperation_pollers                             r!   _RunzUpdateBgpPeer._Run8   s    ..t4**4+<+<+>?F}}%%Hmm++33G2249I9IJJ44L++lAZ->->-@ABK **;GD"&N))))5 )4(I(I+(I$#((D,I,II !(I+k'
 ..56		$	$	0		&	&	2&*&C&C#&1&G&G"#((,GG)-)D)D"& 'H 99+tL 	$ "*!D!D,$2M2M "E "
 	))001GH$?) 006)==H,B,BdFF ..!//**	  $ &e +$
$e
$ ' 44T:%%!// 
	&	&%11#1100
 	$$]3		)	)(44#1133
 	33#11#		
 
	&	&(66)F)F
 	&&'78		)	)55#1166		
 ++7#0#K#Kt'K'K$d 
 ++&AAt'K'K   ''(89..88;; 66L		&	&	4	4^	D}}
 ((&&__&(	f 
E &&,,-!)) ''
 - M {{	
+22ii* 7
 m((..$!)) ''
 /  }}W.?@>>-44IIz(	
 +h 
E	Ds   "Y">YY!c                 $    | j                  |      S )zSee base.UpdateCommand.r   ry   r1   s     r!   RunzUpdateBgpPeer.Run   s    99T?r#   F)
__name__
__module____qualname____doc__r   classmethodr"   r'   r   r   rC   r#   r!   r   r       s>     6*
3 
3  ENr#   r   c                   *    e Zd ZdZdZed        Zd Zy)UpdateBgpPeerBetar   Nc                 &    | j                  |       y r%   r&   r   s     r!   r'   zUpdateBgpPeerBeta.Args
  r(   r#   c                 (    | j                  |d      S )Runs the command.

    Args:
      args: contains arguments passed to the command.

    Returns:
      The result of patching the router updating the bgp peer with the
      information provided in the arguments.
    Fr.   r   r   s     r!   r   zUpdateBgpPeerBeta.Run  s     99TE922r#   r   r   r   r   r   r   r'   r   rC   r#   r!   r   r     s!    5* 
3r#   r   c                   *    e Zd ZdZdZed        Zd Zy)UpdateBgpPeerAlphar   Nc                 &    | j                  |       y r%   r&   r   s     r!   r'   zUpdateBgpPeerAlpha.Args!  r(   r#   c                 (    | j                  |d      S )r   Tr   r   r   s     r!   r   zUpdateBgpPeerAlpha.Run%  s     99TD911r#   r   rC   r#   r!   r   r     s!    5* 
2r#   r   c                    |j                   |j                  |j                  |j                  |j                  d}|j
                  S|j
                  r$|j                  j                  j                  |d<   n#|j                  j                  j                  |d<   |j                  |j                  |d<   |j                  |j                  |d<   |j                  |j                  |d<   |j                  |j                  |d<   |j                  |j                  |d<   |j                  |j                  |d	<   |j                   |j                   |d
<   |j"                  ||d<   |j$                  |d<   |j&                  |d<   |j)                         D ]  \  }}|	t+        | ||        |j,                  rd| _        |rt1        || |      }nt3        || |      }|t+        | d|       yy)z>Updates base attributes of a BGP peer based on flag arguments.)interfaceName	ipAddresspeerIpAddresspeerAsnadvertisedRoutePriorityNenable
enableIpv6ipv6NexthopAddresspeerIpv6NexthopAddress
enableIpv4ipv4NexthopAddresspeerIpv4NexthopAddresscustomLearnedRoutePriorityrQ   exportPoliciesimportPoliciesbfd)	interface
ip_addresspeer_ip_addresspeer_asnadvertised_route_priorityenabledrY   EnableValueValuesEnumTRUEFALSEenable_ipv6ipv6_nexthop_addresspeer_ipv6_nexthop_addressenable_ipv4ipv4_nexthop_addresspeer_ipv4_nexthop_addresscustom_learned_route_priorityrS   export_policiesimport_policiesr[   r\   rP   rQ   _UpdateBgpPeerBfdMessageMode_UpdateBgpPeerBfdMessage)	r   r/   r1   r-   r.   r   r   r   r   s	            r!   rV   rV   2  s    ~~??++!%!?!?% 
\\|| ..DDIIeHo ..DDJJeHo	!**E,	*"&";";E
	##/&*&D&DE
"#	!**E,	*"&";";E
	##/&*&D&DE
"#	''3*.*L*LE
&'	  ,(CE
$% 00% 00%[[]kdEdD%  # 
&&$(D!
&xt
<C
"8T4
8C_D% r#   c                    |j                  d      s4|j                  d      s#|j                  d      s|j                  d      sy|j                  |j                  }n| j                         }i }|j                  (| j                  j	                  |j                        |d<   |j
                  |d<   |j                  |d<   |j                  |d	<   |j                         D ]  \  }}|	t        |||        |S )
6Updates BGP peer BFD messages based on flag arguments.bfd_min_receive_intervalbfd_min_transmit_intervalbfd_session_initialization_modebfd_multiplierNsessionInitializationModeminReceiveIntervalminTransmitInterval
multiplier)
IsSpecifiedr   RouterBgpPeerBfdr   (SessionInitializationModeValueValuesEnumr   r   r   r[   r\   r/   r   r1   r   r   r   r   s          r!   r   r   g  s     12			5	6			;	<			*	+	XX
((C

#
#
%C
%	))5!!JJ00	
 

%&
 !% = =%!%!?!?%++%[[]kdEc4 # 
*r#   c                 H   |j                  d      s4|j                  d      s#|j                  d      s|j                  d      sy|j                  |j                  }n| j                         }i }|j                  P| j                  j	                  |j                        |d<   | j                  j                  |j                        |d<   |j                  |d<   |j                  |d	<   |j                  |d
<   |j                         D ]  \  }}|	t        |||        |S )r   r   r   r   r   Nr   r   r   r   r   )r   r   r   r   ModeValueValuesEnumr   r   r   r   r[   r\   r   s          r!   r   r     s#    12			5	6			;	<			*	+	XX
((C

#
#
%C
%	))5--AA,,E&M 	!!JJ00	
 

%&
 !% = =%!%!?!?%++%[[]kdEc4 # 
*r#   DESCRIPTIONz^
        *{command}* is used to update a BGP peer on a Compute Engine
        router.
        Nr   )"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.routersr   r   googlecloudsdk.corer   r   ReleaseTracksrF   GAUniverseCompatibleUpdateCommandr   BETAr   ALPHAr   rV   r   r   detailed_helprC   r#   r!   <module>r      s   B &  ' 7 8 < . ( < C # ) D%%(()_D&& _  *_D D%%**+3 3 ,3, D%%++,2* 2 -26 2j:B   r#   