[PR #412] [MERGED] feature/import-from: add import-from feature to disks on create #450

Closed
opened 2026-02-28 00:42:14 +03:00 by kerem · 0 comments
Owner

📋 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: masterHead: feature/import-from


📝 Commits (2)

  • bf903a2 feature/import-from: add import-from feature to disks on create
  • 8f087ca feature/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-from option in Proxmox/Qemu VM creation with disks (scsi, ide, virtio,sata).
If the import-from option is set in the input JSON the only other required option is storage.

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:

  1. Create VM
  2. Import cloud-img
  3. Expand disk from image to desired size
  4. Boot

Then noticed that downstream in terraform-provider-proxmox the feature import-from for disks was implemented in 2.x versions that were never published. It seems to be removed now in 3.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 ImportFrom with the json mapper import-from (as in orig. docs of API) to the structs:

  • qemuDisk - proxmox/config_qemu_disk.go
  • QemuIdeDisk - proxmox/config_qemu_disk_ide.go
  • QemuSataDisk - proxmox/config_qemu_disk_sata.go
  • QemuScsiDisk - proxmox/config_qemu_disk_scsi.go
  • QemuVirtIODisk - proxmox/config_qemu_disk_virtio.go

The 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.go l.259-261.

The validation had to change as the otherwise required size and format are not needed here.
See proxmox/config_qemu_disk.go l.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.json

{
  "memory": {
    "capacity": 3072,
    "balloon": 0
  },
  "cpu": {
    "cores": 2
  },
  "bios": "seabios",
  "scsihw": "virtio-scsi-pci",
  "ostype": "l26",
  "name": "go-test",
  "disks": {
    "scsi": {
      "0": {
        "disk": {
          "storage": "vms-data",
          "import-from": "/var/lib/vz/template/iso/ubuntu-22.04-server-cloudimg-amd64.img"
        }
      }
    },
    "ide": {
      "0": {
        "disk": {
          "storage": "vms-data",
          "import-from": "/var/lib/vz/template/iso/ubuntu-22.04-server-cloudimg-amd64.img"
        }
      }
    },
    "sata": {
      "0": {
        "disk": {
          "storage": "vms-data",
          "import-from": "/var/lib/vz/template/iso/ubuntu-22.04-server-cloudimg-amd64.img"
        }
      }
    },
    "virtio": {
      "0": {
        "disk": {
          "storage": "vms-data",
          "import-from": "/var/lib/vz/template/iso/ubuntu-22.04-server-cloudimg-amd64.img"
        }
      }
    }
  },
  "bootdisk": "scsi0"
}

Got the VM created as expected:

image


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Telmate/proxmox-api-go/pull/412 **Author:** [@noahlehmann](https://github.com/noahlehmann) **Created:** 4/16/2025 **Status:** ✅ Merged **Merged:** 5/7/2025 **Merged by:** [@Tinyblargon](https://github.com/Tinyblargon) **Base:** `master` ← **Head:** `feature/import-from` --- ### 📝 Commits (2) - [`bf903a2`](https://github.com/Telmate/proxmox-api-go/commit/bf903a243b4ccd23e4d84f4ff8b8324bb14343d2) feature/import-from: add import-from feature to disks on create - [`8f087ca`](https://github.com/Telmate/proxmox-api-go/commit/8f087ca002fe486795210efca7851a545aae0174) feature/import-from: change import-from to import_from for json consistency ### 📊 Changes **5 files changed** (+20 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 Description # TL;DR; This PR implements the `import-from` option in Proxmox/Qemu VM creation with disks (scsi, ide, virtio,sata). If the `import-from` option is set in the input `JSON` the only other required option is `storage`. 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: 1. Create VM 2. Import cloud-img 3. Expand disk from image to desired size 4. Boot Then noticed that downstream in [terraform-provider-proxmox](https://github.com/Telmate/terraform-provider-proxmox) the feature `import-from` for disks was implemented in `2.x` versions that were never published. It seems to be removed now in `3.x`, see https://github.com/Telmate/terraform-provider-proxmox/issues/1236. [This comment](https://github.com/Telmate/terraform-provider-proxmox/issues/1236#issuecomment-2628006405) pointed out the need for upstream changes. --- ## How? I simply added the field `ImportFrom` with the json mapper `import-from` (as in orig. docs of API) to the structs: - `qemuDisk` - `proxmox/config_qemu_disk.go` - `QemuIdeDisk` - `proxmox/config_qemu_disk_ide.go` - `QemuSataDisk` - `proxmox/config_qemu_disk_sata.go` - `QemuScsiDisk` - `proxmox/config_qemu_disk_scsi.go` - `QemuVirtIODisk` - `proxmox/config_qemu_disk_virtio.go` The 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.go` l.259-261. The validation had to change as the otherwise required `size` and `format` are not needed here. See `proxmox/config_qemu_disk.go` l.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.json` ```json { "memory": { "capacity": 3072, "balloon": 0 }, "cpu": { "cores": 2 }, "bios": "seabios", "scsihw": "virtio-scsi-pci", "ostype": "l26", "name": "go-test", "disks": { "scsi": { "0": { "disk": { "storage": "vms-data", "import-from": "/var/lib/vz/template/iso/ubuntu-22.04-server-cloudimg-amd64.img" } } }, "ide": { "0": { "disk": { "storage": "vms-data", "import-from": "/var/lib/vz/template/iso/ubuntu-22.04-server-cloudimg-amd64.img" } } }, "sata": { "0": { "disk": { "storage": "vms-data", "import-from": "/var/lib/vz/template/iso/ubuntu-22.04-server-cloudimg-amd64.img" } } }, "virtio": { "0": { "disk": { "storage": "vms-data", "import-from": "/var/lib/vz/template/iso/ubuntu-22.04-server-cloudimg-amd64.img" } } } }, "bootdisk": "scsi0" } ``` Got the VM created as expected: ![image](https://github.com/user-attachments/assets/23d2945d-8b51-4c32-a3e7-a5b892c63edb) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 00:42:14 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/proxmox-api-go#450
No description provided.