all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: "Michael Köppl" <m.koeppl@proxmox.com>, pve-devel@lists.proxmox.com
Subject: Re: [PATCH pve-manager v5 6/7] close #4369: api: optionally only suggest unique IDs
Date: Tue, 22 Sep 2026 16:33:28 +0200	[thread overview]
Message-ID: <d0615f98-5b18-471a-8b40-24e913e95440@proxmox.com> (raw)
In-Reply-To: <20260921155410.938337-7-m.koeppl@proxmox.com>

Am 21.09.26 um 5:54 PM schrieb Michael Köppl:
> At the moment, the `/cluster/nextid` API endpoint will return the lowest
> available VM/CT ID, which means that it will suggest re-using VM IDs.
> This can be undesirable, so add an optional check to ensure that it
> chooses an ID which is not and has never been in use.
> 
> This optional behaviour is enabled when `unique-next-id: 1` in
> the datacenter config, and the previously used IDs are tracked as a
> list in the file `/etc/pve/used-guest-ids`.
> 
> Originally-by: Daniel Krambrock <krambrock@hrz.uni-marburg.de>
> Originally-by: Severen Redwood <severen.redwood@sitehost.co.nz>
> Signed-off-by: Michael Köppl <m.koeppl@proxmox.com>
> ---
>  PVE/API2/Cluster.pm | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
> index 4e5efbfd9..8178562a5 100644
> --- a/PVE/API2/Cluster.pm
> +++ b/PVE/API2/Cluster.pm
> @@ -20,6 +20,7 @@ use PVE::RPCEnvironment;
>  use PVE::SafeSyslog;
>  use PVE::Storage;
>  use PVE::Tools qw(extract_param);
> +use PVE::UsedGuestIDs;
>  
>  use PVE::API2::ACMEAccount;
>  use PVE::API2::ACMEPlugin;
> @@ -1041,12 +1042,18 @@ __PACKAGE__->register_method({
>  
>          my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
>          my $next_id = $dc_conf->{'next-id'} // {};
> +        my $used_ids;
> +        if ($dc_conf->{'unique-next-id'}) {
> +            $used_ids = PVE::UsedGuestIDs::read_list();
> +        } else {
> +            $used_ids = {};
> +        }
>  
>          my $lower = $next_id->{lower} // 100;
>          my $upper = $next_id->{upper} // (1000 * 1000); # note, lower than the schema-maximum
>  
>          for (my $i = $lower; $i < $upper; $i++) {
> -            return $i if !defined($idlist->{$i});
> +            return $i if !defined($idlist->{$i}) and !defined($used_ids->{$i});

Style nit: use '&&' instead of 'and' for logical expressions

>          }
>  
>          die "unable to get any free VMID in range [$lower, $upper]\n";





  reply	other threads:[~2026-09-22 14:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 15:54 [PATCH many v5 0/7] add option to prevent suggesting previously used VMIDs Michael Köppl
2026-09-21 15:54 ` [PATCH pve-cluster v5 1/7] cluster files: add used-guest-ids Michael Köppl
2026-09-22 14:22   ` Fiona Ebner
2026-09-21 15:54 ` [PATCH pve-cluster v5 2/7] datacenter config: add unique-next-id to schema Michael Köppl
2026-09-22 14:22   ` Fiona Ebner
2026-09-22 14:43     ` Michael Köppl
2026-09-23  7:48       ` Fiona Ebner
2026-09-23  8:01         ` Fiona Ebner
2026-09-23  8:18           ` Fiona Ebner
2026-09-21 15:54 ` [PATCH pve-guest-common v5 3/7] add module to track previously used guest IDs Michael Köppl
2026-09-22 14:22   ` Fiona Ebner
2026-09-22 15:55     ` Michael Köppl
2026-09-23  7:52       ` Fiona Ebner
2026-09-21 15:54 ` [PATCH qemu-server v5 4/7] api: record VM ID as used on creation, cloning, and destruction Michael Köppl
2026-09-22 14:33   ` Fiona Ebner
2026-09-21 15:54 ` [PATCH pve-container v5 5/7] api: record CT " Michael Köppl
2026-09-21 15:54 ` [PATCH pve-manager v5 6/7] close #4369: api: optionally only suggest unique IDs Michael Köppl
2026-09-22 14:33   ` Fiona Ebner [this message]
2026-09-21 15:54 ` [PATCH pve-manager v5 7/7] close #4369: ui: add datacenter option for unique VM/CT IDs Michael Köppl
2026-09-22 15:02 ` [PATCH many v5 0/7] add option to prevent suggesting previously used VMIDs Fiona Ebner
2026-09-23  8:13   ` Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d0615f98-5b18-471a-8b40-24e913e95440@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=m.koeppl@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal