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