refactor: update all API blueprints (certs, dhcp, firewall, logs, network, proxy, wireguard)
This commit is contained in:
+27
-8
@@ -9,6 +9,16 @@ import logging
|
||||
from flask import Blueprint, request
|
||||
|
||||
from daemon.client import NotFound, get, post
|
||||
from daemon.iface import (
|
||||
GET_NETWORK_INFER_DHCP_RANGES,
|
||||
GET_NETWORK_INFER_ZONES,
|
||||
GET_NETWORK_INTERFACE_NAME,
|
||||
GET_NETWORK_INTERFACES,
|
||||
POST_NETWORK_APPLY,
|
||||
POST_NETWORK_INTERFACE_NAME,
|
||||
POST_NETWORK_INTERFACE_RELOAD,
|
||||
)
|
||||
from lib.common import validate_interface_name
|
||||
from webui.api.common import _error, _ok
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -26,7 +36,7 @@ def list_interfaces():
|
||||
JSON with interface config + runtime state.
|
||||
"""
|
||||
try:
|
||||
return _ok(get("/network/interfaces"))
|
||||
return _ok(get(GET_NETWORK_INTERFACES))
|
||||
except RuntimeError as exc:
|
||||
logger.error("Failed to list network interfaces: %s", exc)
|
||||
return _error(str(exc), 500)
|
||||
@@ -43,7 +53,10 @@ def get_interface(name: str):
|
||||
JSON with interface config and runtime state.
|
||||
"""
|
||||
try:
|
||||
return _ok(get("/network/interfaces/" + name, {"name": name}))
|
||||
validate_interface_name(name)
|
||||
return _ok(get(GET_NETWORK_INTERFACE_NAME, {"name": name}))
|
||||
except ValueError as exc:
|
||||
return _error(str(exc), 400)
|
||||
except NotFound as exc:
|
||||
logger.info("Interface '%s' not found: %s", name, exc)
|
||||
return _error(str(exc), 404)
|
||||
@@ -65,11 +78,14 @@ def save_interface(name: str):
|
||||
Returns:
|
||||
JSON confirmation.
|
||||
"""
|
||||
body = request.get_json(silent=True) or {}
|
||||
body = {**(request.get_json(silent=True) or {}), "name": name}
|
||||
try:
|
||||
post("/network/interfaces/" + name, body)
|
||||
validate_interface_name(name)
|
||||
post(POST_NETWORK_INTERFACE_NAME, body)
|
||||
logger.info("Interface '%s' config saved", name)
|
||||
return _ok({"name": name, "applied": True})
|
||||
except ValueError as exc:
|
||||
return _error(str(exc), 400)
|
||||
except NotFound as exc:
|
||||
return _error(str(exc), 404)
|
||||
except RuntimeError as exc:
|
||||
@@ -88,9 +104,12 @@ def reload_interface(name: str):
|
||||
JSON confirmation.
|
||||
"""
|
||||
try:
|
||||
post("/network/interfaces/" + name + "/reload", {"name": name})
|
||||
validate_interface_name(name)
|
||||
post(POST_NETWORK_INTERFACE_RELOAD, {"name": name})
|
||||
logger.info("Interface '%s' reloaded", name)
|
||||
return _ok({"name": name, "reloaded": True})
|
||||
except ValueError as exc:
|
||||
return _error(str(exc), 400)
|
||||
except RuntimeError as exc:
|
||||
logger.error("Failed to reload interface '%s': %s", name, exc)
|
||||
return _error(str(exc), 500)
|
||||
@@ -107,7 +126,7 @@ def apply_all():
|
||||
JSON with number of interfaces applied.
|
||||
"""
|
||||
try:
|
||||
result = post("/network/apply", {})
|
||||
result = post(POST_NETWORK_APPLY, {})
|
||||
logger.info("Network config applied: %d interfaces", result.get("applied", 0))
|
||||
return _ok(result)
|
||||
except RuntimeError as exc:
|
||||
@@ -126,7 +145,7 @@ def infer_dhcp_ranges():
|
||||
JSON with per-interface suggested DHCP ranges.
|
||||
"""
|
||||
try:
|
||||
return _ok(get("/network/infer-dhcp-ranges"))
|
||||
return _ok(get(GET_NETWORK_INFER_DHCP_RANGES))
|
||||
except RuntimeError as exc:
|
||||
logger.error("Failed to infer DHCP ranges: %s", exc)
|
||||
return _error(str(exc), 500)
|
||||
@@ -143,7 +162,7 @@ def infer_zones():
|
||||
JSON with per-interface suggested zone names.
|
||||
"""
|
||||
try:
|
||||
return _ok(get("/network/infer-zones"))
|
||||
return _ok(get(GET_NETWORK_INFER_ZONES))
|
||||
except RuntimeError as exc:
|
||||
logger.error("Failed to infer zones: %s", exc)
|
||||
return _error(str(exc), 500)
|
||||
|
||||
Reference in New Issue
Block a user