]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/qemu/ProcessorEdit.js
ui: eslint: enforce "no-extra-boolean-cast" rule
[pve-manager.git] / www / manager6 / qemu / ProcessorEdit.js
CommitLineData
59e85a54 1Ext.define('PVE.qemu.ProcessorInputPanel', {
ef4ef788 2 extend: 'Proxmox.panel.InputPanel',
42902182 3 alias: 'widget.pveQemuProcessorPanel',
c8802a60 4 onlineHelp: 'qm_cpu',
59e85a54 5
1eeb6f17
DC
6 insideWizard: false,
7
b839766e
SR
8 viewModel: {
9 data: {
10 socketCount: 1,
11 coreCount: 1,
7376c56e 12 showCustomModelPermWarning: false,
5034f339 13 },
b839766e
SR
14 formulas: {
15 totalCoreCount: get => get('socketCount') * get('coreCount'),
16 },
17 },
5034f339 18
b839766e
SR
19 controller: {
20 xclass: 'Ext.app.ViewController',
5034f339 21 },
76f56b02 22
59e85a54
DM
23 onGetValues: function(values) {
24 var me = this;
25
5034f339
DC
26 if (Array.isArray(values['delete'])) {
27 values['delete'] = values['delete'].join(',');
28 }
29
30 PVE.Utils.delete_if_default(values, 'cpulimit', '0', 0);
31 PVE.Utils.delete_if_default(values, 'cpuunits', '1024', 0);
32
59e85a54 33 // build the cpu options:
ec0bd652 34 me.cpu.cputype = values.cputype;
1eeb6f17 35
06064872
TL
36 if (values.flags) {
37 me.cpu.flags = values.flags;
38 } else {
39 delete me.cpu.flags;
40 }
76f56b02 41
ec0bd652 42 delete values.cputype;
1eeb6f17 43 delete values.flags;
59e85a54
DM
44 var cpustring = PVE.Parser.printQemuCpu(me.cpu);
45
46 // remove cputype delete request:
47 var del = values['delete'];
48 delete values['delete'];
49 if (del) {
50 del = del.split(',');
51 Ext.Array.remove(del, 'cputype');
52 } else {
53 del = [];
54 }
55
56 if (cpustring) {
ec0bd652 57 values.cpu = cpustring;
59e85a54
DM
58 } else {
59 del.push('cpu');
60 }
61
ec0bd652
DC
62 var delarr = del.join(',');
63 if (delarr) {
64 values['delete'] = delarr;
59e85a54
DM
65 }
66
67 return values;
68 },
69
7376c56e
SR
70 setValues: function(values) {
71 let me = this;
72
73 let type = values.cputype;
74 let typeSelector = me.lookupReference('cputype');
75 let typeStore = typeSelector.getStore();
76 typeStore.on('load', (store, records, success) => {
77 if (!success || !type || records.some(x => x.data.name === type)) {
78 return;
79 }
80
81 // if we get here, a custom CPU model is selected for the VM but we
82 // don't have permission to configure it - it will not be in the
83 // list retrieved from the API, so add it manually to allow changing
84 // other processor options
85 typeStore.add({
86 name: type,
87 displayname: type.replace(/^custom-/, ''),
88 custom: 1,
89 vendor: gettext("Unknown"),
90 });
91 typeSelector.select(type);
92 });
93
94 me.callParent([values]);
95 },
96
5034f339
DC
97 cpu: {},
98
99 column1: [
100 {
101 xtype: 'proxmoxintegerfield',
102 name: 'sockets',
103 minValue: 1,
104 maxValue: 4,
105 value: '1',
106 fieldLabel: gettext('Sockets'),
b839766e
SR
107 allowBlank: false,
108 bind: {
109 value: '{socketCount}',
110 },
5034f339
DC
111 },
112 {
113 xtype: 'proxmoxintegerfield',
114 name: 'cores',
115 minValue: 1,
116 maxValue: 128,
117 value: '1',
118 fieldLabel: gettext('Cores'),
b839766e
SR
119 allowBlank: false,
120 bind: {
121 value: '{coreCount}',
122 },
123 },
5034f339
DC
124 ],
125
126 column2: [
127 {
128 xtype: 'CPUModelSelector',
129 name: 'cputype',
7376c56e 130 reference: 'cputype',
f6710aac 131 fieldLabel: gettext('Type'),
5034f339
DC
132 },
133 {
134 xtype: 'displayfield',
135 fieldLabel: gettext('Total cores'),
136 name: 'totalcores',
b839766e
SR
137 isFormField: false,
138 bind: {
139 value: '{totalCoreCount}',
140 },
141 },
5034f339
DC
142 ],
143
7376c56e
SR
144 columnB: [
145 {
146 xtype: 'displayfield',
147 userCls: 'pmx-hint',
148 value: gettext('WARNING: You do not have permission to configure custom CPU types, if you change the type you will not be able to go back!'),
149 hidden: true,
150 bind: {
151 hidden: '{!showCustomModelPermWarning}',
152 },
153 },
154 ],
155
5034f339
DC
156 advancedColumn1: [
157 {
158 xtype: 'proxmoxintegerfield',
159 name: 'vcpus',
160 minValue: 1,
de63d77a 161 maxValue: 1,
5034f339
DC
162 value: '',
163 fieldLabel: gettext('VCPUs'),
164 deleteEmpty: true,
165 allowBlank: true,
b839766e
SR
166 emptyText: '1',
167 bind: {
168 emptyText: '{totalCoreCount}',
169 maxValue: '{totalCoreCount}',
170 },
5034f339
DC
171 },
172 {
173 xtype: 'numberfield',
174 name: 'cpulimit',
175 minValue: 0,
176 maxValue: 128, // api maximum
177 value: '',
178 step: 1,
179 fieldLabel: gettext('CPU limit'),
180 allowBlank: true,
f6710aac
TL
181 emptyText: gettext('unlimited'),
182 },
06064872
TL
183 ],
184
185 advancedColumn2: [
5034f339
DC
186 {
187 xtype: 'proxmoxintegerfield',
188 name: 'cpuunits',
189 fieldLabel: gettext('CPU units'),
190 minValue: 8,
191 maxValue: 500000,
192 value: '1024',
193 deleteEmpty: true,
f6710aac 194 allowBlank: true,
06064872 195 },
5034f339
DC
196 {
197 xtype: 'proxmoxcheckbox',
198 fieldLabel: gettext('Enable NUMA'),
199 name: 'numa',
f6710aac
TL
200 uncheckedValue: 0,
201 },
06064872
TL
202 ],
203 advancedColumnB: [
5034f339 204 {
06064872 205 xtype: 'label',
f6710aac 206 text: 'Extra CPU Flags:',
5034f339
DC
207 },
208 {
06064872 209 xtype: 'vmcpuflagselector',
f6710aac
TL
210 name: 'flags',
211 },
212 ],
59e85a54
DM
213});
214
215Ext.define('PVE.qemu.ProcessorEdit', {
9fccc702 216 extend: 'Proxmox.window.Edit',
59e85a54 217
06064872
TL
218 width: 700,
219
8058410f 220 initComponent: function() {
59e85a54 221 var me = this;
5034f339 222
a764c5f7 223 var ipanel = Ext.create('PVE.qemu.ProcessorInputPanel');
59e85a54
DM
224
225 Ext.apply(me, {
226 subject: gettext('Processors'),
f6710aac 227 items: ipanel,
59e85a54
DM
228 });
229
230 me.callParent();
231
232 me.load({
233 success: function(response, options) {
234 var data = response.result.data;
ec0bd652 235 var value = data.cpu;
59e85a54
DM
236 if (value) {
237 var cpu = PVE.Parser.parseQemuCpu(value);
238 ipanel.cpu = cpu;
239 data.cputype = cpu.cputype;
76f56b02 240 if (cpu.flags) {
06064872 241 data.flags = cpu.flags;
76f56b02 242 }
7376c56e
SR
243
244 let caps = Ext.state.Manager.get('GuiCap');
245 if (data.cputype.indexOf('custom-') === 0 &&
8058410f 246 !caps.nodes['Sys.Audit']) {
7376c56e
SR
247 let vm = ipanel.getViewModel();
248 vm.set("showCustomModelPermWarning", true);
249 }
59e85a54
DM
250 }
251 me.setValues(data);
f6710aac 252 },
59e85a54 253 });
f6710aac 254 },
59e85a54 255});