обновление agent.py
Browse files
agent.py
CHANGED
|
@@ -255,21 +255,31 @@ class PublicAddress:
|
|
| 255 |
label = _read("/root/.vast_containerlabel")
|
| 256 |
instance_id = label.replace("C.", "").strip()
|
| 257 |
if key and instance_id:
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
if not self.host:
|
| 275 |
try:
|
|
|
|
| 255 |
label = _read("/root/.vast_containerlabel")
|
| 256 |
instance_id = label.replace("C.", "").strip()
|
| 257 |
if key and instance_id:
|
| 258 |
+
# Здесь нельзя откатываться на «внешний ip + тот же порт»: снаружи
|
| 259 |
+
# порт другой, и нода зарегистрируется по адресу, куда менеджер не
|
| 260 |
+
# достучится. Лучше долбиться в API, пока не ответит.
|
| 261 |
+
for attempt in range(1, 11):
|
| 262 |
+
try:
|
| 263 |
+
status, data = http_json("GET", f"{VAST_API}/instances/{instance_id}/",
|
| 264 |
+
headers={"Authorization": f"Bearer {key}"}, timeout=30)
|
| 265 |
+
if status != 200:
|
| 266 |
+
raise RuntimeError(f"HTTP {status}: {str(data)[:200]}")
|
| 267 |
+
inst = data["instances"]
|
| 268 |
+
self.host = self.host or inst.get("public_ipaddr", "").strip()
|
| 269 |
+
for spec, binds in (inst.get("ports") or {}).items():
|
| 270 |
+
inner = int(spec.split("/")[0])
|
| 271 |
+
for b in binds:
|
| 272 |
+
if b.get("HostIp") == "0.0.0.0":
|
| 273 |
+
self.ports[inner] = int(b["HostPort"])
|
| 274 |
+
if not self.host or not self.ports:
|
| 275 |
+
raise RuntimeError("Vast ещё не отдал адрес и проброс портов")
|
| 276 |
+
log(f"публичный адрес: {self.host}, проброшено портов: {len(self.ports)}")
|
| 277 |
+
self._loaded = True
|
| 278 |
+
return
|
| 279 |
+
except Exception as e:
|
| 280 |
+
log(f"Vast API не ответил (попытка {attempt} из 10): {e}")
|
| 281 |
+
time.sleep(15)
|
| 282 |
+
raise RuntimeError("Vast API так и не отдал проброс портов")
|
| 283 |
|
| 284 |
if not self.host:
|
| 285 |
try:
|