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

handle enable shell, wrapper for swssconfig from config #3

Open
wants to merge 3 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
37 changes: 37 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3534,6 +3534,43 @@ def delete(ctx):

sflow_tbl['global'].pop('agent_id')
config_db.set_entry('SFLOW', 'global', sflow_tbl['global'])
@config.group(cls=AbbreviationGroup)
@click.pass_context
def switch(ctx):
"""switch related config"""
pass

@switch.command('sdk_shell')
@click.pass_context
@click.argument('en', metavar='<en>', required=True, type=click.Choice(['enable', 'disable']))
def set_sdk_diag_shell(ctx, en):
banagiri marked this conversation as resolved.
Show resolved Hide resolved
tmp_file = "/tmp/swss.json"
json_file = "/etc/swss/config.d/switch.json"

import time
try:
os.remove(tmp_file)
except:
pass

command = " docker cp swss:" + json_file + " " + tmp_file
print(command)
subprocess.Popen(command, shell=True)
time.sleep(2)

with open (tmp_file, "r") as f:
cfg = json.load(f)

cfg[0]["SWITCH_TABLE:switch"]["sdk_diag_shell"] = 1 if en == 'enable' else 0

with open (tmp_file, "w") as f:
json.dump(cfg,f,indent=4, ensure_ascii=False)

command = " docker cp " + tmp_file +" "+ "swss:"+json_file
subprocess.Popen(command, shell=True)

command = "docker exec swss swssconfig " + json_file
subprocess.Popen(command, shell=True)

if __name__ == '__main__':
config()