From a00f53fbaa7196a6d775320d57ebd4262f6a8066 Mon Sep 17 00:00:00 2001 From: grossmj Date: Tue, 19 Nov 2024 12:21:35 +1000 Subject: [PATCH] Fix error 500 on PUT for cloud, nat, vmware and vpcs nodes. Fixes #2426 --- gns3server/api/routes/compute/cloud_nodes.py | 2 +- gns3server/api/routes/compute/nat_nodes.py | 2 +- gns3server/api/routes/compute/vmware_nodes.py | 2 +- gns3server/api/routes/compute/vpcs_nodes.py | 14 ++++++++++---- gns3server/compute/notification_manager.py | 2 +- gns3server/controller/notification.py | 6 +++--- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/gns3server/api/routes/compute/cloud_nodes.py b/gns3server/api/routes/compute/cloud_nodes.py index 6dc135d5..fd333ab3 100644 --- a/gns3server/api/routes/compute/cloud_nodes.py +++ b/gns3server/api/routes/compute/cloud_nodes.py @@ -85,7 +85,7 @@ def get_cloud(node: Cloud = Depends(dep_node)) -> schemas.Cloud: @router.put("/{node_id}", response_model=schemas.Cloud) -def update_cloud(node_data: schemas.CloudUpdate, node: Cloud = Depends(dep_node)) -> schemas.Cloud: +async def update_cloud(node_data: schemas.CloudUpdate, node: Cloud = Depends(dep_node)) -> schemas.Cloud: """ Update a cloud node. """ diff --git a/gns3server/api/routes/compute/nat_nodes.py b/gns3server/api/routes/compute/nat_nodes.py index d271d279..06788f6a 100644 --- a/gns3server/api/routes/compute/nat_nodes.py +++ b/gns3server/api/routes/compute/nat_nodes.py @@ -80,7 +80,7 @@ def get_nat_node(node: Nat = Depends(dep_node)) -> schemas.NAT: @router.put("/{node_id}", response_model=schemas.NAT) -def update_nat_node(node_data: schemas.NATUpdate, node: Nat = Depends(dep_node)) -> schemas.NAT: +async def update_nat_node(node_data: schemas.NATUpdate, node: Nat = Depends(dep_node)) -> schemas.NAT: """ Update a NAT node. """ diff --git a/gns3server/api/routes/compute/vmware_nodes.py b/gns3server/api/routes/compute/vmware_nodes.py index f1e3752c..30f79902 100644 --- a/gns3server/api/routes/compute/vmware_nodes.py +++ b/gns3server/api/routes/compute/vmware_nodes.py @@ -97,7 +97,7 @@ def get_vmware_node(node: VMwareVM = Depends(dep_node)) -> schemas.VMware: response_model=schemas.VMware, dependencies=[Depends(compute_authentication)] ) -def update_vmware_node(node_data: schemas.VMwareUpdate, node: VMwareVM = Depends(dep_node)) -> schemas.VMware: +async def update_vmware_node(node_data: schemas.VMwareUpdate, node: VMwareVM = Depends(dep_node)) -> schemas.VMware: """ Update a VMware node. """ diff --git a/gns3server/api/routes/compute/vpcs_nodes.py b/gns3server/api/routes/compute/vpcs_nodes.py index 143ceef8..bd5181b6 100644 --- a/gns3server/api/routes/compute/vpcs_nodes.py +++ b/gns3server/api/routes/compute/vpcs_nodes.py @@ -91,15 +91,21 @@ def get_vpcs_node(node: VPCSVM = Depends(dep_node)) -> schemas.VPCS: response_model=schemas.VPCS, dependencies=[Depends(compute_authentication)] ) -def update_vpcs_node(node_data: schemas.VPCSUpdate, node: VPCSVM = Depends(dep_node)) -> schemas.VPCS: +async def update_vpcs_node(node_data: schemas.VPCSUpdate, node: VPCSVM = Depends(dep_node)) -> schemas.VPCS: """ Update a VPCS node. """ node_data = jsonable_encoder(node_data, exclude_unset=True) - node.name = node_data.get("name", node.name) - node.console = node_data.get("console", node.console) - node.console_type = node_data.get("console_type", node.console_type) + name = node_data.get("name", node.name) + if node.name != name: + node.name = name + console = node_data.get("console", node.console) + if node.console != console: + node.console = console + console_type = node_data.get("console_type", node.console_type) + if node.console_type != console_type: + node.console_type = console_type node.updated() return node.asdict() diff --git a/gns3server/compute/notification_manager.py b/gns3server/compute/notification_manager.py index 44c9ca39..30f0a805 100644 --- a/gns3server/compute/notification_manager.py +++ b/gns3server/compute/notification_manager.py @@ -54,7 +54,7 @@ class NotificationManager: """ for listener in self._listeners: - asyncio.get_event_loop().call_soon_threadsafe(listener.put_nowait, (action, event, kwargs)) + asyncio.get_running_loop().call_soon_threadsafe(listener.put_nowait, (action, event, kwargs)) @staticmethod def reset(): diff --git a/gns3server/controller/notification.py b/gns3server/controller/notification.py index 19672fb0..3a63d9b8 100644 --- a/gns3server/controller/notification.py +++ b/gns3server/controller/notification.py @@ -73,7 +73,7 @@ class Notification: """ for controller_listener in self._controller_listeners: - asyncio.get_event_loop().call_soon_threadsafe(controller_listener.put_nowait, (action, event, {})) + asyncio.get_running_loop().call_soon_threadsafe(controller_listener.put_nowait, (action, event, {})) def project_has_listeners(self, project_id): """ @@ -134,7 +134,7 @@ class Notification: except KeyError: return for listener in project_listeners: - asyncio.get_event_loop().call_soon_threadsafe(listener.put_nowait, (action, event, {})) + asyncio.get_running_loop().call_soon_threadsafe(listener.put_nowait, (action, event, {})) def _send_event_to_all_projects(self, action, event): """ @@ -146,4 +146,4 @@ class Notification: """ for project_listeners in self._project_listeners.values(): for listener in project_listeners: - asyncio.get_event_loop().call_soon_threadsafe(listener.put_nowait, (action, event, {})) + asyncio.get_running_loop().call_soon_threadsafe(listener.put_nowait, (action, event, {}))