From ca65e0990485c55e20bcb24e0aa4f2ada7bf611b Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Wed, 27 Apr 2022 13:14:13 +0200 Subject: [PATCH] api: next-id: honor new datacenter.cfg upper/lower range option Signed-off-by: Thomas Lamprecht --- PVE/API2/Cluster.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm index 718a8eb9..1f4f4b08 100644 --- a/PVE/API2/Cluster.pm +++ b/PVE/API2/Cluster.pm @@ -737,11 +737,17 @@ __PACKAGE__->register_method({ raise_param_exc({ vmid => "VM $vmid already exists" }); } - for (my $i = 100; $i < 10000; $i++) { + my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg'); + my $next_id = $dc_conf->{'next-id'} // {}; + + 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}); } - die "unable to get any free VMID\n"; + die "unable to get any free VMID in range [$lower, $upper]\n"; }}); 1;