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

Added 'config core' and 'show cores' CLI commands #663

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def _reset_failed_services():
'bgp',
'dhcp_relay',
'hostcfgd',
'coredump-config',
'hostname-config',
'interfaces-config',
'lldp',
Expand All @@ -359,6 +360,7 @@ def _reset_failed_services():

def _restart_services():
services_to_restart = [
'coredump-config',
'hostname-config',
'interfaces-config',
'ntp-config',
Expand Down Expand Up @@ -1503,3 +1505,35 @@ def del_ntp_server(ctx, ntp_ip_address):

if __name__ == '__main__':
config()

#
# 'core' group ('config core ...')
#
@config.group()
def core():
""" Configure coredump """
if os.geteuid() != 0:
exit("Root privileges are required for this operation")
pass

@core.command()
@click.argument('disable', required=False)
def disable(disable):
"""Administratively Disable coredump generation"""
config_db = ConfigDBConnector()
config_db.connect()
table = "COREDUMP"
key = "config"
config_db.set_entry(table, key, {"enabled": "false"})
run_command("systemctl restart coredump-config")

@core.command()
@click.argument('enable', required=False)
def enable(enable):
"""Administratively Enable coredump generation"""
config_db = ConfigDBConnector()
config_db.connect()
table = "COREDUMP"
key = "config"
config_db.set_entry(table, key, {"enabled": "true"})
run_command("systemctl restart coredump-config")
2 changes: 1 addition & 1 deletion scripts/generate_dump
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ main() {
continue
fi
# don't gzip already-gzipped log files :)
if [ -z "${file##*.gz}" ]; then
if [ -z "${file##*.gz}" ] || [ -z "${file##*.lz4}" ]; then
save_file $file log false
else
save_file $file log true
Expand Down
58 changes: 58 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,64 @@ def system_memory(verbose):
cmd = "free -m"
run_command(cmd, display_cmd=verbose)

#
# 'coredumpctl' group ("show cores")
#

@cli.group(cls=AliasedGroup, default_if_no_args=False)
def cores():
"""Show core dump events encountered"""
pass

# 'config' subcommand ("show cores config")
@cores.command()
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def config(verbose):
""" Show coredump configuration """
# Default admin mode
admin_mode = True
# Obtain config from Config DB
config_db = ConfigDBConnector()
if config_db is not None:
config_db.connect()
table_data = config_db.get_table('COREDUMP')
if table_data is not None:
config_data = table_data.get('config')
if config_data is not None:
admin_mode = config_data.get('enabled')
if admin_mode is not None and admin_mode.lower() == 'false':
admin_mode = False

# Core dump administrative mode
if admin_mode:
print('Coredump : %s' % 'Enabled')
else:
print('Coredump : %s' % 'Disabled')

# 'list' subcommand ("show cores list")
@cores.command()
@click.argument('pattern', required=False)
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def list(verbose, pattern):
""" List available coredumps """

cmd = "coredumpctl list"
if pattern is not None:
cmd = cmd + " " + pattern
run_command(cmd, display_cmd=verbose)

# 'info' subcommand ("show cores info")
@cores.command()
@click.argument('pattern', required=False)
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def info(verbose, pattern):
""" Show information about one or more coredumps """

cmd = "coredumpctl info"
if pattern is not None:
cmd = cmd + " " + pattern
run_command(cmd, display_cmd=verbose)

@cli.group(cls=AliasedGroup, default_if_no_args=False)
def vlan():
"""Show VLAN information"""
Expand Down