Skip to content

Commit

Permalink
[config] Add commands to remove BGP neighbor configuration (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvisnu authored and jleveque committed Sep 10, 2019
1 parent a6a44e8 commit da5cc8c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
40 changes: 40 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,31 @@ def _change_bgp_session_status(ipaddr_or_hostname, status, verbose):
for ip_addr in ip_addrs:
_change_bgp_session_status_by_addr(ip_addr, status, verbose)

def _validate_bgp_neighbor(neighbor_ip_or_hostname):
"""validates whether the given ip or host name is a BGP neighbor
"""
ip_addrs = []
if _is_neighbor_ipaddress(neighbor_ip_or_hostname.lower()):
ip_addrs.append(neighbor_ip_or_hostname.lower())
else:
ip_addrs = _get_neighbor_ipaddress_list_by_hostname(neighbor_ip_or_hostname.upper())

if not ip_addrs:
click.get_current_context().fail("Could not locate neighbor '{}'".format(neighbor_ip_or_hostname))

return ip_addrs

def _remove_bgp_neighbor_config(neighbor_ip_or_hostname):
"""Removes BGP configuration of the given neighbor
"""
ip_addrs = _validate_bgp_neighbor(neighbor_ip_or_hostname)
config_db = ConfigDBConnector()
config_db.connect()

for ip_addr in ip_addrs:
config_db.mod_entry('bgp_neighbor', ip_addr, None)
click.echo("Removed configuration of BGP neighbor {}".format(ip_addr))

def _change_hostname(hostname):
current_hostname = os.uname()[1]
if current_hostname != hostname:
Expand Down Expand Up @@ -952,6 +977,21 @@ def neighbor(ipaddr_or_hostname, verbose):
"""Start up BGP session by neighbor IP address or hostname"""
_change_bgp_session_status(ipaddr_or_hostname, 'up', verbose)

#
# 'remove' subgroup ('config bgp remove ...')
#

@bgp.group()
def remove():
"Remove BGP neighbor configuration from the device"
pass

@remove.command('neighbor')
@click.argument('neighbor_ip_or_hostname', metavar='<neighbor_ip_or_hostname>', required=True)
def remove_neighbor(neighbor_ip_or_hostname):
"""Deletes BGP neighbor configuration of given hostname or ip from devices"""
_remove_bgp_neighbor_config(neighbor_ip_or_hostname)

#
# 'interface' group ('config interface ...')
#
Expand Down
22 changes: 22 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,8 @@ The list of possible BGP config commands are given below.
startup
all
neighbor
remove
neighbor

**config bgp shut down all**

Expand Down Expand Up @@ -1524,6 +1526,26 @@ This command is used to start up the particular IPv4 or IPv6 BGP neighbor using
admin@sonic:~$ sudo config bgp startup neighbor SONIC02SPINE
```


**config bgp remove neighbor <neighbor_ip_or_hostname>**

This command is used to remove particular IPv4 or IPv6 BGP neighbor configuration using either the IP address or hostname.

- Usage:
sudo config bgp remove neighbor <neighbor_ip_or_hostname>

- Examples:
```
admin@sonic:~$ sudo config bgp remove neighbor 192.168.1.124
```
```
admin@sonic:~$ sudo config bgp remove neighbor 2603:10b0:b0f:346::4a
```
```
admin@sonic:~$ sudo config bgp remove neighbor SONIC02SPINE
```


Go Back To [Beginning of the document](#SONiC-COMMAND-LINE-INTERFACE-GUIDE) or [Beginning of this section](#BGP-Configuration-And-Show-Commands)


Expand Down

0 comments on commit da5cc8c

Please sign in to comment.