From 4ca50e4fdac628e1cf819f357fe56959eecab3ad Mon Sep 17 00:00:00 2001 From: Caleb Date: Sat, 16 Nov 2024 10:27:38 -0500 Subject: [PATCH] audit disk activities --- .../plugins/pool_/pool_disk_operations.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/middlewared/middlewared/plugins/pool_/pool_disk_operations.py b/src/middlewared/middlewared/plugins/pool_/pool_disk_operations.py index 0246f3a5a4b4..8bb604bc8034 100644 --- a/src/middlewared/middlewared/plugins/pool_/pool_disk_operations.py +++ b/src/middlewared/middlewared/plugins/pool_/pool_disk_operations.py @@ -16,9 +16,9 @@ class Config: @accepts(Int('id'), Dict( 'options', Str('label', required=True), - )) + ), audit='Disk Detach', audit_callback=True) @returns(Bool('detached')) - async def detach(self, oid, options): + async def detach(self, audit_callback, oid, options): """ Detach a disk from pool of id `id`. @@ -49,7 +49,7 @@ async def detach(self, oid, options): disk = await self.middleware.call( 'disk.label_to_disk', found[1]['path'].replace('/dev/', '') ) - + audit_callback(disk) await self.middleware.call('zfs.pool.detach', pool['name'], found[1]['guid']) if disk: @@ -64,9 +64,9 @@ async def detach(self, oid, options): @accepts(Int('id'), Dict( 'options', Str('label', required=True), - )) + ), audit='Disk Offline', audit_callback=True) @returns(Bool('offline_successful')) - async def offline(self, oid, options): + async def offline(self, audit_callback, oid, options): """ Offline a disk from pool of id `id`. @@ -94,6 +94,12 @@ async def offline(self, oid, options): verrors.add('options.label', f'Label {options["label"]} not found on this pool.') verrors.check() + if found[1]['type'] != 'DISK': + disk_paths = [d['path'] for d in found[1]['children']] + else: + disk_paths = [found[1]['path']] + audit_callback(', '.join(disk_paths)) + await self.middleware.call('zfs.pool.offline', pool['name'], found[1]['guid']) return True