Skip to content

Commit

Permalink
Add date to show version (sonic-net#2086)
Browse files Browse the repository at this point in the history
- What I did
Add the current date attribute to the "show version" output that includes the current date and hour on the switch.

- How I did it
In sonic-utilities, in the "version" subcommand, print of the current date will be added using "datetime" from the "datetime" library.

- How to verify it
Execute "show version" command and verify "Date" row under the "Uptime" row.

Signed-off-by: EdenGri <eden7045@gmail.com>
  • Loading branch information
EdenGri authored Mar 23, 2022
1 parent 61b1396 commit 510a9b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ This command displays relevant information as the SONiC and Linux kernel version
Model Number: MSN2700-CS2FO
Hardware Rev: A1
Uptime: 14:40:15 up 3 min, 1 user, load average: 1.26, 1.45, 0.66
Date: Fri 22 Mar 2019 14:40:15
Docker images:
REPOSITORY TAG IMAGE ID SIZE
Expand Down
24 changes: 14 additions & 10 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from tabulate import tabulate
from utilities_common import util_base
from utilities_common.db import Db
from datetime import datetime
import utilities_common.constants as constants
from utilities_common.general import load_db_config

Expand Down Expand Up @@ -1083,10 +1084,12 @@ def version(verbose):
version_info = device_info.get_sonic_version_info()
platform_info = device_info.get_platform_info()
chassis_info = platform.get_chassis_info()

sys_uptime_cmd = "uptime"
sys_uptime = subprocess.Popen(sys_uptime_cmd, shell=True, text=True, stdout=subprocess.PIPE)

sys_date = datetime.now()

click.echo("\nSONiC Software Version: SONiC.{}".format(version_info['build_version']))
click.echo("Distribution: Debian {}".format(version_info['debian_version']))
click.echo("Kernel: {}".format(version_info['kernel_version']))
Expand All @@ -1101,6 +1104,7 @@ def version(verbose):
click.echo("Model Number: {}".format(chassis_info['model']))
click.echo("Hardware Revision: {}".format(chassis_info['revision']))
click.echo("Uptime: {}".format(sys_uptime.stdout.read().strip()))
click.echo("Date: {}".format(sys_date.strftime("%a %d %b %Y %X")))
click.echo("\nDocker images:")
cmd = 'sudo docker images --format "table {{.Repository}}\\t{{.Tag}}\\t{{.ID}}\\t{{.Size}}"'
p = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE)
Expand Down Expand Up @@ -1158,7 +1162,7 @@ def techsupport(since, global_timeout, cmd_timeout, verbose, allow_process_stop,

if since:
cmd += " -s '{}'".format(since)

if debug_dump:
cmd += " -d "

Expand Down Expand Up @@ -1263,7 +1267,7 @@ def snmp(ctx, db):

# ("show runningconfiguration snmp community")
@snmp.command('community')
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL,
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL,
help="Display the output in JSON format")
@clicommon.pass_db
def community(db, json_output):
Expand All @@ -1284,7 +1288,7 @@ def community(db, json_output):

# ("show runningconfiguration snmp contact")
@snmp.command('contact')
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL,
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL,
help="Display the output in JSON format")
@clicommon.pass_db
def contact(db, json_output):
Expand Down Expand Up @@ -1312,7 +1316,7 @@ def contact(db, json_output):

# ("show runningconfiguration snmp location")
@snmp.command('location')
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL,
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL,
help="Display the output in JSON format")
@clicommon.pass_db
def location(db, json_output):
Expand All @@ -1339,13 +1343,13 @@ def location(db, json_output):

# ("show runningconfiguration snmp user")
@snmp.command('user')
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL,
@click.option('--json', 'json_output', required=False, is_flag=True, type=click.BOOL,
help="Display the output in JSON format")
@clicommon.pass_db
def users(db, json_output):
"""show SNMP running configuration user"""
snmp_users = db.cfgdb.get_table('SNMP_USER')
snmp_user_header = ['User', "Permission Type", "Type", "Auth Type", "Auth Password", "Encryption Type",
snmp_user_header = ['User', "Permission Type", "Type", "Auth Type", "Auth Password", "Encryption Type",
"Encryption Password"]
snmp_user_body = []
if json_output:
Expand All @@ -1358,7 +1362,7 @@ def users(db, json_output):
snmp_user_encryption_type = snmp_users[snmp_user].get('SNMP_USER_ENCRYPTION_TYPE', 'Null')
snmp_user_encryption_password = snmp_users[snmp_user].get('SNMP_USER_ENCRYPTION_PASSWORD', 'Null')
snmp_user_type = snmp_users[snmp_user].get('SNMP_USER_TYPE', 'Null')
snmp_user_body.append([snmp_user, snmp_user_permissions_type, snmp_user_type, snmp_user_auth_type,
snmp_user_body.append([snmp_user, snmp_user_permissions_type, snmp_user_type, snmp_user_auth_type,
snmp_user_auth_password, snmp_user_encryption_type, snmp_user_encryption_password])
click.echo(tabulate(natsorted(snmp_user_body), snmp_user_header))

Expand All @@ -1375,7 +1379,7 @@ def show_run_snmp(db, ctx):
snmp_contact_body = []
snmp_comm_header = ["Community String", "Community Type"]
snmp_comm_body = []
snmp_user_header = ['User', "Permission Type", "Type", "Auth Type", "Auth Password", "Encryption Type",
snmp_user_header = ['User', "Permission Type", "Type", "Auth Type", "Auth Password", "Encryption Type",
"Encryption Password"]
snmp_user_body = []
try:
Expand Down Expand Up @@ -1409,7 +1413,7 @@ def show_run_snmp(db, ctx):
snmp_user_encryption_type = snmp_users[snmp_user].get('SNMP_USER_ENCRYPTION_TYPE', 'Null')
snmp_user_encryption_password = snmp_users[snmp_user].get('SNMP_USER_ENCRYPTION_PASSWORD', 'Null')
snmp_user_type = snmp_users[snmp_user].get('SNMP_USER_TYPE', 'Null')
snmp_user_body.append([snmp_user, snmp_user_permissions_type, snmp_user_type, snmp_user_auth_type,
snmp_user_body.append([snmp_user, snmp_user_permissions_type, snmp_user_type, snmp_user_auth_type,
snmp_user_auth_password, snmp_user_encryption_type, snmp_user_encryption_password])
click.echo(tabulate(natsorted(snmp_user_body), snmp_user_header))

Expand Down

0 comments on commit 510a9b9

Please sign in to comment.