Correctly handle numbers in zfs module

This change will check if a value is a int or float and
convert the type accordingly.
This commit is contained in:
Jorge Schrauwen 2017-12-02 11:07:20 +01:00
parent a40f87b2b4
commit 4b0a353084

View File

@ -8,6 +8,7 @@ Salt interface to ZFS commands
from __future__ import absolute_import
# Import Python libs
import re
import logging
# Import Salt libs
@ -20,6 +21,10 @@ from salt.utils.odict import OrderedDict
__virtualname__ = 'zfs'
log = logging.getLogger(__name__)
# Precompiled regex for value transform
re_zfs_numb = re.compile("^(\d+|\d+(?=\d*)\.\d+)$")
# Function alias to set mapping.
__func_alias__ = {
'list_': 'list',
@ -375,7 +380,10 @@ def list_(name=None, **kwargs):
ds_data = {}
for prop in properties:
ds_data[prop] = ds[properties.index(prop)]
prop_value = ds[properties.index(prop)]
if re_zfs_numb.match(prop_value):
prop_value = float(prop_value) if '.' in prop_value else int(prop_value)
ds_data[prop] = prop_value
ret[ds_data['name']] = ds_data
del ret[ds_data['name']]['name']
@ -1263,7 +1271,10 @@ def get(*dataset, **kwargs):
ds_data = {}
for field in fields:
ds_data[field] = ds[fields.index(field)]
prop_value = ds[fields.index(field)]
if re_zfs_numb.match(prop_value):
prop_value = float(prop_value) if '.' in prop_value else int(prop_value)
ds_data[field] = prop_value
ds_name = ds_data['name']
ds_prop = ds_data['property']