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