From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH manager v2 1/3] ui: utils: factor out 'media=cdrom' check
Date: Fri, 8 May 2026 15:38:04 +0200 [thread overview]
Message-ID: <20260508134110.4001168-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260508134110.4001168-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 be95d216..6a27f253 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1962,6 +1962,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 = {};
@@ -1972,7 +1979,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
next prev 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 ` Dominik Csapak [this message]
2026-05-08 13:38 ` [PATCH manager v2 2/3] ui: factor out the guest key nic regex check Dominik Csapak
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-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.