@@ -238,6 +238,31 @@ def _change_bgp_session_status(ipaddr_or_hostname, status, verbose):
238
238
for ip_addr in ip_addrs :
239
239
_change_bgp_session_status_by_addr (ip_addr , status , verbose )
240
240
241
+ def _validate_bgp_neighbor (neighbor_ip_or_hostname ):
242
+ """validates whether the given ip or host name is a BGP neighbor
243
+ """
244
+ ip_addrs = []
245
+ if _is_neighbor_ipaddress (neighbor_ip_or_hostname .lower ()):
246
+ ip_addrs .append (neighbor_ip_or_hostname .lower ())
247
+ else :
248
+ ip_addrs = _get_neighbor_ipaddress_list_by_hostname (neighbor_ip_or_hostname .upper ())
249
+
250
+ if not ip_addrs :
251
+ click .get_current_context ().fail ("Could not locate neighbor '{}'" .format (neighbor_ip_or_hostname ))
252
+
253
+ return ip_addrs
254
+
255
+ def _remove_bgp_neighbor_config (neighbor_ip_or_hostname ):
256
+ """Removes BGP configuration of the given neighbor
257
+ """
258
+ ip_addrs = _validate_bgp_neighbor (neighbor_ip_or_hostname )
259
+ config_db = ConfigDBConnector ()
260
+ config_db .connect ()
261
+
262
+ for ip_addr in ip_addrs :
263
+ config_db .mod_entry ('bgp_neighbor' , ip_addr , None )
264
+ click .echo ("Removed configuration of BGP neighbor {}" .format (ip_addr ))
265
+
241
266
def _change_hostname (hostname ):
242
267
current_hostname = os .uname ()[1 ]
243
268
if current_hostname != hostname :
@@ -952,6 +977,21 @@ def neighbor(ipaddr_or_hostname, verbose):
952
977
"""Start up BGP session by neighbor IP address or hostname"""
953
978
_change_bgp_session_status (ipaddr_or_hostname , 'up' , verbose )
954
979
980
+ #
981
+ # 'remove' subgroup ('config bgp remove ...')
982
+ #
983
+
984
+ @bgp .group ()
985
+ def remove ():
986
+ "Remove BGP neighbor configuration from the device"
987
+ pass
988
+
989
+ @remove .command ('neighbor' )
990
+ @click .argument ('neighbor_ip_or_hostname' , metavar = '<neighbor_ip_or_hostname>' , required = True )
991
+ def remove_neighbor (neighbor_ip_or_hostname ):
992
+ """Deletes BGP neighbor configuration of given hostname or ip from devices"""
993
+ _remove_bgp_neighbor_config (neighbor_ip_or_hostname )
994
+
955
995
#
956
996
# 'interface' group ('config interface ...')
957
997
#
0 commit comments