-
Notifications
You must be signed in to change notification settings - Fork 658
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
kdump-Remote-SSH-Configurations #3400
base: master
Are you sure you want to change the base?
Changes from 131 commits
8e1a4b4
3893fc9
03c2b63
6f34f88
18caaba
7d7226c
49b511a
a67a777
2094bc7
7ae0635
518837e
d74f909
17e0790
999d298
361bb75
48eb48d
194f333
45fe33e
8c97669
2453d25
cfbdd13
1b7091b
82f8000
7efce5d
12f0279
3c22c75
6d2f7ce
f4856c7
2d0cacb
c1f2076
d3e975a
18895d3
4fe15b1
8588324
65a07b0
247cb24
edd60cf
c9d4b83
146c2c8
668a357
16927d0
301b953
d32c898
26530b9
fb3c04c
557d2da
88f72c5
d52d4fd
871bc9b
1a94b1e
e6af5ca
c5b1917
eb35995
8d20e9c
af76fe1
efbfa46
8eaf182
bd1d2f1
657d913
9a95762
91c24c2
adda82e
6810b25
ac0b0e6
82f94b9
486a486
f709f03
ebaefc0
bc04bb7
6f9c74f
1bbf78a
98f3e14
bc87384
617523b
d8fe5b8
a5c5f34
318f658
53a3530
dd13c18
9f21cf6
4e66ca1
2400b33
91763ef
2ea0e24
76eb141
1eec069
ba6af36
5eedadd
3e9b1a3
71a42f7
b73360e
51648ac
0c87f96
f05ce6b
f252fb8
7f96d23
1194a45
f3e8098
9e657d8
8d760b1
35ced45
5aaab85
b8eb084
9144810
41a3a41
50847d1
b928199
2510c85
886d21c
ec1cc1a
036257f
48d1cae
d1c5543
c620c18
b30391d
05c420f
fcc77a7
ef95754
06ccd35
d8ac24c
8401e77
adc256a
b1f9379
5527452
bf91f71
368328b
b3b5d18
46fb9d5
94d2609
5f91081
3604182
e5ccfcb
18809cb
762a163
b231c11
ba8172a
60c067b
e05c85d
a2c829d
6549fe1
ab53019
5a6cf43
9912125
f68fa48
e5a93ac
0343e5b
2dede5b
3fdee51
3bda604
d7efd0d
a966efa
cc6c765
3970ec8
a6ec1ce
3951942
1d64ffc
5741922
6abe2f9
eebdd79
e93041a
5bdc5c9
077d336
ea02048
e6968ae
a1d4077
d8fb143
2db858c
d9c8f39
41c0be3
00e7c5f
623f822
e5357c8
6f1d7fc
89cc594
bf6102d
2a7595b
88dd4f0
9fae7d0
96ecc6d
826bb11
9f18a6a
3bc371f
4109593
d897d79
6670418
d1b6c32
dbafbac
ef1252d
e4d24c5
eaf3efa
b2911e2
b57b1ed
2898e78
49b674e
72cbd6a
db43785
7f1f2f4
0ea1d54
e1f2c7a
8f70056
57982a0
3200dea
956c0dc
1f83d6a
eb1a597
bc212a5
5a55046
43d9caf
5cf9b60
90cf8f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import sys | ||
|
||
import click | ||
from utilities_common.cli import AbbreviationGroup, pass_db | ||
|
||
|
||
from utilities_common.cli import AbbreviationGroup, pass_db | ||
from pathlib import Path | ||
# | ||
# 'kdump' group ('sudo config kdump ...') | ||
# | ||
|
||
@click.group(cls=AbbreviationGroup, name="kdump") | ||
def kdump(): | ||
"""Configure the KDUMP mechanism""" | ||
pass | ||
|
||
|
||
def check_kdump_table_existence(kdump_table): | ||
"""Checks whether the 'KDUMP' table is configured in Config DB. | ||
|
||
|
@@ -32,9 +31,15 @@ def check_kdump_table_existence(kdump_table): | |
sys.exit(2) | ||
|
||
|
||
def echo_reboot_warning(): | ||
"""Prints the warning message about reboot requirements.""" | ||
click.echo("KDUMP configuration changes may require a reboot to take effect.") | ||
click.echo("Save SONiC configuration using 'config save' before issuing the reboot command.") | ||
# | ||
# 'disable' command ('sudo config kdump disable') | ||
# | ||
|
||
|
||
@kdump.command(name="disable", short_help="Disable the KDUMP mechanism") | ||
@pass_db | ||
def kdump_disable(db): | ||
|
@@ -43,13 +48,13 @@ def kdump_disable(db): | |
check_kdump_table_existence(kdump_table) | ||
|
||
db.cfgdb.mod_entry("KDUMP", "config", {"enabled": "false"}) | ||
click.echo("KDUMP configuration changes may require a reboot to take effect.") | ||
click.echo("Save SONiC configuration using 'config save' before issuing the reboot command.") | ||
|
||
echo_reboot_warning() | ||
|
||
# | ||
# 'enable' command ('sudo config kdump enable') | ||
# | ||
|
||
|
||
@kdump.command(name="enable", short_help="Enable the KDUMP mechanism") | ||
@pass_db | ||
def kdump_enable(db): | ||
|
@@ -58,13 +63,13 @@ def kdump_enable(db): | |
check_kdump_table_existence(kdump_table) | ||
|
||
db.cfgdb.mod_entry("KDUMP", "config", {"enabled": "true"}) | ||
click.echo("KDUMP configuration changes may require a reboot to take effect.") | ||
click.echo("Save SONiC configuration using 'config save' before issuing the reboot command.") | ||
|
||
echo_reboot_warning() | ||
|
||
# | ||
# 'memory' command ('sudo config kdump memory ...') | ||
# | ||
|
||
|
||
@kdump.command(name="memory", short_help="Configure the memory for KDUMP mechanism") | ||
@click.argument('kdump_memory', metavar='<kdump_memory>', required=True) | ||
@pass_db | ||
|
@@ -74,13 +79,13 @@ def kdump_memory(db, kdump_memory): | |
check_kdump_table_existence(kdump_table) | ||
|
||
db.cfgdb.mod_entry("KDUMP", "config", {"memory": kdump_memory}) | ||
click.echo("KDUMP configuration changes may require a reboot to take effect.") | ||
click.echo("Save SONiC configuration using 'config save' before issuing the reboot command.") | ||
|
||
echo_reboot_warning() | ||
|
||
# | ||
# 'num_dumps' command ('sudo config keump num_dumps ...') | ||
# 'num_dumps' command ('sudo config kdump num_dumps ...') | ||
# | ||
|
||
|
||
@kdump.command(name="num_dumps", short_help="Configure the maximum dump files of KDUMP mechanism") | ||
@click.argument('kdump_num_dumps', metavar='<kdump_num_dumps>', required=True, type=int) | ||
@pass_db | ||
|
@@ -90,3 +95,110 @@ def kdump_num_dumps(db, kdump_num_dumps): | |
check_kdump_table_existence(kdump_table) | ||
|
||
db.cfgdb.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps}) | ||
echo_reboot_warning() | ||
|
||
|
||
# 'remote' command ('sudo config kdump remote ...') | ||
@kdump.command(name="remote", short_help="Enable or Disable Kdump Remote") | ||
@click.argument('action', required=True, type=click.Choice(['enable', 'disable'], case_sensitive=False)) | ||
@pass_db | ||
def kdump_remote(db, action): | ||
|
||
"""Enable or Disable Kdump Remote Mode""" | ||
kdump_table = db.cfgdb.get_table("KDUMP") | ||
check_kdump_table_existence(kdump_table) | ||
current_remote_status = kdump_table.get("config", {}).get("remote", "false").lower() | ||
|
||
if action.lower() == 'enable' and current_remote_status == 'true': | ||
click.echo("Error: Kdump Remote Mode is already enabled.") | ||
return | ||
|
||
elif action.lower() == 'disable' and current_remote_status == 'false': | ||
click.echo("Error: Kdump Remote Mode is already disabled.") | ||
return | ||
|
||
if action.lower() == 'disable': | ||
ssh_string = kdump_table.get("config", {}).get("ssh_string", None) | ||
ssh_key = kdump_table.get("config", {}).get("ssh_key", None) | ||
if ssh_string or ssh_key: | ||
click.echo("Error: Remove SSH_string, SSH_key from Config DB before disabling Kdump Remote Mode.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should the SSH keys removed before KDUMP global disable? any dependency? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SSH keys needs to be removed before disabling Kdump Remote Mode to avoid leftover values in the configuration files. If not removed, these keys will stay in the "kdump-tools" file and could cause confusion or security issues later. Clearing them ensures the configuration is accurate and clean |
||
return | ||
|
||
remote = 'true' if action.lower() == 'enable' else 'false' | ||
db.cfgdb.mod_entry("KDUMP", "config", {"remote": remote}) | ||
file_path = Path('/etc/default/kdump-tools') | ||
|
||
# Values to be set for SSH and SSH_KEY | ||
DEFAULT_SSH = "<user at server>" | ||
DEFAULT_SSH_KEY = "<path>" | ||
|
||
with open(file_path, 'r') as file: | ||
lines = file.readlines() | ||
updated_lines = [] | ||
|
||
for line in lines: | ||
if remote: | ||
if line.startswith("#SSH="): | ||
updated_lines.append(f'SSH={DEFAULT_SSH}\n') | ||
elif line.startswith("#SSH_KEY="): | ||
updated_lines.append(f'SSH_KEY={DEFAULT_SSH_KEY}\n') | ||
else: | ||
updated_lines.append(line) | ||
else: | ||
if line.startswith("SSH="): | ||
updated_lines.append(f'#SSH={DEFAULT_SSH}\n') | ||
elif line.startswith("SSH_KEY="): | ||
updated_lines.append(f'#SSH_KEY={DEFAULT_SSH_KEY}\n') | ||
else: | ||
updated_lines.append(line) | ||
|
||
with open(file_path, 'w') as file: | ||
file.writelines(updated_lines) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't this be handled in hostcfgd? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're correct; this could be managed by hostcfgd for better consistency. We chose to handle it directly here for simplicity and immediate updates. we will modify the code hostcfgd to handle this and remove from utility |
||
echo_reboot_warning() | ||
|
||
|
||
# 'add' command ('sudo config kdump add ...') | ||
@kdump.command(name="add", short_help="Add SSH connection string or SSH key path.") | ||
@click.argument('item', type=click.Choice(['ssh_string', 'ssh_path'])) | ||
@click.argument('value', metavar='<value>', required=True) | ||
@pass_db | ||
def add_kdump_item(db, item, value): | ||
"""Add SSH connection string or SSH key path for kdump""" | ||
kdump_table = db.cfgdb.get_table("KDUMP") | ||
check_kdump_table_existence(kdump_table) | ||
|
||
# Check if remote mode is enabled | ||
remote_mode_enabled = kdump_table.get("config", {}).get("remote", "false").lower() | ||
if remote_mode_enabled != "true": | ||
click.echo("Error: Enable remote mode first.") | ||
return | ||
|
||
# Check if the item is already added | ||
existing_value = kdump_table.get("config", {}).get(item) | ||
if existing_value: | ||
click.echo(f"Error: {item} is already added.") | ||
return | ||
|
||
# Add item to config_db | ||
db.cfgdb.mod_entry("KDUMP", "config", {item: value}) | ||
echo_reboot_warning() | ||
|
||
|
||
@kdump.command(name="remove", short_help="Remove SSH connection string or SSH key path.") | ||
@click.argument('item', type=click.Choice(['ssh_string', 'ssh_path'])) | ||
@pass_db | ||
def remove_kdump_item(db, item): | ||
"""Remove SSH connection string or SSH key path for kdump""" | ||
kdump_table = db.cfgdb.get_table("KDUMP") | ||
check_kdump_table_existence(kdump_table) | ||
|
||
# Check if the item is already configured | ||
existing_value = kdump_table.get("config", {}).get(item) | ||
if not existing_value: | ||
click.echo(f"Error: {item} is not configured.") | ||
return | ||
|
||
# Remove item from config_db | ||
db.cfgdb.mod_entry("KDUMP", "config", {item: ""}) | ||
click.echo(f"{item} removed successfully.") | ||
echo_reboot_warning() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This need not be error; you can just report INFO level message.