Skip to content

Commit

Permalink
NAS-133677 / 25.04 / Convert pool.dataset.details to new API (#15443)
Browse files Browse the repository at this point in the history
* add pool_dataset_details to new api

* use new api in plugin

* dont query user properties

* fix bugs found during QA

* address review
  • Loading branch information
yocalebo authored Jan 21, 2025
1 parent 484419c commit 064f768
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 161 deletions.
1 change: 1 addition & 0 deletions src/middlewared/middlewared/api/v25_04_0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from .netdata import * # noqa
from .nfs import * # noqa
from .pool import * # noqa
from .pool_dataset_details import * # noqa
from .pool_resilver import * # noqa
from .pool_scrub import * # noqa
from .pool_snapshot_count import * # noqa
Expand Down
99 changes: 99 additions & 0 deletions src/middlewared/middlewared/api/v25_04_0/pool_dataset_details.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from middlewared.api.base import BaseModel

from pydantic import ConfigDict, Field


class ZFSValues(BaseModel):
value: str | None
rawvalue: str
parsed: str | int | None
source: str
source_info: str | None


class PDD_NFSEntry(BaseModel):
enabled: bool
path: str


class PDD_SMBEntry(BaseModel):
enabled: bool
path: str
share_name: str


class PDD_ISCSIEntry(BaseModel):
enabled: bool
path: str
type_: str = Field(alias="type")


class PDD_VMEntry(BaseModel):
name: str
path: str


class PDD_VirtEntry(BaseModel):
name: str
path: str


class PDD_AppEntry(BaseModel):
name: str
path: str


class PoolDatasetDetailsModel(BaseModel):
model_config = ConfigDict(extra="allow")
id: str
type_: str = Field(alias="type")
name: str
pool: str
encrypted: bool
encryption_root: str | None
key_loaded: bool
mountpoint: str
snapshot_count: int
locked: bool
atime: bool
casesensitive: bool
readonly: bool
thick_provisioned: bool
nfs_shares: list[PDD_NFSEntry]
smb_shares: list[PDD_SMBEntry]
iscsi_shares: list[PDD_ISCSIEntry]
vms: list[PDD_VMEntry]
apps: list[PDD_AppEntry]
virt_instances: list[PDD_VirtEntry]
replication_tasks_count: int
snapshot_tasks_count: int
cloudsync_tasks_count: int
rsync_tasks_count: int
deduplication: ZFSValues
sync: ZFSValues
compression: ZFSValues
origin: ZFSValues
quota: ZFSValues
refquota: ZFSValues
reservation: ZFSValues
refreservation: ZFSValues
key_format: ZFSValues
encryption_algorithm: ZFSValues
used: ZFSValues
usedbychildren: ZFSValues
usedbydataset: ZFSValues
usedbysnapshots: ZFSValues
available: ZFSValues


class PoolDatasetDetailsEntry(PoolDatasetDetailsModel):
model_config = ConfigDict(extra="allow")
children: list[PoolDatasetDetailsModel]


class PoolDatasetDetailsArgs(BaseModel):
pass


class PoolDatasetDetailsResults(BaseModel):
result: list[PoolDatasetDetailsEntry]
184 changes: 23 additions & 161 deletions src/middlewared/middlewared/plugins/pool_/dataset_details.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import os
import pathlib

from middlewared.api import api_method
from middlewared.api.current import (
PoolDatasetDetailsArgs,
PoolDatasetDetailsResults,
)
from middlewared.plugins.boot import BOOT_POOL_NAME_VALID
from middlewared.plugins.zfs_.utils import zvol_path_to_name, TNUserProp
from middlewared.service import Service, private
from middlewared.schema import accepts, List, returns
from middlewared.utils.mount import getmntinfo
from middlewared.utils.zfs import query_imported_fast_impl

Expand All @@ -14,167 +18,11 @@ class PoolDatasetService(Service):
class Config:
namespace = 'pool.dataset'

@accepts(roles=['DATASET_READ', 'READONLY_ADMIN'])
@returns(List(
'dataset_details',
example=[{
'id': 'tank',
'type': 'FILESYSTEM',
'name': 'tank',
'pool': 'tank',
'encrypted': False,
'encryption_root': None,
'key_loaded': False,
'children': [
{
'id': 'tank/soemthing',
'type': 'VOLUME',
'name': 'tank/soemthing',
'pool': 'tank',
'encrypted': False,
'encryption_root': None,
'key_loaded': False,
'children': [],
'managed_by': {
'value': '10.231.1.155',
'rawvalue': '10.231.1.155',
'source': 'LOCAL',
'parsed': '10.231.1.155'
},
'quota_warning': {'value': '80', 'rawvalue': '80', 'source': 'LOCAL', 'parsed': '80'},
'quota_critical': {'value': '95', 'rawvalue': '95', 'source': 'LOCAL', 'parsed': '95'},
'refquota_warning': {'value': '80', 'rawvalue': '80', 'source': 'LOCAL', 'parsed': '80'},
'refquota_critical': {'value': '95', 'rawvalue': '95', 'source': 'LOCAL', 'parsed': '95'},
'reservation': {
'parsed': None, 'rawvalue': '0', 'value': None, 'source': 'DEFAULT', 'source_info': None
},
'refreservation': {
'parsed': None, 'rawvalue': '0', 'value': None, 'source': 'DEFAULT', 'source_info': None
},
'key_format': {
'parsed': 'none', 'rawvalue': 'none', 'value': None, 'source': 'DEFAULT', 'source_info': None
},
'volsize': {
'parsed': 57344, 'rawvalue': '57344', 'value': '56K', 'source': 'LOCAL', 'source_info': None
},
'encryption_algorithm': {
'parsed': 'off', 'rawvalue': 'off', 'value': None, 'source': 'DEFAULT', 'source_info': None
},
'used': {
'parsed': 57344, 'rawvalue': '57344', 'value': '56K', 'source': 'NONE', 'source_info': None
},
'usedbychildren': {
'parsed': 0, 'rawvalue': '0', 'value': '0B', 'source': 'NONE', 'source_info': None
},
'usedbydataset': {
'parsed': 57344, 'rawvalue': '57344', 'value': '56K', 'source': 'NONE', 'source_info': None
},
'usedbysnapshots': {
'parsed': 0, 'rawvalue': '0', 'value': '0B', 'source': 'NONE', 'source_info': None
},
'available': {
'parsed': 14328811520, 'rawvalue': '14328811520',
'value': '13.3G', 'source': 'NONE', 'source_info': None
},
'mountpoint': '/mnt/tank/something',
'sync': {
'parsed': 'standard', 'rawvalue': 'standard',
'value': 'STANDARD', 'source': 'DEFAULT', 'source_info': None
},
'compression': {
'parsed': 'lz4', 'rawvalue': 'lz4',
'value': 'LZ4', 'source': 'INHERITED', 'source_info': 'tank',
},
'deduplication': {
'parsed': 'on', 'rawvalue': 'on',
'value': 'ON', 'source': 'LOCAL', 'source_info': None,
},
'user_properties': {},
'snapshot_count': 0,
'locked': False,
'thick_provisioned': True,
'nfs_shares': [{
'enabled': True,
'path': '/mnt/tank/something'
}],
'smb_shares': [{
'enabled': False,
'path': '/mnt/tank/something/smbshare01',
'share_name': 'Home Pictures',
}],
'iscsi_shares': [{
'enabled': False,
'type': 'DISK',
'path': '/mnt/tank/something',
}],
'vms': [{
'name': 'deb01',
'path': '/dev/zvol/tank/something',
}],
'apps': [{
'name': 'diskoverdata',
'path': '/mnt/tank/something'
}],
'replication_tasks_count': 0,
'snapshot_tasks_count': 0,
'cloudsync_tasks_count': 0,
'rsync_tasks_count': 0
}
],
'mountpoint': '/mnt/tank',
'quota': {'parsed': None, 'rawvalue': '0', 'value': None, 'source': 'DEFAULT', 'source_info': None},
'refquota': {'parsed': None, 'rawvalue': '0', 'value': None, 'source': 'DEFAULT', 'source_info': None},
'reservation': {'parsed': None, 'rawvalue': '0', 'value': None, 'source': 'DEFAULT', 'source_info': None},
'refreservation': {
'parsed': None, 'rawvalue': '0', 'value': None, 'source': 'DEFAULT', 'source_info': None
},
'encryption_algorithm': {
'parsed': 'off', 'rawvalue': 'off', 'value': None, 'source': 'DEFAULT', 'source_info': None
},
'origin': {
'parsed': '', 'rawvalue': '', 'value': '', 'source': 'NONE', 'source_info': None
},
'used': {
'parsed': 3874467840, 'rawvalue': '3874467840', 'value': '3.61G', 'source': 'NONE', 'source_info': None
},
'usedbychildren': {
'parsed': 3874369536, 'rawvalue': '3874369536', 'value': '3.61G', 'source': 'NONE', 'source_info': None
},
'usedbydataset': {
'parsed': 98304, 'rawvalue': '98304', 'value': '96K', 'source': 'NONE', 'source_info': None
},
'usedbysnapshots': {'parsed': 0, 'rawvalue': '0', 'value': '0B', 'source': 'NONE', 'source_info': None},
'available': {
'parsed': 14328811520, 'rawvalue': '14328811520',
'value': '13.3G', 'source': 'NONE', 'source_info': None
},
'user_properties': {},
'snapshot_count': 0,
'locked': False,
'atime': False,
'casesensitive': True,
'readonly': False,
'nfs_shares': [],
'smb_shares': [],
'iscsi_shares': [],
'vms': [],
'virt_instances': [],
'apps': [{
'name': 'plex',
'path': '/mnt/evo/data',
}],
'replication_tasks_count': 0,
'snapshot_tasks_count': 0,
'cloudsync_tasks_count': 0,
'rsync_tasks_count': 0,
}]
))
def details(self):
"""
Retrieve all dataset(s) details outlining any services/tasks which might be consuming the dataset(s).
"""
@private
def build_filters_and_options(self):
options = {
'extra': {
'retrieve_user_props': False,
'flat': True,
'order_by': 'name',
'properties': [
Expand Down Expand Up @@ -210,7 +58,21 @@ def details(self):
if i['name'] not in BOOT_POOL_NAME_VALID:
valid_pools.append(i['name'])

datasets = self.middleware.call_sync('pool.dataset.query', [['name', 'in', valid_pools]], options)
return [['name', 'in', valid_pools]], options


@api_method(
PoolDatasetDetailsArgs,
PoolDatasetDetailsResults,
roles=['DATASET_READ']
)
def details(self):
"""
Retrieve all dataset(s) details outlining any
services/tasks which might be consuming them.
"""
filters, options = self.build_filters_and_options()
datasets = self.middleware.call_sync('pool.dataset.query', filters, options)
mnt_info = getmntinfo()
info = self.build_details(mnt_info)
for dataset in datasets:
Expand Down

0 comments on commit 064f768

Please sign in to comment.