Skip to content

Commit

Permalink
Fix error 500 on PUT for cloud, nat, vmware and vpcs nodes. Fixes #2426
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Nov 19, 2024
1 parent 8db81de commit a00f53f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gns3server/api/routes/compute/cloud_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion gns3server/api/routes/compute/nat_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion gns3server/api/routes/compute/vmware_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
14 changes: 10 additions & 4 deletions gns3server/api/routes/compute/vpcs_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion gns3server/compute/notification_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def emit(self, action, event, **kwargs):
"""

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():
Expand Down
6 changes: 3 additions & 3 deletions gns3server/controller/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def controller_emit(self, action, event):
"""

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):
"""
Expand Down Expand Up @@ -134,7 +134,7 @@ def _send_event_to_project(self, project_id, action, event):
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):
"""
Expand All @@ -146,4 +146,4 @@ def _send_event_to_all_projects(self, action, event):
"""
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, {}))

0 comments on commit a00f53f

Please sign in to comment.