blob: ebdb4dc5caf845e2812ffd869ff821c044c38d67 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from functools import partial
from ansible import errors
from ansible.module_utils.common.text import formatters
def dehumanize_zfs_properties(data):
''' zfs module sometimes wrongly indicates changed=true in check mode if sizes use human-readable format '''
try:
from jinja2.runtime import Undefined
if isinstance(data, Undefined):
return data
for prop, value in data.items():
if prop in ['quota', 'refquota', 'reservation', 'refreservation', 'recordsize', 'volsize']:
data[prop] = str(formatters.human_to_bytes(value))
return data
except Exception as e:
raise errors.AnsibleFilterError("dehumanize_zfs_properties(): %s" % str(e))
class FilterModule(object):
''' zfs filters '''
filter_map = {
'dehumanize_zfs_properties': dehumanize_zfs_properties,
}
def filters(self):
return self.filter_map
|