octavia/octavia/common/jinja/lvs/templates/macros.j2

135 lines
5.4 KiB
Django/Jinja

{# Copyright (c) 2018 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
#}
{%- macro lb_algo_macro(pool) -%}
lb_algo {{ pool.lb_algorithm }}
{%- endmacro -%}
{% macro misc_path_macro(member, health_monitor) -%}
misc_path "{{ health_monitor.check_script_path }} {{ member.monitor_address|default(member.address, true) }} {{ member.monitor_port|default(member.protocol_port, true) }}"
{%- endmacro %}
{%- macro misc_check_macro(pool, member, health_monitor) -%}
MISC_CHECK {
{{ misc_path_macro(member, health_monitor) }}
misc_timeout {{ pool.health_monitor.timeout }}
}
{%- endmacro -%}
{%- macro http_url_macro(health_monitor, health_monitor_status_code) %}
url {
path {{ health_monitor.url_path }}
status_code {{ health_monitor_status_code }}
}
{% endmacro -%}
{%- macro http_get_macro(pool, member, health_monitor) -%}
HTTP_GET {
{% for status_code in health_monitor.expected_codes %}
{{ http_url_macro(health_monitor, status_code) -}}
{% endfor %}
connect_ip {{ member.monitor_address|default(member.address, true) }}
connect_port {{ member.monitor_port|default(member.protocol_port, true) }}
connect_timeout {{ health_monitor.timeout }}
}
{%- endmacro -%}
{%- macro tcp_check_macro(pool, member, health_monitor) -%}
TCP_CHECK {
connect_ip {{ member.monitor_address|default(member.address, true) }}
connect_port {{ member.monitor_port|default(member.protocol_port, true) }}
connect_timeout {{ health_monitor.timeout }}
}
{%- endmacro -%}
{% macro health_monitor_rs_macro(constants, pool, member) %}
{% if pool.health_monitor and pool.health_monitor.enabled %}
{% if pool.health_monitor.type == constants.HEALTH_MONITOR_UDP_CONNECT %}
{{ misc_check_macro(pool, member, pool.health_monitor) -}}
{% elif pool.health_monitor.type == constants.HEALTH_MONITOR_HTTP and pool.health_monitor.http_method == constants.HEALTH_MONITOR_HTTP_METHOD_GET %}
{{ http_get_macro(pool, member, pool.health_monitor) -}}
{% elif pool.health_monitor.type == constants.HEALTH_MONITOR_TCP %}
{{ tcp_check_macro(pool, member, pool.health_monitor) -}}
{% endif %}
{% endif %}
{% endmacro %}
{% macro realserver_macro(constants, pool, member, listener) %}
{% if member.enabled %}
# Configuration for Member {{ member.id }}
real_server {{ member.address }} {{ member.protocol_port }} {
weight {{ member.weight }}
{% if listener.connection_limit %}
uthreshold {{ listener.connection_limit }}
{% endif %}
{{- health_monitor_rs_macro(constants, pool, member) }}
}
{% else %}
# Member {{ member.id }} is disabled
{% endif %}
{% endmacro %}
{% macro health_monitor_vs_macro(default_pool) %}
{% if default_pool and default_pool.health_monitor and default_pool.health_monitor.enabled %}
delay_loop {{ default_pool.health_monitor.delay }}
delay_before_retry {{ default_pool.health_monitor.delay }}
{% if default_pool.health_monitor.fall_threshold %}
retry {{ default_pool.health_monitor.fall_threshold }}
{% endif %}
{% endif %}
{% endmacro %}
{% macro virtualserver_macro(constants, listener, lb_vip_address, default_pool) %}
{% set need_render = [] %}
{% if default_pool and default_pool.enabled and default_pool.members %}
{% for member in default_pool.members %}
{% do need_render.append(member.enabled) %}
{% endfor %}
{% endif %}
{% if need_render|length > 0 %}
virtual_server {{ lb_vip_address }} {{ listener.protocol_port }} {
{{ lb_algo_macro(default_pool) }}
lb_kind NAT
protocol {{ listener.protocol_mode.upper() }}
{% if default_pool.session_persistence and default_pool.session_persistence.type == constants.SESSION_PERSISTENCE_SOURCE_IP %}
{# set our defined defaults as I saw this not be consistent #}
{# in testing #}
{% if default_pool.session_persistence.persistence_timeout %}
persistence_timeout {{ default_pool.session_persistence.persistence_timeout }}
{% else %}
persistence_timeout 360
{% endif %}
{% if default_pool.session_persistence.persistence_granularity %}
persistence_granularity {{ default_pool.session_persistence.persistence_granularity }}
{% else %}
persistence_granularity 255.255.255.255
{% endif %}
{% endif %}
{{ health_monitor_vs_macro(default_pool) }}
{% if default_pool.protocol.lower() == "udp" %}
# Configuration for Pool {{ default_pool.id }}
{% if default_pool.health_monitor and default_pool.health_monitor.enabled %}
# Configuration for HealthMonitor {{ default_pool.health_monitor.id }}
{% endif %}
{% for member in default_pool.members %}
{{- realserver_macro(constants, default_pool, member, listener) }}
{% endfor %}
{% endif %}
}
{% endif %}
{% endmacro %}