[PR #279] [MERGED] feat: add support for unlinking disks from VM #366

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

📋 Pull Request Information

Original PR: https://github.com/Telmate/proxmox-api-go/pull/279
Author: @FredrickB
Created: 11/7/2023
Status: Merged
Merged: 12/6/2023
Merged by: @mleone87

Base: masterHead: add-detaching-disks-functionality-to-client


📝 Commits (1)

  • d062c3c feat: add support for unlinking disks from VM

📊 Changes

3 files changed (+49 additions, -0 deletions)

View changed files

📝 README.md (+2 -0)
📝 main.go (+28 -0)
📝 proxmox/client.go (+19 -0)

📄 Description

Added support for unlinking a disk from a VM with optional force-removal. This is the first step to fix an issue
in the Proxmox Terraform provider where the disks are not removed correctly if removed from the HCL as part
of a cloud-init based VM.

Testing

I have tested the changes on a local Proxmox install, version 8.0.4 with the following modified example JSON for creating the Qemu VM:

qemu1.json (supply name of iso-file uploaded to Proxmox node):

{
  "name": "golang1.test.com",
  "desc": "Test proxmox-api-go",
  "memory": 512,
  "os": "l26",
  "cores": 2,
  "sockets": 1,
  "iso": {
    "file": "iso/<some-iso>.iso",
    "storage": "local"
  },
  "disk": {
    "0": {
      "type": "virtio",
      "storage": "local",
      "storage_type": "dir",
      "size": "5G",
      "backup": true
    },
    "1": {
      "type": "virtio",
      "storage": "local",
      "storage_type": "dir",
      "size": "1G",
      "backup": true
    },
    "2": {
      "type": "virtio",
      "storage": "local",
      "storage_type": "dir",
      "size": "1G",
      "backup": true
    }
  },
  "network": {
    "0": {
      "model": "virtio",
      "bridge": "nat"
    }
  }
}
./proxmox-api-go --insecure createQemu 100 <proxmox-node-name> < qemu1.json

Scenarios

Should unlink the disk virtio1 and leave it as Unused Disk 0 in tab Hardware of VM

./proxmox-api-go unlink 100 <proxmox-node-name> virtio1

Should unlink the disk virtio2 and remove it from tab Hardware of VM

./proxmox-api-go unlink 100 <proxmox-node-name> virtio2 true

Should unlink the disks virtio1 and virtio2 and remove both from tab Hardware of VM

./proxmox-api-go unlink 100 <proxmox-node-name> "virtio1,virtio2" true

🔄 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/279 **Author:** [@FredrickB](https://github.com/FredrickB) **Created:** 11/7/2023 **Status:** ✅ Merged **Merged:** 12/6/2023 **Merged by:** [@mleone87](https://github.com/mleone87) **Base:** `master` ← **Head:** `add-detaching-disks-functionality-to-client` --- ### 📝 Commits (1) - [`d062c3c`](https://github.com/Telmate/proxmox-api-go/commit/d062c3c600ea0abfe962c2e3fa831a523cdc672b) feat: add support for unlinking disks from VM ### 📊 Changes **3 files changed** (+49 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+2 -0) 📝 `main.go` (+28 -0) 📝 `proxmox/client.go` (+19 -0) </details> ### 📄 Description Added support for unlinking a disk from a VM with optional force-removal. This is the first step to fix an issue in the Proxmox Terraform provider where the disks are not removed correctly if removed from the HCL as part of a cloud-init based VM. ## Testing I have tested the changes on a local Proxmox install, version `8.0.4` with the following modified example JSON for creating the Qemu VM: `qemu1.json` (supply name of iso-file uploaded to Proxmox node): ```json { "name": "golang1.test.com", "desc": "Test proxmox-api-go", "memory": 512, "os": "l26", "cores": 2, "sockets": 1, "iso": { "file": "iso/<some-iso>.iso", "storage": "local" }, "disk": { "0": { "type": "virtio", "storage": "local", "storage_type": "dir", "size": "5G", "backup": true }, "1": { "type": "virtio", "storage": "local", "storage_type": "dir", "size": "1G", "backup": true }, "2": { "type": "virtio", "storage": "local", "storage_type": "dir", "size": "1G", "backup": true } }, "network": { "0": { "model": "virtio", "bridge": "nat" } } } ``` ```bash ./proxmox-api-go --insecure createQemu 100 <proxmox-node-name> < qemu1.json ``` ### Scenarios #### Unlink disk, but don't delete it Should unlink the disk `virtio1` and leave it as `Unused Disk 0` in tab `Hardware` of VM ```bash ./proxmox-api-go unlink 100 <proxmox-node-name> virtio1 ``` #### Unlink disk, and delete it Should unlink the disk `virtio2` and remove it from tab `Hardware` of VM ```bash ./proxmox-api-go unlink 100 <proxmox-node-name> virtio2 true ``` #### Unlink and delete multiple disks Should unlink the disks `virtio1` and `virtio2` and remove both from tab `Hardware` of VM ```bash ./proxmox-api-go unlink 100 <proxmox-node-name> "virtio1,virtio2" true ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 00:41:55 +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#366
No description provided.