forked from sonic-net/sonic-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkdump.py
More file actions
90 lines (72 loc) · 2.67 KB
/
Copy pathkdump.py
File metadata and controls
90 lines (72 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import sys
import click
from utilities_common.cli import AbbreviationGroup, pass_db
#
# 'kdump' group ('sudo config kdump ...')
#
@click.group(cls=AbbreviationGroup, name="kdump")
def kdump():
"""Configure the KDUMP mechanism"""
pass
#
# 'disable' command ('sudo config kdump disable')
#
@kdump.command(name="disable", short_help="Disable the KDUMP mechanism")
@pass_db
def kdump_disable(db):
"""Disable the KDUMP mechanism"""
kdump_table = db.cfgdb.get_table("KDUMP")
if not kdump_table:
click.echo("Unable to retrieve 'KDUMP' table from Config DB.")
sys.exit(1)
if "config" not in kdump_table:
click.echo("Unable to retrieve key 'config' from KDUMP table.")
sys.exit(2)
db.cfgdb.mod_entry("KDUMP", "config", {"enabled": "false"})
#
# 'enable' command ('sudo config kdump enable')
#
@kdump.command(name="enable", short_help="Enable the KDUMP mechanism")
@pass_db
def kdump_enable(db):
"""Enable the KDUMP mechanism"""
kdump_table = db.cfgdb.get_table("KDUMP")
if not kdump_table:
click.echo("Unable to retrieve KDUMP table from CONFIG DB.")
sys.exit(3)
if "config" not in kdump_table:
click.echo("Unable to retrieve key 'config' from KDUMP table.")
sys.exit(4)
db.cfgdb.mod_entry("KDUMP", "config", {"enabled": "true"})
#
# '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
def kdump_memory(db, kdump_memory):
"""Reserve memory for kdump capture kernel"""
kdump_table = db.cfgdb.get_table("KDUMP")
if not kdump_table:
click.echo("Unable to retrieve KDUMP table from CONFIG DB.")
sys.exit(5)
if "config" not in kdump_table:
click.echo("Unable to retrieve key 'config' from KDUMP table.")
sys.exit(6)
db.cfgdb.mod_entry("KDUMP", "config", {"memory": kdump_memory})
#
# 'num_dumps' command ('sudo config keump 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
def kdump_num_dumps(db, kdump_num_dumps):
"""Set maximum number of dump files for kdump"""
kdump_table = db.cfgdb.get_table("KDUMP")
if not kdump_table:
click.echo("Unable to retrieve KDUMP table from CONFIG DB.")
sys.exit(7)
if "config" not in kdump_table:
click.echo("Unable to retrieve key 'config' from KDUMP table.")
sys.exit(8)
db.cfgdb.mod_entry("KDUMP", "config", {"num_dumps": kdump_num_dumps})