blob: 5a6f5c4cd6a91be8795b3cbb0b67c1be62d3e73c [file] [log] [blame]
Dmitry Teselkin9b3097a2018-11-21 15:45:07 +03001def cast_dict_keys_to_int(x, *args, **kwargs):
2 '''
3 Return a dictionary with keys casted to int.
4 This usually is required when you want sort the dict later.
5
6 Jinja examples:
7
8 .. code-block: jinja
9
10 {%- set ruleset = salt['sharedlib.call']('misc.cast_dict_keys_to_int', c.get('ruleset', {})) %}
11
12 .. code-block:: jinja
13
14 {%- set func = salt['sharedlib.get']('misc.cast_dict_keys_to_int') %}
15 {%- for c_name, c in t.chains.items() %}
16 {%- set ruleset = func(c.get('ruleset', {})) %}
17 {%- for rule_id, r in ruleset | dictsort %}
18 ...
19 {%- endfor %}
20 '''
21 return dict([(int(key),value) for key,value in x.items()])
22