Merge pull request #445 from Ninpo/support-zfs-0.8.0
Support parsing zpool output for ZFS >=0.8.0
This commit is contained in:
commit
ff9ccee438
1 changed files with 17 additions and 2 deletions
|
@ -25,9 +25,12 @@ Be aware of security implications of doing this!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import logging
|
||||||
|
from pkg_resources import parse_version
|
||||||
import bumblebee.engine
|
import bumblebee.engine
|
||||||
from bumblebee.util import execute, bytefmt, asbool
|
from bumblebee.util import execute, bytefmt, asbool
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(bumblebee.engine.Module):
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
|
@ -63,7 +66,16 @@ class Module(bumblebee.engine.Module):
|
||||||
return state
|
return state
|
||||||
|
|
||||||
def _update_widgets(self, widgets):
|
def _update_widgets(self, widgets):
|
||||||
|
zfs_version_path = "/sys/module/zfs/version"
|
||||||
# zpool list -H: List all zpools, use script mode (no headers and tabs as separators).
|
# zpool list -H: List all zpools, use script mode (no headers and tabs as separators).
|
||||||
|
try:
|
||||||
|
with open(zfs_version_path, 'r') as zfs_mod_version:
|
||||||
|
zfs_version = zfs_mod_version.readline().rstrip().split('-')[0]
|
||||||
|
except IOError:
|
||||||
|
# ZFS isn't installed or the module isn't loaded, stub the version
|
||||||
|
zfs_version = "0.0.0"
|
||||||
|
logging.error("ZFS version information not found at {}, check the module is loaded.".format(zfs_version_path))
|
||||||
|
|
||||||
raw_zpools = execute(('sudo ' if self._usesudo else '') + 'zpool list -H').split('\n')
|
raw_zpools = execute(('sudo ' if self._usesudo else '') + 'zpool list -H').split('\n')
|
||||||
|
|
||||||
for widget in widgets:
|
for widget in widgets:
|
||||||
|
@ -71,8 +83,11 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
for raw_zpool in raw_zpools:
|
for raw_zpool in raw_zpools:
|
||||||
try:
|
try:
|
||||||
# Ignored fields (assigned to _) are "expandsz" and "altroot"
|
# Ignored fields (assigned to _) are "expandsz" and "altroot", also "ckpoint" in ZFS 0.8.0+
|
||||||
name, size, alloc, free, _, frag, cap, dedup, health, _ = raw_zpool.split('\t')
|
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('%')
|
cap = cap.rstrip('%')
|
||||||
percentuse=int(cap)
|
percentuse=int(cap)
|
||||||
percentfree=100-percentuse
|
percentfree=100-percentuse
|
||||||
|
|
Loading…
Reference in a new issue