mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 07:11:13 +02:00
refactor: use explicit conversion in f-strings
This commit is contained in:
32 files changed
+65
-65
No files matched your search
@@ -255,7 +255,7 @@ class ExecuteMultipleDeviceConfigCommands(BaseTool):
|
||||
except Exception as e:
|
||||
# Overall execution failed
|
||||
logger.error("Error executing configurations on all devices: %s", e)
|
||||
return [{"status": "failed", "error": f"Execution error: {str(e)}"}]
|
||||
return [{"status": "failed", "error": f"Execution error: {e!s}"}]
|
||||
|
||||
logger.info(
|
||||
"Multiple device configuration execution completed. Results: %s",
|
||||
@@ -285,7 +285,7 @@ class ExecuteMultipleDeviceConfigCommands(BaseTool):
|
||||
)
|
||||
return Result(
|
||||
host=task.host,
|
||||
result=f"Configuration failed (ReadTimeout): {str(e)}",
|
||||
result=f"Configuration failed (ReadTimeout): {e!s}",
|
||||
failed=True,
|
||||
)
|
||||
|
||||
@@ -305,7 +305,7 @@ class ExecuteMultipleDeviceConfigCommands(BaseTool):
|
||||
)
|
||||
return Result(
|
||||
host=task.host,
|
||||
result=f"Configuration failed (Unhandled Exception): {str(e)}",
|
||||
result=f"Configuration failed (Unhandled Exception): {e!s}",
|
||||
failed=True,
|
||||
)
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ class ExecuteMultipleDeviceCommands(BaseTool):
|
||||
except Exception as e:
|
||||
# Overall execution failed
|
||||
logger.error("Error executing display on all devices: %s", e)
|
||||
return [{"status": "failed", "error": f"Execution error: {str(e)}"}]
|
||||
return [{"status": "failed", "error": f"Execution error: {e!s}"}]
|
||||
|
||||
logger.debug(
|
||||
"Multiple device display execution completed. Results: %s",
|
||||
@@ -288,7 +288,7 @@ class ExecuteMultipleDeviceCommands(BaseTool):
|
||||
)
|
||||
return Result(
|
||||
host=task.host,
|
||||
result=f"diagnostic command failed (ReadTimeout): {str(e)}",
|
||||
result=f"diagnostic command failed (ReadTimeout): {e!s}",
|
||||
failed=True,
|
||||
)
|
||||
|
||||
@@ -313,7 +313,7 @@ class ExecuteMultipleDeviceCommands(BaseTool):
|
||||
)
|
||||
return Result(
|
||||
host=task.host,
|
||||
result=f"diagnostic command failed (Unhandled): {str(e)}",
|
||||
result=f"diagnostic command failed (Unhandled): {e!s}",
|
||||
failed=True,
|
||||
)
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ class GNS3LinkTool(BaseTool):
|
||||
created_links.append(link_info)
|
||||
|
||||
except Exception as e:
|
||||
error_msg = f"Failed to create link {i}: {str(e)}"
|
||||
error_msg = f"Failed to create link {i}: {e!s}"
|
||||
logger.error(error_msg)
|
||||
created_links.append({"error": error_msg})
|
||||
|
||||
@@ -257,7 +257,7 @@ class GNS3LinkTool(BaseTool):
|
||||
return [{"error": f"Invalid JSON input: {e}"}]
|
||||
except Exception as e:
|
||||
logger.error("Failed to process link creation: %s", e)
|
||||
return [{"error": f"Failed to process link creation: {str(e)}"}]
|
||||
return [{"error": f"Failed to process link creation: {e!s}"}]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -244,7 +244,7 @@ class GNS3CreateNodeTool(BaseTool):
|
||||
|
||||
except Exception as e:
|
||||
error_info = {
|
||||
"error": f"Node {i + 1} creation failed: {str(e)}",
|
||||
"error": f"Node {i + 1} creation failed: {e!s}",
|
||||
"status": "failed",
|
||||
}
|
||||
results.append(error_info)
|
||||
@@ -280,7 +280,7 @@ class GNS3CreateNodeTool(BaseTool):
|
||||
return {"error": f"Invalid JSON input: {e}"}
|
||||
except Exception as e:
|
||||
logger.error("Failed to process node creation request: %s", e)
|
||||
return {"error": f"Failed to process node creation request: {str(e)}"}
|
||||
return {"error": f"Failed to process node creation request: {e!s}"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -168,7 +168,7 @@ class GNS3TemplateTool(BaseTool):
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Failed to connect to GNS3 server or retrieve templates: %s", e)
|
||||
return {"error": f"Failed to retrieve templates: {str(e)}"}
|
||||
return {"error": f"Failed to retrieve templates: {e!s}"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -239,7 +239,7 @@ class GNS3PacketFilterTool(BaseTool):
|
||||
return {"error": f"Invalid JSON input: {e}"}
|
||||
except Exception as e:
|
||||
logger.error("Failed to process packet filter request: %s", e)
|
||||
return {"error": f"Failed to process packet filter request: {str(e)}"}
|
||||
return {"error": f"Failed to process packet filter request: {e!s}"}
|
||||
|
||||
def _get_available_filters(self, gns3_ctx: dict, project_id: str, link_id: str) -> dict[str, Any]:
|
||||
"""Get available filter types for the link."""
|
||||
@@ -260,7 +260,7 @@ class GNS3PacketFilterTool(BaseTool):
|
||||
return {
|
||||
"action": "get_available",
|
||||
"link_id": link_id,
|
||||
"error": f"Failed to get available filters: {str(e)}",
|
||||
"error": f"Failed to get available filters: {e!s}",
|
||||
"status": "failed",
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ class GNS3PacketFilterTool(BaseTool):
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Unexpected error during BPF validation: %s", e)
|
||||
return {"valid": False, "error": f"BPF validation error: {str(e)}"}
|
||||
return {"valid": False, "error": f"BPF validation error: {e!s}"}
|
||||
|
||||
def _set_filters(
|
||||
self,
|
||||
@@ -384,7 +384,7 @@ class GNS3PacketFilterTool(BaseTool):
|
||||
return {
|
||||
"action": "set",
|
||||
"link_id": link_id,
|
||||
"error": f"Failed to set filters: {str(e)}",
|
||||
"error": f"Failed to set filters: {e!s}",
|
||||
"status": "failed",
|
||||
}
|
||||
|
||||
@@ -407,7 +407,7 @@ class GNS3PacketFilterTool(BaseTool):
|
||||
return {
|
||||
"action": "get",
|
||||
"link_id": link_id,
|
||||
"error": f"Failed to get filters: {str(e)}",
|
||||
"error": f"Failed to get filters: {e!s}",
|
||||
"status": "failed",
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ class GNS3PacketFilterTool(BaseTool):
|
||||
return {
|
||||
"action": "clear",
|
||||
"link_id": link_id,
|
||||
"error": f"Failed to clear filters: {str(e)}",
|
||||
"error": f"Failed to clear filters: {e!s}",
|
||||
"status": "failed",
|
||||
}
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ class GNS3StartNodeTool(BaseTool):
|
||||
return {"error": f"Invalid JSON input: {e}"}
|
||||
except Exception as e:
|
||||
logger.error("Failed to start nodes: %s", e)
|
||||
return {"error": f"Failed to start nodes: {str(e)}"}
|
||||
return {"error": f"Failed to start nodes: {e!s}"}
|
||||
|
||||
|
||||
# Backward-compat alias: the waiting variant was removed; both names now
|
||||
|
||||
@@ -198,7 +198,7 @@ class GNS3StopNodeTool(BaseTool):
|
||||
return {"error": f"Invalid JSON input: {e}"}
|
||||
except Exception as e:
|
||||
logger.error("Failed to stop nodes: %s", e)
|
||||
return {"error": f"Failed to stop nodes: {str(e)}"}
|
||||
return {"error": f"Failed to stop nodes: {e!s}"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -209,7 +209,7 @@ class GNS3SuspendNodeTool(BaseTool):
|
||||
return {"error": f"Invalid JSON input: {e}"}
|
||||
except Exception as e:
|
||||
logger.error("Failed to suspend nodes: %s", e)
|
||||
return {"error": f"Failed to suspend nodes: {str(e)}"}
|
||||
return {"error": f"Failed to suspend nodes: {e!s}"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -241,7 +241,7 @@ class GNS3UpdateNodeNameTool(BaseTool):
|
||||
return {"error": f"Invalid JSON input: {e}"}
|
||||
except Exception as e:
|
||||
logger.error("Failed to update node names: %s", e)
|
||||
return {"error": f"Failed to update node names: {str(e)}"}
|
||||
return {"error": f"Failed to update node names: {e!s}"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -104,4 +104,4 @@ class GNS3WaitTool(BaseTool):
|
||||
return {"error": f"Invalid JSON input: {e}"}
|
||||
except Exception as e:
|
||||
logger.error("Wait tool failed: %s", e)
|
||||
return {"error": f"Wait tool failed: {str(e)}"}
|
||||
return {"error": f"Wait tool failed: {e!s}"}
|
||||
@@ -325,7 +325,7 @@ class PacketAnalysisTool(BaseTool):
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"PacketAnalysisTool error: {e}", exc_info=True)
|
||||
return f'{{"error": "Analysis failed: {str(e)}"}}'
|
||||
return f'{{"error": "Analysis failed: {e!s}"}}'
|
||||
|
||||
finally:
|
||||
# Clean up temp file
|
||||
@@ -497,7 +497,7 @@ class PacketAnalysisTool(BaseTool):
|
||||
return '{"error": "tshark not installed. Please install tshark: apt install tshark"}'
|
||||
except Exception as e:
|
||||
logger.error(f"tshark execution error: {e}", exc_info=True)
|
||||
return f'{{"error": "tshark failed: {str(e)}"}}'
|
||||
return f'{{"error": "tshark failed: {e!s}"}}'
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -227,7 +227,7 @@ class VPCSCommands(BaseTool):
|
||||
except Exception as e:
|
||||
# Overall execution failed
|
||||
logger.error("Error executing commands on all VPCS devices: %s", e)
|
||||
return [{"status": "failed", "error": f"Execution error: {str(e)}"}]
|
||||
return [{"status": "failed", "error": f"Execution error: {e!s}"}]
|
||||
|
||||
logger.debug(
|
||||
"VPCS command execution completed. Results: %s",
|
||||
@@ -262,7 +262,7 @@ class VPCSCommands(BaseTool):
|
||||
)
|
||||
return Result(
|
||||
host=task.host,
|
||||
result=f"Command failed (ReadTimeout): {str(e)}",
|
||||
result=f"Command failed (ReadTimeout): {e!s}",
|
||||
failed=True,
|
||||
)
|
||||
|
||||
@@ -289,7 +289,7 @@ class VPCSCommands(BaseTool):
|
||||
)
|
||||
return Result(
|
||||
host=task.host,
|
||||
result=f"Command failed: {str(retry_e)}",
|
||||
result=f"Command failed: {retry_e!s}",
|
||||
failed=True,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user