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 v3 01/13] ui: utils: factor out 'media=cdrom' check
Date: Fri, 15 May 2026 10:44:19 +0200	[thread overview]
Message-ID: <20260515085349.1123127-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260515085349.1123127-1-d.csapak@proxmox.com>

this is a check we have all over the place and is prone to typos when
one tries to check it in a new place.

introduce a 'diskIsCdrom' check in Utils and use that in every place.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/manager6/Utils.js              | 9 ++++++++-
 www/manager6/qemu/BootOrderEdit.js | 6 +++---
 www/manager6/qemu/CreateWizard.js  | 4 ++--
 www/manager6/qemu/HardwareView.js  | 6 +++---
 www/manager6/window/GuestImport.js | 2 +-
 5 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 01e80682..a4d0e92b 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1966,6 +1966,13 @@ Ext.define('PVE.Utils', {
             return true;
         },
 
+        diskIsCdrom: function (value) {
+            if (!value) {
+                return false;
+            }
+            return !!value.toString().match(/media=cdrom/);
+        },
+
         sortByPreviousUsage: function (vmconfig, nodename) {
             let controllerList = ['ide', 'virtio', 'scsi', 'sata'];
             let usedControllers = {};
@@ -1976,7 +1983,7 @@ Ext.define('PVE.Utils', {
             for (const property of Object.keys(vmconfig)) {
                 if (
                     property.match(PVE.Utils.bus_match) &&
-                    !vmconfig[property].match(/media=cdrom/)
+                    !PVE.Utils.diskIsCdrom(vmconfig[property])
                 ) {
                     const foundController = property.match(PVE.Utils.bus_match)[1];
                     usedControllers[foundController]++;
diff --git a/www/manager6/qemu/BootOrderEdit.js b/www/manager6/qemu/BootOrderEdit.js
index 521a3d6e..c7117c1a 100644
--- a/www/manager6/qemu/BootOrderEdit.js
+++ b/www/manager6/qemu/BootOrderEdit.js
@@ -51,7 +51,7 @@ Ext.define('PVE.qemu.BootOrderPanel', {
         },
     },
 
-    isCloudinit: (v) => v.match(/media=cdrom/) && v.match(/[:/]vm-\d+-cloudinit/),
+    isCloudinit: (v) => PVE.Utils.diskIsCdrom(v) && v.match(/[:/]vm-\d+-cloudinit/),
 
     isDisk: function (value) {
         return PVE.Utils.bus_match.test(value);
@@ -97,7 +97,7 @@ Ext.define('PVE.qemu.BootOrderPanel', {
                     Ext.Object.each(me.vmconfig, function (key, value) {
                         if (
                             me.isDisk(key) &&
-                            value.match(/media=cdrom/) &&
+                            PVE.Utils.diskIsCdrom(value) &&
                             !me.isCloudinit(value)
                         ) {
                             list.push(key);
@@ -196,7 +196,7 @@ Ext.define('PVE.qemu.BootOrderPanel', {
                             iconCls;
                         if (value.match(/^net\d+$/)) {
                             iconCls = 'exchange';
-                        } else if (desc.match(/media=cdrom/)) {
+                        } else if (PVE.Utils.diskIsCdrom(desc)) {
                             metaData.tdCls = 'pve-itype-icon-cdrom';
                         } else {
                             iconCls = 'hdd-o';
diff --git a/www/manager6/qemu/CreateWizard.js b/www/manager6/qemu/CreateWizard.js
index 5eb784c4..2ee209da 100644
--- a/www/manager6/qemu/CreateWizard.js
+++ b/www/manager6/qemu/CreateWizard.js
@@ -33,14 +33,14 @@ Ext.define('PVE.qemu.CreateWizard', {
     // cannot know which one is a bootable iso and hardcodes the known values (ide0/2, net0)
     calculateBootOrder: function (values) {
         // user selected windows + second cdrom
-        if (values.ide0 && values.ide0.match(/media=cdrom/)) {
+        if (values.ide0 && PVE.Utils.diskIsCdrom(values.ide0)) {
             let disk;
             PVE.Utils.forEachBus(['ide', 'scsi', 'virtio', 'sata'], (type, id) => {
                 let confId = type + id;
                 if (!values[confId]) {
                     return undefined;
                 }
-                if (values[confId].match(/media=cdrom/)) {
+                if (PVE.Utils.diskIsCdrom(values[confId])) {
                     return undefined;
                 }
                 disk = confId;
diff --git a/www/manager6/qemu/HardwareView.js b/www/manager6/qemu/HardwareView.js
index 64cb4a7b..471e3a8f 100644
--- a/www/manager6/qemu/HardwareView.js
+++ b/www/manager6/qemu/HardwareView.js
@@ -22,7 +22,7 @@ Ext.define('PVE.qemu.HardwareView', {
             if (value.match(/vm-.*-cloudinit/)) {
                 iconCls = 'cloud';
                 txt = rowdef.cloudheader;
-            } else if (value.match(/media=cdrom/)) {
+            } else if (PVE.Utils.diskIsCdrom(value)) {
                 metaData.tdCls = 'pve-itype-icon-cdrom';
                 return rowdef.cdheader;
             }
@@ -417,7 +417,7 @@ Ext.define('PVE.qemu.HardwareView', {
                 let value = me.getObjectValue(rec.data.key, '', true);
                 if (isCloudInitKey(value)) {
                     return;
-                } else if (value.match(/media=cdrom/)) {
+                } else if (PVE.Utils.diskIsCdrom(value)) {
                     editor = 'PVE.qemu.CDEdit';
                 } else if (!diskCap) {
                     return;
@@ -757,7 +757,7 @@ Ext.define('PVE.qemu.HardwareView', {
             const isRunning = me.pveSelNode.data.running;
 
             const isCloudInit = isCloudInitKey(value);
-            const isCDRom = value && !!value.toString().match(/media=cdrom/);
+            const isCDRom = value && PVE.Utils.diskIsCdrom(value);
 
             const isUnusedDisk = key.match(/^unused\d+/);
             const isUsedDisk = !isUnusedDisk && row.isOnStorageBus && !isCDRom;
diff --git a/www/manager6/window/GuestImport.js b/www/manager6/window/GuestImport.js
index 9c9b0f1b..9a01e81d 100644
--- a/www/manager6/window/GuestImport.js
+++ b/www/manager6/window/GuestImport.js
@@ -1065,7 +1065,7 @@ Ext.define('PVE.window.GuestImport', {
 
                 let cdroms = [];
                 for (const [id, value] of Object.entries(me.vmConfig)) {
-                    if (!Ext.isString(value) || !value.match(/media=cdrom/)) {
+                    if (!Ext.isString(value) || !PVE.Utils.diskIsCdrom(value)) {
                         continue;
                     }
                     cdroms.push({
-- 
2.47.3





  reply	other threads:[~2026-05-15  8:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15  8:44 [PATCH manager v3 00/13] ui: split out disks and nics into grids Dominik Csapak
2026-05-15  8:44 ` Dominik Csapak [this message]
2026-05-15  8:44 ` [PATCH manager v3 02/13] ui: factor out the guest key nic regex check Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 03/13] ui: parser: qemu drive: allow '-' in key names Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 04/13] ui: add pending grid Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 05/13] ui: revert button: add parentXType and reloadCallback Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 06/13] ui: button: add config remove button Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 07/13] ui: qemu: hardware: wrap in container Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 08/13] ui: qemu: introduce hardware disk grid Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 09/13] ui: qemu: introduce hardware net grid Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 10/13] ui: qemu: hardware view: separate disks into own grid Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 11/13] ui: qemu: hardware view: separate nics " Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 12/13] ui: qemu: hardware view: inline edit/remove/revert button in general grid Dominik Csapak
2026-05-15  8:44 ` [PATCH manager v3 13/13] ui: qemu: hardware view: inline 'add efi' menuitem Dominik Csapak
2026-05-15  9:18 ` [PATCH manager v3 00/13] ui: split out disks and nics into grids Dominik Csapak
2026-05-15  9:20   ` 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=20260515085349.1123127-2-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