From 7f640475b5606ba4a09fb6ce2b7f5d7ec9eb134e Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 15 Mar 2018 16:21:32 +0100 Subject: [PATCH] add PVE.Utils.forEachBus and use it in qemu/HardwareView this iterates over all busses or over the ones you specify ( a single or an array ) Signed-off-by: Dominik Csapak --- 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 87699e567..bb6a5141b 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 4b7d7e124..04fded6da 100644 --- a/www/manager6/qemu/HardwareView.js +++ b/www/manager6/qemu/HardwareView.js @@ -147,8 +147,8 @@ Ext.define('PVE.qemu.HardwareView', { }; - for (i = 0; i < 4; i++) { - confid = "ide" + i.toString(); + PVE.Utils.forEachBus(undefined, function(type, id) { + var confid = type + id; rows[confid] = { group: 1, tdCls: 'pve-itype-icon-storage', @@ -157,40 +157,7 @@ Ext.define('PVE.qemu.HardwareView', { 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(); - 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 = "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] = {