-
Notifications
You must be signed in to change notification settings - Fork 263
refactor: reimplement delete guest api call #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tinyblargon
wants to merge
1
commit into
Telmate:master
Choose a base branch
from
Tinyblargon:delete-guest
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+52
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -108,11 +108,6 @@ func (c *clientNew) guestDelete(ctx context.Context, vmr *VmRef) error { | |||||
| if !ok { | ||||||
| return errorMsg{}.guestDoesNotExist(vmr.vmId) | ||||||
| } | ||||||
| if haState := rawGuest.GetHaState(); haState != "" { | ||||||
| if _, err = guestID.deleteHaResource(ctx, ca); err != nil { | ||||||
| return err | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| guestType := rawGuest.GetType() | ||||||
| vmr.node = rawGuest.GetNode() | ||||||
|
|
@@ -142,16 +137,15 @@ func (c *clientNew) guestDelete(ctx context.Context, vmr *VmRef) error { | |||||
| return err | ||||||
| } | ||||||
|
|
||||||
| haEnabled := rawGuest.GetHaState() != "" | ||||||
| if rawGuest.GetStatus() != PowerStateStopped { // Check if guest is running | ||||||
| for { | ||||||
| var guestStatus RawGuestStatus | ||||||
| guestStatus, err = vmr.getRawGuestStatus_Unsafe(ctx, c.oldClient) | ||||||
| if err != nil { | ||||||
| if haEnabled { | ||||||
| if _, err = guestID.deleteHaResource(ctx, ca); err != nil { // It's faster to delete HA resource first, instead of stopping via HA | ||||||
| return err | ||||||
| } | ||||||
| if guestStatus.GetState() == PowerStateStopped { | ||||||
| break | ||||||
| } | ||||||
| haEnabled = false | ||||||
| } | ||||||
| for { | ||||||
| if version.Encode() >= version_8_0_0 { // Try to force stop the guest if supported | ||||||
| err = vmr.forceStop_Unsafe(ctx, ca) | ||||||
| } else { | ||||||
|
|
@@ -160,21 +154,36 @@ func (c *clientNew) guestDelete(ctx context.Context, vmr *VmRef) error { | |||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| var guestStatus RawGuestStatus | ||||||
| guestStatus, err = vmr.getRawGuestStatus_Unsafe(ctx, c.oldClient) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
| if guestStatus.GetState() == PowerStateStopped { | ||||||
| break | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| return vmr.delete_Unsafe(ctx, c.oldClient) | ||||||
| return vmr.delete_Unsafe(ctx, c.apiGet(), haEnabled) | ||||||
| } | ||||||
|
|
||||||
| func (vmr VmRef) DeleteNoCheck(ctx context.Context, c *Client) error { | ||||||
| if err := c.checkInitialized(); err != nil { | ||||||
| return err | ||||||
| } | ||||||
| return vmr.delete_Unsafe(ctx, c) | ||||||
| return vmr.delete_Unsafe(ctx, c.new().apiGet(), false) | ||||||
| } | ||||||
|
|
||||||
| func (vmr *VmRef) delete_Unsafe(ctx context.Context, c *Client) error { | ||||||
| _, err := c.DeleteVmParams(ctx, vmr, nil) // TODO use a more optimized version | ||||||
| return err | ||||||
| func (vmr *VmRef) delete_Unsafe(ctx context.Context, c clientApiInterface, purge bool) error { | ||||||
| return c.deleteGuest(ctx, vmr, purge) | ||||||
| } | ||||||
|
|
||||||
| 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) | ||||||
| } | ||||||
|
|
||||||
| // ForceStop stops the guest immediately without a graceful shutdown and cancels any stop/shutdown operations in progress. | ||||||
|
|
@@ -197,6 +206,9 @@ func (c *clientNew) guestStopForce(ctx context.Context, vmr *VmRef) error { | |||||
| return vmr.forceStop_Unsafe(ctx, c.apiGet()) | ||||||
| } | ||||||
|
|
||||||
| // 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. | ||||||
|
||||||
| // Gives error when HA is enabled. | |
| // Returns an error when HA is enabled. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
deleteGuestfunction lacks documentation. Consider adding a comment explaining what the function does and what thepurgeparameter means. For example: "deleteGuest deletes the guest VM. When purge is true, it also removes the VM from HA resources and related configurations."