How to generate virtual machine id safely?

Egor

New Member
Nov 21, 2016
28
1
3
31
Web UI shows me the recommended virtual machine id:
upload_2017-3-9_14-38-32.png

How can I get this recommended ID via Proxmox API in order to avoid collisions while creating virtual machines?
The best scenario of course is when I can send POST request without specifying vm id myself and let proxmox assign it for me, because that will eliminate possible race conditions.
 
you can get the next free vmid with the api call under
/cluster/nextid

an api call without vmid is not likely, because of the "post once exactly"[1] principle
if we would allow a create call without vmid, and you send the request accidentally twice, we would create two vms
this is really not desireable

[1]: https://tools.ietf.org/html/draft-nottingham-http-poe-00
 
you can get the next free vmid with the api call under
/cluster/nextid

Thank you!

an api call without vmid is not likely, because of the "post once exactly"[1] principle
if we would allow a create call without vmid, and you send the request accidentally twice, we would create two vms
this is really not desireable

[1]: https://tools.ietf.org/html/draft-nottingham-http-poe-00

The idea is good, but, I think, implementation is not perfect. We are supporting a lot of hypervisors and this is the first time I see that thing with VmId. All the others just use virtual machine name as a key, so this won't allow for collision to happen =)
 
The idea is good, but, I think, implementation is not perfect. We are supporting a lot of hypervisors and this is the first time I see that thing with VmId. All the others just use virtual machine name as a key, so this won't allow for collision to happen =)
what if you want to create 2 vms with the same name? the same collision happens just with the name instead of the id

you can of course generate a random id until you find some that does not already exists (this minimizes a race, since the nextid call tries to find the lowest free id)
 
what if you want to create 2 vms with the same name? the same collision happens just with the name instead of the id

you can of course generate a random id until you find some that does not already exists (this minimizes a race, since the nextid call tries to find the lowest free id)
I am sorry to take up your time, as original question has already found its answer, but I want to know this.

What is the real world use case that demands 2 different virtual machines with the same name?

Please, don't think bad about me, it is just the first time I see that there is a need for that =)
 
Simple example: Clone a VM, the name will also be cloned. This name is only relevant for human beeings to identify your VM and does not have any influence on DNS for example, so machines with the same name do no harm (with LXC there are problems, but only minor name resolution problems by hosts, not by dns).

I have hundreds of machines in different networks running on my cluster and names can of course be used multiple times.
 
Simple example: Clone a VM, the name will also be cloned. This name is only relevant for human beeings to identify your VM and does not have any influence on DNS for example, so machines with the same name do no harm (with LXC there are problems, but only minor name resolution problems by hosts, not by dns).

I have hundreds of machines in different networks running on my cluster and names can of course be used multiple times.

1. If different vms have the same name it would be difficult for them to identify the one they need right? =)
2. When you are cloning, I guess, it is possible to ask a user to specify a new name for it and offer some standard name like "MyVm-clone1" (i.e. append suffix "-clone[n]").
3. In VmWare there is a problem with mac address collision when you are cloning. Probably, Proxmox has the same problem.
4. We also have a lot of virtual machines in our infrastructure, but all of them have different names =)
 
1. If different vms have the same name it would be difficult for them to identify the one they need right? =)

You normally group them, so there is no confusion. I have groups for different departments and often their respective administrators only see "their" stuff. In PVE, the ID is unique, so a name is only for humans.

I use pools for grouping (and then permissions for the entire group) and I also use ranges of numbers for different machines, so that I know that machines in the 1xxx range are crucial, 2xxx are still infrastructure but can fail, etc. From the "outside" I have logic to monitor them more often and do more backups, etc.

3. In VmWare there is a problem with mac address collision when you are cloning. Probably, Proxmox has the same problem.

Yes, the problem itself is the same for every cloning mechanism of every product, yet how they handle it differs.

4. We also have a lot of virtual machines in our infrastructure, but all of them have different names =)

Because you're used to VMware logic :-D
PVE uses IDs, so I think in them. Every API call you do with the REST api uses this identifier, not the name.

I really don't care about the names, often they are not every "descriptive", so I add more information about the machines in the machine description like IP, DNS, OS, purpose, etc. I hope there will be some way to query this information from the guest in the future.
 
I have the problem that generating multiple vm’s uses the same vmid (calling the nextid api method) so I need a way to secure or lock an id if exists
 
AFAIK, this only works if you create the VM immediately after querying nextid

Actually I am doing that. The application I am using is trying to create VM's not sure if in parallel or too fast. I just see the last machine created with the first id. :S
 

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!