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