Skip to content

Commit

Permalink
remove schema validation from zfs_/dataset_actions.py (#15687)
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo authored Feb 12, 2025
1 parent 6e704e3 commit f940253
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/middlewared/middlewared/plugins/zfs_/dataset_actions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import errno
import libzfs

from middlewared.schema import accepts, Bool, Dict, Str
from middlewared.service import CallError, Service
from middlewared.service_exception import ValidationError
from middlewared.plugins.zfs_.utils import path_to_dataset_impl


Expand Down Expand Up @@ -43,15 +43,12 @@ def child_dataset_names(self, path):
except libzfs.ZFSException as e:
raise CallError(f'Failed retrieving child datsets for {path} with error {e}')

@accepts(
Str('name'),
Dict(
'options',
Bool('recursive', default=False),
Bool('force_mount', default=False),
)
)
def mount(self, name, options):
def mount(self, name: str, options: dict | None = None):
if options is None:
options = dict()
options.setdefault('recursive', False)
options.setdefault('force_mount', False)

try:
with libzfs.ZFS() as zfs:
dataset = zfs.get_dataset(name)
Expand All @@ -64,8 +61,11 @@ def mount(self, name, options):
handle_ds_not_found(e.code, name)
raise CallError(f'Failed to mount dataset: {e}')

@accepts(Str('name'), Dict('options', Bool('force', default=False)))
def umount(self, name, options):
def umount(self, name: str, options: dict | None = None):
if options is None:
options = dict()
options.setdefault('force', False)

try:
with libzfs.ZFS() as zfs:
dataset = zfs.get_dataset(name)
Expand All @@ -75,15 +75,12 @@ def umount(self, name, options):
handle_ds_not_found(e.code, name)
raise CallError(f'Failed to umount dataset: {e}')

@accepts(
Str('dataset'),
Dict(
'options',
Str('new_name', required=True, empty=False),
Bool('recursive', default=False)
)
)
def rename(self, name, options):
def rename(self, name: str, options: dict):
options.setdefault('recursive', False)
options.setdefault('new_name', None)
if not options['new_name']:
raise ValidationError('new_name', 'new_name is required')

try:
with libzfs.ZFS() as zfs:
dataset = zfs.get_dataset(name)
Expand Down

0 comments on commit f940253

Please sign in to comment.