Skip to content

Commit

Permalink
Inform if the disk is not SSD
Browse files Browse the repository at this point in the history
  • Loading branch information
sujinmkang committed Dec 1, 2021
1 parent 1ea88e2 commit 3ac184a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ssdutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
try:
import argparse
import os
import subprocess
import sys

from sonic_py_common import device_info, logger
Expand All @@ -16,11 +17,20 @@

DEFAULT_DEVICE="/dev/sda"
SYSLOG_IDENTIFIER = "ssdutil"
DISK_TYPE_SSD = "0"

# Global logger instance
log = logger.Logger(SYSLOG_IDENTIFIER)


def get_disk_type(diskdev):
"""Check disk type"""
cmd = "cat /sys/block/{}/queue/rotational".format(diskdev.replace('/dev/',''))
proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE)
out = proc.stdout.readline()
return out.rstrip()


def import_ssd_api(diskdev):
"""
Loads platform specific or generic ssd_util module from source
Expand Down Expand Up @@ -65,6 +75,11 @@ def ssdutil():
parser.add_argument("-e", "--vendor", action="store_true", default=False, help="Show vendor output (extended output if provided by platform vendor)")
args = parser.parse_args()

disk_type = get_disk_type(args.device)
if disk_type != DISK_TYPE_SSD:
print("Disk is not SSD")
sys.exit(1)

ssd = import_ssd_api(args.device)

print("Device Model : {}".format(ssd.get_model()))
Expand Down

0 comments on commit 3ac184a

Please sign in to comment.