Proxmox API: Adding disk only if not yet existing?

hvisage

Renowned Member
May 21, 2013
249
19
83
Goodday
referring to https://forum.proxmox.com/threads/create-disk-using-the-proxmox-api.27580/post-138824 this will (silently) create a new disk and attach that (ie.put the current staoge as a Unused disk, create the new storage and attach that in the old disk's place).

Is there an option I missed to (a) ignore the creation if a disk is already attached in that position and/or (b) throw and error is disk already exists?

Or should I rather use the work flow of creating the volume in storage, then attaching that, and to fail if the expected storage name/vole already exists?
 
Hi,
I don't think there's such an option (at least I don't know from the top of my head), but you could use the GET /nodes/<node>/qemu/<id>/config API call and check if there is already a disk at a certain place beforehand.
 
mmm... I'm seeing "interesting" differences between PUT and POST

Code:
scsi2: "local-zfs:vm-366810-disk-2,discard=on,ssd=1"

POST of those lines seems to create always, wil POST would either break (after a time out of trying to wait for that local-zfs:vm-366810-disk-2 to become "available", so not immediately ;( ) but repeat runs will "force" that.

a simple
Code:
local-zfs:<size>
seems to always create the disk. So that seems to be missing information in the documentation (Or did I yet again missed something?)
 
mmm... I'm seeing "interesting" differences between PUT and POST

Code:
scsi2: "local-zfs:vm-366810-disk-2,discard=on,ssd=1"

POST of those lines seems to create always, wil POST would either break (after a time out of trying to wait for that local-zfs:vm-366810-disk-2 to become "available", so not immediately ;( ) but repeat runs will "force" that.
PUT is synchronous so it can time out, while the POST call creates a worker task and thus should be used for calls involving storage, see also here.

a simple
Code:
local-zfs:<size>
seems to always create the disk. So that seems to be missing information in the documentation (Or did I yet again missed something?)
Yes, this is special syntax for allocating new disks. Which part of the documentation are you referring to?
 
PUT is synchronous so it can time out, while the POST call creates a worker task and thus should be used for calls involving storage, see also here.
Ah! missed that, thank you!!
Yes, this is special syntax for allocating new disks. Which part of the documentation are you referring to?
https://pve.proxmox.com/pve-docs/chapter-qm.html#qm_options
https://pve.proxmox.com/pve-docs/qm.1.html
https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/config

I see the references to [file=]<volume> in ide/virtio/scsi, but nowhere there the <storage>:<size> syntax that auto-creates the storage, or is there another place I missed?

Busy trying to find Ansible "consistent" idempotent methods to create VMs + storage without starting a month long coding project
 
You are right. We are going to document this in a future version, thanks!
 
  • Like
Reactions: hvisage
Today I did stumble on it in the pct(1) documentation though ;)
(But not the QEMU/qm(1) yet )
 
It is in there, but well hidden:
Code:
   CLI Usage Examples
       Using an iso file uploaded on the local storage, create a VM with a 4 GB IDE disk on the local-lvm storage

           qm create 300 -ide0 local-lvm:4 -net0 e1000 -cdrom local:iso/proxmox-mailgateway_2.1.iso

We are going to mention it in more places including the API viewer.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!