mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-09-06 10:05:22 +03:00
Merge pull request #2705 from yueguobin/fix/project-deletion-compute-status-check
Fix: Check compute connection status before project deletion
This commit is contained in:
commit
255d1e4057
@ -375,6 +375,11 @@ class Compute:
|
||||
log.info(f"Connecting to compute '{self._id}'")
|
||||
response = await self._run_http_query("GET", "/capabilities")
|
||||
except ComputeError as e:
|
||||
# Update connection status and notify UI
|
||||
self._connected = False
|
||||
self._last_error = str(e)
|
||||
self._controller.notification.controller_emit("compute.updated", self.asdict())
|
||||
|
||||
if report_failed_connection:
|
||||
raise
|
||||
log.warning(f"Cannot connect to compute '{self._id}': {e}")
|
||||
|
||||
@ -1029,6 +1029,29 @@ class Project:
|
||||
except ControllerError as e:
|
||||
# ignore missing images or other conflicts when deleting a project
|
||||
log.warning(f"Conflict while deleting project: {e}")
|
||||
|
||||
# Check if all computes used by this project are connected before deletion
|
||||
# We need to check from the topology file because _project_created_on_compute
|
||||
# gets reset during open()
|
||||
disconnected_computes = []
|
||||
for compute_id in self._computes:
|
||||
try:
|
||||
compute = self._controller.get_compute(compute_id)
|
||||
if not compute.connected:
|
||||
disconnected_computes.append(compute)
|
||||
except ControllerError:
|
||||
# Compute doesn't exist anymore, consider it disconnected
|
||||
log.warning(f"Compute '{compute_id}' not found in controller")
|
||||
# We can't add it to disconnected_computes without the compute object
|
||||
pass
|
||||
|
||||
if disconnected_computes:
|
||||
compute_names = ", ".join([f"'{c.name}'" for c in disconnected_computes])
|
||||
raise ControllerForbiddenError(
|
||||
f"Cannot delete project '{self.name}': {len(disconnected_computes)} compute(s) are disconnected: {compute_names}. "
|
||||
f"Please fix the connection or delete the project manually on those computes."
|
||||
)
|
||||
|
||||
await self.delete_on_computes()
|
||||
await self.close()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user