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