Search code examples
proxmox

get next free vnc port via proxmox api


After searching the proxmox forum and the api documentation I havent found a way to find next free vnc port like you can do with the next available vm id (see https://pve.proxmox.com/pve-docs/api-viewer/#/cluster/nextid )

Here's what I want to do.

  1. I have a template which I clone through the API.
  2. After that I set some config values through the API.

In step 2 I want to set the vnc port through the args parameter ( https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}/config).

The problem is I haven't found a possibility to find the next available free vnc port.
Unfortunately there also doesn't seem to be a way (other than via SSH) to run scripts on the node itself.

I know there are some workarounds

  • I could try every port (just no)
  • Track the available ports on my own (fails as soon as somebdy changes something outside my application)
  • run a startup scripts (proxmox calls those hookscripts) in which I parse all configs and set my port accordingly.
    this is probably the best option from above.

But before I implement something like that I want to make sure I haven't missed an easy way.

So, is there any way via API to find out then next available vnc port?


Solution

  • The short answer is: no, it's not possible to get the next free vnc port via API.

    Which leaves the options I outlined above. Depends on your use case which is the best, although the first one is definitly the worst and only an option if you can't implement one of the other options.
    And even then, if you have a lot of VMs it's just not viable.