fix: 阿里云/腾讯云list_vps补分页(超100台实例不再漏同步)
This commit is contained in:
+27
-19
@@ -79,25 +79,33 @@ class AliyunAdapter(BaseAdapter):
|
|||||||
return {"ok": False, "message": str(e)}
|
return {"ok": False, "message": str(e)}
|
||||||
|
|
||||||
def list_vps(self) -> list:
|
def list_vps(self) -> list:
|
||||||
data = self._call("DescribeInstances", {"PageSize": "100"})
|
# 分页拉取:单次最多 100 条,按 TotalCount 翻页,避免实例超 100 台时漏同步
|
||||||
result = []
|
result = []
|
||||||
for inst in data.get("Instances", {}).get("Instance", []):
|
page = 1
|
||||||
public_ips = inst.get("PublicIpAddress", {}).get("IpAddress", [])
|
while True:
|
||||||
eip = inst.get("EipAddress", {}).get("IpAddress")
|
data = self._call("DescribeInstances", {"PageSize": "100", "PageNumber": str(page)})
|
||||||
mem_mb = inst.get("Memory") or 0
|
instances = data.get("Instances", {}).get("Instance", [])
|
||||||
status_map = {"Running": "active", "Stopped": "stopped"}
|
for inst in instances:
|
||||||
result.append(
|
public_ips = inst.get("PublicIpAddress", {}).get("IpAddress", [])
|
||||||
NormalizedVPS(
|
eip = inst.get("EipAddress", {}).get("IpAddress")
|
||||||
external_id=inst.get("InstanceId"),
|
mem_mb = inst.get("Memory") or 0
|
||||||
name=inst.get("InstanceName") or inst.get("InstanceId"),
|
status_map = {"Running": "active", "Stopped": "stopped"}
|
||||||
ip_address=eip or (public_ips[0] if public_ips else None),
|
result.append(
|
||||||
region=inst.get("RegionId"),
|
NormalizedVPS(
|
||||||
os=inst.get("OSName"),
|
external_id=inst.get("InstanceId"),
|
||||||
cpu_cores=inst.get("Cpu"),
|
name=inst.get("InstanceName") or inst.get("InstanceId"),
|
||||||
memory_gb=round(mem_mb / 1024, 1) if mem_mb else None,
|
ip_address=eip or (public_ips[0] if public_ips else None),
|
||||||
status=status_map.get(inst.get("Status"), inst.get("Status") or "unknown"),
|
region=inst.get("RegionId"),
|
||||||
currency="CNY",
|
os=inst.get("OSName"),
|
||||||
raw=inst,
|
cpu_cores=inst.get("Cpu"),
|
||||||
|
memory_gb=round(mem_mb / 1024, 1) if mem_mb else None,
|
||||||
|
status=status_map.get(inst.get("Status"), inst.get("Status") or "unknown"),
|
||||||
|
currency="CNY",
|
||||||
|
raw=inst,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
total = int(data.get("TotalCount") or 0)
|
||||||
|
if not instances or page * 100 >= total:
|
||||||
|
break
|
||||||
|
page += 1
|
||||||
return result
|
return result
|
||||||
|
|||||||
+25
-17
@@ -94,24 +94,32 @@ class TencentAdapter(BaseAdapter):
|
|||||||
return {"ok": False, "message": str(e)}
|
return {"ok": False, "message": str(e)}
|
||||||
|
|
||||||
def list_vps(self) -> list:
|
def list_vps(self) -> list:
|
||||||
data = self._call("DescribeInstances", {"Limit": 100})
|
# 分页拉取:单次最多 100 条,按 TotalCount 翻页,避免实例超 100 台时漏同步
|
||||||
result = []
|
result = []
|
||||||
status_map = {"RUNNING": "active", "STOPPED": "stopped"}
|
status_map = {"RUNNING": "active", "STOPPED": "stopped"}
|
||||||
for inst in data.get("InstanceSet", []):
|
offset = 0
|
||||||
public_ips = inst.get("PublicIpAddresses", [])
|
while True:
|
||||||
result.append(
|
data = self._call("DescribeInstances", {"Limit": 100, "Offset": offset})
|
||||||
NormalizedVPS(
|
inst_set = data.get("InstanceSet", [])
|
||||||
external_id=inst.get("InstanceId"),
|
for inst in inst_set:
|
||||||
name=inst.get("InstanceName") or inst.get("InstanceId"),
|
public_ips = inst.get("PublicIpAddresses", [])
|
||||||
ip_address=public_ips[0] if public_ips else None,
|
result.append(
|
||||||
region=inst.get("Placement", {}).get("Zone"),
|
NormalizedVPS(
|
||||||
os=inst.get("OsName"),
|
external_id=inst.get("InstanceId"),
|
||||||
cpu_cores=inst.get("CPU"),
|
name=inst.get("InstanceName") or inst.get("InstanceId"),
|
||||||
memory_gb=inst.get("Memory"),
|
ip_address=public_ips[0] if public_ips else None,
|
||||||
disk_gb=inst.get("SystemDisk", {}).get("DiskSize"),
|
region=inst.get("Placement", {}).get("Zone"),
|
||||||
status=status_map.get(inst.get("InstanceState"), inst.get("InstanceState") or "unknown"),
|
os=inst.get("OsName"),
|
||||||
currency="CNY",
|
cpu_cores=inst.get("CPU"),
|
||||||
raw=inst,
|
memory_gb=inst.get("Memory"),
|
||||||
|
disk_gb=inst.get("SystemDisk", {}).get("DiskSize"),
|
||||||
|
status=status_map.get(inst.get("InstanceState"), inst.get("InstanceState") or "unknown"),
|
||||||
|
currency="CNY",
|
||||||
|
raw=inst,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
total = int(data.get("TotalCount") or 0)
|
||||||
|
offset += len(inst_set)
|
||||||
|
if not inst_set or offset >= total:
|
||||||
|
break
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user