diff --git a/proxmox.go b/proxmox.go index 1ee490e..b38fffb 100644 --- a/proxmox.go +++ b/proxmox.go @@ -10,6 +10,7 @@ import ( "io" "mime/multipart" "net/http" + "net/url" "os" "path/filepath" "strings" @@ -146,6 +147,42 @@ func (c *Client) Get(ctx context.Context, p string, v interface{}) error { return c.Req(ctx, http.MethodGet, p, nil, v) } +// GetWithParams is a helper function to append query parameters to the URL +func (c *Client) GetWithParams(ctx context.Context, p string, d interface{}, v interface{}) error { + // Parse data and append to URL + if d != nil { + queryString, err := dataParserForURL(d) + if err != nil { + return err + } + p = p + "?" + queryString + } + return c.Req(ctx, http.MethodGet, p, nil, v) +} + +// dataParserForUrl parses the data and appends it to the URL as a query string +func dataParserForURL(d interface{}) (string, error) { + jsonBytes, err := json.Marshal(d) + if err != nil { + return "", err + } + + var m map[string]interface{} + err = json.Unmarshal(jsonBytes, &m) + if err != nil { + return "", err + } + + values := url.Values{} + for key, value := range m { + strValue := fmt.Sprintf("%v", value) + values.Set(key, strValue) + } + + return values.Encode(), nil + +} + func (c *Client) Post(ctx context.Context, p string, d interface{}, v interface{}) error { var data []byte if d != nil { diff --git a/types.go b/types.go index 0efca11..1a409b4 100644 --- a/types.go +++ b/types.go @@ -1611,3 +1611,13 @@ type VzdumpConfig struct { IPConfig8 string `json:"ipconfig8,omitempty"` IPConfig9 string `json:"ipconfig9,omitempty"` } + +type PendingConfiguration []PendingConfigItem + +type PendingConfigItem struct { + Key string `json:"key,omitempty"` + Delete *int `json:"delete,omitempty"` + // Proxmox API doc says "Pending" & "Value" fields return string but in reality it could be anything + Pending interface{} `json:"pending,omitempty"` + Value interface{} `json:"value,omitempty"` +} diff --git a/virtual_machine.go b/virtual_machine.go index 576eb43..c605dbd 100644 --- a/virtual_machine.go +++ b/virtual_machine.go @@ -675,3 +675,8 @@ func (v *VirtualMachine) UnmountCloudInitISO(ctx context.Context, device string) } return nil } + +func (v *VirtualMachine) Pending(ctx context.Context) (pending *PendingConfiguration, err error) { + err = v.client.Get(ctx, fmt.Sprintf("/nodes/%s/qemu/%d/pending", v.Node, v.VMID), &pending) + return +}