From a53a116b96f0b549bd05428de2912c4caa0a05c1 Mon Sep 17 00:00:00 2001 From: Pivnoy Date: Wed, 13 Mar 2024 21:30:19 +0300 Subject: [PATCH] vzdump api call --- types.go | 26 ++++++++++++++++++++++++++ virtual_machine.go | 13 +++++++++++++ 2 files changed, 39 insertions(+) diff --git a/types.go b/types.go index c646411..8299267 100644 --- a/types.go +++ b/types.go @@ -1242,3 +1242,29 @@ type FirewallIPSet struct { Digest string `json:"digest,omitempty"` Comment string `json:"comment,omitempty"` } + +type ( + ModeType = string + CompressType = string +) + +const ( + ModeSnapshot = ModeType("snapshot") + ModeSuspend = ModeType("suspend") + ModeStop = ModeType("stop") + + CompressZero = CompressType("0") + CompressOne = CompressType("1") + CompressGzip = CompressType("gzip") + CompressLzo = CompressType("lzo") + CompressZstd = CompressType("zstd") +) + +type VirtualMachineBackupOptions struct { + VMID uint64 `json:"vmid"` + Storage string `json:"storage,omitempty"` + Remove int `json:"remove,omitempty"` + Mode ModeType `json:"mode,omitempty"` + Compress CompressType `json:"compess,omitempty"` + Notes string `json:"notes,omitempty"` +} diff --git a/virtual_machine.go b/virtual_machine.go index 3e379d8..47d8fcd 100644 --- a/virtual_machine.go +++ b/virtual_machine.go @@ -643,3 +643,16 @@ func (v *VirtualMachine) ConvertToTemplate(ctx context.Context) (task *Task, err } return NewTask(upid, v.client), nil } + +func (v *VirtualMachine) Vzdump(ctx context.Context, params *VirtualMachineBackupOptions) (task *Task, err error) { + var upid UPID + + if params == nil { + params = &VirtualMachineBackupOptions{} + } + + if err = v.client.Post(ctx, fmt.Sprintf("/nodes/%s/vzdump", v.Node), params, &upid); err != nil { + return nil, err + } + return NewTask(upid, v.client), nil +}