From e9610cc9091bcdc7c6bca26a1705369f14a9c8cf Mon Sep 17 00:00:00 2001 From: bugclerk <40872210+bugclerk@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:59:54 -0700 Subject: [PATCH] NAS-132010 / 24.10.0 / add zvols to zvol_config.txt (by yocalebo) (#230) * add zvols to zvol_config.txt (cherry picked from commit 26c8edc5b2b3605ddd465b9fa1072bd6fa7f5aea) * fix unit tests (cherry picked from commit 2ab4bd6a809939c976be4e579d08e4de15e7682c) --------- Co-authored-by: caleb --- ixdiagnose/plugins/zfs.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ixdiagnose/plugins/zfs.py b/ixdiagnose/plugins/zfs.py index cb7c1e2..bfb1cf8 100644 --- a/ixdiagnose/plugins/zfs.py +++ b/ixdiagnose/plugins/zfs.py @@ -30,13 +30,14 @@ def zfs_getacl_impl(dataset_name: str, props_dict: dict) -> str: def resource_output(client: MiddlewareClient, resource_type: str) -> str: - if resource_type == 'zfs': - cp = run(['zfs', 'get', 'all', '-t', 'filesystem'], check=False) + if resource_type in ('filesystem', 'volume'): + cp = run(['zfs', 'get', 'all', '-t', resource_type], check=False) else: cp = run([resource_type, 'get', 'all'], check=False) if cp.returncode: return f'Failed to retrieve {resource_type!r} resources: {cp.stderr}' + base = 'zpool get all' if resource_type == 'zpool' else 'zfs get all' prop_list = {'acltype', 'mounted', 'mountpoint'} resource_context = resource_name = None output = '' @@ -46,24 +47,24 @@ def resource_output(client: MiddlewareClient, resource_type: str) -> str: for index, resource_line in enumerate(filter(bool, map(str.strip, output_lines[1:]))): resource_name = resource_line.split()[0].strip() if resource_context != resource_name: - if resource_context is not None and resource_type == 'zfs': + if resource_context is not None and resource_type == 'filesystem': output += zfs_getacl(resource_context, prop_dict) prop_dict = {} - header_str = f'{resource_type} get all {resource_name}' + header_str = f'{base} {resource_name}' next_line = '\n\n' if index != 0 else '' output += f'{next_line}{"=" * (len(header_str) + 5)}\n {header_str}\n{"=" * (len(header_str) + 5)}\n\n' output += f'{props_header}\n' resource_context = resource_name - if resource_type == 'zfs': + if resource_type == 'filesystem': prop = resource_line.split()[1] if prop in prop_list: prop_dict[prop] = resource_line.split()[2] output += f'{resource_line}\n' - if resource_name is not None and resource_type == 'zfs': + if resource_name is not None and resource_type == 'filesystem': output += zfs_getacl(resource_name, prop_dict) return output @@ -128,7 +129,8 @@ class ZFS(Plugin): ), ] ), - PythonMetric('dataset_config', resource_output, 'zfs', 'ZFS Datasets Configuration', serializable=False), + PythonMetric('dataset_config', resource_output, 'filesystem', 'ZFS Datasets Configuration', serializable=False), + PythonMetric('zvol_config', resource_output, 'volume', 'ZFS ZVOL Configuration', serializable=False), PythonMetric('pool_config', resource_output, 'zpool', 'ZFS Pools Configuration', serializable=False), ] serializable_metrics = [