Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lldp cmds to config 802.1q tlv #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3535,5 +3535,52 @@ def delete(ctx):
sflow_tbl['global'].pop('agent_id')
config_db.set_entry('SFLOW', 'global', sflow_tbl['global'])

@config.group()
@click.pass_context
@click.option('-s', '--redis-unix-socket-path', help='unix socket path for redis connection')
def lldp(ctx, redis_unix_socket_path):
"""lldp related configuration tasks"""
kwargs = {}
if redis_unix_socket_path:
kwargs['unix_socket_path'] = redis_unix_socket_path
config_db = ConfigDBConnector(**kwargs)
config_db.connect(wait_for_init=False)
ctx.obj = {'db': config_db}
pass


@lldp.command('dot1q_adv_type')
@click.argument('cap_type', metavar='<type>', required=True)
@click.argument('enable', metavar='<enable>', required=True)
@click.argument('interface_name', metavar='<interface_name>', required=False)
@click.pass_context
def dot1q_adv_type(ctx, cap_type, enable, interface_name="all"):
db = ctx.obj['db']
if cap_type not in ["all", "name", "pvid"] :
ctx.fail("Invalid type {} all/name/pvid".format(cap_type))

if enable not in ["enable", "disable"] :
ctx.fail("Invalid option {} enable/disable".format(cap_type))
all_port_list = db.get_keys("PORT")
port_list = []
if interface_name == "all":
port_list = all_port_list
else:
interface_name = interface_name.split(',')
for port in interface_name:
if port in all_port_list:
port_list.append(port)
else:
print("Warning: invalid interface {}".format(port))
print(port_list)
print(interface_name)
for port in port_list:
port_cfg = db.get_entry('CFG_LLDP_DOT1Q_CAPBILITY', port)
if cap_type == "all" or cap_type == "name":
port_cfg["name"] = 1 if enable == "enable" else 0
if cap_type == "all" or cap_type == "pvid":
port_cfg["pvid"] = 1 if enable == "enable" else 0
db.set_entry('CFG_LLDP_DOT1Q_CAPBILITY', port, port_cfg)

if __name__ == '__main__':
config()