Files
haproxy-openmanager/backend/models/backend.py
T
taylanbakircioglu 0fc18fde38 feat: Add HAProxy options support for backends and frontends
Implemented comprehensive HAProxy options field support for both backend and frontend entities to enable standard HAProxy directives like 'option http-keep-alive', 'option httplog', 'option forwardfor', etc.

Changes:
- Database: Added 'options' TEXT column to backends and frontends tables
- Models: Added options field to BackendConfig, BackendConfigUpdate, and FrontendConfig
- API Endpoints: Updated CREATE, UPDATE, and GET endpoints to handle options field
  * Backend: CREATE/UPDATE/GET with options support
  * Frontend: CREATE/UPDATE/GET with options support (fixed 5 SELECT queries)
- Config Generator: Added options block generation for both backends and frontends
- Bulk Import Parser:
  * Added options field to ParsedBackend and ParsedFrontend dataclasses
  * Implemented option directive parsing with validation
  * Added unknown option warnings
  * Fixed bulk parse response to include options field
- Bulk Import Merge: Added options field comparison in UPDATE logic
- UI Components:
  * BackendServers.js: Added options TextArea form field
  * FrontendManagement.js: Added options TextArea form field

Features:
- Multi-line options support (newline-separated format)
- Option validation with known HAProxy options list
- Backward compatible (NULL options for existing entities)
- Bulk import support with merge strategy
- Full CRUD support for both manual and bulk operations

Technical Details:
- Format: Newline-separated TEXT field for multiple options
- Validation: Warns about unknown options but allows them
- Config Generation: Each option written as separate directive
- Agent: Standard HAProxy config validation applies

Total: 10 files modified, ~195 lines added, 26 integration points verified
2025-11-13 10:12:30 +03:00

87 lines
3.3 KiB
Python

from pydantic import BaseModel, validator
from typing import Optional, List
class ServerConfig(BaseModel):
server_name: str
server_address: str
server_port: int
weight: int = 100
max_connections: Optional[int] = None
check_enabled: bool = True
check_port: Optional[int] = None
backup_server: bool = False
ssl_enabled: bool = False
ssl_verify: Optional[str] = None
ssl_certificate_id: Optional[int] = None # SSL certificate for backend server
cookie_value: Optional[str] = None
inter: Optional[int] = None
fall: Optional[int] = None
rise: Optional[int] = None
is_active: bool = True
class BackendConfig(BaseModel):
name: str
cluster_id: int
balance_method: str = 'roundrobin'
mode: str = 'http'
health_check_uri: Optional[str] = None
health_check_interval: Optional[int] = 2000
health_check_expected_status: Optional[int] = 200
fullconn: Optional[int] = None
cookie_name: Optional[str] = None
cookie_options: Optional[str] = None
default_server_inter: Optional[int] = None
default_server_fall: Optional[int] = None
default_server_rise: Optional[int] = None
request_headers: Optional[str] = None
response_headers: Optional[str] = None
timeout_connect: Optional[int] = 10000
timeout_server: Optional[int] = 60000
timeout_queue: Optional[int] = 60000
options: Optional[str] = None
servers: List[ServerConfig] = []
@validator('health_check_interval', 'timeout_connect', 'timeout_server', 'timeout_queue', 'fullconn')
def check_positive(cls, v):
if v is not None and v <= 0:
raise ValueError('Timeout, interval, and connection values must be positive')
return v
@validator('health_check_expected_status')
def check_http_status(cls, v):
if v is not None and (v < 100 or v > 599):
raise ValueError('HTTP status code must be between 100 and 599')
return v
class BackendConfigUpdate(BaseModel):
name: Optional[str] = None
balance_method: Optional[str] = None
mode: Optional[str] = None
health_check_uri: Optional[str] = None
health_check_interval: Optional[int] = None
health_check_expected_status: Optional[int] = None
fullconn: Optional[int] = None
cookie_name: Optional[str] = None
cookie_options: Optional[str] = None
default_server_inter: Optional[int] = None
default_server_fall: Optional[int] = None
default_server_rise: Optional[int] = None
request_headers: Optional[str] = None
response_headers: Optional[str] = None
timeout_connect: Optional[int] = None
timeout_server: Optional[int] = None
timeout_queue: Optional[int] = None
options: Optional[str] = None
servers: Optional[List[ServerConfig]] = None
@validator('health_check_interval', 'timeout_connect', 'timeout_server', 'timeout_queue', 'fullconn')
def check_positive_update(cls, v):
if v is not None and v <= 0:
raise ValueError('Timeout, interval, and connection values must be positive')
return v
@validator('health_check_expected_status')
def check_http_status_update(cls, v):
if v is not None and (v < 100 or v > 599):
raise ValueError('HTTP status code must be between 100 and 599')
return v