Last active
March 2, 2021 04:03
-
-
Save shundezhang/fd28601e99c20d2530f1c837fec4fa01 to your computer and use it in GitHub Desktop.
pyudev-example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyudev | |
# install pyudev | |
# apt install python3-pyudev | |
context = pyudev.Context() | |
for device in context.list_devices(subsystem="block"): | |
if device.device_type == u"disk": | |
property_dict = dict(device.items()) | |
if ('ID_MODEL' in property_dict): | |
print("====== " + property_dict.get('DEVNAME', "Unknown") + " =========") | |
for key in property_dict.keys(): | |
print(key, property_dict.get(key)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
====== /dev/sda ========= | |
DEVLINKS /dev/disk/by-id/wwn-0x600508b1001c0d600a6fc481e768a56f /dev/disk/by-id/scsi-3600508b1001c0d600a6fc481e768a56f /dev/disk/by-dname/sda /dev/disk/by-path/pci-0000:0c:00.0-scsi-0:1:0:0 | |
DEVNAME /dev/sda | |
DEVPATH /devices/pci0000:00/0000:00:1c.0/0000:0c:00.0/host0/target0:1:0/0:1:0:0/block/sda | |
DEVTYPE disk | |
ID_BUS scsi | |
ID_MODEL LOGICAL_VOLUME | |
ID_MODEL_ENC LOGICAL\x20VOLUME\x20\x20 | |
ID_PART_TABLE_TYPE dos | |
ID_PART_TABLE_UUID 805c3080 | |
ID_PATH pci-0000:0c:00.0-scsi-0:1:0:0 | |
ID_PATH_TAG pci-0000_0c_00_0-scsi-0_1_0_0 | |
ID_REVISION 6.40 | |
ID_SCSI 1 | |
ID_SCSI_SERIAL 5001438007C467C0 | |
ID_SERIAL 3600508b1001c0d600a6fc481e768a56f | |
ID_SERIAL_SHORT 600508b1001c0d600a6fc481e768a56f | |
ID_TYPE disk | |
ID_VENDOR HP | |
ID_VENDOR_ENC HP\x20\x20\x20\x20\x20\x20 | |
ID_WWN 0x600508b1001c0d60 | |
ID_WWN_VENDOR_EXTENSION 0x0a6fc481e768a56f | |
ID_WWN_WITH_EXTENSION 0x600508b1001c0d600a6fc481e768a56f | |
MAJOR 8 | |
MINOR 0 | |
SUBSYSTEM block | |
TAGS :systemd: | |
USEC_INITIALIZED 5964830 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment