Skip to content

Commit

Permalink
audit disk activities
Browse files Browse the repository at this point in the history
  • Loading branch information
yocalebo committed Nov 16, 2024
1 parent 3320b95 commit 4ca50e4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/middlewared/middlewared/plugins/pool_/pool_disk_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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:
Expand All @@ -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`.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4ca50e4

Please sign in to comment.