Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage mangment API: disks infos #1953

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

christophehenry
Copy link

@christophehenry christophehenry commented Sep 17, 2024

The problem

Rel: YunoHost/issues#1823.
Add API for getting infos on hard drives.

share/actionsmap.yml Outdated Show resolved Hide resolved
@christophehenry christophehenry marked this pull request as ready for review September 18, 2024 15:50
@christophehenry
Copy link
Author

christophehenry commented Sep 18, 2024

Ok I think this is a good first step. Here is an exemple of the result this produces:

{
    "sda": {
        "devname": "/dev/sda",
        "model": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "serial": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "size": xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
        "links": [
            "/dev/disk/by-diskseq/1",
            "/dev/disk/by-id/ata-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "/dev/disk/by-id/wwn-xxxxxxxxxxxxxxxxxxxxxxxx",
            "/dev/disk/by-path/pci-0000:01:00.1-ata-1",
            "/dev/disk/by-path/pci-0000:01:00.1-ata-1.0"
        ],
        "partitions": {
            "sda1": {
                "devname": "/dev/sda",
                "filesystem": "btrfs",
                "encrypted": true,
                "mountpoint": "/home"
            }
        }
    },
    "sdb": {
        "devname": "/dev/sdb",
        "model": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "serial": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "size": xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
        "links": [
            "/dev/disk/by-diskseq/2",
            "/dev/disk/by-id/ata-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "/dev/disk/by-id/wwn-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "/dev/disk/by-path/pci-0000:0a:00.0-ata-6",
            "/dev/disk/by-path/pci-0000:0a:00.0-ata-6.0"
        ],
        "partitions": {
            "sdb1": {
                "devname": "/dev/sdb",
                "filesystem": "vfat",
                "encrypted": false,
                "mountpoint": "/boot/efi"
            },
            "sdb2": {
                "devname": "/dev/sdb",
                "filesystem": "ext4",
                "encrypted": false,
                "mountpoint": "/boot"
            },
            "sdb3": {
                "devname": "/dev/sdb",
                "filesystem": "btrfs",
                "encrypted": true,
                "mountpoint": "/"
            }
        }
    }
}

In a future PR, I'd like to add the device type (HDD, SSD, …) and RPM for HDDs. I don't really know how to do that. TrueNAS does it by using its own library. In the meantime, this is ready for review.

src/disks.py Outdated
Comment on lines 31 to 39
encrypted_provider = glob(f"/sys/block/dm-*/slaves/{child_dev.sys_name}")
if encrypted_provider:
# retrive the dm-x part
dm = encrypted_provider[0].split("/")[3]
enc_dev = pyudev.Devices.from_name(device.context, "block", dm)
# This work for LUKS, what about other partition mecanisms?
partname = f"/dev/mapper/{enc_dev.properties['DM_NAME']}"
encrypted = True
else:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method detects LUKS partitions but I'm not sure it does not detect other unecrypted partitions, like LVM. If someone with more system knowlege than me could check this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could use pyparted here but this needs sufficient rights. If I'm not mistaken, yunohost-api is running as root, so this shouldn't be an issue, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this solution detects LVM (non-LUKS) partitions as encrypted. And I can't figure out how to retrieve FS with pyparted. I don't know how gparted and KDE partition manager detect the partition filesystem.

@christophehenry christophehenry changed the title WIP: Storage mangment API: disks infos Storage mangment API: disks infos Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants