]>
Commit | Line | Data |
---|---|---|
df15b3da | 1 | /*jslint confusion: true */ |
d5e771ce | 2 | /* 'change' property is assigned a string and then a function */ |
df15b3da | 3 | Ext.define('PVE.qemu.HDInputPanel', { |
ef4ef788 | 4 | extend: 'Proxmox.panel.InputPanel', |
85806e47 | 5 | alias: 'widget.pveQemuHDInputPanel', |
c8802a60 | 6 | onlineHelp: 'qm_hard_disk', |
df15b3da DM |
7 | |
8 | insideWizard: false, | |
9 | ||
10 | unused: false, // ADD usused disk imaged | |
11 | ||
12 | vmconfig: {}, // used to select usused disks | |
13 | ||
8e1df0ac AL |
14 | viewModel: {}, |
15 | ||
180d7ef5 DM |
16 | controller: { |
17 | ||
18 | xclass: 'Ext.app.ViewController', | |
19 | ||
20 | onControllerChange: function(field) { | |
21 | var value = field.getValue(); | |
ed1ac8f4 TL |
22 | |
23 | var allowIOthread = value.match(/^(virtio|scsi)/); | |
24 | this.lookup('iothread').setDisabled(!allowIOthread); | |
25 | if (!allowIOthread) { | |
26 | this.lookup('iothread').setValue(false); | |
27 | } | |
36958639 | 28 | |
f9261fde NC |
29 | var virtio = value.match(/^virtio/); |
30 | this.lookup('ssd').setDisabled(virtio); | |
31 | if (virtio) { | |
32 | this.lookup('ssd').setValue(false); | |
33 | } | |
34 | ||
75357e9f | 35 | this.lookup('scsiController').setVisible(value.match(/^scsi/)); |
180d7ef5 DM |
36 | }, |
37 | ||
38 | control: { | |
9cac6b75 | 39 | 'field[name=controller]': { |
180d7ef5 DM |
40 | change: 'onControllerChange', |
41 | afterrender: 'onControllerChange' | |
9cac6b75 | 42 | }, |
2414ef15 EK |
43 | 'field[name=iothread]' : { |
44 | change: function(f, value) { | |
45 | if (!this.getView().insideWizard) { | |
46 | return; | |
47 | } | |
48 | var vmScsiType = value ? 'virtio-scsi-single': 'virtio-scsi-pci'; | |
49 | this.lookupReference('scsiController').setValue(vmScsiType); | |
50 | } | |
180d7ef5 | 51 | } |
8e1df0ac AL |
52 | }, |
53 | ||
54 | init: function(view) { | |
55 | var vm = this.getViewModel(); | |
56 | if (view.isCreate) { | |
57 | vm.set('isIncludedInBackup', true); | |
58 | } | |
180d7ef5 DM |
59 | } |
60 | }, | |
61 | ||
df15b3da DM |
62 | onGetValues: function(values) { |
63 | var me = this; | |
64 | ||
9a8a5735 | 65 | var params = {}; |
df15b3da | 66 | var confid = me.confid || (values.controller + values.deviceid); |
7a6e0635 | 67 | |
df15b3da DM |
68 | if (me.unused) { |
69 | me.drive.file = me.vmconfig[values.unusedId]; | |
70 | confid = values.controller + values.deviceid; | |
d5e771ce | 71 | } else if (me.isCreate) { |
df15b3da DM |
72 | if (values.hdimage) { |
73 | me.drive.file = values.hdimage; | |
74 | } else { | |
75 | me.drive.file = values.hdstorage + ":" + values.disksize; | |
76 | } | |
77 | me.drive.format = values.diskformat; | |
78 | } | |
7a6e0635 | 79 | |
8e1df0ac | 80 | PVE.Utils.propertyStringSet(me.drive, values.backup, 'backup'); |
e4e36020 DC |
81 | PVE.Utils.propertyStringSet(me.drive, values.noreplicate, 'replicate', 'no'); |
82 | PVE.Utils.propertyStringSet(me.drive, values.discard, 'discard', 'on'); | |
83 | PVE.Utils.propertyStringSet(me.drive, values.ssd, 'ssd', 'on'); | |
84 | PVE.Utils.propertyStringSet(me.drive, values.iothread, 'iothread', 'on'); | |
85 | PVE.Utils.propertyStringSet(me.drive, values.cache, 'cache'); | |
df15b3da | 86 | |
c2233c8f DC |
87 | var names = ['mbps_rd', 'mbps_wr', 'iops_rd', 'iops_wr']; |
88 | Ext.Array.each(names, function(name) { | |
c2233c8f | 89 | var burst_name = name + '_max'; |
e4e36020 DC |
90 | PVE.Utils.propertyStringSet(me.drive, values[name], name); |
91 | PVE.Utils.propertyStringSet(me.drive, values[burst_name], burst_name); | |
c2233c8f DC |
92 | }); |
93 | ||
94 | ||
df15b3da | 95 | params[confid] = PVE.Parser.printQemuDrive(me.drive); |
7a6e0635 TL |
96 | |
97 | return params; | |
df15b3da DM |
98 | }, |
99 | ||
100 | setVMConfig: function(vmconfig) { | |
101 | var me = this; | |
102 | ||
103 | me.vmconfig = vmconfig; | |
104 | ||
105 | if (me.bussel) { | |
7206af4b | 106 | me.bussel.setVMConfig(vmconfig); |
42bd6556 | 107 | me.scsiController.setValue(vmconfig.scsihw); |
df15b3da DM |
108 | } |
109 | if (me.unusedDisks) { | |
7a6e0635 | 110 | var disklist = []; |
df15b3da DM |
111 | Ext.Object.each(vmconfig, function(key, value) { |
112 | if (key.match(/^unused\d+$/)) { | |
113 | disklist.push([key, value]); | |
114 | } | |
115 | }); | |
116 | me.unusedDisks.store.loadData(disklist); | |
117 | me.unusedDisks.setValue(me.confid); | |
118 | } | |
119 | }, | |
120 | ||
121 | setDrive: function(drive) { | |
122 | var me = this; | |
123 | ||
124 | me.drive = drive; | |
125 | ||
126 | var values = {}; | |
127 | var match = drive.file.match(/^([^:]+):/); | |
128 | if (match) { | |
129 | values.hdstorage = match[1]; | |
130 | } | |
131 | ||
132 | values.hdimage = drive.file; | |
20d3180b | 133 | values.backup = PVE.Parser.parseBoolean(drive.backup, 0); |
1b6f87ab | 134 | values.noreplicate = !PVE.Parser.parseBoolean(drive.replicate, 1); |
df15b3da | 135 | values.diskformat = drive.format || 'raw'; |
ac7db8f7 | 136 | values.cache = drive.cache || '__default__'; |
df15b3da | 137 | values.discard = (drive.discard === 'on'); |
f9261fde | 138 | values.ssd = PVE.Parser.parseBoolean(drive.ssd); |
df15b3da DM |
139 | values.iothread = PVE.Parser.parseBoolean(drive.iothread); |
140 | ||
c2233c8f DC |
141 | values.mbps_rd = drive.mbps_rd; |
142 | values.mbps_wr = drive.mbps_wr; | |
143 | values.iops_rd = drive.iops_rd; | |
144 | values.iops_wr = drive.iops_wr; | |
145 | values.mbps_rd_max = drive.mbps_rd_max; | |
146 | values.mbps_wr_max = drive.mbps_wr_max; | |
147 | values.iops_rd_max = drive.iops_rd_max; | |
148 | values.iops_wr_max = drive.iops_wr_max; | |
149 | ||
df15b3da DM |
150 | me.setValues(values); |
151 | }, | |
152 | ||
153 | setNodename: function(nodename) { | |
154 | var me = this; | |
771aec96 DC |
155 | me.down('#hdstorage').setNodename(nodename); |
156 | me.down('#hdimage').setStorage(undefined, nodename); | |
df15b3da DM |
157 | }, |
158 | ||
159 | initComponent : function() { | |
160 | var me = this; | |
161 | ||
c2233c8f DC |
162 | var labelWidth = 140; |
163 | ||
df15b3da DM |
164 | me.drive = {}; |
165 | ||
166 | me.column1 = []; | |
167 | me.column2 = []; | |
168 | ||
546d09c2 DC |
169 | me.advancedColumn1 = []; |
170 | me.advancedColumn2 = []; | |
171 | ||
df15b3da | 172 | if (!me.confid || me.unused) { |
42902182 | 173 | me.bussel = Ext.create('PVE.form.ControllerSelector', { |
df15b3da DM |
174 | vmconfig: me.insideWizard ? {ide2: 'cdrom'} : {} |
175 | }); | |
176 | me.column1.push(me.bussel); | |
2414ef15 | 177 | |
42bd6556 EK |
178 | me.scsiController = Ext.create('Ext.form.field.Display', { |
179 | fieldLabel: gettext('SCSI Controller'), | |
180 | reference: 'scsiController', | |
471d03aa DC |
181 | bind: me.insideWizard ? { |
182 | value: '{current.scsihw}' | |
183 | } : undefined, | |
42bd6556 | 184 | renderer: PVE.Utils.render_scsihw, |
471d03aa | 185 | submitValue: false, |
42bd6556 EK |
186 | hidden: true |
187 | }); | |
188 | me.column1.push(me.scsiController); | |
df15b3da DM |
189 | } |
190 | ||
191 | if (me.unused) { | |
09cacce7 | 192 | me.unusedDisks = Ext.create('Proxmox.form.KVComboBox', { |
7a6e0635 | 193 | name: 'unusedId', |
df15b3da DM |
194 | fieldLabel: gettext('Disk image'), |
195 | matchFieldWidth: false, | |
196 | listConfig: { | |
197 | width: 350 | |
198 | }, | |
199 | data: [], | |
200 | allowBlank: false | |
201 | }); | |
202 | me.column1.push(me.unusedDisks); | |
d5e771ce | 203 | } else if (me.isCreate) { |
771aec96 DC |
204 | me.column1.push({ |
205 | xtype: 'pveDiskStorageSelector', | |
df15b3da | 206 | storageContent: 'images', |
771aec96 | 207 | name: 'disk', |
df15b3da | 208 | nodename: me.nodename, |
771aec96 | 209 | autoSelect: me.insideWizard |
df15b3da | 210 | }); |
df15b3da DM |
211 | } else { |
212 | me.column1.push({ | |
213 | xtype: 'textfield', | |
214 | disabled: true, | |
215 | submitValue: false, | |
216 | fieldLabel: gettext('Disk image'), | |
217 | name: 'hdimage' | |
218 | }); | |
219 | } | |
220 | ||
f9261fde NC |
221 | me.column2.push( |
222 | { | |
223 | xtype: 'CacheTypeSelector', | |
224 | name: 'cache', | |
225 | value: '__default__', | |
226 | fieldLabel: gettext('Cache') | |
227 | }, | |
546d09c2 DC |
228 | { |
229 | xtype: 'proxmoxcheckbox', | |
230 | fieldLabel: gettext('Discard'), | |
546d09c2 | 231 | reference: 'discard', |
546d09c2 | 232 | name: 'discard' |
f9261fde NC |
233 | } |
234 | ); | |
235 | ||
236 | me.advancedColumn1.push( | |
237 | { | |
238 | xtype: 'proxmoxcheckbox', | |
239 | disabled: me.confid && me.confid.match(/^virtio/), | |
240 | fieldLabel: gettext('SSD emulation'), | |
241 | labelWidth: labelWidth, | |
242 | name: 'ssd', | |
243 | reference: 'ssd' | |
546d09c2 DC |
244 | }, |
245 | { | |
246 | xtype: 'proxmoxcheckbox', | |
247 | disabled: me.confid && !me.confid.match(/^(virtio|scsi)/), | |
248 | fieldLabel: 'IO thread', | |
249 | labelWidth: labelWidth, | |
250 | reference: 'iothread', | |
251 | name: 'iothread' | |
c2233c8f DC |
252 | }, |
253 | { | |
254 | xtype: 'numberfield', | |
255 | name: 'mbps_rd', | |
256 | minValue: 1, | |
257 | step: 1, | |
258 | fieldLabel: gettext('Read limit') + ' (MB/s)', | |
259 | labelWidth: labelWidth, | |
260 | emptyText: gettext('unlimited') | |
261 | }, | |
262 | { | |
263 | xtype: 'numberfield', | |
264 | name: 'mbps_wr', | |
265 | minValue: 1, | |
266 | step: 1, | |
267 | fieldLabel: gettext('Write limit') + ' (MB/s)', | |
268 | labelWidth: labelWidth, | |
269 | emptyText: gettext('unlimited') | |
270 | }, | |
271 | { | |
272 | xtype: 'proxmoxintegerfield', | |
273 | name: 'iops_rd', | |
274 | minValue: 10, | |
275 | step: 10, | |
276 | fieldLabel: gettext('Read limit') + ' (ops/s)', | |
277 | labelWidth: labelWidth, | |
278 | emptyText: gettext('unlimited') | |
279 | }, | |
280 | { | |
281 | xtype: 'proxmoxintegerfield', | |
282 | name: 'iops_wr', | |
283 | minValue: 10, | |
284 | step: 10, | |
285 | fieldLabel: gettext('Write limit') + ' (ops/s)', | |
286 | labelWidth: labelWidth, | |
287 | emptyText: gettext('unlimited') | |
546d09c2 DC |
288 | } |
289 | ); | |
290 | ||
291 | me.advancedColumn2.push( | |
292 | { | |
293 | xtype: 'proxmoxcheckbox', | |
0bead056 TL |
294 | fieldLabel: gettext('Backup'), |
295 | autoEl: { | |
296 | tag: 'div', | |
297 | 'data-qtip': gettext('Include volume in backup job'), | |
298 | }, | |
546d09c2 | 299 | labelWidth: labelWidth, |
8e1df0ac AL |
300 | name: 'backup', |
301 | bind: { | |
302 | value: '{isIncludedInBackup}', | |
303 | }, | |
546d09c2 DC |
304 | }, |
305 | { | |
306 | xtype: 'proxmoxcheckbox', | |
307 | fieldLabel: gettext('Skip replication'), | |
308 | labelWidth: labelWidth, | |
309 | name: 'noreplicate' | |
c2233c8f DC |
310 | }, |
311 | { | |
312 | xtype: 'numberfield', | |
313 | name: 'mbps_rd_max', | |
314 | minValue: 1, | |
315 | step: 1, | |
316 | fieldLabel: gettext('Read max burst') + ' (MB)', | |
317 | labelWidth: labelWidth, | |
318 | emptyText: gettext('default') | |
319 | }, | |
320 | { | |
321 | xtype: 'numberfield', | |
322 | name: 'mbps_wr_max', | |
323 | minValue: 1, | |
324 | step: 1, | |
325 | fieldLabel: gettext('Write max burst') + ' (MB)', | |
326 | labelWidth: labelWidth, | |
327 | emptyText: gettext('default') | |
328 | }, | |
329 | { | |
330 | xtype: 'proxmoxintegerfield', | |
331 | name: 'iops_rd_max', | |
332 | minValue: 10, | |
333 | step: 10, | |
334 | fieldLabel: gettext('Read max burst') + ' (ops)', | |
335 | labelWidth: labelWidth, | |
336 | emptyText: gettext('default') | |
337 | }, | |
338 | { | |
339 | xtype: 'proxmoxintegerfield', | |
340 | name: 'iops_wr_max', | |
341 | minValue: 10, | |
342 | step: 10, | |
343 | fieldLabel: gettext('Write max burst') + ' (ops)', | |
344 | labelWidth: labelWidth, | |
345 | emptyText: gettext('default') | |
546d09c2 DC |
346 | } |
347 | ); | |
348 | ||
df15b3da DM |
349 | me.callParent(); |
350 | } | |
351 | }); | |
d5e771ce | 352 | /*jslint confusion: false */ |
df15b3da DM |
353 | |
354 | Ext.define('PVE.qemu.HDEdit', { | |
9fccc702 | 355 | extend: 'Proxmox.window.Edit', |
df15b3da DM |
356 | |
357 | isAdd: true, | |
358 | ||
7cb345b8 WL |
359 | backgroundDelay: 5, |
360 | ||
df15b3da DM |
361 | initComponent : function() { |
362 | var me = this; | |
363 | ||
364 | var nodename = me.pveSelNode.data.node; | |
7a6e0635 TL |
365 | if (!nodename) { |
366 | throw "no node name specified"; | |
df15b3da DM |
367 | } |
368 | ||
369 | var unused = me.confid && me.confid.match(/^unused\d+$/); | |
370 | ||
d5e771ce | 371 | me.isCreate = me.confid ? unused : true; |
df15b3da DM |
372 | |
373 | var ipanel = Ext.create('PVE.qemu.HDInputPanel', { | |
374 | confid: me.confid, | |
375 | nodename: nodename, | |
376 | unused: unused, | |
d5e771ce | 377 | isCreate: me.isCreate |
df15b3da DM |
378 | }); |
379 | ||
380 | var subject; | |
381 | if (unused) { | |
382 | me.subject = gettext('Unused Disk'); | |
d5e771ce | 383 | } else if (me.isCreate) { |
df15b3da DM |
384 | me.subject = gettext('Hard Disk'); |
385 | } else { | |
386 | me.subject = gettext('Hard Disk') + ' (' + me.confid + ')'; | |
387 | } | |
388 | ||
389 | me.items = [ ipanel ]; | |
390 | ||
391 | me.callParent(); | |
d5e771ce EK |
392 | /*jslint confusion: true*/ |
393 | /* 'data' is assigned an empty array in same file, and here we | |
394 | * use it like an object | |
395 | */ | |
df15b3da DM |
396 | me.load({ |
397 | success: function(response, options) { | |
398 | ipanel.setVMConfig(response.result.data); | |
399 | if (me.confid) { | |
400 | var value = response.result.data[me.confid]; | |
401 | var drive = PVE.Parser.parseQemuDrive(me.confid, value); | |
402 | if (!drive) { | |
185a77e5 | 403 | Ext.Msg.alert(gettext('Error'), 'Unable to parse drive options'); |
df15b3da DM |
404 | me.close(); |
405 | return; | |
406 | } | |
407 | ipanel.setDrive(drive); | |
408 | me.isValid(); // trigger validation | |
409 | } | |
410 | } | |
411 | }); | |
d5e771ce | 412 | /*jslint confusion: false*/ |
df15b3da DM |
413 | } |
414 | }); |