2022-07-25 14:08:31 +00:00
|
|
|
"""Storage queries."""
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
import typing
|
|
|
|
import strawberry
|
|
|
|
from selfprivacy_api.utils.block_devices import BlockDevices
|
|
|
|
|
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class StorageVolume:
|
2022-07-30 14:48:33 +00:00
|
|
|
"""Stats and basic info about a volume or a system disk."""
|
|
|
|
|
2022-07-25 14:17:57 +00:00
|
|
|
total_space: str
|
|
|
|
free_space: str
|
|
|
|
used_space: str
|
2022-07-25 14:08:31 +00:00
|
|
|
root: bool
|
|
|
|
name: str
|
2022-07-30 15:01:51 +00:00
|
|
|
model: typing.Optional[str]
|
|
|
|
serial: typing.Optional[str]
|
2022-07-30 14:48:33 +00:00
|
|
|
type: str
|
2022-07-25 14:08:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
@strawberry.type
|
|
|
|
class Storage:
|
2022-07-30 14:48:33 +00:00
|
|
|
"""GraphQL queries to get storage information."""
|
|
|
|
|
2022-07-25 14:08:31 +00:00
|
|
|
@strawberry.field
|
|
|
|
def volumes(self) -> typing.List[StorageVolume]:
|
|
|
|
"""Get list of volumes"""
|
|
|
|
return [
|
|
|
|
StorageVolume(
|
2022-07-30 14:48:33 +00:00
|
|
|
total_space=str(volume.fssize)
|
|
|
|
if volume.fssize is not None
|
|
|
|
else str(volume.size),
|
2022-07-25 14:17:57 +00:00
|
|
|
free_space=str(volume.fsavail),
|
|
|
|
used_space=str(volume.fsused),
|
2022-07-25 14:08:31 +00:00
|
|
|
root=volume.name == "sda1",
|
|
|
|
name=volume.name,
|
2022-07-30 14:48:33 +00:00
|
|
|
model=volume.model,
|
|
|
|
serial=volume.serial,
|
|
|
|
type=volume.type,
|
2022-07-25 14:08:31 +00:00
|
|
|
)
|
|
|
|
for volume in BlockDevices().get_block_devices()
|
|
|
|
]
|