|
|
@ -154,6 +154,7 @@ class Compute:
|
|
|
|
return self._interfaces_cache
|
|
|
|
return self._interfaces_cache
|
|
|
|
|
|
|
|
|
|
|
|
async def update(self, **kwargs):
|
|
|
|
async def update(self, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
for kw in kwargs:
|
|
|
|
for kw in kwargs:
|
|
|
|
if kw not in ("user", "password"):
|
|
|
|
if kw not in ("user", "password"):
|
|
|
|
setattr(self, kw, kwargs[kw])
|
|
|
|
setattr(self, kw, kwargs[kw])
|
|
|
@ -373,7 +374,7 @@ class Compute:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@locking
|
|
|
|
@locking
|
|
|
|
async def connect(self):
|
|
|
|
async def connect(self, report_failed_connection=False):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Check if remote server is accessible
|
|
|
|
Check if remote server is accessible
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -383,6 +384,8 @@ class Compute:
|
|
|
|
log.info(f"Connecting to compute '{self._id}'")
|
|
|
|
log.info(f"Connecting to compute '{self._id}'")
|
|
|
|
response = await self._run_http_query("GET", "/capabilities")
|
|
|
|
response = await self._run_http_query("GET", "/capabilities")
|
|
|
|
except ComputeError as e:
|
|
|
|
except ComputeError as e:
|
|
|
|
|
|
|
|
if report_failed_connection:
|
|
|
|
|
|
|
|
raise
|
|
|
|
log.warning(f"Cannot connect to compute '{self._id}': {e}")
|
|
|
|
log.warning(f"Cannot connect to compute '{self._id}': {e}")
|
|
|
|
# Try to reconnect after 5 seconds if server unavailable only if not during tests (otherwise we create a ressource usage bomb)
|
|
|
|
# Try to reconnect after 5 seconds if server unavailable only if not during tests (otherwise we create a ressource usage bomb)
|
|
|
|
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
|
|
|
|
if not hasattr(sys, "_called_from_test") or not sys._called_from_test:
|
|
|
@ -491,7 +494,7 @@ class Compute:
|
|
|
|
# Try to reconnect after 1 second if server unavailable only if not during tests (otherwise we create a ressources usage bomb)
|
|
|
|
# Try to reconnect after 1 second if server unavailable only if not during tests (otherwise we create a ressources usage bomb)
|
|
|
|
from gns3server.api.server import app
|
|
|
|
from gns3server.api.server import app
|
|
|
|
if not app.state.exiting and not hasattr(sys, "_called_from_test"):
|
|
|
|
if not app.state.exiting and not hasattr(sys, "_called_from_test"):
|
|
|
|
log.info(f"Reconnecting to to compute '{self._id}' WebSocket '{ws_url}'")
|
|
|
|
log.info(f"Reconnecting to compute '{self._id}' WebSocket '{ws_url}'")
|
|
|
|
asyncio.get_event_loop().call_later(1, lambda: asyncio.ensure_future(self.connect()))
|
|
|
|
asyncio.get_event_loop().call_later(1, lambda: asyncio.ensure_future(self.connect()))
|
|
|
|
|
|
|
|
|
|
|
|
self._cpu_usage_percent = None
|
|
|
|
self._cpu_usage_percent = None
|
|
|
@ -572,7 +575,7 @@ class Compute:
|
|
|
|
msg = ""
|
|
|
|
msg = ""
|
|
|
|
|
|
|
|
|
|
|
|
if response.status == 401:
|
|
|
|
if response.status == 401:
|
|
|
|
raise ControllerUnauthorizedError(f"Invalid authentication for compute {self.id}")
|
|
|
|
raise ControllerUnauthorizedError(f"Invalid authentication for compute '{self.name}' [{self.id}]")
|
|
|
|
elif response.status == 403:
|
|
|
|
elif response.status == 403:
|
|
|
|
raise ControllerForbiddenError(msg)
|
|
|
|
raise ControllerForbiddenError(msg)
|
|
|
|
elif response.status == 404:
|
|
|
|
elif response.status == 404:
|
|
|
|