pve-manager/www/manager6/qemu/ProcessorEdit.js
Dominik Csapak 3190f6266e rework ProcessorEdit and merge with CPUOptions using advanced options
make ProcessorEdit static and merge with CPUOptions
moves some fields in the advanced options

this also changes how we add the flag checkboxes,
which is static now, but if we want to add more, we have to
create a better way than add a checkbox for each flag anyway

also increases the cpulimit to 128 (as per api)
and fixes a small whitespace error

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-04-06 11:45:14 +02:00

215 lines
4.2 KiB
JavaScript

Ext.define('PVE.qemu.ProcessorInputPanel', {
extend: 'Proxmox.panel.InputPanel',
alias: 'widget.pveQemuProcessorPanel',
onlineHelp: 'qm_cpu',
insideWizard: false,
controller: {
xclass: 'Ext.app.ViewController',
updateCores: function() {
var me = this.getView();
var sockets = me.down('field[name=sockets]').getValue();
var cores = me.down('field[name=cores]').getValue();
me.down('field[name=totalcores]').setValue(sockets*cores);
var vcpus = me.down('field[name=vcpus]');
vcpus.setMaxValue(sockets*cores);
vcpus.setEmptyText(sockets*cores);
vcpus.validate();
},
control: {
'field[name=sockets]': {
change: 'updateCores'
},
'field[name=cores]': {
change: 'updateCores'
}
}
},
onGetValues: function(values) {
var me = this;
if (Array.isArray(values['delete'])) {
values['delete'] = values['delete'].join(',');
}
PVE.Utils.delete_if_default(values, 'cpulimit', '0', 0);
PVE.Utils.delete_if_default(values, 'cpuunits', '1024', 0);
// build the cpu options:
me.cpu.cputype = values.cputype;
var flags = [];
['pcid', 'spec-ctrl'].forEach(function(flag) {
if (values[flag]) {
flags.push('+' + flag.toString());
}
delete values[flag];
});
me.cpu.flags = flags.length ? flags.join(';') : undefined;
delete values.cputype;
delete values.flags;
var cpustring = PVE.Parser.printQemuCpu(me.cpu);
// remove cputype delete request:
var del = values['delete'];
delete values['delete'];
if (del) {
del = del.split(',');
Ext.Array.remove(del, 'cputype');
} else {
del = [];
}
if (cpustring) {
values.cpu = cpustring;
} else {
del.push('cpu');
}
var delarr = del.join(',');
if (delarr) {
values['delete'] = delarr;
}
return values;
},
cpu: {},
column1: [
{
xtype: 'proxmoxintegerfield',
name: 'sockets',
minValue: 1,
maxValue: 4,
value: '1',
fieldLabel: gettext('Sockets'),
allowBlank: false
},
{
xtype: 'proxmoxintegerfield',
name: 'cores',
minValue: 1,
maxValue: 128,
value: '1',
fieldLabel: gettext('Cores'),
allowBlank: false
}
],
column2: [
{
xtype: 'CPUModelSelector',
name: 'cputype',
value: '__default__',
fieldLabel: gettext('Type')
},
{
xtype: 'displayfield',
fieldLabel: gettext('Total cores'),
name: 'totalcores',
value: '1'
}
],
advancedColumn1: [
{
xtype: 'proxmoxintegerfield',
name: 'vcpus',
minValue: 1,
value: '',
fieldLabel: gettext('VCPUs'),
deleteEmpty: true,
allowBlank: true,
emptyText: '1'
},
{
xtype: 'numberfield',
name: 'cpulimit',
minValue: 0,
maxValue: 128, // api maximum
value: '',
step: 1,
fieldLabel: gettext('CPU limit'),
allowBlank: true,
emptyText: gettext('unlimited')
},
{
xtype: 'proxmoxintegerfield',
name: 'cpuunits',
fieldLabel: gettext('CPU units'),
minValue: 8,
maxValue: 500000,
value: '1024',
deleteEmpty: true,
allowBlank: true
}
],
advancedColumn2: [
{
xtype: 'proxmoxcheckbox',
fieldLabel: gettext('Enable NUMA'),
name: 'numa',
uncheckedValue: 0
},
{
xtype: 'proxmoxcheckbox',
fieldLabel: 'PCID',
name: 'pcid',
uncheckedValue: 0
},
{
xtype: 'proxmoxcheckbox',
fieldLabel: 'SPEC-CTRL',
name: 'spec-ctrl',
uncheckedValue: 0
}
]
});
Ext.define('PVE.qemu.ProcessorEdit', {
extend: 'Proxmox.window.Edit',
initComponent : function() {
var me = this;
var ipanel = Ext.create('PVE.qemu.ProcessorInputPanel');
Ext.apply(me, {
subject: gettext('Processors'),
items: ipanel
});
me.callParent();
me.load({
success: function(response, options) {
var data = response.result.data;
var value = data.cpu;
if (value) {
var cpu = PVE.Parser.parseQemuCpu(value);
ipanel.cpu = cpu;
data.cputype = cpu.cputype;
if (cpu.flags) {
var flags = cpu.flags.split(';');
flags.forEach(function(flag) {
var sign = flag.substr(0,1);
flag = flag.substr(1);
data[flag] = (sign === '+');
});
}
}
me.setValues(data);
}
});
}
});