UpdateVMConfig updates the configuration for a VM or container. For LXC: uses PUT (synchronous, no task ID) For QEMU: uses POST (asynchronous, returns task ID).
(vm *VM, config *VMConfig)
| 73 | // For LXC: uses PUT (synchronous, no task ID) |
| 74 | // For QEMU: uses POST (asynchronous, returns task ID). |
| 75 | func (c *Client) UpdateVMConfig(vm *VM, config *VMConfig) error { |
| 76 | endpoint := fmt.Sprintf("/nodes/%s/%s/%d/config", vm.Node, vm.Type, vm.ID) |
| 77 | data := buildConfigPayload(vm.Type, config) |
| 78 | |
| 79 | if vm.Type == VMTypeLXC { |
| 80 | err := c.httpClient.Put(context.Background(), endpoint, data, nil) |
| 81 | if err != nil { |
| 82 | c.logger.Error("Failed to update LXC config for %s %d with payload %+v: %v", vm.Type, vm.ID, data, err) |
| 83 | } |
| 84 | return err |
| 85 | } else if vm.Type == VMTypeQemu { |
| 86 | err := c.httpClient.Post(context.Background(), endpoint, data, nil) |
| 87 | if err != nil { |
| 88 | c.logger.Error("Failed to update QEMU config for %s %d with payload %+v: %v", vm.Type, vm.ID, data, err) |
| 89 | } |
| 90 | return err |
| 91 | } |
| 92 | |
| 93 | return fmt.Errorf("unsupported VM type: %s", vm.Type) |
| 94 | } |
| 95 | |
| 96 | // ResizeVMStorage resizes a disk for a VM or container. |
| 97 | func (c *Client) ResizeVMStorage(vm *VM, disk string, size string) error { |
no test coverage detected