From 42cba3733df8e2b1945c41f58d4798f7ba1c520c Mon Sep 17 00:00:00 2001 From: Philipp Born Date: Sat, 16 Dec 2023 11:09:11 +0100 Subject: [PATCH] fix: prevent deletion attempts for non-existent vmID -1 Fixes #31. --- pkg/proxmox/goproxmox/api_client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/proxmox/goproxmox/api_client.go b/pkg/proxmox/goproxmox/api_client.go index ede81522..8d2b535d 100644 --- a/pkg/proxmox/goproxmox/api_client.go +++ b/pkg/proxmox/goproxmox/api_client.go @@ -138,6 +138,12 @@ func (c *APIClient) FindVMResource(ctx context.Context, vmID uint64) (*proxmox.C // DeleteVM deletes a VM based on the nodeName and vmID. func (c *APIClient) DeleteVM(ctx context.Context, nodeName string, vmID int64) (*proxmox.Task, error) { + // A vmID can not be lower than 100. + // If the provided vmID is lower (like -1 in issue #31), just error out without calling the API. + if vmID < 100 { + return nil, fmt.Errorf("vm with id %d does not exist", vmID) + } + node, err := c.Node(ctx, nodeName) if err != nil { return nil, fmt.Errorf("cannot find node with name %s: %w", nodeName, err)