2019-05-10 01:49:38 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: ft=jinja
|
|
|
|
|
2017-01-19 03:29:15 +01:00
|
|
|
{%- set key = 0 -%}
|
|
|
|
{%- set value = 1 -%}
|
2019-05-10 01:49:38 +02:00
|
|
|
{%- set carryovers = ['real_server', 'virtual_server', 'virtual_server_group', 'vrrp_instance', 'vrrp_script', 'vrrp_sync_group'] -%}
|
|
|
|
|
|
|
|
{%- macro print_config(data, carryover='', recurse=-1, indent=0) -%}
|
2017-01-19 02:40:19 +01:00
|
|
|
{%- set recurse = recurse + 1 -%}
|
2017-01-19 01:51:16 +01:00
|
|
|
{%- if data is none -%}
|
2017-01-19 02:40:19 +01:00
|
|
|
{{- '\n' -}}
|
|
|
|
{%- elif data is string or data is number -%}
|
2017-01-21 04:36:42 +01:00
|
|
|
{{- data|string|indent(indent, True) }}{{ '\n' -}}
|
2017-01-19 03:47:53 +01:00
|
|
|
{%- else -%}
|
2017-01-19 02:40:19 +01:00
|
|
|
{%- if recurse > 0 -%}
|
|
|
|
{{- '{\n' -}}
|
2017-01-21 04:36:42 +01:00
|
|
|
{%- set indent = indent + 2 -%}
|
2017-01-19 02:40:19 +01:00
|
|
|
{%- endif -%}
|
2017-01-19 03:47:53 +01:00
|
|
|
{%- if data is mapping -%}
|
|
|
|
{%- for item in data|dictsort -%}
|
2017-01-19 13:48:26 +01:00
|
|
|
{%- if item[key] in carryovers -%}
|
2019-05-10 01:49:38 +02:00
|
|
|
{{- print_config(item[value], carryover=item[key], indent=indent) -}}
|
2017-01-19 13:48:26 +01:00
|
|
|
{%- else -%}
|
2017-01-21 06:59:22 +01:00
|
|
|
{%- set carryIndent = indent -%}
|
|
|
|
{%- set forwardIndent = indent -%}
|
2017-01-19 13:48:26 +01:00
|
|
|
{%- if carryover -%}
|
2017-01-21 06:59:22 +01:00
|
|
|
{{- carryover|indent(indent, True) }}{{ ' ' -}}
|
2017-01-21 05:27:03 +01:00
|
|
|
{%- set carryIndent = 0 -%}
|
2017-01-19 13:48:26 +01:00
|
|
|
{%- endif -%}
|
2017-01-21 04:36:42 +01:00
|
|
|
{%- if item[value] is string or item[value] is not iterable -%}
|
2017-01-21 06:12:44 +01:00
|
|
|
{%- set forwardIndent = 0 -%}
|
2017-01-21 04:36:42 +01:00
|
|
|
{%- endif -%}
|
2019-05-10 01:49:38 +02:00
|
|
|
{{- item[key]|indent(carryIndent, True) }} {{ print_config(item[value], recurse=recurse, indent=forwardIndent) -}}
|
2017-01-19 13:48:26 +01:00
|
|
|
{%- endif -%}
|
2017-01-19 03:47:53 +01:00
|
|
|
{%- endfor -%}
|
|
|
|
{%- else -%}
|
|
|
|
{%- for item in data -%}
|
2019-05-10 01:49:38 +02:00
|
|
|
{{- print_config(item, indent=indent) -}}
|
2017-01-19 03:47:53 +01:00
|
|
|
{%- endfor -%}
|
2017-01-19 03:38:51 +01:00
|
|
|
{%- endif -%}
|
|
|
|
{%- if recurse > 0 -%}
|
2017-01-21 05:27:03 +01:00
|
|
|
{{- '}'|indent(indent - 2, True) -}}{{ '\n' }}
|
2017-01-19 03:38:51 +01:00
|
|
|
{%- endif -%}
|
2017-01-19 01:51:16 +01:00
|
|
|
{%- endif -%}
|
|
|
|
{%- endmacro -%}
|