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 v4 01/12] ui: utils: factor out 'media=cdrom' check
Date: Mon, 31 Aug 2026 14:27:36 +0200	[thread overview]
Message-ID: <20260831122953.2980232-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260831122953.2980232-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 8b99371d..4eaec7b4 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -2014,6 +2014,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 = {};
@@ -2024,7 +2031,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 6239aeca..22112f8d 100644
--- a/www/manager6/qemu/BootOrderEdit.js
+++ b/www/manager6/qemu/BootOrderEdit.js
@@ -60,7 +60,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);
@@ -106,7 +106,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);
@@ -205,7 +205,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 f7f4b46f..d1e5d6c1 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;
             }
@@ -440,7 +440,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;
@@ -780,7 +780,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 1013fe14..fd05d558 100644
--- a/www/manager6/window/GuestImport.js
+++ b/www/manager6/window/GuestImport.js
@@ -1075,7 +1075,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-08-31 12:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 12:27 [PATCH manager v4 00/12] ui: split out disks and nics into grids Dominik Csapak
2026-08-31 12:27 ` Dominik Csapak [this message]
2026-08-31 12:27 ` [PATCH manager v4 02/12] ui: factor out the guest key nic regex check Dominik Csapak
2026-08-31 12:27 ` [PATCH manager v4 03/12] ui: add pending grid Dominik Csapak
2026-08-31 12:27 ` [PATCH manager v4 04/12] ui: revert button: add parentXType and reloadCallback Dominik Csapak
2026-08-31 12:27 ` [PATCH manager v4 05/12] ui: button: add config remove button Dominik Csapak
2026-08-31 12:27 ` [PATCH manager v4 06/12] ui: qemu: hardware: wrap in container Dominik Csapak
2026-08-31 12:27 ` [PATCH manager v4 07/12] ui: qemu: introduce hardware disk grid Dominik Csapak
2026-08-31 12:27 ` [PATCH manager v4 08/12] ui: qemu: introduce hardware net grid Dominik Csapak
2026-08-31 12:27 ` [PATCH manager v4 09/12] ui: qemu: hardware view: separate disks into own grid Dominik Csapak
2026-08-31 12:27 ` [PATCH manager v4 10/12] ui: qemu: hardware view: separate nics " Dominik Csapak
2026-08-31 12:27 ` [PATCH manager v4 11/12] ui: qemu: hardware view: inline edit/remove/revert button in general grid Dominik Csapak
2026-08-31 12:27 ` [PATCH manager v4 12/12] ui: qemu: hardware view: inline 'add efi' menuitem Dominik Csapak
2026-08-31 13:20 ` [PATCH manager v4 00/12] ui: split out disks and nics into grids Jonas Theisen
2026-08-31 14:11   ` Aaron Lauterer
2026-08-31 14:38   ` Jonas Theisen

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=20260831122953.2980232-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