From a40f87b2b449bafe25c84152431872b4c754859d Mon Sep 17 00:00:00 2001 From: Jorge Schrauwen Date: Sat, 2 Dec 2017 10:48:39 +0100 Subject: [PATCH] Allow request of parsable output in zfs module This commit updates salt.modules.zfs to allow requesting parsable output for ```zfs.list``` and ```zfs.get```. This requires for the salt.stats.zfs to be able to correctly handle multiple ways of formatting values as mentioned in #44404 --- salt/modules/zfs.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/salt/modules/zfs.py b/salt/modules/zfs.py index da1de85844..eeb0e2446c 100644 --- a/salt/modules/zfs.py +++ b/salt/modules/zfs.py @@ -292,7 +292,7 @@ def rename(name, new_name, **kwargs): def list_(name=None, **kwargs): ''' .. versionadded:: 2015.5.0 - .. versionchanged:: 2016.3.0 + .. versionchanged:: Oxygen Return a list of all datasets or a specified dataset on the system and the values of their used, available, referenced, and mountpoint properties. @@ -312,6 +312,9 @@ def list_(name=None, **kwargs): property to sort on (default = name) order : string [ascending|descending] sort order (default = ascending) + parsable : boolean + display numbers in parsable (exact) values + .. versionadded:: Oxygen CLI Example: @@ -329,8 +332,13 @@ def list_(name=None, **kwargs): sort = kwargs.get('sort', None) ltype = kwargs.get('type', None) order = kwargs.get('order', 'ascending') + parsable = kwargs.get('parsable', False) cmd = '{0} list -H'.format(zfs) + # parsable output + if parsable: + cmd = '{0} -p'.format(cmd) + # filter on type if ltype: cmd = '{0} -t {1}'.format(cmd, ltype) @@ -1164,6 +1172,7 @@ def set(*dataset, **kwargs): def get(*dataset, **kwargs): ''' .. versionadded:: 2016.3.0 + .. versionchanged:: Oxygen Displays properties for the given datasets. @@ -1183,6 +1192,9 @@ def get(*dataset, **kwargs): source : string comma-separated list of sources to display. Must be one of the following: local, default, inherited, temporary, and none. The default value is all sources. + parsable : boolean + display numbers in parsable (exact) values + .. versionadded:: Oxygen .. note:: @@ -1206,8 +1218,13 @@ def get(*dataset, **kwargs): fields = kwargs.get('fields', 'value,source') ltype = kwargs.get('type', None) source = kwargs.get('source', None) + parsable = kwargs.get('parsable', False) cmd = '{0} get -H'.format(zfs) + # parsable output + if parsable: + cmd = '{0} -p'.format(cmd) + # recursively get if depth: cmd = '{0} -d {1}'.format(cmd, depth)