def cast_dict_keys_to_int(x, *args, **kwargs): | |
''' | |
Return a dictionary with keys casted to int. | |
This usually is required when you want sort the dict later. | |
Jinja examples: | |
.. code-block: jinja | |
{%- set ruleset = salt['sharedlib.call']('misc.cast_dict_keys_to_int', c.get('ruleset', {})) %} | |
.. code-block:: jinja | |
{%- set func = salt['sharedlib.get']('misc.cast_dict_keys_to_int') %} | |
{%- for c_name, c in t.chains.items() %} | |
{%- set ruleset = func(c.get('ruleset', {})) %} | |
{%- for rule_id, r in ruleset | dictsort %} | |
... | |
{%- endfor %} | |
''' | |
return dict([(int(key),value) for key,value in x.items()]) | |