Skip to content

Commit

Permalink
Management vrf snmp cli support (sonic-net#472)
Browse files Browse the repository at this point in the history
* [sonic-utilities] managementVRF cli support(l3mdev)

This commit adds CLI support for management VRF using l3dev. mVRF can
be enabled using config vrf add mgmt and deleted using config vrf del mgmt.
Show commands for management VRF are added which displays the linux command
output, will update show command display after concluding what would be the
output for the show commands.
Added cli to configure management interface(eth0), config interface ip eth0
add can be used to configure eth0 ip and config ip eth0 remove is used to
remove eth0 ip.

New cli config/show commands:

config vrf add mgmt
config vrf del mgmt
config interface eth0 ip add ip/mask gatewayIP
config interface eth0 ip remove ip/mask

show mgmt-vrf
show mgmt-vrf route
show mgmt-vrf addresses
show mgmt-vrf interfaces

Signed-off-by: Harish Venkatraman <harish_venkatraman@dell.com>
  • Loading branch information
Harish Venkatraman authored and lguohan committed Oct 29, 2019
1 parent e78d7b8 commit 8218b09
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
98 changes: 98 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,104 @@ def vrf_del (ctx, vrfname):
else:
click.echo("Deletion of data vrf={} is not yet supported".format(vrfname))

@config.group()
@click.pass_context
def snmpagentaddress(ctx):
"""SNMP agent listening IP address, port, vrf configuration"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {'db': config_db}
pass

@snmpagentaddress.command('add')
@click.argument('agentip', metavar='<SNMP AGENT LISTENING IP Address>', required=True)
@click.option('-p', '--port', help="SNMP AGENT LISTENING PORT")
@click.option('-v', '--vrf', help="VRF Name mgmt/DataVrfName/None")
@click.pass_context
def add_snmp_agent_address(ctx, agentip, port, vrf):
"""Add the SNMP agent listening IP:Port%Vrf configuration"""

#Construct SNMP_AGENT_ADDRESS_CONFIG table key in the format ip|<port>|<vrf>
key = agentip+'|'
if port:
key = key+port
key = key+'|'
if vrf:
key = key+vrf
config_db = ctx.obj['db']
config_db.set_entry('SNMP_AGENT_ADDRESS_CONFIG', key, {})

#Restarting the SNMP service will regenerate snmpd.conf and rerun snmpd
cmd="systemctl restart snmp"
os.system (cmd)

@snmpagentaddress.command('del')
@click.argument('agentip', metavar='<SNMP AGENT LISTENING IP Address>', required=True)
@click.option('-p', '--port', help="SNMP AGENT LISTENING PORT")
@click.option('-v', '--vrf', help="VRF Name mgmt/DataVrfName/None")
@click.pass_context
def del_snmp_agent_address(ctx, agentip, port, vrf):
"""Delete the SNMP agent listening IP:Port%Vrf configuration"""

key = agentip+'|'
if port:
key = key+port
key = key+'|'
if vrf:
key = key+vrf
config_db = ctx.obj['db']
config_db.set_entry('SNMP_AGENT_ADDRESS_CONFIG', key, None)
cmd="systemctl restart snmp"
os.system (cmd)

@config.group()
@click.pass_context
def snmptrap(ctx):
"""SNMP Trap server configuration to send traps"""
config_db = ConfigDBConnector()
config_db.connect()
ctx.obj = {'db': config_db}
pass

@snmptrap.command('modify')
@click.argument('ver', metavar='<SNMP Version>', type=click.Choice(['1', '2', '3']), required=True)
@click.argument('serverip', metavar='<SNMP TRAP SERVER IP Address>', required=True)
@click.option('-p', '--port', help="SNMP Trap Server port, default 162", default="162")
@click.option('-v', '--vrf', help="VRF Name mgmt/DataVrfName/None", default="None")
@click.option('-c', '--comm', help="Community", default="public")
@click.pass_context
def modify_snmptrap_server(ctx, ver, serverip, port, vrf, comm):
"""Modify the SNMP Trap server configuration"""

#SNMP_TRAP_CONFIG for each SNMP version
config_db = ctx.obj['db']
if ver == "1":
#By default, v1TrapDest value in snmp.yml is "NotConfigured". Modify it.
config_db.mod_entry('SNMP_TRAP_CONFIG',"v1TrapDest",{"DestIp": serverip, "DestPort": port, "vrf": vrf, "Community": comm})
elif ver == "2":
config_db.mod_entry('SNMP_TRAP_CONFIG',"v2TrapDest",{"DestIp": serverip, "DestPort": port, "vrf": vrf, "Community": comm})
else:
config_db.mod_entry('SNMP_TRAP_CONFIG',"v3TrapDest",{"DestIp": serverip, "DestPort": port, "vrf": vrf, "Community": comm})

cmd="systemctl restart snmp"
os.system (cmd)

@snmptrap.command('del')
@click.argument('ver', metavar='<SNMP Version>', type=click.Choice(['1', '2', '3']), required=True)
@click.pass_context
def delete_snmptrap_server(ctx, ver):
"""Delete the SNMP Trap server configuration"""

config_db = ctx.obj['db']
if ver == "1":
config_db.mod_entry('SNMP_TRAP_CONFIG',"v1TrapDest",None)
elif ver == "2":
config_db.mod_entry('SNMP_TRAP_CONFIG',"v2TrapDest",None)
else:
config_db.mod_entry('SNMP_TRAP_CONFIG',"v3TrapDest",None)
cmd="systemctl restart snmp"
os.system (cmd)

@vlan.group('dhcp_relay')
@click.pass_context
def vlan_dhcp_relay(ctx):
Expand Down
43 changes: 43 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,49 @@ def address ():
click.echo("Management IP address = {0}".format(key[1]))
click.echo("Management Network Default Gateway = {0}".format(mgmt_ip_data[key]['gwaddr']))

#
# 'snmpagentaddress' group ("show snmpagentaddress ...")
#

@cli.group('snmpagentaddress', invoke_without_command=True)
@click.pass_context
def snmpagentaddress (ctx):
"""Show SNMP agent listening IP address configuration"""
config_db = ConfigDBConnector()
config_db.connect()
agenttable = config_db.get_table('SNMP_AGENT_ADDRESS_CONFIG')

header = ['ListenIP', 'ListenPort', 'ListenVrf']
body = []
for agent in agenttable.keys():
body.append([agent[0], agent[1], agent[2]])
click.echo(tabulate(body, header))

#
# 'snmptrap' group ("show snmptrap ...")
#

@cli.group('snmptrap', invoke_without_command=True)
@click.pass_context
def snmptrap (ctx):
"""Show SNMP agent Trap server configuration"""
config_db = ConfigDBConnector()
config_db.connect()
traptable = config_db.get_table('SNMP_TRAP_CONFIG')

header = ['Version', 'TrapReceiverIP', 'Port', 'VRF', 'Community']
body = []
for row in traptable.keys():
if row == "v1TrapDest":
ver=1
elif row == "v2TrapDest":
ver=2
else:
ver=3
body.append([ver, traptable[row]['DestIp'], traptable[row]['DestPort'], traptable[row]['vrf'], traptable[row]['Community']])
click.echo(tabulate(body, header))


#
# 'interfaces' group ("show interfaces ...")
#
Expand Down

0 comments on commit 8218b09

Please sign in to comment.