cloudinit via api

YOsip

New Member
Feb 21, 2023
9
0
1
Hi:),
I saw a documentation how to attach a cloudinit drive to vm, and I want to do the same from the API.

1. I have created a vm (vm id: 9000 )
2. I have downloaded cloudinit image and uploaded it to ISO Images (/var/lib/vz/template/iso/focal-server-cloudimg-amd64.img)
3. ?? I want to add cloudinit drive to my vm specifying the image path (like in the example), and I don't understant the API

The example I saw is:
# download the image wget https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img # create a new VM with VirtIO SCSI controller qm create 9000 --memory 2048 --net0 virtio,bridge=vmbr0 --scsihw virtio-scsi-pci # import the downloaded disk to the local-lvm storage, attaching it as a SCSI drive qm set 9000 --scsi0 local-lvm:0,import-from=/path/to/bionic-server-cloudimg-amd64.img #The next step is to configure a CD-ROM drive, which will be used to pass the Cloud-Init data to the VM. qm set 9000 --ide2 local-lvm:cloudinit
(I am following this documentation: https://pve.proxmox.com/wiki/Cloud-Init_Support)

can you please help me understand what is the equivalent of the last two commands in the API calls?

Also, in the API tree I see:
PUT /api2/json/nodes/{node}/qemu/{vmid}/cloudinit (btw I think PUT & GET are reverted)
required: node, vmid; optional: new, old
can you please elaborate on new&old values?
 
Last edited:
Hi, the qm set commands correspond to a POST or PUT request to the /nodes/{node}/qemu/{vmid}/config endpoint [1].
With this you can also set the cloud-init options described in the wiki page you linked. The /cloudinit endpoint, on the other hand, is just for reading the current and pending cloud-init config (GET), and regenerating the cloud-init drive (PUT), as described in the API docs. Hope that helps!

[1] https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/config
[2] https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/cloudinit
 
Hi, the qm set commands correspond to a POST or PUT request to the /nodes/{node}/qemu/{vmid}/config endpoint [1].
With this you can also set the cloud-init options described in the wiki page you linked. The /cloudinit endpoint, on the other hand, is just for reading the current and pending cloud-init config (GET), and regenerating the cloud-init drive (PUT), as described in the API docs. Hope that helps!

[1] https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/config
[2] https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/qemu/{vmid}/cloudinit
Thank you! :)
 
I have another question in continuation to the previous one :)
using :
Code:
POST /api2/json/nodes/{node}/qemu/{vmid}/config
with option cicustom,
Screen Shot 2023-03-13 at 13.33.20.png
I can specify the cloud-init yaml configuration file names (of type meta, network, user, vendor) stored under local storage of type snippets, do I understand correctly? Not pass the fils themself, right?

And if so, how can I upload these files to the local storage using an api call?

(I saw this endpoint: POST /api2/json/nodes/{node}/storage/{storage}/upload, but the documentation states that it only uploads templates and ISO images)
 
I can specify the cloud-init yaml configuration file names (of type meta, network, user, vendor) stored under local storage of type snippets, do I understand correctly? Not pass the fils themself, right?
Yes, you can set cicustom e.g. to user=local:snippets/user.cfg to use the file snippets/user.cfg on the local storage instead of the autogenerated user data. The storage doesn't need to be local though, it just needs to have the content type "Snippets" enabled.

also saw this from a while ago: https://bugzilla.proxmox.com/show_bug.cgi?id=2208 with status UNDECIDED, so is it currently not supported?
Correct, it's currently not supported. You could, however, build some custom solution using ssh/sftp or some shared storage (NFS, CIFS, ...).
 
Yes, you can set cicustom e.g. to user=local:snippets/user.cfg to use the file snippets/user.cfg on the local storage instead of the autogenerated user data. The storage doesn't need to be local though, it just needs to have the content type "Snippets" enabled.


Correct, it's currently not supported. You could, however, build some custom solution using ssh/sftp or some shared storage (NFS, CIFS, ...).
Thank you for the explanation :)
 

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!