feat: Add pool sharing for domains

Allow multiple domains to share the same backend pool using share_with parameter.
This saves pool slots when domains point to the same servers.

- Add share_with parameter to haproxy_add_domain
- Add helper functions for shared domain management
- Protect shared pools from being cleared on domain removal
- Update documentation with pool sharing examples

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kaffa
2026-02-05 00:34:22 +09:00
parent 95ab0583b3
commit 4a411202d3
4 changed files with 133 additions and 9 deletions

View File

@@ -332,6 +332,63 @@ def remove_domain_from_config(domain: str) -> None:
save_servers_config(config)
def get_shared_domain(domain: str) -> Optional[str]:
"""Get the parent domain that this domain shares a pool with.
Args:
domain: Domain name to check
Returns:
Parent domain name if sharing, None otherwise
"""
config = load_servers_config()
domain_config = config.get(domain, {})
return domain_config.get("_shares")
def add_shared_domain_to_config(domain: str, shares_with: str) -> None:
"""Add a domain that shares a pool with another domain.
Args:
domain: New domain name
shares_with: Existing domain to share pool with
"""
with file_lock(f"{SERVERS_FILE}.lock"):
config = load_servers_config()
config[domain] = {"_shares": shares_with}
save_servers_config(config)
def get_domains_sharing_pool(pool: str) -> list[str]:
"""Get all domains that use a specific pool.
Args:
pool: Pool name (e.g., 'pool_5')
Returns:
List of domain names using this pool
"""
domains = []
for domain, backend in get_map_contents():
if backend == pool and not domain.startswith("."):
domains.append(domain)
return domains
def is_shared_domain(domain: str) -> bool:
"""Check if a domain is sharing another domain's pool.
Args:
domain: Domain name to check
Returns:
True if domain has _shares reference, False otherwise
"""
config = load_servers_config()
domain_config = config.get(domain, {})
return "_shares" in domain_config
# Certificate configuration functions
def load_certs_config() -> list[str]: