From 887db72e74a7014d6e6aa9d8fbb6d49b3b77790c Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 21 Jan 2025 07:42:44 -0500 Subject: [PATCH 1/3] add pool.dataset.snapshot_count to new api --- src/middlewared/middlewared/api/v25_04_0/__init__.py | 1 + .../middlewared/api/v25_04_0/pool_snapshot_count.py | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 src/middlewared/middlewared/api/v25_04_0/pool_snapshot_count.py diff --git a/src/middlewared/middlewared/api/v25_04_0/__init__.py b/src/middlewared/middlewared/api/v25_04_0/__init__.py index fd548874eeab1..bbaea44d3d3a7 100644 --- a/src/middlewared/middlewared/api/v25_04_0/__init__.py +++ b/src/middlewared/middlewared/api/v25_04_0/__init__.py @@ -47,6 +47,7 @@ from .pool import * # noqa from .pool_resilver import * # noqa from .pool_scrub import * # noqa +from .pool_snapshot_count import * # noqa from .pool_snapshottask import * # noqa from .privilege import * # noqa from .rdma import * # noqa diff --git a/src/middlewared/middlewared/api/v25_04_0/pool_snapshot_count.py b/src/middlewared/middlewared/api/v25_04_0/pool_snapshot_count.py new file mode 100644 index 0000000000000..893b29e6dac15 --- /dev/null +++ b/src/middlewared/middlewared/api/v25_04_0/pool_snapshot_count.py @@ -0,0 +1,9 @@ +from middlewared.api.base import BaseModel + + +class PoolDatasetSnapshotCountArgs(BaseModel): + dataset: str + + +class PoolDatasetSnapshotCountResults(BaseModel): + result: int From 1d09d5ea55eccae242a3fb4737c35325fc520515 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 21 Jan 2025 07:42:56 -0500 Subject: [PATCH 2/3] convert snapshot_count.py to new api --- .../plugins/pool_/snapshot_count.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/middlewared/middlewared/plugins/pool_/snapshot_count.py b/src/middlewared/middlewared/plugins/pool_/snapshot_count.py index 26a09cd3d2e24..8b7eb8bba2b6f 100644 --- a/src/middlewared/middlewared/plugins/pool_/snapshot_count.py +++ b/src/middlewared/middlewared/plugins/pool_/snapshot_count.py @@ -1,16 +1,21 @@ -from middlewared.schema import accepts, returns, Int, Str +from middlewared.api import api_method +from middlewared.api.current import ( + PoolDatasetSnapshotCountArgs, + PoolDatasetSnapshotCountResults, +) + from middlewared.service import Service class PoolDatasetService(Service): - class Config: namespace = "pool.dataset" - @accepts(Str("dataset"), roles=['DATASET_READ']) - @returns(Int()) + @api_method( + PoolDatasetSnapshotCountArgs, + PoolDatasetSnapshotCountResults, + roles=["DATASET_READ"], + ) def snapshot_count(self, dataset): - """ - Returns snapshot count for specified `dataset`. - """ + """Returns snapshot count for specified `dataset`.""" return self.middleware.call_sync("zfs.snapshot.count", [dataset])[dataset] From b5b370b319eed1b7283824109aef6c12b14235a1 Mon Sep 17 00:00:00 2001 From: Caleb Date: Tue, 21 Jan 2025 08:05:51 -0500 Subject: [PATCH 3/3] remove superfluous newline --- src/middlewared/middlewared/plugins/pool_/snapshot_count.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/middlewared/middlewared/plugins/pool_/snapshot_count.py b/src/middlewared/middlewared/plugins/pool_/snapshot_count.py index 8b7eb8bba2b6f..afc171f11f15d 100644 --- a/src/middlewared/middlewared/plugins/pool_/snapshot_count.py +++ b/src/middlewared/middlewared/plugins/pool_/snapshot_count.py @@ -3,7 +3,6 @@ PoolDatasetSnapshotCountArgs, PoolDatasetSnapshotCountResults, ) - from middlewared.service import Service