
    .                         S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  SSK
Jr  SS	KJr  SSKr " S
 S\5      rg)z*Distributed Cloud Edge Network router API.    )absolute_import)division)unicode_literalsN)encoding)utils)parser_errors)
exceptionsc                   v    \ rS rSrSrSrSrSrSS jrS r	S	 r
S
 rS rS rS rS rS rS rS rS rS rSrg)RoutersClient   z2Client for private connections service in the API.	interfacebgp_peerroute_advertisementsNc                     U=(       d    [         R                  " U5      U l        U=(       d    [         R                  " U5      U l        U R                  R
                  U l        [         R                  " U5      U l        g N)	r   GetClientInstance_clientGetMessagesModule	_messages projects_locations_zones_routers_serviceGetResourceParser_resource_parser)selfrelease_trackclientmessagess       Clib/googlecloudsdk/api_lib/edge_cloud/networking/routers/routers.py__init__RoutersClient.__init__&   sT    CU44]CDLG!8!8!GDNLLAADM!33MBD    c                 X    [         R                  " U R                  XR                  5      $ )z=Waits for the given google.longrunning.Operation to complete.)r   WaitForOperationr   r   )r   	operations     r   r#   RoutersClient.WaitForOperation,   s    !!$,,	==IIr!   c                    [         R                  " U5      nU R                  R                  UR                  S9nUR
                  Gb+  U R                  R                  SUR
                  UR                  UR                  UR                  S9nUR                  b  UR                  c  [        R                  " S5      e [        R                  " UR                  5      nUR                  UR$                  :  a#  [        R                  " SUR$                  -  5      eSR'                  UR                  UR                  5      n	UR(                  S:X  a  Xl        OXl        UR/                  5       Ul        UR2                  bZ  U R                  R                  S	UR2                  UR                  UR                  UR                  S
9n
U
R/                  5       Ul        UR4                  b  UR4                  Ul        UR8                  R;                  U5        U$ ! [          a$  n[        R                  " [#        U5      5      eSnAff = f)z&Mutate the router to add an interface.nameNz<edgenetwork.projects.locations.zones.interconnectAttachments)interconnectAttachmentsId
projectsIdlocationsIdzonesIdz---ip-address and --ip-mask-length must be setz'--ip-mask-length should be less than %sz{0}/{1}   z,edgenetwork.projects.locations.zones.subnets)	subnetsIdr*   r+   r,   )r   CopyProtoMessager   	Interfaceinterface_nameinterconnect_attachmentr   Creater*   r+   r,   ip_mask_length
ip_addressr   ArgumentException	ipaddress
ValueErrorstrmax_prefixlenformatversionipv4Cidripv6CidrRelativeNamelinkedInterconnectAttachment
subnetworkloopback_ip_addressesloopbackIpAddressesr   append)r   
router_refargsexistingreplacementnew_interfaceattachment_refr5   errcidr
subnet_refs              r   ModifyToAddInterface"RoutersClient.ModifyToAddInterface0   s   ++H5KNN,,$2E2E,FM##/,,33
H$($@$@** ,,$$ 4 &n 
			$(?--;
 	
8))$//:
 
		z77	7--5
8P8PP
 	
 doot/B/BCd			q	 !%!%3A3N3N3Pm0"((//
8OO** ,,$$ 0 &j ",!8!8!:m!!-*.*D*Dm'  /;  8--c#h778s   > H 
IH>>Ic                 V   UR                   (       a  UR                   O/ nUUR                  (       a  UR                  /O/ -   n/ n[        R                  " U5      n[        R                  " U5      nUR                   HK  nUR
                  U;   d  M  UR                  R                  U5        UR                  UR
                  5        MM     [        [        U5      [        U5      -
  5      nU(       a6  SR                  SR                  U5      5      n	[        R                  " U	5      eU$ )z1Mutate the router to delete a list of interfaces.zinterface [{}] not found, )interface_namesr1   r   r/   r   r(   removerD   sortedsetr;   joincore_exceptionsError)
r   rF   rG   input_remove_listactual_remove_listrH   existing_routerifacenot_found_interface	error_msgs
             r   ModifyToRemoveInterface%RoutersClient.ModifyToRemoveInterfacec   s    150D0D,,")040C0C /3.A.A-BIKM ++H5K//9O **	(	($$U+!!%**- + !%7!88:,33
))'
(*i!!),,r!   c                 d   [         R                  " U5      nUR                  UR                  UR                  S.nUR
                  b  UR
                  US'   SU;   a  UR                  b  UR                  US'   U R                  R                  " S0 UD6nUR                  R                  U5        U$ )z$Mutate the router to add a BGP peer.)r(   r   peerAsnpeerIpv4Cidrpeer_ipv6_rangepeerIpv6Cidr )r   r/   	peer_namer   peer_asnpeer_ipv4_rangerd   r   BgpPeerbgpPeerrD   )r   rF   rG   rH   bgp_peer_argsnew_bgp_peers         r   ModifyToAddBgpPeer RoutersClient.ModifyToAddBgpPeer}   s     ++H5K^^==M '&*&:&:mN# D T%9%9%E&*&:&:mN#>>)):M:L|,r!   c                 V   UR                   (       a  UR                   O/ nUUR                  (       a  UR                  /O/ -   n/ n[        R                  " U5      n[        R                  " U5      nUR                   HK  nUR
                  U;   d  M  UR                  R                  U5        UR                  UR
                  5        MM     [        [        U5      [        U5      -
  5      nU(       a6  SR                  SR                  U5      5      n	[        R                  " U	5      eU$ )z&Mutate the router to delete BGP peers.zpeer [{}] not foundrQ   )
peer_namesrg   r   r/   rk   r(   rS   rD   rT   rU   r;   rV   rW   rX   )
r   rF   rG   rY   rZ   rH   r[   peernot_found_peerr^   s
             r   ModifyToRemoveBgpPeer#RoutersClient.ModifyToRemoveBgpPeer   s    +/??)04 /3nn-=DFH++H5K//9O''	'	'""4(!!$)), ( C 12S9K5LLMN'..tyy/HIi!!),,r!   c                 F   U R                   R                  UR                  5       S9nU R                  R	                  U5      nU R                  XU5      nU R                   R                  UR                  5       UU R                  S9nU R                  R                  U5      $ )z Create an interface on a router.r'   r(   router
updateMask)	r   2EdgenetworkProjectsLocationsZonesRoutersGetRequestr?   r   GetrN   4EdgenetworkProjectsLocationsZonesRoutersPatchRequestFIELD_PATH_INTERFACEPatchr   rE   rF   get_router_reqrouter_objectnew_router_objectupdate_router_reqs          r   AddInterfaceRoutersClient.AddInterface   s     ^^VV$$& W (NMM%%n5M 11*2?A [[$$& ,, \ . ==011r!   c                 D   U R                   R                  UR                  5       S9nU R                  R	                  U5      nU R                  X$5      nU R                   R                  UR                  5       UU R                  S9nU R                  R                  U5      $ )z(Remove a list of interfaces on a router.r'   rw   )	r   rz   r?   r   r{   r_   r|   r}   r~   r   s          r   RemoveInterfaceRoutersClient.RemoveInterface   s     ^^VV$$& W (NMM%%n5M44TI[[$$& ,, \ .
 ==011r!   c                    S nS nU" UR                   5      n[        R                  " U5      nUR                  (       a_  [	        UR                  5      nU" XW-  5      nU(       a4  [
        R                  " SR                  SR                  U5      5      5      eXW-  nOUR                  (       a\  U" UR                  5      n	U" X-
  5      n
U
(       a4  [
        R                  " SR                  SR                  U
5      5      5      eXY-  nO:UR                  (       a  U" UR                  5      nO[        R                  " S5      e[        [        [        [!        U5      5      5      Ul         U$ )z;Create a router based on `existing` with the routes change.c                 &    [        S U  5       5      $ )Nc              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr   )r7   
ip_network).0cidrstrs     r   	<genexpr>SRoutersClient.ModifyToApplyAdvertisementChanges.<locals>.cidrset.<locals>.<genexpr>   s     Hi7%%g..is   #%)rU   )	cidr_strss    r   cidrset@RoutersClient.ModifyToApplyAdvertisementChanges.<locals>.cidrset   s    HiHHHr!   c                 l    [        U 5       Vs/ s H  n[        R                  " U5      PM     sn$ s  snf r   )rT   six	text_type)cidrsrL   s     r   sorted_stringsGRoutersClient.ModifyToApplyAdvertisementChanges.<locals>.sorted_strings   s'    .4Um<mdcmmD!m<<<s    1z5attempting to add routes that are already present: {}rQ   z4attempting to remove routes that are not present: {}z`Missing --add-advertisement-ranges, --remove-advertisement-ranges, or --set-advertisement-ranges)routeAdvertisementsr   r/   add_advertisement_rangesrU   rW   rX   r;   rV   remove_advertisement_rangesset_advertisement_rangesr   r6   listmapr9   rT   )r   rF   rG   r   r   advertisementsrH   to_addalready_presentto_rmalready_missings              r   !ModifyToApplyAdvertisementChanges/RoutersClient.ModifyToApplyAdvertisementChanges   sD   I= X99:N++H5K$$4001f&~'>?o	##CJJ		/*,- 	- n		)	)d667e&u'=>o	##BII		/*,- 	- n		&	&t<<=n++IJ J '+3sF>4J+K&LK#r!   c                 D   U R                   R                  UR                  5       S9nU R                  R	                  U5      nU R                  X$5      nU R                   R                  UR                  5       UU R                  S9nU R                  R                  U5      $ )zNCreate a patch request that updates the Route advertisements of a router.
    r'   rw   )	r   rz   r?   r   r{   r   r|   FIELD_PATH_ROUTE_ADVERTISEMENTSr~   )r   rE   rF   r   r   r   update_router_requests          r   ChangeAdvertisements"RoutersClient.ChangeAdvertisements   s     ^^VV$$& W (NMM%%n5M>> 	KK((*$;; 	L 	=  ==455r!   c                 D   U R                   R                  UR                  5       S9nU R                  R	                  U5      nU R                  X$5      nU R                   R                  UR                  5       UU R                  S9nU R                  R                  U5      $ )z'Mutate the router so to add a BGP peer.r'   rw   )	r   rz   r?   r   r{   rn   r|   FIELD_PATH_BGP_PEERr~   r   s          r   
AddBgpPeerRoutersClient.AddBgpPeer  s     ^^VV$$& W (NMM%%n5M //D[[$$& ++ \ - ==011r!   c                 D   U R                   R                  UR                  5       S9nU R                  R	                  U5      nU R                  X$5      nU R                   R                  UR                  5       UU R                  S9nU R                  R                  U5      $ )z*Mutate the router so to remove a BGP peer.r'   rw   )	r   rz   r?   r   r{   rt   r|   r   r~   r   s          r   RemoveBgpPeerRoutersClient.RemoveBgpPeer  s     ^^VV$$& W (NMM%%n5M 224G[[$$& ++ \ - ==011r!   c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ )z%Get the status of a specified router.r'   )r   7EdgenetworkProjectsLocationsZonesRoutersDiagnoseRequestr?   r   Diagnose)r   rE   get_router_status_reqs      r   	GetStatusRoutersClient.GetStatus!  s?     NNbb$$& c (==!!"788r!   )r   r   r   r   )NN)__name__
__module____qualname____firstlineno____doc__r}   r   r   r   r#   rN   r_   rn   rt   r   r   r   r   r   r   r   __static_attributes__rf   r!   r   r   r      s\    :$"$:!CJ1f4*,2"2 $L6$2 2 9r!   r   )r   
__future__r   r   r   r7   apitools.base.pyr   ,googlecloudsdk.api_lib.edge_cloud.networkingr   googlecloudsdk.callioper   googlecloudsdk.corer	   rW   r   objectr   rf   r!   r   <module>r      s3    1 &  '  % > 1 = 
F9F F9r!   