From a53a116b96f0b549bd05428de2912c4caa0a05c1 Mon Sep 17 00:00:00 2001 From: Pivnoy Date: Wed, 13 Mar 2024 21:30:19 +0300 Subject: [PATCH 1/6] 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 +} From 9ec5fe0b8b40b46b049ee87d4bcb573f1199f231 Mon Sep 17 00:00:00 2001 From: Pivnoy Date: Wed, 13 Mar 2024 21:41:17 +0300 Subject: [PATCH 2/6] struct tag fix --- types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types.go b/types.go index 8299267..3fcd26b 100644 --- a/types.go +++ b/types.go @@ -1265,6 +1265,6 @@ type VirtualMachineBackupOptions struct { Storage string `json:"storage,omitempty"` Remove int `json:"remove,omitempty"` Mode ModeType `json:"mode,omitempty"` - Compress CompressType `json:"compess,omitempty"` + Compress CompressType `json:"compress,omitempty"` Notes string `json:"notes,omitempty"` } From 50b62d3800ab195f14c82fb3a9de7d9fc3cc01ef Mon Sep 17 00:00:00 2001 From: Pivnoy Date: Fri, 15 Mar 2024 13:40:34 +0300 Subject: [PATCH 3/6] replace vzdump method based on proxmox ve api --- nodes.go | 13 +++++++++++++ types.go | 2 +- virtual_machine.go | 13 ------------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/nodes.go b/nodes.go index 8080ac9..73dff3b 100644 --- a/nodes.go +++ b/nodes.go @@ -276,3 +276,16 @@ func (n *Node) GetCustomCertificates(ctx context.Context) (certs *NodeCertificat err = n.client.Get(ctx, fmt.Sprintf("/nodes/%s/certificates/info", n.Name), &certs) return } + +func (n *Node) Vzdump(ctx context.Context, params *VirtualMachineBackupOptions) (task *Task, err error) { + var upid UPID + + if params == nil { + return nil, fmt.Errorf("empty params") + } + + if err = n.client.Post(ctx, fmt.Sprintf("/nodes/%s/vzdump", n.Name), params, &upid); err != nil { + return nil, err + } + return NewTask(upid, n.client), nil +} diff --git a/types.go b/types.go index 3fcd26b..a04667f 100644 --- a/types.go +++ b/types.go @@ -1262,7 +1262,7 @@ const ( type VirtualMachineBackupOptions struct { VMID uint64 `json:"vmid"` - Storage string `json:"storage,omitempty"` + Storage string `json:"storage"` Remove int `json:"remove,omitempty"` Mode ModeType `json:"mode,omitempty"` Compress CompressType `json:"compress,omitempty"` diff --git a/virtual_machine.go b/virtual_machine.go index 47d8fcd..3e379d8 100644 --- a/virtual_machine.go +++ b/virtual_machine.go @@ -643,16 +643,3 @@ 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 -} From ff0cfcef2aeb5e9caaba8eb6b6ac395d26ec3cfb Mon Sep 17 00:00:00 2001 From: Pivnoy Date: Sat, 16 Mar 2024 01:27:17 +0300 Subject: [PATCH 4/6] review comment fixes --- nodes.go | 2 +- types.go | 63 +++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/nodes.go b/nodes.go index 73dff3b..cb7ba15 100644 --- a/nodes.go +++ b/nodes.go @@ -281,7 +281,7 @@ func (n *Node) Vzdump(ctx context.Context, params *VirtualMachineBackupOptions) var upid UPID if params == nil { - return nil, fmt.Errorf("empty params") + params = &VirtualMachineBackupOptions{} } if err = n.client.Post(ctx, fmt.Sprintf("/nodes/%s/vzdump", n.Name), params, &upid); err != nil { diff --git a/types.go b/types.go index a04667f..0d02b4e 100644 --- a/types.go +++ b/types.go @@ -1244,27 +1244,56 @@ type FirewallIPSet struct { } type ( - ModeType = string - CompressType = string + VirtualMachineBackupMode = string + VirtualMachineBackupCompress = string + VirtualMachineBackupNotificationPolicy = 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") + VirtualMachineBackupModeSnapshot = VirtualMachineBackupMode("snapshot") + VirtualMachineBackupModeSuspend = VirtualMachineBackupMode("suspend") + VirtualMachineBackupModeStop = VirtualMachineBackupMode("stop") + + VirtualMachineBackupCompressZero = VirtualMachineBackupCompress("0") + VirtualMachineBackupCompressOne = VirtualMachineBackupCompress("1") + VirtualMachineBackupCompressGzip = VirtualMachineBackupCompress("gzip") + VirtualMachineBackupCompressLzo = VirtualMachineBackupCompress("lzo") + VirtualMachineBackupCompressZstd = VirtualMachineBackupCompress("zstd") + + VirtualMachineBackupNotificationPolicyAlways = VirtualMachineBackupNotificationPolicy("always") + VirtualMachineBackupNotificationPolicyFailure = VirtualMachineBackupNotificationPolicy("failure") + VirtualMachineBackupNotificationPolicyNever = VirtualMachineBackupNotificationPolicy("never") ) type VirtualMachineBackupOptions struct { - VMID uint64 `json:"vmid"` - Storage string `json:"storage"` - Remove int `json:"remove,omitempty"` - Mode ModeType `json:"mode,omitempty"` - Compress CompressType `json:"compress,omitempty"` - Notes string `json:"notes,omitempty"` + All bool `json:"all,omitempty"` + BwLimit uint `json:"bwlimit,omitempty"` + Compress VirtualMachineBackupCompress `json:"compress,omitempty"` + DumpDir string `json:"dumpDir,omitempty"` + Exclude string `json:"exclude,omitempty"` + ExcludePath []string `json:"exclude-path,omitempty"` + IoNice uint `json:"ionice,omitempty"` + LockWait uint `json:"lockwait,omitempty"` + MailTo string `json:"mailto,omitempty"` + Mode VirtualMachineBackupMode `json:"mode,omitempty"` + Node string `json:"node,omitempty"` + NotesTemplate string `json:"notes-template,omitempty"` + NotificationPolicy VirtualMachineBackupNotificationPolicy `json:"notification-policy,omitempty"` + NotificationTarget string `json:"notification-target,omitempty"` + Performance string `json:"performance,omitempty"` + Pigz int `json:"pigz,omitempty"` + Pool string `json:"pool,omitempty"` + Protected string `json:"protected,omitempty"` + PruneBackups string `json:"prune-backups,omitempty"` + Quiet bool `json:"quiet,omitempty"` + Remove bool `json:"remove,omitempty"` + Script string `json:"script,omitempty"` + StdExcludes bool `json:"stdexcludes,omitempty"` + StdOut bool `json:"stdout,omitempty"` + Stop bool `json:"stop,omitempty"` + StopWait uint `json:"stopwait,omitempty"` + Storage string `json:"storage,omitempty"` + TmpDir string `json:"tmpdir,omitempty"` + VMID uint64 `json:"vmid,omitempty"` + Zstd uint `json:"zstd,omitempty"` } From 375c1b53994dde2fdd5ba999bf9a63e9bdf1f418 Mon Sep 17 00:00:00 2001 From: Pivnoy Date: Sat, 30 Mar 2024 16:10:05 +0300 Subject: [PATCH 5/6] cluster tasks api call --- cluster.go | 10 ++++++++++ types.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cluster.go b/cluster.go index a3da92c..c8c3f64 100644 --- a/cluster.go +++ b/cluster.go @@ -49,3 +49,13 @@ func (cl *Cluster) Resources(ctx context.Context, filters ...string) (rs Cluster return rs, cl.client.Get(ctx, u.String(), &rs) } + +func (cl *Cluster) Tasks(ctx context.Context) (Tasks, error) { + var tasks Tasks + + if err := cl.client.Get(ctx, "/cluster/tasks", &tasks); err != nil { + return nil, err + } + + return tasks, nil +} diff --git a/types.go b/types.go index 63f9651..8c0059b 100644 --- a/types.go +++ b/types.go @@ -580,7 +580,7 @@ type VirtualMachineMoveDiskOptions struct { type UPID string -type Tasks []*Tasks +type Tasks []*Task type Task struct { client *Client UPID UPID From 6e5c7e34535bfabed0d863030f3b535ab5faa528 Mon Sep 17 00:00:00 2001 From: Pivnoy Date: Sat, 30 Mar 2024 16:27:43 +0300 Subject: [PATCH 6/6] add client instance to cluster task --- cluster.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cluster.go b/cluster.go index c8c3f64..244e701 100644 --- a/cluster.go +++ b/cluster.go @@ -57,5 +57,9 @@ func (cl *Cluster) Tasks(ctx context.Context) (Tasks, error) { return nil, err } + for index := range tasks { + tasks[index].client = cl.client + } + return tasks, nil }