From 671f64b67284f507aa3fd73166fa683b2af457e5 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Thu, 19 Jan 2017 07:48:26 -0500 Subject: [PATCH] Added the first of the carryovers. --- keepalived/templates/config.jinja | 14 +++++++++++--- test/test_keepalived_config.py | 5 +++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/keepalived/templates/config.jinja b/keepalived/templates/config.jinja index fe0b3e3..81f3cd9 100644 --- a/keepalived/templates/config.jinja +++ b/keepalived/templates/config.jinja @@ -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 -%} @@ -20,7 +28,7 @@ {%- endfor -%} {%- endif -%} {%- if recurse > 0 -%} - {{- '}\n' -}} + {{- '}\n' -}} {%- endif -%} {%- endif -%} {%- endmacro -%} diff --git a/test/test_keepalived_config.py b/test/test_keepalived_config.py index 30abe51..091e2c7 100755 --- a/test/test_keepalived_config.py +++ b/test/test_keepalived_config.py @@ -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()