new options

This commit is contained in:
Mateusz Gruszczyński
2025-11-03 10:53:52 +01:00
parent 45d8634f08
commit 82f335020b

View File

@@ -96,7 +96,6 @@ def update_haproxy_config(frontend_name, frontend_ip, frontend_port, lb_method,
if is_backend_exist(backend_name): if is_backend_exist(backend_name):
return f"Backend {backend_name} already exists. Cannot add duplicate." return f"Backend {backend_name} already exists. Cannot add duplicate."
# Tryb no-lb - prosty frontend→backend z pojedynczym serwerem
is_no_lb = lb_method == 'no-lb' is_no_lb = lb_method == 'no-lb'
if is_no_lb and len(backend_servers) > 1: if is_no_lb and len(backend_servers) > 1:
backend_servers = backend_servers[:1] backend_servers = backend_servers[:1]
@@ -130,7 +129,6 @@ def update_haproxy_config(frontend_name, frontend_ip, frontend_port, lb_method,
acl_name_sanitized = f"is_{sanitize_name(frontend_hostname)}" acl_name_sanitized = f"is_{sanitize_name(frontend_hostname)}"
haproxy_cfg.write(f" acl {acl_name_sanitized} hdr(host) -i {frontend_hostname}\n") haproxy_cfg.write(f" acl {acl_name_sanitized} hdr(host) -i {frontend_hostname}\n")
# W trybie no-lb używamy prostych nagłówków HTTP-request
if is_no_lb: if is_no_lb:
haproxy_cfg.write(f" http-request set-header X-Forwarded-For %[src]\n") haproxy_cfg.write(f" http-request set-header X-Forwarded-For %[src]\n")
if use_ssl: if use_ssl:
@@ -211,7 +209,6 @@ def update_haproxy_config(frontend_name, frontend_ip, frontend_port, lb_method,
# ===== PRIMARY BACKEND ===== # ===== PRIMARY BACKEND =====
haproxy_cfg.write(f"\nbackend {backend_name}\n") haproxy_cfg.write(f"\nbackend {backend_name}\n")
# Balance tylko dla standardowego trybu
if not is_no_lb: if not is_no_lb:
haproxy_cfg.write(f" balance {lb_method}\n") haproxy_cfg.write(f" balance {lb_method}\n")
@@ -247,7 +244,10 @@ def update_haproxy_config(frontend_name, frontend_ip, frontend_port, lb_method,
if is_backend_exist(ssl_redirect_backend_name): if is_backend_exist(ssl_redirect_backend_name):
return f"Redirect backend {ssl_redirect_backend_name} already exists. Cannot add duplicate." return f"Redirect backend {ssl_redirect_backend_name} already exists. Cannot add duplicate."
haproxy_cfg.write(f"\nfrontend redirect_https\n") # Generate unique name for redirect frontend
redirect_frontend_name = f"redirect_https_{sanitize_name(frontend_hostname)}" if frontend_hostname else f"redirect_https_{frontend_name}"
haproxy_cfg.write(f"\nfrontend {redirect_frontend_name}\n")
haproxy_cfg.write(f" bind {frontend_ip}:{ssl_redirect_port}\n") haproxy_cfg.write(f" bind {frontend_ip}:{ssl_redirect_port}\n")
haproxy_cfg.write(f" mode http\n") haproxy_cfg.write(f" mode http\n")