Skip to content

Conversation

@Tinyblargon
Copy link
Collaborator

Optimizes the logic to reduce the amount of API calls made when deleting a guest with HA enabled.
implements the delete guest API call

@Tinyblargon Tinyblargon requested a review from Copilot November 29, 2025 00:57
@Tinyblargon Tinyblargon added type/refactoring Existing code has been cleaned up. There should be no new functionality modifies/go Pull requests that update Go code size/M Denotes a PR that changes 30-99 lines, ignoring generated files test/done This PR has been tested and the result was succesfull labels Nov 29, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the guest deletion logic to optimize API calls when deleting guests with HA (High Availability) enabled. The key improvement is reordering when HA resources are deleted: for running guests with HA, the code now deletes the HA resource first before stopping the guest, which avoids the slower HA-controlled shutdown process. For stopped guests with HA, the deletion is handled via Proxmox's purge parameter.

Key Changes

  • Moved HA resource deletion to occur before guest shutdown (for running guests) instead of before any status checks
  • Implemented a new deleteGuest API call that uses the Proxmox purge parameter to handle HA cleanup for stopped guests
  • Added deleteTask helper function to handle DELETE requests with task completion waiting

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
proxmox/vmref.go Refactored guestDelete to optimize HA handling; added deleteGuest implementation and updated delete_Unsafe signature to accept purge parameter
proxmox/client__api__reusable.go Added deleteTask function to perform DELETE requests and wait for task completion
proxmox/client__api__mock.go Added deleteGuest mock function to support testing
proxmox/client__api.go Added deleteGuest to the clientApiInterface
proxmox/client.go Added deprecation notice to DeleteVmParams function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// forceStop stops the guest immediately without a graceful shutdown and cancels any stop/shutdown operations in progress.
// This function requires Proxmox VE 8.0 or later.
// Gives error when HA is enabled.
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The grammar in this comment is awkward. Consider rephrasing to "Returns an error when HA is enabled" or "Will error if HA is enabled" for better clarity.

Suggested change
// Gives error when HA is enabled.
// Returns an error when HA is enabled.

Copilot uses AI. Check for mistakes.
Comment on lines +181 to 187
func (c *clientAPI) deleteGuest(ctx context.Context, vmr *VmRef, purge bool) error {
var urlOptions string
if purge {
urlOptions = "?purge=1"
}
return c.deleteTask(ctx, "/nodes/"+vmr.node.String()+"/"+vmr.vmType.String()+"/"+vmr.vmId.String()+urlOptions)
}
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deleteGuest function lacks documentation. Consider adding a comment explaining what the function does and what the purge parameter means. For example: "deleteGuest deletes the guest VM. When purge is true, it also removes the VM from HA resources and related configurations."

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

modifies/go Pull requests that update Go code size/M Denotes a PR that changes 30-99 lines, ignoring generated files test/done This PR has been tested and the result was succesfull type/refactoring Existing code has been cleaned up. There should be no new functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant