Added key hash pairs.
This commit is contained in:
parent
d66a776ddb
commit
f96a5b9b4b
@ -1,17 +1,24 @@
|
|||||||
{%- macro keepalived_config(data) -%}
|
{%- macro keepalived_config(data, recurse=-1) -%}
|
||||||
|
{%- set recurse = recurse + 1 -%}
|
||||||
{%- if data is none -%}
|
{%- if data is none -%}
|
||||||
{{ '\n' }}
|
{{- '\n' -}}
|
||||||
{%- elif data is mapping -%}
|
|
||||||
{%- for key, value in data.iteritems() -%}
|
|
||||||
{{ key }} {{ keepalived_config(value) }}
|
|
||||||
{%- endfor -%}
|
|
||||||
{%- elif data is string or data is number -%}
|
{%- elif data is string or data is number -%}
|
||||||
{{ data }}{{ '\n' }}
|
{{- data }}{{ '\n' -}}
|
||||||
{%- else -%}
|
{%- elif data is mapping -%}
|
||||||
{{ '{\n' }}
|
{%- if recurse > 0 -%}
|
||||||
{%- for value in data -%}
|
{{- '{\n' -}}
|
||||||
{{ keepalived_config(value) }}
|
{%- endif -%}
|
||||||
|
{%- for key, value in data.iteritems() -%}
|
||||||
|
{{- key }} {{ keepalived_config(value, recurse) -}}
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
{{ '}\n' }}
|
{%- if recurse > 0 -%}
|
||||||
|
{{- '}\n' -}}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- else -%}
|
||||||
|
{{- '{\n' -}}
|
||||||
|
{%- for value in data -%}
|
||||||
|
{{- keepalived_config(value) -}}
|
||||||
|
{%- endfor -%}
|
||||||
|
{{- '}\n' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endmacro -%}
|
{%- endmacro -%}
|
||||||
|
@ -44,5 +44,10 @@ class TestKeepalivedConfiguration(unittest.TestCase):
|
|||||||
result = 'flintstone {\nfred\nwilma\npebbles\n}\n'
|
result = 'flintstone {\nfred\nwilma\npebbles\n}\n'
|
||||||
self.renderTest(testdata, result)
|
self.renderTest(testdata, result)
|
||||||
|
|
||||||
|
def test_key_hash_pair(self):
|
||||||
|
testdata = {'friends': {'rubble': 'barney'}}
|
||||||
|
result = 'friends {\nrubble barney\n}\n'
|
||||||
|
self.renderTest(testdata, result)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user