feat: Vultr/DO/Cloudflare适配器分页处理(避免多VPS/域名同步遗漏)+ 分页测试

This commit is contained in:
gouki
2026-08-02 17:59:51 +00:00
parent 8ba58caaa8
commit 3ef84180b4
4 changed files with 135 additions and 68 deletions
+46 -28
View File
@@ -49,36 +49,54 @@ class VultrAdapter(BaseAdapter):
)
def list_vps(self) -> list:
data = self._get("/instances")
result = []
for inst in data.get("instances", []):
ram_mb = inst.get("ram") or 0
result.append(
NormalizedVPS(
external_id=inst.get("id"),
name=inst.get("label") or inst.get("id"),
ip_address=inst.get("main_ip"),
region=inst.get("region"),
os=inst.get("os"),
cpu_cores=inst.get("vcpu_count"),
memory_gb=round(ram_mb / 1024, 1) if ram_mb else None,
disk_gb=inst.get("disk"),
status="active" if inst.get("status") == "active" else (inst.get("status") or "unknown"),
monthly_cost=inst.get("monthly_cost"),
currency="USD",
raw=inst,
cursor = ""
while True:
path = "/instances?per_page=100"
if cursor:
path += f"&cursor={cursor}"
data = self._get(path)
for inst in data.get("instances", []):
ram_mb = inst.get("ram") or 0
result.append(
NormalizedVPS(
external_id=inst.get("id"),
name=inst.get("label") or inst.get("id"),
ip_address=inst.get("main_ip"),
region=inst.get("region"),
os=inst.get("os"),
cpu_cores=inst.get("vcpu_count"),
memory_gb=round(ram_mb / 1024, 1) if ram_mb else None,
disk_gb=inst.get("disk"),
status="active" if inst.get("status") == "active" else (inst.get("status") or "unknown"),
monthly_cost=inst.get("monthly_cost"),
currency="USD",
raw=inst,
)
)
)
cursor = data.get("meta", {}).get("links", {}).get("next") or ""
if not cursor:
break
return result
def list_domains(self) -> list:
data = self._get("/domains")
return [
NormalizedDomain(
external_id=d.get("domain"),
domain_name=d.get("domain"),
registrar="vultr",
raw=d,
)
for d in data.get("domains", [])
]
result = []
cursor = ""
while True:
path = "/domains?per_page=100"
if cursor:
path += f"&cursor={cursor}"
data = self._get(path)
for d in data.get("domains", []):
result.append(
NormalizedDomain(
external_id=d.get("domain"),
domain_name=d.get("domain"),
registrar="vultr",
raw=d,
)
)
cursor = data.get("meta", {}).get("links", {}).get("next") or ""
if not cursor:
break
return result