mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-29 18:21:10 +00:00
* feat(node): implement CRUD API for proxmox node config Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> * fix: add unit tests, fix UnmarshalJSON Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --------- Signed-off-by: Björn Brauer <zaubernerd@zaubernerd.de> Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
package nodes
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/bpg/terraform-provider-proxmox/proxmox/api"
|
|
)
|
|
|
|
// GetConfig retrieves the config for a node.
|
|
func (c *Client) GetConfig(ctx context.Context) (*[]ConfigGetResponseData, error) {
|
|
resBody := &ConfigGetResponseBody{}
|
|
|
|
err := c.DoRequest(ctx, http.MethodGet, c.ExpandPath("config"), nil, resBody)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error retrieving node config: %w", err)
|
|
}
|
|
|
|
if resBody.Data == nil {
|
|
return nil, api.ErrNoDataObjectInResponse
|
|
}
|
|
|
|
return resBody.Data, nil
|
|
}
|
|
|
|
// UpdateConfig updates the config for a node.
|
|
func (c *Client) UpdateConfig(ctx context.Context, d *ConfigUpdateRequestBody) error {
|
|
err := c.DoRequest(ctx, http.MethodPost, c.ExpandPath("config"), d, nil)
|
|
if err != nil {
|
|
return fmt.Errorf("error updating node config: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|