Skip to content

Commit c62e776

Browse files
committed
lsblk.py: add devid in output
Add a function to obtain devid from the device path and add it to the output Signed-off-by: Damien Thenot <[email protected]>
1 parent 836bb4b commit c62e776

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

SOURCES/etc/xapi.d/plugins/lsblk.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
from xcpngutils import run_command, error_wrapped
1010

11+
def get_devid_from_device_path(device_path):
12+
result = run_command(["find", "-L", "/dev/disk/by-id", "-samefile", device_path])
13+
result_output = result["stdout"].decode("utf-8").strip()
14+
return result_output.split("\n")
15+
1116
@error_wrapped
1217
def list_block_devices(session, args):
1318
result = run_command(["lsblk", "-P", "-b", "-o", "NAME,KNAME,PKNAME,SIZE,TYPE,RO,MOUNTPOINT"])
@@ -20,6 +25,7 @@ def list_block_devices(session, args):
2025
output_dict = {key.lower(): output_dict[key].strip('"') for key in output_dict}
2126
kname = output_dict["kname"]
2227
pkname = output_dict["pkname"]
28+
output_dict["devid"] = get_devid_from_device_path("/dev/" + kname)
2329
if pkname != "":
2430
parent = blockdevices[pkname]
2531
if "children" not in parent:

0 commit comments

Comments
 (0)