Skip to content

Commit

Permalink
feat: add unsafe create for snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyblargon committed Feb 29, 2024
1 parent 8c93ee1 commit eee8b3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cli/command/create/create-snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
if err != nil {
return
}
err = config.CreateSnapshot(client, vmr)
err = config.Create(client, vmr)
if err != nil {
return
}
Expand Down
17 changes: 14 additions & 3 deletions proxmox/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(&params)
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 {
Expand Down

0 comments on commit eee8b3e

Please sign in to comment.