API - Get VM gen id

ksl28

Member
Aug 31, 2023
31
4
8
Hey,

I need to map all of our VMs across several proxmox installations, and need to discover the vmgenid for a virtual machine.
Given that VMID 100 can exists in all our clusters, i cant really rely on that as the unique identifier for my usecase.

For now i am looping through each of the VMs, and then getting the vmgenid here - https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}/config

I had hoped i could get the ID more quickly - like with the https://pve.proxmox.com/pve-docs/api-viewer/#/cluster/resources
https://proxmox01:8006/api2/json/cluster/resources?type=vm


1. Is it possible to do a single API call for a PVE node in a cluster, and then get the vmgenid back, instead of having to loop through each host?
2. Is the vmgenid truly unique - or will it change if a snapshot is taken, etc?
I understand that if someone deletes the VM and restores it, that it MIGHT be changed - and that is fine. As long as it does NOT change for the VMs lifetime.
 
1. Is it possible to do a single API call for a PVE node in a cluster, and then get the vmgenid back, instead of having to loop through each host?
You will need to loop through each VM. Alternatively, you can grep/awk/sed in /etc/pve/. If this is a onetime exercise, it may be a case where shell search would be more efficient.

2. Is the vmgenid truly unique - or will it change if a snapshot is taken, etc?
yes, the code generating it uses functions that you can rely to be unique.

You can also start specifying your own vmgenid that is centrally managed to ensure uniqueness. (man qm)

Another option is to set VM ID ranges to be non-overlapping for your clusters.



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
You will need to loop through each VM. Alternatively, you can grep/awk/sed in /etc/pve/. If this is a onetime exercise, it may be a case where shell search would be more efficient.


yes, the code generating it uses functions that you can rely to be unique.

You can also start specifying your own vmgenid that is centrally managed to ensure uniqueness. (man qm)

Another option is to set VM ID ranges to be non-overlapping for your clusters.



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox

Really awesome reply, and it showcases a lot of different methods

Would it be possible to do a feature request (if yes, then how?), to include the vmgenid in the cluster resources response?
 
Would it be possible to do a feature request (if yes, then how?), to include the vmgenid in the cluster resources response?
Yes, of course you can submit a FR. Here is an article that goes over your options : https://www.proxmox.com/en/about/open-source/developers

That said, vmgenid is necessary for you at this time. Someone else might need a different field. You can see how the resource field can blow up.
A lot of this information, even internally in PVE, needs to be assembled via several API calls. So its hard to imagine that the stable API will be changed to help something that can be done via customer-facing API.

Best


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Yes, of course you can submit a FR. Here is an article that goes over your options : https://www.proxmox.com/en/about/open-source/developers

That said, vmgenid is necessary for you at this time. Someone else might need a different field. You can see how the resource field can blow up.
A lot of this information, even internally in PVE, needs to be assembled via several API calls. So its hard to imagine that the stable API will be changed to help something that can be done via customer-facing API.

Best


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
That makes perfect sense to be honest - but its worth a shot :)

Just tested a restore with Veeam (new placement option), and saw that the ID is not changed.
Looks like a Veeam bug, but not sure if it could affect Proxmox VMs running - that two VMs have the same ID?

1748449458276.png
 
Just tested a restore with Veeam (new placement option), and saw that the ID is not changed.
Looks like a Veeam bug, but not sure if it could affect Proxmox VMs running - that two VMs have the same ID?
Based on the description below, the vmgenid is a serial number that is used by OS (some OS'es in some cases) to track whether the underlying hardware/state has changed. It is not used by PVE as a hypervisor. Remember, it is just a random UUID without any "secret" information built into it.

Code:
The VM generation ID (vmgenid) device exposes a 128-bit integer value identifier to the guest OS. This allows to notify the guest operating 
system when the virtual machine is executed with a different configuration (e.g. snapshot execution or creation from a template). The guest 
operating system notices the change, and is then able to react as appropriate by marking its copies of distributed databases as dirty,
 re-initializing its random number generator, etc.
Note that auto-creation only works when done through API/CLI create or update methods, but not when manually editing the config file.

So it may be desirable to have the same vmgenid after backup restore because OS/Applications can depend on it.

I think you are stretching the purpose of this field to use it as some sort of VM tracking mechanism across PVE clusters. A centralized management (via comment, tag, name, etc) will always yield better results.

Good luck



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Based on the description below, the vmgenid is a serial number that is used by OS (some OS'es in some cases) to track whether the underlying hardware/state has changed. It is not used by PVE as a hypervisor. Remember, it is just a random UUID without any "secret" information built into it.

Code:
The VM generation ID (vmgenid) device exposes a 128-bit integer value identifier to the guest OS. This allows to notify the guest operating
system when the virtual machine is executed with a different configuration (e.g. snapshot execution or creation from a template). The guest
operating system notices the change, and is then able to react as appropriate by marking its copies of distributed databases as dirty,
 re-initializing its random number generator, etc.
Note that auto-creation only works when done through API/CLI create or update methods, but not when manually editing the config file.

So it may be desirable to have the same vmgenid after backup restore because OS/Applications can depend on it.

I think you are stretching the purpose of this field to use it as some sort of VM tracking mechanism across PVE clusters. A centralized management (via comment, tag, name, etc) will always yield better results.

Good luck



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox

Thanks for the reply.

I am looking for a value that is always unique, across all my Proxmox clusters.
I initially created the solution based on the combination of the VMID and the PVE Cluster name, but that gave to many relations in the database, for it to work in a good way.

Its basically this functionality i am looking for:
https://support.hornetsecurity.com/hc/en-us/articles/19688383111569-Find-the-UUID-of-a-VMware-VM

So wanted to use the vmgenid instead - still think its a viable solution, as long as we take into consideration, that in case of a restore it might not be unique.