[Feature] Add Apis -- Exec and Get Command Output #55
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
API Design Document
Overview
This document outlines the design and implementation of the new APIs for executing commands on virtual machines (VMs) and retrieving their output. These APIs are part of the TopoMojo project and are intended to enhance the functionality of VM management.
API Endpoints
1. Execute VM Command
POST /api/vm/{id}/exec
id
(string): The ID of the VM.commandList
(array of strings): The list of commands to execute.200 OK
: Returns the process ID (pid) of the started command execution.403 Forbidden
: If the user is not authorized to manage the VM.400 Bad Request
: If there is an error in executing the command.2. Get VM Command Output
GET /api/vm/{id}/exec/{pid}
id
(string): The ID of the VM.pid
(integer): The process ID of the command execution.200 OK
: Returns the output of the command execution.403 Forbidden
: If the user is not authorized to manage the VM.400 Bad Request
: If there is an error in retrieving the command output.Implementation Details
VM Controller
src/TopoMojo.Api/Features/Vm/VmController.cs
ExecVmCommand
: Handles the execution of commands on VMs.GetVmCommandOutput
: Retrieves the output of executed commands.Hypervisor Service
src/TopoMojo.Hypervisor/IHypervisorService.cs
ExecCommand
: Executes commands on the VM.GetCommandOutput
: Retrieves the output of executed commands.Proxmox Client
src/TopoMojo.Hypervisor/Proxmox/ProxmoxClient.cs
ExecCommand
: Implements the command execution logic.GetCommandOutput
: Implements the logic to retrieve command output.Mock Hypervisor Service
src/TopoMojo.Hypervisor/vMock/MockHypervisorService.cs
ExecCommand
: Mock implementation for command execution.GetCommandOutput
: Mock implementation for retrieving command output.Conclusion
These new APIs provide a robust mechanism for executing commands on VMs and retrieving their output, enhancing the overall functionality of the TopoMojo project. The implementation details ensure that the APIs are well-integrated with the existing system architecture.