Added the first of the carryovers.

This commit is contained in:
Jeff Baskin 2017-01-19 07:48:26 -05:00
parent 4c329515f7
commit 671f64b672
2 changed files with 16 additions and 3 deletions

View File

@ -1,6 +1,7 @@
{%- set key = 0 -%}
{%- set value = 1 -%}
{%- macro keepalived_config(data, recurse=-1) -%}
{%- set carryovers = ['vrrp_script'] -%}
{%- macro keepalived_config(data, carryover='', recurse=-1) -%}
{%- set recurse = recurse + 1 -%}
{%- if data is none -%}
{{- '\n' -}}
@ -12,7 +13,14 @@
{%- endif -%}
{%- if data is mapping -%}
{%- for item in data|dictsort -%}
{{- item[key] }} {{ keepalived_config(item[value], recurse) -}}
{%- if item[key] in carryovers -%}
{{- keepalived_config(item[value], carryover=item[key]) -}}
{%- else -%}
{%- if carryover -%}
{{- carryover }}{{ ' ' -}}
{%- endif -%}
{{- item[key] }} {{ keepalived_config(item[value], recurse=recurse) -}}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{%- for item in data -%}

View File

@ -59,5 +59,10 @@ class TestKeepalivedConfiguration(unittest.TestCase):
result = 'fred flintstone\nwilma flintstone\nbarney rubble\nbetty rubble\n'
self.renderTest(testdata, result)
def test_carryover(self):
testdata = {'vrrp_script': {'gizmo': {'fred': 'flintstone', 'barney': 'rubble'}}}
result = 'vrrp_script gizmo {\nbarney rubble\nfred flintstone\n}\n'
self.renderTest(testdata, result)
if __name__ == '__main__':
unittest.main()