[pve-devel] [PATCH manager 4/8] add PVE.Utils.forEachBus and use it in qemu/HardwareView
Dominik Csapak
d.csapak at proxmox.com
Thu Mar 15 16:21:32 CET 2018
this iterates over all busses or over the ones you specify
( a single or an array )
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
www/manager6/Utils.js | 31 +++++++++++++++++++++++++++++++
www/manager6/qemu/HardwareView.js | 39 +++------------------------------------
2 files changed, 34 insertions(+), 36 deletions(-)
diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 87699e56..bb6a5141 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -894,6 +894,37 @@ Ext.define('PVE.Utils', { utilities: {
callback(evt.target.result);
};
reader.readAsText(file);
+ },
+
+ bus_counts: { ide: 4, sata: 6, scsi: 16, virtio: 16 },
+
+ // types is either undefined (all busses), an array of busses, or a single bus
+ forEachBus: function(types, func) {
+ var busses = Object.keys(PVE.Utils.bus_counts);
+ var i, j, count, cont;
+
+ if (Ext.isArray(types)) {
+ busses = types;
+ } else if (Ext.isDefined(types)) {
+ busses = [ types ];
+ }
+
+ // check if we only have valid busses
+ for (i = 0; i < busses.length; i++) {
+ if (!PVE.Utils.bus_counts[busses[i]]) {
+ throw "invalid bus: '" + busses[i] + "'";
+ }
+ }
+
+ for (i = 0; i < busses.length; i++) {
+ count = PVE.Utils.bus_counts[busses[i]];
+ for (j = 0; j < count; j++) {
+ cont = func(busses[i], j);
+ if (!cont && cont !== undefined) {
+ return;
+ }
+ }
+ }
}
},
diff --git a/www/manager6/qemu/HardwareView.js b/www/manager6/qemu/HardwareView.js
index 4b7d7e12..04fded6d 100644
--- a/www/manager6/qemu/HardwareView.js
+++ b/www/manager6/qemu/HardwareView.js
@@ -147,30 +147,8 @@ Ext.define('PVE.qemu.HardwareView', {
};
- for (i = 0; i < 4; i++) {
- confid = "ide" + i.toString();
- rows[confid] = {
- group: 1,
- tdCls: 'pve-itype-icon-storage',
- editor: 'PVE.qemu.HDEdit',
- never_delete: caps.vms['VM.Config.Disk'] ? false : true,
- header: gettext('Hard Disk') + ' (' + confid +')',
- cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
- };
- }
- for (i = 0; i < 6; i++) {
- confid = "sata" + i.toString();
- rows[confid] = {
- group: 1,
- tdCls: 'pve-itype-icon-storage',
- editor: 'PVE.qemu.HDEdit',
- never_delete: caps.vms['VM.Config.Disk'] ? false : true,
- header: gettext('Hard Disk') + ' (' + confid +')',
- cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
- };
- }
- for (i = 0; i < 16; i++) {
- confid = "scsi" + i.toString();
+ PVE.Utils.forEachBus(undefined, function(type, id) {
+ var confid = type + id;
rows[confid] = {
group: 1,
tdCls: 'pve-itype-icon-storage',
@@ -179,18 +157,7 @@ Ext.define('PVE.qemu.HardwareView', {
header: gettext('Hard Disk') + ' (' + confid +')',
cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
};
- }
- for (i = 0; i < 16; i++) {
- confid = "virtio" + i.toString();
- rows[confid] = {
- group: 1,
- tdCls: 'pve-itype-icon-storage',
- editor: 'PVE.qemu.HDEdit',
- never_delete: caps.vms['VM.Config.Disk'] ? false : true,
- header: gettext('Hard Disk') + ' (' + confid +')',
- cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
- };
- }
+ });
for (i = 0; i < 32; i++) {
confid = "net" + i.toString();
rows[confid] = {
--
2.11.0
More information about the pve-devel
mailing list