From eee8b3e0428b5f008817d41ae97ff35d3234f309 Mon Sep 17 00:00:00 2001 From: Tinyblargon <76069640+Tinyblargon@users.noreply.github.com> Date: Thu, 29 Feb 2024 20:10:37 +0100 Subject: [PATCH] feat: add unsafe create for snapshots --- cli/command/create/create-snapshot.go | 2 +- proxmox/snapshot.go | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cli/command/create/create-snapshot.go b/cli/command/create/create-snapshot.go index e187fa68..a0fb057e 100644 --- a/cli/command/create/create-snapshot.go +++ b/cli/command/create/create-snapshot.go @@ -29,7 +29,7 @@ var ( if err != nil { return } - err = config.CreateSnapshot(client, vmr) + err = config.Create(client, vmr) if err != nil { return } diff --git a/proxmox/snapshot.go b/proxmox/snapshot.go index 147fcdf7..2602c7b3 100644 --- a/proxmox/snapshot.go +++ b/proxmox/snapshot.go @@ -23,7 +23,8 @@ func (config ConfigSnapshot) mapToApiValues() map[string]interface{} { } } -func (config ConfigSnapshot) CreateSnapshot(c *Client, vmr *VmRef) (err error) { +// Creates a snapshot and validates the input +func (config ConfigSnapshot) Create(c *Client, vmr *VmRef) (err error) { err = c.CheckVmRef(vmr) if err != nil { return @@ -32,13 +33,23 @@ func (config ConfigSnapshot) CreateSnapshot(c *Client, vmr *VmRef) (err error) { if err != nil { return } + return config.Create_Unsafe(c, vmr) +} + +// Create a snapshot without validating the input, use ConfigSnapshot.Create() to validate the input. +func (config ConfigSnapshot) Create_Unsafe(c *Client, vmr *VmRef) error { params := config.mapToApiValues() - _, err = c.PostWithTask(params, "/nodes/"+vmr.node+"/"+vmr.vmType+"/"+strconv.Itoa(vmr.vmId)+"/snapshot/") + _, err := c.PostWithTask(params, "/nodes/"+vmr.node+"/"+vmr.vmType+"/"+strconv.Itoa(vmr.vmId)+"/snapshot/") if err != nil { params, _ := json.Marshal(¶ms) return fmt.Errorf("error creating Snapshot: %v, (params: %v)", err, string(params)) } - return + return nil +} + +// deprecated use ConfigSnapshot.Create() instead +func (config ConfigSnapshot) CreateSnapshot(c *Client, vmr *VmRef) error { + return config.Create(c, vmr) } func (config ConfigSnapshot) Validate() error {