From 3a2fcb1abfb79ddb3dd943f09f2bf203f335b6c4 Mon Sep 17 00:00:00 2001 From: Alex Boag-Munroe Date: Thu, 26 Sep 2019 00:25:18 +0100 Subject: [PATCH] Support parsing zpool output for ZFS >=0.8.0 Query /sys/module/zfs/version for ZFS version and account for the additional CKPOINT field in ZFS 0.8.0 and higher. --- bumblebee/modules/zpool.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bumblebee/modules/zpool.py b/bumblebee/modules/zpool.py index 701c1c1..5b6092a 100644 --- a/bumblebee/modules/zpool.py +++ b/bumblebee/modules/zpool.py @@ -25,6 +25,7 @@ Be aware of security implications of doing this! """ import time +from pkg_resources import parse_version import bumblebee.engine from bumblebee.util import execute, bytefmt, asbool @@ -64,6 +65,8 @@ class Module(bumblebee.engine.Module): def _update_widgets(self, widgets): # zpool list -H: List all zpools, use script mode (no headers and tabs as separators). + with open('/sys/module/zfs/version', 'r') as zfs_mod_version: + zfs_version = zfs_mod_version.readline().rstrip().split('-')[0] raw_zpools = execute(('sudo ' if self._usesudo else '') + 'zpool list -H').split('\n') for widget in widgets: @@ -71,8 +74,11 @@ class Module(bumblebee.engine.Module): for raw_zpool in raw_zpools: try: - # Ignored fields (assigned to _) are "expandsz" and "altroot" - name, size, alloc, free, _, frag, cap, dedup, health, _ = raw_zpool.split('\t') + # Ignored fields (assigned to _) are "expandsz" and "altroot", also "ckpoint" in ZFS 0.8.0+ + if parse_version(zfs_version) < parse_version("0.8.0"): + name, size, alloc, free, _, frag, cap, dedup, health, _ = raw_zpool.split('\t') + else: + name, size, alloc, free, _, _, frag, cap, dedup, health, _ = raw_zpool.split('\t') cap = cap.rstrip('%') percentuse=int(cap) percentfree=100-percentuse