Add multi-firewall dynamic targets (pfsense_connect, v1.1.0)
This commit is contained in:
@@ -15,27 +15,28 @@ from pfsense_mcp.guards import is_dry_run_response, require_writes
|
||||
|
||||
def register(mcp: FastMCP) -> None:
|
||||
@mcp.tool()
|
||||
def pfsense_list_dhcp_leases(limit: int = 200, offset: int = 0, query: str = "") -> str:
|
||||
def pfsense_list_dhcp_leases(limit: int = 200, offset: int = 0, query: str = "", target: str = "", url: str = "", api_key: str = "", verify_ssl: bool | None = None) -> str:
|
||||
"""List DHCP leases. query example: 'hostname__contains=nas' or 'ip__contains=10.77'."""
|
||||
client = get_client()
|
||||
client = get_client(target=target, url=url, api_key=api_key, verify_ssl=verify_ssl)
|
||||
result = client.get(
|
||||
"status/dhcp_server/leases", params=client.list_params(limit, offset, query)
|
||||
)
|
||||
return json.dumps(result, indent=2, default=str)
|
||||
|
||||
@mcp.tool()
|
||||
def pfsense_list_dhcp_servers(limit: int = 50, offset: int = 0) -> str:
|
||||
def pfsense_list_dhcp_servers(limit: int = 50, offset: int = 0, target: str = "", url: str = "", api_key: str = "", verify_ssl: bool | None = None) -> str:
|
||||
"""List DHCP server configurations per interface (ranges, options, enabled state)."""
|
||||
client = get_client()
|
||||
client = get_client(target=target, url=url, api_key=api_key, verify_ssl=verify_ssl)
|
||||
result = client.get("services/dhcp_servers", params={"limit": limit, "offset": offset})
|
||||
return json.dumps(result, indent=2, default=str)
|
||||
|
||||
@mcp.tool()
|
||||
def pfsense_list_dhcp_static_mappings(
|
||||
interface_id: str, limit: int = 200, offset: int = 0
|
||||
interface_id: str, limit: int = 200, offset: int = 0,
|
||||
target: str = "", url: str = "", api_key: str = "", verify_ssl: bool | None = None,
|
||||
) -> str:
|
||||
"""List DHCP static mappings (reservations) for a DHCP server. interface_id: parent interface (e.g. 'lan')."""
|
||||
client = get_client()
|
||||
client = get_client(target=target, url=url, api_key=api_key, verify_ssl=verify_ssl)
|
||||
result = client.get(
|
||||
"services/dhcp_server/static_mappings",
|
||||
params={"parent_id": interface_id, "limit": limit, "offset": offset},
|
||||
@@ -49,6 +50,10 @@ def register(mcp: FastMCP) -> None:
|
||||
ip: str,
|
||||
hostname: str = "",
|
||||
description: str = "",
|
||||
target: str = "",
|
||||
url: str = "",
|
||||
api_key: str = "",
|
||||
verify_ssl: bool | None = None,
|
||||
) -> str:
|
||||
"""Add a DHCP static mapping (reservation) on an interface's DHCP server."""
|
||||
payload: dict[str, Any] = {
|
||||
@@ -61,19 +66,19 @@ def register(mcp: FastMCP) -> None:
|
||||
if settings.dry_run:
|
||||
return json.dumps(is_dry_run_response("add_dhcp_static_mapping", payload), indent=2)
|
||||
require_writes("add_dhcp_static_mapping", payload)
|
||||
client = get_client()
|
||||
client = get_client(target=target, url=url, api_key=api_key, verify_ssl=verify_ssl)
|
||||
result = client.post("services/dhcp_server/static_mapping", data=payload)
|
||||
audit_log("add_dhcp_static_mapping", payload | {"result": result})
|
||||
return json.dumps(result, indent=2, default=str)
|
||||
|
||||
@mcp.tool()
|
||||
def pfsense_delete_dhcp_static_mapping(interface_id: str, mapping_id: int) -> str:
|
||||
def pfsense_delete_dhcp_static_mapping(interface_id: str, mapping_id: int, target: str = "", url: str = "", api_key: str = "", verify_ssl: bool | None = None) -> str:
|
||||
"""Delete a DHCP static mapping by id."""
|
||||
payload = {"parent_id": interface_id, "id": mapping_id}
|
||||
if settings.dry_run:
|
||||
return json.dumps(is_dry_run_response("delete_dhcp_static_mapping", payload), indent=2)
|
||||
require_writes("delete_dhcp_static_mapping", payload)
|
||||
client = get_client()
|
||||
client = get_client(target=target, url=url, api_key=api_key, verify_ssl=verify_ssl)
|
||||
result = client.delete("services/dhcp_server/static_mapping", params=payload)
|
||||
audit_log("delete_dhcp_static_mapping", payload | {"result": result})
|
||||
return json.dumps(result, indent=2, default=str)
|
||||
|
||||
Reference in New Issue
Block a user