From: Daniel Krambrock via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Daniel Krambrock <krambrock@hrz.uni-marburg.de>
Subject: [pve-devel] [PATCH manager] close #4369: make VMID suggestion strategy configurable
Date: Wed, 22 May 2024 14:05:50 +0200 [thread overview]
Message-ID: <mailman.225.1716379933.319.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20240522120553.49114-1-krambrock@hrz.uni-marburg.de>
[-- Attachment #1: Type: message/rfc822, Size: 7996 bytes --]
From: Daniel Krambrock <krambrock@hrz.uni-marburg.de>
To: pve-devel@lists.proxmox.com
Subject: [PATCH manager] close #4369: make VMID suggestion strategy configurable
Date: Wed, 22 May 2024 14:05:50 +0200
Message-ID: <20240522120553.49114-2-krambrock@hrz.uni-marburg.de>
VMID suggestion strategy is set in datacenter config
Signed-off-by: Daniel Krambrock <krambrock@hrz.uni-marburg.de>
---
PVE/API2/Cluster.pm | 16 +++++++++--
PVE/Makefile | 1 +
PVE/UsedVmidList.pm | 53 +++++++++++++++++++++++++++++++++++
www/manager6/dc/OptionView.js | 14 +++++++++
4 files changed, 82 insertions(+), 2 deletions(-)
create mode 100644 PVE/UsedVmidList.pm
diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
index 04387ab4..be79ddf0 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::UsedVmidList;
use PVE::API2::ACMEAccount;
use PVE::API2::ACMEPlugin;
@@ -813,12 +814,23 @@ __PACKAGE__->register_method({
my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
my $next_id = $dc_conf->{'next-id'} // {};
+ my $strategy = $dc_conf->{'next-id-strategy'} // "next-free";
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});
+ if ($strategy eq "next-free") {
+ for (my $i = $lower; $i < $upper; $i++) {
+ return $i if !defined($idlist->{$i});
+ }
+ } elsif ($strategy eq "max+1") {
+ return %$idlist ? (List::Util::max(keys %$idlist) + 1) : $lower
+ } elsif ($strategy eq "list") {
+ for (my $i = $lower; $i < $upper; $i++) {
+ return $i if (!defined($idlist->{$i}) and !PVE::UsedVmidList::is_on_vmid_list($i)) ;
+ }
+ } else {
+ die "unable to get any free VMID with strategy $strategy\n";
}
die "unable to get any free VMID in range [$lower, $upper]\n";
diff --git a/PVE/Makefile b/PVE/Makefile
index 660de4d0..fe627296 100644
--- a/PVE/Makefile
+++ b/PVE/Makefile
@@ -14,6 +14,7 @@ PERLSOURCE = \
Jobs.pm \
NodeConfig.pm \
Report.pm \
+ UsedVmidList.pm \
VZDump.pm
all: pvecfg.pm $(SUBDIRS)
diff --git a/PVE/UsedVmidList.pm b/PVE/UsedVmidList.pm
new file mode 100644
index 00000000..a60c75d6
--- /dev/null
+++ b/PVE/UsedVmidList.pm
@@ -0,0 +1,53 @@
+package PVE::UsedVmidList;
+
+use strict;
+use warnings;
+
+use PVE::Cluster;
+
+my $parse_vmid_list = sub {
+ my ($filename, $raw) = @_;
+
+ return [] if !defined($raw);
+
+ my @parsed;
+ my @lines = split(/\n/, $raw);
+ foreach my $line (@lines) {
+ next if $line =~ m/^\s*$/;
+
+ if ($line =~ m/^(\d+)$/) {
+ push(@parsed, $1);
+ } else {
+ warn "Skipping invalid used_vmids.list entry: $line\n";
+ }
+ }
+
+ return \@parsed;
+};
+
+my $write_vmid_list = sub {
+ my ($filename, @data) = @_;
+
+ return join("\n", sort @data);
+};
+
+PVE::Cluster::cfs_register_file('used_vmids.list', $parse_vmid_list, $write_vmid_list);
+
+sub add_vmid {
+ my ($vmid) = @_;
+
+ PVE::Cluster::cfs_lock_file('used_vmids.list', 10, sub {
+ my $vmid_list = PVE::Cluster::cfs_read_file('used_vmids.list');
+
+ push(@$vmid_list, $vmid);
+ PVE::Cluster::cfs_write_file('used_vmids.list', join("\n", @$vmid_list));
+ });
+}
+
+sub is_on_vmid_list {
+ my ($vmid) = @_;
+ my $vmid_list = PVE::Cluster::cfs_read_file('used_vmids.list');
+ return scalar(grep { $_ == $vmid } @$vmid_list);
+}
+
+1;
diff --git a/www/manager6/dc/OptionView.js b/www/manager6/dc/OptionView.js
index b200fd12..613a2183 100644
--- a/www/manager6/dc/OptionView.js
+++ b/www/manager6/dc/OptionView.js
@@ -339,6 +339,20 @@ Ext.define('PVE.dc.OptionView', {
submitValue: true,
}],
});
+ me.add_combobox_row('next-id-strategy', gettext('Next Free VMID Strategy'), {
+ renderer: v => {
+ if (v === '__default__') {return Proxmox.Utils.defaultText;}
+ return v;
+ },
+ comboItems: [
+ ['__default__', Proxmox.Utils.defaultText + ' (next-free)'],
+ ['next-free', 'next-free'],
+ ['max+1', 'max+1'],
+ ['list', 'list'],
+ ],
+ defaultValue: '__default__',
+ deleteEmpty: true,
+ });
me.rows['tag-style'] = {
required: true,
renderer: (value) => {
--
2.39.2
[-- Attachment #2: Type: text/plain, Size: 160 bytes --]
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next parent reply other threads:[~2024-05-22 12:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240522120553.49114-1-krambrock@hrz.uni-marburg.de>
2024-05-22 12:05 ` Daniel Krambrock via pve-devel [this message]
2024-05-22 12:05 ` [pve-devel] [PATCH cluster] " Daniel Krambrock via pve-devel
2024-05-22 12:05 ` [pve-devel] [PATCH container] " Daniel Krambrock via pve-devel
2024-05-22 12:05 ` [pve-devel] [PATCH qemu] " Daniel Krambrock via pve-devel
2024-06-05 8:56 ` [pve-devel] (no subject) Shannon Sterz
[not found] ` <20240522120553.49114-2-krambrock@hrz.uni-marburg.de>
2024-06-05 8:57 ` [pve-devel] [PATCH manager] close #4369: make VMID suggestion strategy configurable Shannon Sterz
[not found] ` <20240522120553.49114-3-krambrock@hrz.uni-marburg.de>
2024-06-05 8:57 ` [pve-devel] [PATCH cluster] " Shannon Sterz
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=mailman.225.1716379933.319.pve-devel@lists.proxmox.com \
--to=pve-devel@lists.proxmox.com \
--cc=krambrock@hrz.uni-marburg.de \
/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