Skip to content

Commit 217079b

Browse files
committed
check the disk available
1 parent 3ac184a commit 217079b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ssdutil/main.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,19 @@
2525

2626
def get_disk_type(diskdev):
2727
"""Check disk type"""
28-
cmd = "cat /sys/block/{}/queue/rotational".format(diskdev.replace('/dev/',''))
28+
diskdev_name = diskdev.replace('/dev/','')
29+
cmd = "lsblk -l -n |grep disk"
2930
proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE)
30-
out = proc.stdout.readline()
31-
return out.rstrip()
31+
outs = proc.stdout.readlines()
32+
for out in outs:
33+
if out.split()[0] in diskdev_name:
34+
cmd = "cat /sys/block/{}/queue/rotational".format(diskdev_name)
35+
proc = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE)
36+
out = proc.stdout.readline()
37+
return out.rstrip()
38+
39+
print("disk {} does not exist in the device".format(diskdev_name))
40+
sys.exit(1)
3241

3342

3443
def import_ssd_api(diskdev):

0 commit comments

Comments
 (0)