selfprivacy-rest-api/selfprivacy_api/graphql/queries/storage.py

34 lines
977 B
Python
Raw Normal View History

2022-07-25 17:08:31 +03:00
"""Storage queries."""
# pylint: disable=too-few-public-methods
import typing
import strawberry
2022-08-13 02:39:37 +03:00
2022-08-13 01:26:47 +03:00
from selfprivacy_api.graphql.common_types.service import (
2022-08-13 01:12:28 +03:00
StorageVolume,
)
2022-07-25 17:08:31 +03:00
from selfprivacy_api.utils.block_devices import BlockDevices
@strawberry.type
class Storage:
"""GraphQL queries to get storage information."""
2022-07-25 17:08:31 +03:00
@strawberry.field
def volumes(self) -> typing.List[StorageVolume]:
"""Get list of volumes"""
return [
StorageVolume(
total_space=str(volume.fssize)
if volume.fssize is not None
else str(volume.size),
2022-07-25 17:17:57 +03:00
free_space=str(volume.fsavail),
used_space=str(volume.fsused),
2022-07-25 17:08:31 +03:00
root=volume.name == "sda1",
name=volume.name,
model=volume.model,
serial=volume.serial,
type=volume.type,
2022-07-25 17:08:31 +03:00
)
for volume in BlockDevices().get_block_devices()
]