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 <d.csapak@proxmox.com>
This commit is contained in:
parent
d8a97e7413
commit
7f640475b5
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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] = {
|
||||
|
Loading…
Reference in New Issue
Block a user