Hide empty server slots (0.0.0.0) from list_servers output
Only show servers with actual IP addresses. Empty slots are HAProxy pre-allocated placeholders that add noise to the output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -73,9 +73,12 @@ def _haproxy_list_servers_impl(domain: str) -> str:
|
|||||||
for server_name, srv_info in backend_servers.items():
|
for server_name, srv_info in backend_servers.items():
|
||||||
addr = srv_info["addr"]
|
addr = srv_info["addr"]
|
||||||
port = srv_info["port"]
|
port = srv_info["port"]
|
||||||
status = "active" if addr != "0.0.0.0" else "disabled"
|
if addr == "0.0.0.0":
|
||||||
servers.append(f"• {server_name}: {addr}:{port} ({status})")
|
continue
|
||||||
|
servers.append(f"• {server_name}: {addr}:{port}")
|
||||||
|
|
||||||
|
if not servers:
|
||||||
|
return f"No active servers for {domain} ({backend})"
|
||||||
return f"Servers for {domain} ({backend}):\n" + "\n".join(servers)
|
return f"Servers for {domain} ({backend}):\n" + "\n".join(servers)
|
||||||
except (HaproxyError, ValueError) as e:
|
except (HaproxyError, ValueError) as e:
|
||||||
return f"Error: {e}"
|
return f"Error: {e}"
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ class TestHaproxyListServers:
|
|||||||
|
|
||||||
result = registered_tools["haproxy_list_servers"](domain="example.com")
|
result = registered_tools["haproxy_list_servers"](domain="example.com")
|
||||||
|
|
||||||
|
assert "No active servers" in result
|
||||||
assert "pool_1" in result
|
assert "pool_1" in result
|
||||||
assert "disabled" in result
|
|
||||||
|
|
||||||
def test_list_servers_with_active_servers(self, mock_socket_class, mock_select, patch_config_paths, response_builder):
|
def test_list_servers_with_active_servers(self, mock_socket_class, mock_select, patch_config_paths, response_builder):
|
||||||
"""List servers with active servers."""
|
"""List servers with active servers."""
|
||||||
@@ -90,7 +90,6 @@ class TestHaproxyListServers:
|
|||||||
|
|
||||||
assert "10.0.0.1" in result
|
assert "10.0.0.1" in result
|
||||||
assert "10.0.0.2" in result
|
assert "10.0.0.2" in result
|
||||||
assert "active" in result
|
|
||||||
|
|
||||||
|
|
||||||
class TestHaproxyAddServer:
|
class TestHaproxyAddServer:
|
||||||
|
|||||||
Reference in New Issue
Block a user