dns: switch to active upstream pool and wave fallback behavior
This commit is contained in:
@@ -259,6 +259,11 @@ class DNSBenchmarkResponse:
|
||||
recommended_meta: List[str]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class DNSUpstreamPoolState:
|
||||
items: List[DNSBenchmarkUpstream]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SmartdnsServiceState:
|
||||
state: str
|
||||
@@ -1185,6 +1190,48 @@ class ApiClient:
|
||||
},
|
||||
)
|
||||
|
||||
def dns_upstream_pool_get(self) -> DNSUpstreamPoolState:
|
||||
data = cast(Dict[str, Any], self._json(self._request("GET", "/api/v1/dns/upstream-pool")) or {})
|
||||
raw = data.get("items") or []
|
||||
if not isinstance(raw, list):
|
||||
raw = []
|
||||
items: List[DNSBenchmarkUpstream] = []
|
||||
for row in raw:
|
||||
if not isinstance(row, dict):
|
||||
continue
|
||||
addr = str(row.get("addr") or "").strip()
|
||||
if not addr:
|
||||
continue
|
||||
items.append(DNSBenchmarkUpstream(addr=addr, enabled=bool(row.get("enabled", True))))
|
||||
return DNSUpstreamPoolState(items=items)
|
||||
|
||||
def dns_upstream_pool_set(self, items: List[DNSBenchmarkUpstream]) -> DNSUpstreamPoolState:
|
||||
data = cast(
|
||||
Dict[str, Any],
|
||||
self._json(
|
||||
self._request(
|
||||
"POST",
|
||||
"/api/v1/dns/upstream-pool",
|
||||
json_body={
|
||||
"items": [{"addr": u.addr, "enabled": bool(u.enabled)} for u in (items or [])],
|
||||
},
|
||||
)
|
||||
)
|
||||
or {},
|
||||
)
|
||||
raw = data.get("items") or []
|
||||
if not isinstance(raw, list):
|
||||
raw = []
|
||||
out: List[DNSBenchmarkUpstream] = []
|
||||
for row in raw:
|
||||
if not isinstance(row, dict):
|
||||
continue
|
||||
addr = str(row.get("addr") or "").strip()
|
||||
if not addr:
|
||||
continue
|
||||
out.append(DNSBenchmarkUpstream(addr=addr, enabled=bool(row.get("enabled", True))))
|
||||
return DNSUpstreamPoolState(items=out)
|
||||
|
||||
def dns_benchmark(
|
||||
self,
|
||||
upstreams: List[DNSBenchmarkUpstream],
|
||||
|
||||
Reference in New Issue
Block a user