all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH manager v2 2/3] ui: factor out the guest key nic regex check
Date: Fri,  8 May 2026 15:38:05 +0200	[thread overview]
Message-ID: <20260508134110.4001168-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260508134110.4001168-1-d.csapak@proxmox.com>

It's better to have these regexes in one place, otherwise they're easily
typoed.

I noticed that some of the checks were not anchored at the end, but all
valid values these can have, should match the new check as well.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/manager6/Utils.js              | 7 +++++++
 www/manager6/lxc/Network.js        | 4 ++--
 www/manager6/qemu/BootOrderEdit.js | 6 +++---
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 6a27f253..035539fb 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1969,6 +1969,13 @@ Ext.define('PVE.Utils', {
             return !!value.toString().match(/media=cdrom/);
         },
 
+        keyIsNic: function (value) {
+            if (!value) {
+                return false;
+            }
+            return !!value.toString().match(/^net\d+$/);
+        },
+
         sortByPreviousUsage: function (vmconfig, nodename) {
             let controllerList = ['ide', 'virtio', 'scsi', 'sata'];
             let usedControllers = {};
diff --git a/www/manager6/lxc/Network.js b/www/manager6/lxc/Network.js
index e56d47c0..b2737471 100644
--- a/www/manager6/lxc/Network.js
+++ b/www/manager6/lxc/Network.js
@@ -89,7 +89,7 @@ Ext.define('PVE.lxc.NetworkInputPanel', {
                 value: cdata.name,
                 validator: function (value) {
                     for (const [key, netRaw] of Object.entries(me.dataCache)) {
-                        if (!key.match(/^net\d+/) || key === me.ifname) {
+                        if (!PVE.Utils.keyIsNic(key) || key === me.ifname) {
                             continue;
                         }
                         let net = PVE.Parser.parseLxcNetwork(netRaw);
@@ -385,7 +385,7 @@ Ext.define(
                 let records = [];
                 me.dataCache = confResponse.result.data || {};
                 for (const [key, value] of Object.entries(confResponse.result.data)) {
-                    if (!key.match(/^net\d+/)) {
+                    if (!PVE.Utils.keyIsNic(key)) {
                         continue;
                     }
                     let config = PVE.Parser.parseLxcNetwork(value);
diff --git a/www/manager6/qemu/BootOrderEdit.js b/www/manager6/qemu/BootOrderEdit.js
index c7117c1a..12f3b672 100644
--- a/www/manager6/qemu/BootOrderEdit.js
+++ b/www/manager6/qemu/BootOrderEdit.js
@@ -60,7 +60,7 @@ Ext.define('PVE.qemu.BootOrderPanel', {
     isBootdev: function (dev, value) {
         return (
             (this.isDisk(dev) && !this.isCloudinit(value)) ||
-            /^net\d+/.test(dev) ||
+            PVE.Utils.keyIsNic(dev) ||
             /^hostpci\d+/.test(dev) ||
             (/^usb\d+/.test(dev) && !/spice/.test(value))
         );
@@ -105,7 +105,7 @@ Ext.define('PVE.qemu.BootOrderPanel', {
                     });
                 } else if (orderList[i] === 'n') {
                     Ext.Object.each(me.vmconfig, function (key, value) {
-                        if (/^net\d+/.test(key)) {
+                        if (PVE.Utils.keyIsNic(key)) {
                             list.push(key);
                         }
                     });
@@ -194,7 +194,7 @@ Ext.define('PVE.qemu.BootOrderPanel', {
 
                         let icon = '',
                             iconCls;
-                        if (value.match(/^net\d+$/)) {
+                        if (PVE.Utils.keyIsNic(value)) {
                             iconCls = 'exchange';
                         } else if (PVE.Utils.diskIsCdrom(desc)) {
                             metaData.tdCls = 'pve-itype-icon-cdrom';
-- 
2.47.3





  parent reply	other threads:[~2026-05-08 13:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08 13:38 [PATCH manager v2 0/3] ui: split out disks and nics into grids Dominik Csapak
2026-05-08 13:38 ` [PATCH manager v2 1/3] ui: utils: factor out 'media=cdrom' check Dominik Csapak
2026-05-08 13:38 ` Dominik Csapak [this message]
2026-05-08 13:38 ` [PATCH manager v2 3/3] ui: qemu hardware view: split out disks and nics into grids Dominik Csapak

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=20260508134110.4001168-3-d.csapak@proxmox.com \
    --to=d.csapak@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