mirror of
https://github.com/Telmate/proxmox-api-go.git
synced 2026-04-25 23:45:55 +03:00
[PR #412] [MERGED] feature/import-from: add import-from feature to disks on create #450
Labels
No labels
good first issue
issue/confirmed
issue/critical
proposal/accepted
pull-request
type/bug
type/enhancement
type/feature
type/question
type/refactoring
type/testing
type/testing
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/proxmox-api-go#450
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Telmate/proxmox-api-go/pull/412
Author: @noahlehmann
Created: 4/16/2025
Status: ✅ Merged
Merged: 5/7/2025
Merged by: @Tinyblargon
Base:
master← Head:feature/import-from📝 Commits (2)
bf903a2feature/import-from: add import-from feature to disks on create8f087cafeature/import-from: change import-from to import_from for json consistency📊 Changes
5 files changed (+20 additions, -6 deletions)
View changed files
📝
proxmox/config_qemu_disk.go(+12 -6)📝
proxmox/config_qemu_disk_ide.go(+2 -0)📝
proxmox/config_qemu_disk_sata.go(+2 -0)📝
proxmox/config_qemu_disk_scsi.go(+2 -0)📝
proxmox/config_qemu_disk_virtio.go(+2 -0)📄 Description
TL;DR;
This PR implements the
import-fromoption in Proxmox/Qemu VM creation with disks (scsi, ide, virtio,sata).If the
import-fromoption is set in the inputJSONthe only other required option isstorage.I am rather new to Golang, so please do point out any problems I might have missed.
Why?
Stumbled upon this when trying to replicate my current Ansible workflow in OpenTofu.
I was using prebuilt cloud images with clou-init preinstalled to have faster VM creation and no need to build custom iso-images.
The workflow:
Then noticed that downstream in terraform-provider-proxmox the feature
import-fromfor disks was implemented in2.xversions that were never published. It seems to be removed now in3.x, see https://github.com/Telmate/terraform-provider-proxmox/issues/1236.This comment pointed out the need for upstream changes.
How?
I simply added the field
ImportFromwith the json mapperimport-from(as in orig. docs of API) to the structs:qemuDisk-proxmox/config_qemu_disk.goQemuIdeDisk-proxmox/config_qemu_disk_ide.goQemuSataDisk-proxmox/config_qemu_disk_sata.goQemuScsiDisk-proxmox/config_qemu_disk_scsi.goQemuVirtIODisk-proxmox/config_qemu_disk_virtio.goThe mapping to API values had to be changed, as the API expects a specific pattern:
From API docs:
Use STORAGE_ID:0 and the 'import-from' parameter to import from an existing volume.See
proxmox/config_qemu_disk.gol.259-261.The validation had to change as the otherwise required
sizeandformatare not needed here.See
proxmox/config_qemu_disk.gol.530-537.Tests
I tested the changes with a running test cluster and the following
vm.json./proxmox-api-go -insecure createQemu 888 pve-1 < vm.jsonGot the VM created as expected:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.