Skip to content

Commit

Permalink
check the disk available
Browse files Browse the repository at this point in the history
  • Loading branch information
sujinmkang committed Dec 5, 2021
1 parent 3ac184a commit 217079b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ssdutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@

def get_disk_type(diskdev):
"""Check disk type"""
cmd = "cat /sys/block/{}/queue/rotational".format(diskdev.replace('/dev/',''))
diskdev_name = diskdev.replace('/dev/','')
cmd = "lsblk -l -n |grep disk"
proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE)
out = proc.stdout.readline()
return out.rstrip()
outs = proc.stdout.readlines()
for out in outs:
if out.split()[0] in diskdev_name:

This comment has been minimized.

Copy link
@prgeor

prgeor Dec 6, 2021

Contributor

shouldn't we be checking the diskdev_name in the 'outs' which is the list of disks available in the host?

if diskdev_name in out.split()[0]:
cmd = "cat /sys/block/{}/queue/rotational".format(diskdev_name)
proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE)
out = proc.stdout.readline()
return out.rstrip()

print("disk {} does not exist in the device".format(diskdev_name))
sys.exit(1)


def import_ssd_api(diskdev):
Expand Down

0 comments on commit 217079b

Please sign in to comment.