]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/Utils.js
ui: guest backup view: add encrypted column for PBS storages
[pve-manager.git] / www / manager6 / Utils.js
CommitLineData
b0a6d326
EK
1Ext.ns('PVE');
2
63b9faae
EK
3// avoid errors related to Accessible Rich Internet Applications
4// (access for people with disabilities)
0be88ae1 5// TODO reenable after all components are upgraded
63b9faae
EK
6Ext.enableAria = false;
7Ext.enableAriaButtons = false;
8Ext.enableAriaPanels = false;
9
b0a6d326 10// avoid errors when running without development tools
0be88ae1
DC
11if (!Ext.isDefined(Ext.global.console)) {
12 var console = {
0be88ae1 13 log: function() {}
b0a6d326
EK
14 };
15}
0be88ae1 16console.log("Starting PVE Manager");
b0a6d326
EK
17
18Ext.Ajax.defaultHeaders = {
19 'Accept': 'application/json'
20};
21
9fa2e36d 22Ext.define('PVE.Utils', { utilities: {
b0a6d326 23
9fa2e36d 24 // this singleton contains miscellaneous utilities
b0a6d326 25
0be88ae1 26 toolkit: undefined, // (extjs|touch), set inside Toolkit.js
b0a6d326 27
98a01af2
EK
28 bus_match: /^(ide|sata|virtio|scsi)\d+$/,
29
b0a6d326
EK
30 log_severity_hash: {
31 0: "panic",
32 1: "alert",
33 2: "critical",
34 3: "error",
35 4: "warning",
36 5: "notice",
37 6: "info",
38 7: "debug"
39 },
40
41 support_level_hash: {
42 'c': gettext('Community'),
43 'b': gettext('Basic'),
44 's': gettext('Standard'),
45 'p': gettext('Premium')
46 },
47
8ec8af9c 48 noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.',
b0a6d326
EK
49
50 kvm_ostypes: {
45d6c71a 51 'Linux': [
ca71cd5d 52 { desc: '5.x - 2.6 Kernel', val: 'l26' },
45d6c71a
TL
53 { desc: '2.4 Kernel', val: 'l24' }
54 ],
55 'Microsoft Windows': [
beb3c8a4 56 { desc: '10/2016/2019', val: 'win10' },
45d6c71a
TL
57 { desc: '8.x/2012/2012r2', val: 'win8' },
58 { desc: '7/2008r2', val: 'win7' },
59 { desc: 'Vista/2008', val: 'w2k8' },
60 { desc: 'XP/2003', val: 'wxp' },
61 { desc: '2000', val: 'w2k' }
62 ],
63 'Solaris Kernel': [
64 { desc: '-', val: 'solaris'}
65 ],
66 'Other': [
67 { desc: '-', val: 'other'}
68 ]
b0a6d326
EK
69 },
70
428bc4a2
DC
71 get_health_icon: function(state, circle) {
72 if (circle === undefined) {
73 circle = false;
74 }
75
76 if (state === undefined) {
77 state = 'uknown';
78 }
79
80 var icon = 'faded fa-question';
81 switch(state) {
82 case 'good':
83 icon = 'good fa-check';
84 break;
23c83a3a
DC
85 case 'upgrade':
86 icon = 'warning fa-upload';
87 break;
aa240b29
DC
88 case 'old':
89 icon = 'warning fa-refresh';
90 break;
428bc4a2
DC
91 case 'warning':
92 icon = 'warning fa-exclamation';
93 break;
94 case 'critical':
95 icon = 'critical fa-times';
96 break;
97 default: break;
98 }
99
100 if (circle) {
101 icon += '-circle';
102 }
103
104 return icon;
105 },
106
95d0de89
DC
107 parse_ceph_version: function(service) {
108 if (service.ceph_version_short) {
109 return service.ceph_version_short;
110 }
111
112 if (service.ceph_version) {
35306f47 113 var match = service.ceph_version.match(/version (\d+(\.\d+)*)/);
95d0de89
DC
114 if (match) {
115 return match[1];
116 }
117 }
118
119 return undefined;
120 },
121
005e0a60 122 compare_ceph_versions: function(a, b) {
3a08795a
DC
123 let avers = [];
124 let bvers = [];
125
005e0a60
DC
126 if (a === b) {
127 return 0;
128 }
3a08795a
DC
129
130 if (Ext.isArray(a)) {
131 avers = a.slice(); // copy array
132 } else {
133 avers = a.toString().split('.');
134 }
135
136 if (Ext.isArray(b)) {
137 bvers = b.slice(); // copy array
138 } else {
139 bvers = b.toString().split('.');
140 }
35306f47
TL
141
142 while (true) {
143 let av = avers.shift();
144 let bv = bvers.shift();
145
146 if (av === undefined && bv === undefined) {
147 return 0;
148 } else if (av === undefined) {
149 return -1;
150 } else if (bv === undefined) {
151 return 1;
152 } else {
153 let diff = parseInt(av, 10) - parseInt(bv, 10);
154 if (diff != 0) return diff;
155 // else we need to look at the next parts
005e0a60
DC
156 }
157 }
158
005e0a60
DC
159 },
160
2f5b82ae
DC
161 get_ceph_icon_html: function(health, fw) {
162 var state = PVE.Utils.map_ceph_health[health];
163 var cls = PVE.Utils.get_health_icon(state);
164 if (fw) {
165 cls += ' fa-fw';
166 }
167 return "<i class='fa " + cls + "'></i> ";
168 },
169
046e640c
DC
170 map_ceph_health: {
171 'HEALTH_OK':'good',
23c83a3a 172 'HEALTH_UPGRADE':'upgrade',
aa240b29 173 'HEALTH_OLD':'old',
046e640c
DC
174 'HEALTH_WARN':'warning',
175 'HEALTH_ERR':'critical'
176 },
177
dfe6d184 178 render_ceph_health: function(healthObj) {
046e640c
DC
179 var state = {
180 iconCls: PVE.Utils.get_health_icon(),
181 text: ''
182 };
183
dfe6d184 184 if (!healthObj || !healthObj.status) {
046e640c
DC
185 return state;
186 }
187
dfe6d184 188 var health = PVE.Utils.map_ceph_health[healthObj.status];
046e640c
DC
189
190 state.iconCls = PVE.Utils.get_health_icon(health, true);
dfe6d184 191 state.text = healthObj.status;
046e640c
DC
192
193 return state;
194 },
195
fee716d3 196 render_zfs_health: function(value) {
8c8604ba
TM
197 if (typeof value == 'undefined'){
198 return "";
199 }
fee716d3
DC
200 var iconCls = 'question-circle';
201 switch (value) {
8c8604ba 202 case 'AVAIL':
fee716d3
DC
203 case 'ONLINE':
204 iconCls = 'check-circle good';
205 break;
206 case 'REMOVED':
207 case 'DEGRADED':
208 iconCls = 'exclamation-circle warning';
209 break;
210 case 'UNAVAIL':
211 case 'FAULTED':
212 case 'OFFLINE':
213 iconCls = 'times-circle critical';
214 break;
215 default: //unknown
216 }
217
218 return '<i class="fa fa-' + iconCls + '"></i> ' + value;
8c8604ba 219
fee716d3
DC
220 },
221
14ba33fb
TL
222 render_pbs_fingerprint: fp => fp.substring(0, 23),
223
3003a59d
TL
224 render_backup_encryption: function(v, meta, record) {
225 if (!v) {
226 return gettext('No');
227 }
228
229 let tip = '';
230 if (v.match(/^[a-fA-F0-9]{2}:/)) { // fingerprint
231 tip = `Key fingerprint ${PVE.Utils.render_pbs_fingerprint(v)}`;
232 }
233 let icon = `<i class="fa fa-fw fa-lock good"></i>`;
234 return `<span data-qtip="${tip}">${icon} ${gettext('Encrypted')}</span>`;
235 },
236
01ad47af
AL
237 render_backup_status: function(value, meta, record) {
238 if (typeof value == 'undefined') {
239 return "";
240 }
241
242 let iconCls = 'check-circle good';
243 let text = gettext('Yes');
244
245 if (!PVE.Parser.parseBoolean(value.toString())) {
246 iconCls = 'times-circle critical';
247
248 text = gettext('No');
249
250 let reason = record.get('reason');
251 if (typeof reason !== 'undefined') {
252 if (reason in PVE.Utils.backup_reasons_table) {
253 reason = PVE.Utils.backup_reasons_table[record.get('reason')];
254 }
255 text = `${text} - ${reason}`;
256 }
257 }
258
259 return `<i class="fa fa-${iconCls}"></i> ${text}`;
260 },
261
7f08d0d1
AL
262 render_backup_days_of_week: function(val) {
263 var dows = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
264 var selected = [];
265 var cur = -1;
266 val.split(',').forEach(function(day){
267 cur++;
268 var dow = (dows.indexOf(day)+6)%7;
269 if (cur === dow) {
270 if (selected.length === 0 || selected[selected.length-1] === 0) {
271 selected.push(1);
272 } else {
273 selected[selected.length-1]++;
274 }
275 } else {
276 while (cur < dow) {
277 cur++;
278 selected.push(0);
279 }
280 selected.push(1);
281 }
282 });
283
284 cur = -1;
285 var days = [];
286 selected.forEach(function(item) {
287 cur++;
288 if (item > 2) {
289 days.push(Ext.Date.dayNames[(cur+1)] + '-' + Ext.Date.dayNames[(cur+item)%7]);
290 cur += item-1;
291 } else if (item == 2) {
292 days.push(Ext.Date.dayNames[cur+1]);
293 days.push(Ext.Date.dayNames[(cur+2)%7]);
294 cur++;
295 } else if (item == 1) {
296 days.push(Ext.Date.dayNames[(cur+1)%7]);
297 }
298 });
299 return days.join(', ');
300 },
301
302 render_backup_selection: function(value, metaData, record) {
303 let allExceptText = gettext('All except {0}');
304 let allText = '-- ' + gettext('All') + ' --';
305 if (record.data.all) {
306 if (record.data.exclude) {
307 return Ext.String.format(allExceptText, record.data.exclude);
308 }
309 return allText;
310 }
311 if (record.data.vmid) {
312 return record.data.vmid;
313 }
314
315 if (record.data.pool) {
316 return "Pool '"+ record.data.pool + "'";
317 }
318
319 return "-";
320 },
321
01ad47af
AL
322 backup_reasons_table: {
323 'backup=yes': gettext('Enabled'),
324 'backup=no': gettext('Disabled'),
325 'enabled': gettext('Enabled'),
326 'disabled': gettext('Disabled'),
327 'not a volume': gettext('Not a volume'),
328 'efidisk but no OMVF BIOS': gettext('EFI Disk without OMVF BIOS'),
329 },
330
45d6c71a
TL
331 get_kvm_osinfo: function(value) {
332 var info = { base: 'Other' }; // default
333 if (value) {
334 Ext.each(Object.keys(PVE.Utils.kvm_ostypes), function(k) {
335 Ext.each(PVE.Utils.kvm_ostypes[k], function(e) {
336 if (e.val === value) {
337 info = { desc: e.desc, base: k };
338 }
339 });
340 });
b0a6d326 341 }
45d6c71a
TL
342 return info;
343 },
344
345 render_kvm_ostype: function (value) {
346 var osinfo = PVE.Utils.get_kvm_osinfo(value);
347 if (osinfo.desc && osinfo.desc !== '-') {
348 return osinfo.base + ' ' + osinfo.desc;
349 } else {
350 return osinfo.base;
b0a6d326 351 }
b0a6d326
EK
352 },
353
354 render_hotplug_features: function (value) {
23d3881a 355 var fa = [];
b0a6d326
EK
356
357 if (!value || (value === '0')) {
ec99b1c3 358 return gettext('Disabled');
b0a6d326
EK
359 }
360
4dcca8a4
DC
361 if (value === '1') {
362 value = 'disk,network,usb';
363 }
364
b0a6d326
EK
365 Ext.each(value.split(','), function(el) {
366 if (el === 'disk') {
367 fa.push(gettext('Disk'));
368 } else if (el === 'network') {
369 fa.push(gettext('Network'));
370 } else if (el === 'usb') {
b9628aa5 371 fa.push('USB');
b0a6d326
EK
372 } else if (el === 'memory') {
373 fa.push(gettext('Memory'));
374 } else if (el === 'cpu') {
375 fa.push(gettext('CPU'));
376 } else {
377 fa.push(el);
378 }
379 });
380
381 return fa.join(', ');
382 },
383
0beff18b
FE
384 render_localtime: function(value) {
385 if (value === '__default__') {
386 return Proxmox.Utils.defaultText + ' (' + gettext('Enabled for Windows') + ')';
387 }
388 return Proxmox.Utils.format_boolean(value);
389 },
390
1662ccdb
SI
391 render_qga_features: function(value) {
392 if (!value) {
393 return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText + ')';
394 }
395 var props = PVE.Parser.parsePropertyString(value, 'enabled');
396 if (!PVE.Parser.parseBoolean(props.enabled)) {
397 return Proxmox.Utils.disabledText;
398 }
399
400 delete props.enabled;
401 var agentstring = Proxmox.Utils.enabledText;
402
403 Ext.Object.each(props, function(key, value) {
404 var keystring = '' ;
405 agentstring += ', ' + key + ': ';
406
5a6c563c
MD
407 if (key === 'type') {
408 let map = {
409 isa: "ISA",
176a62d3 410 virtio: "VirtIO",
5a6c563c
MD
411 };
412 agentstring += map[value] || Proxmox.Utils.unknownText;
1662ccdb 413 } else {
5a6c563c
MD
414 if (PVE.Parser.parseBoolean(value)) {
415 agentstring += Proxmox.Utils.enabledText;
416 } else {
417 agentstring += Proxmox.Utils.disabledText;
418 }
1662ccdb
SI
419 }
420 });
421
422 return agentstring;
423 },
424
a1ee14a2
DC
425 render_qemu_machine: function(value) {
426 return value || (Proxmox.Utils.defaultText + ' (i440fx)');
427 },
428
17c71f27
DC
429 render_qemu_bios: function(value) {
430 if (!value) {
e7ade592 431 return Proxmox.Utils.defaultText + ' (SeaBIOS)';
17c71f27
DC
432 } else if (value === 'seabios') {
433 return "SeaBIOS";
434 } else if (value === 'ovmf') {
435 return "OVMF (UEFI)";
436 } else {
437 return value;
438 }
439 },
440
8f17b496
TL
441 render_dc_ha_opts: function(value) {
442 if (!value) {
41ca3465 443 return Proxmox.Utils.defaultText;
8f17b496
TL
444 } else {
445 return PVE.Parser.printPropertyString(value);
446 }
447 },
bb469a11
TL
448 render_as_property_string: function(value) {
449 return (!value) ? Proxmox.Utils.defaultText
450 : PVE.Parser.printPropertyString(value);
451 },
8f17b496 452
b0a6d326
EK
453 render_scsihw: function(value) {
454 if (!value) {
e7ade592 455 return Proxmox.Utils.defaultText + ' (LSI 53C895A)';
b0a6d326
EK
456 } else if (value === 'lsi') {
457 return 'LSI 53C895A';
458 } else if (value === 'lsi53c810') {
459 return 'LSI 53C810';
460 } else if (value === 'megasas') {
461 return 'MegaRAID SAS 8708EM2';
462 } else if (value === 'virtio-scsi-pci') {
49f5d1ab
EK
463 return 'VirtIO SCSI';
464 } else if (value === 'virtio-scsi-single') {
465 return 'VirtIO SCSI single';
b0a6d326
EK
466 } else if (value === 'pvscsi') {
467 return 'VMware PVSCSI';
468 } else {
469 return value;
470 }
471 },
472
9c22da32 473 render_spice_enhancements: function(values) {
9c22da32
AL
474 let props = PVE.Parser.parsePropertyString(values);
475 if (Ext.Object.isEmpty(props)) {
3b0facc9 476 return Proxmox.Utils.noneText;
9c22da32
AL
477 }
478
479 let output = [];
480 if (PVE.Parser.parseBoolean(props.foldersharing)) {
481 output.push('Folder Sharing: ' + gettext('Enabled'));
482 }
483 if (props.videostreaming === 'all' || props.videostreaming === 'filter') {
484 output.push('Video Streaming: ' + props.videostreaming);
485 }
486 return output.join(', ');
487 },
488
b0a6d326
EK
489 // fixme: auto-generate this
490 // for now, please keep in sync with PVE::Tools::kvmkeymaps
491 kvm_keymaps: {
492 //ar: 'Arabic',
493 da: 'Danish',
0be88ae1
DC
494 de: 'German',
495 'de-ch': 'German (Swiss)',
496 'en-gb': 'English (UK)',
0a5b8747 497 'en-us': 'English (USA)',
b0a6d326
EK
498 es: 'Spanish',
499 //et: 'Estonia',
500 fi: 'Finnish',
0be88ae1
DC
501 //fo: 'Faroe Islands',
502 fr: 'French',
503 'fr-be': 'French (Belgium)',
b0a6d326
EK
504 'fr-ca': 'French (Canada)',
505 'fr-ch': 'French (Swiss)',
506 //hr: 'Croatia',
507 hu: 'Hungarian',
508 is: 'Icelandic',
0be88ae1 509 it: 'Italian',
b0a6d326
EK
510 ja: 'Japanese',
511 lt: 'Lithuanian',
512 //lv: 'Latvian',
0be88ae1 513 mk: 'Macedonian',
b0a6d326
EK
514 nl: 'Dutch',
515 //'nl-be': 'Dutch (Belgium)',
0be88ae1 516 no: 'Norwegian',
b0a6d326
EK
517 pl: 'Polish',
518 pt: 'Portuguese',
519 'pt-br': 'Portuguese (Brazil)',
520 //ru: 'Russian',
521 sl: 'Slovenian',
522 sv: 'Swedish',
523 //th: 'Thai',
524 tr: 'Turkish'
525 },
526
527 kvm_vga_drivers: {
528 std: gettext('Standard VGA'),
5ca366f2 529 vmware: gettext('VMware compatible'),
b0a6d326
EK
530 qxl: 'SPICE',
531 qxl2: 'SPICE dual monitor',
532 qxl3: 'SPICE three monitors',
533 qxl4: 'SPICE four monitors',
534 serial0: gettext('Serial terminal') + ' 0',
535 serial1: gettext('Serial terminal') + ' 1',
536 serial2: gettext('Serial terminal') + ' 2',
89ae1bb1
DC
537 serial3: gettext('Serial terminal') + ' 3',
538 virtio: 'VirtIO-GPU',
539 none: Proxmox.Utils.noneText
b0a6d326
EK
540 },
541
542 render_kvm_language: function (value) {
e7ade592
DC
543 if (!value || value === '__default__') {
544 return Proxmox.Utils.defaultText;
b0a6d326
EK
545 }
546 var text = PVE.Utils.kvm_keymaps[value];
547 if (text) {
548 return text + ' (' + value + ')';
549 }
550 return value;
551 },
552
553 kvm_keymap_array: function() {
f2782813 554 var data = [['__default__', PVE.Utils.render_kvm_language('')]];
b0a6d326
EK
555 Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) {
556 data.push([key, PVE.Utils.render_kvm_language(value)]);
557 });
558
559 return data;
560 },
561
3438c27e 562 console_map: {
da9d14cd 563 '__default__': Proxmox.Utils.defaultText + ' (xterm.js)',
3438c27e
DC
564 'vv': 'SPICE (remote-viewer)',
565 'html5': 'HTML5 (noVNC)',
4ace5c6f 566 'xtermjs': 'xterm.js'
3438c27e
DC
567 },
568
b0a6d326 569 render_console_viewer: function(value) {
3438c27e
DC
570 value = value || '__default__';
571 if (PVE.Utils.console_map[value]) {
572 return PVE.Utils.console_map[value];
b0a6d326 573 }
3438c27e 574 return value;
b0a6d326
EK
575 },
576
755b9083 577 console_viewer_array: function() {
3438c27e 578 return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) {
755b9083
TL
579 return [v, PVE.Utils.render_console_viewer(v)];
580 });
581 },
582
b0a6d326
EK
583 render_kvm_vga_driver: function (value) {
584 if (!value) {
e7ade592 585 return Proxmox.Utils.defaultText;
b0a6d326 586 }
4f3e66d8
DC
587 var vga = PVE.Parser.parsePropertyString(value, 'type');
588 var text = PVE.Utils.kvm_vga_drivers[vga.type];
589 if (!vga.type) {
590 text = Proxmox.Utils.defaultText;
591 }
0be88ae1 592 if (text) {
b0a6d326
EK
593 return text + ' (' + value + ')';
594 }
595 return value;
596 },
597
598 kvm_vga_driver_array: function() {
f2782813 599 var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]];
b0a6d326
EK
600 Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) {
601 data.push([key, PVE.Utils.render_kvm_vga_driver(value)]);
602 });
603
604 return data;
605 },
606
607 render_kvm_startup: function(value) {
608 var startup = PVE.Parser.parseStartup(value);
609
610 var res = 'order=';
611 if (startup.order === undefined) {
612 res += 'any';
613 } else {
614 res += startup.order;
615 }
616 if (startup.up !== undefined) {
617 res += ',up=' + startup.up;
618 }
619 if (startup.down !== undefined) {
620 res += ',down=' + startup.down;
621 }
622
623 return res;
624 },
625
b0a6d326
EK
626 extractFormActionError: function(action) {
627 var msg;
628 switch (action.failureType) {
629 case Ext.form.action.Action.CLIENT_INVALID:
630 msg = gettext('Form fields may not be submitted with invalid values');
631 break;
632 case Ext.form.action.Action.CONNECT_FAILURE:
633 msg = gettext('Connection error');
634 var resp = action.response;
635 if (resp.status && resp.statusText) {
636 msg += " " + resp.status + ": " + resp.statusText;
637 }
638 break;
639 case Ext.form.action.Action.LOAD_FAILURE:
640 case Ext.form.action.Action.SERVER_INVALID:
e7ade592 641 msg = Proxmox.Utils.extractRequestError(action.result, true);
b0a6d326
EK
642 break;
643 }
644 return msg;
645 },
646
0e244a29
DC
647 contentTypes: {
648 'images': gettext('Disk image'),
649 'backup': gettext('VZDump backup file'),
650 'vztmpl': gettext('Container template'),
651 'iso': gettext('ISO image'),
aef28e04
DC
652 'rootdir': gettext('Container'),
653 'snippets': gettext('Snippets')
0e244a29 654 },
b0a6d326 655
3b8f599b
DM
656 volume_is_qemu_backup: function(volid, format) {
657 return format === 'pbs-vm' || volid.match(':backup/vzdump-qemu-');
658 },
659
660 volume_is_lxc_backup: function(volid, format) {
661 return format === 'pbs-ct' || volid.match(':backup/vzdump-(lxc|openvz)-');
662 },
663
efff7eab
DC
664 authSchema: {
665 ad: {
666 name: gettext('Active Directory Server'),
667 ipanel: 'pveAuthADPanel',
822fb26d 668 syncipanel: 'pveAuthLDAPSyncPanel',
efff7eab
DC
669 add: true,
670 },
671 ldap: {
672 name: gettext('LDAP Server'),
673 ipanel: 'pveAuthLDAPPanel',
822fb26d 674 syncipanel: 'pveAuthLDAPSyncPanel',
efff7eab
DC
675 add: true,
676 },
677 pam: {
678 name: 'Linux PAM',
679 ipanel: 'pveAuthBasePanel',
680 add: false,
681 },
682 pve: {
683 name: 'Proxmox VE authentication server',
684 ipanel: 'pveAuthBasePanel',
685 add: false,
686 },
687 },
688
062a7f49
TL
689 storageSchema: {
690 dir: {
691 name: Proxmox.Utils.directoryText,
692 ipanel: 'DirInputPanel',
693 faIcon: 'folder'
694 },
695 lvm: {
696 name: 'LVM',
697 ipanel: 'LVMInputPanel',
698 faIcon: 'folder'
699 },
700 lvmthin: {
701 name: 'LVM-Thin',
702 ipanel: 'LvmThinInputPanel',
703 faIcon: 'folder'
704 },
705 nfs: {
706 name: 'NFS',
707 ipanel: 'NFSInputPanel',
708 faIcon: 'building'
709 },
710 cifs: {
711 name: 'CIFS',
712 ipanel: 'CIFSInputPanel',
713 faIcon: 'building'
714 },
715 glusterfs: {
716 name: 'GlusterFS',
717 ipanel: 'GlusterFsInputPanel',
718 faIcon: 'building'
719 },
720 iscsi: {
721 name: 'iSCSI',
722 ipanel: 'IScsiInputPanel',
723 faIcon: 'building'
724 },
4a4b2b6e
TL
725 cephfs: {
726 name: 'CephFS',
727 ipanel: 'CephFSInputPanel',
728 faIcon: 'building'
729 },
730 pvecephfs: {
731 name: 'CephFS (PVE)',
732 ipanel: 'CephFSInputPanel',
733 hideAdd: true,
734 faIcon: 'building'
735 },
062a7f49
TL
736 rbd: {
737 name: 'RBD',
738 ipanel: 'RBDInputPanel',
062a7f49
TL
739 faIcon: 'building'
740 },
741 pveceph: {
742 name: 'RBD (PVE)',
0d1ac958
TL
743 ipanel: 'RBDInputPanel',
744 hideAdd: true,
062a7f49
TL
745 faIcon: 'building'
746 },
747 zfs: {
748 name: 'ZFS over iSCSI',
749 ipanel: 'ZFSInputPanel',
750 faIcon: 'building'
751 },
752 zfspool: {
753 name: 'ZFS',
754 ipanel: 'ZFSPoolInputPanel',
755 faIcon: 'folder'
756 },
8b966034
TL
757 pbs: {
758 name: 'Proxmox Backup Server',
ee19d331
TL
759 ipanel: 'PBSInputPanel',
760 faIcon: 'floppy-o',
8b966034 761 },
062a7f49
TL
762 drbd: {
763 name: 'DRBD',
8b966034
TL
764 hideAdd: true,
765 },
062a7f49
TL
766 },
767
9233148b
AD
768 sdnvnetSchema: {
769 vnet: {
770 name: 'vnet',
771 faIcon: 'folder'
772 },
773 },
774
775 sdnzoneSchema: {
776 zone: {
777 name: 'zone',
778 hideAdd: true
779 },
1b4cce60
AD
780 simple: {
781 name: 'Simple',
782 ipanel: 'SimpleInputPanel',
783 faIcon: 'th'
784 },
9233148b 785 vlan: {
f3c1eac7 786 name: 'VLAN',
9233148b 787 ipanel: 'VlanInputPanel',
f3c1eac7 788 faIcon: 'th'
9233148b
AD
789 },
790 qinq: {
f3c1eac7 791 name: 'QinQ',
9233148b 792 ipanel: 'QinQInputPanel',
f3c1eac7 793 faIcon: 'th'
9233148b
AD
794 },
795 vxlan: {
f3c1eac7 796 name: 'VXLAN',
9233148b 797 ipanel: 'VxlanInputPanel',
f3c1eac7 798 faIcon: 'th'
9233148b
AD
799 },
800 evpn: {
f3c1eac7 801 name: 'EVPN',
9233148b 802 ipanel: 'EvpnInputPanel',
f3c1eac7 803 faIcon: 'th'
9233148b
AD
804 },
805 },
806
807 sdncontrollerSchema: {
808 controller: {
809 name: 'controller',
810 hideAdd: true
811 },
812 evpn: {
813 name: 'evpn',
814 ipanel: 'EvpnInputPanel',
f3c1eac7 815 faIcon: 'crosshairs'
9233148b
AD
816 },
817 },
818
819 format_sdnvnet_type: function(value, md, record) {
820 var schema = PVE.Utils.sdnvnetSchema[value];
821 if (schema) {
822 return schema.name;
823 }
824 return Proxmox.Utils.unknownText;
825 },
826
827 format_sdnzone_type: function(value, md, record) {
828 var schema = PVE.Utils.sdnzoneSchema[value];
829 if (schema) {
f3c1eac7 830 return schema.name;
9233148b
AD
831 }
832 return Proxmox.Utils.unknownText;
833 },
834
835 format_sdncontroller_type: function(value, md, record) {
836 var schema = PVE.Utils.sdncontrollerSchema[value];
837 if (schema) {
838 return schema.name;
839 }
840 return Proxmox.Utils.unknownText;
841 },
842
3c23c025 843 format_storage_type: function(value, md, record) {
4a4b2b6e
TL
844 if (value === 'rbd') {
845 value = (!record || record.get('monhost') ? 'rbd' : 'pveceph');
846 } else if (value === 'cephfs') {
847 value = (!record || record.get('monhost') ? 'cephfs' : 'pvecephfs');
3c23c025 848 }
062a7f49
TL
849
850 var schema = PVE.Utils.storageSchema[value];
851 if (schema) {
852 return schema.name;
b0a6d326 853 }
062a7f49 854 return Proxmox.Utils.unknownText;
a3b8efb4
EK
855 },
856
ced1677b 857 format_ha: function(value) {
e7ade592 858 var text = Proxmox.Utils.noneText;
ced1677b
TL
859
860 if (value.managed) {
e7ade592 861 text = value.state || Proxmox.Utils.noneText;
ced1677b 862
e7ade592
DC
863 text += ', ' + Proxmox.Utils.groupText + ': ';
864 text += value.group || Proxmox.Utils.noneText;
ced1677b
TL
865 }
866
867 return text;
868 },
869
b0a6d326 870 format_content_types: function(value) {
0e244a29
DC
871 return value.split(',').sort().map(function(ct) {
872 return PVE.Utils.contentTypes[ct] || ct;
873 }).join(', ');
b0a6d326
EK
874 },
875
876 render_storage_content: function(value, metaData, record) {
877 var data = record.data;
878 if (Ext.isNumber(data.channel) &&
879 Ext.isNumber(data.id) &&
880 Ext.isNumber(data.lun)) {
0be88ae1
DC
881 return "CH " +
882 Ext.String.leftPad(data.channel,2, '0') +
b0a6d326
EK
883 " ID " + data.id + " LUN " + data.lun;
884 }
3b8f599b 885 return data.volid.replace(/^.*?:(.*?\/)?/,'');
b0a6d326
EK
886 },
887
888 render_serverity: function (value) {
889 return PVE.Utils.log_severity_hash[value] || value;
890 },
891
892 render_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
893
894 if (!(record.data.uptime && Ext.isNumeric(value))) {
895 return '';
896 }
897
898 var maxcpu = record.data.maxcpu || 1;
899
900 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
901 return '';
902 }
0be88ae1 903
b0a6d326
EK
904 var per = value * 100;
905
906 return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
907 },
908
909 render_size: function(value, metaData, record, rowIndex, colIndex, store) {
b0a6d326
EK
910
911 if (!Ext.isNumeric(value)) {
912 return '';
913 }
914
e7ade592 915 return Proxmox.Utils.format_size(value);
b0a6d326
EK
916 },
917
946730cd
DC
918 render_bandwidth: function(value) {
919 if (!Ext.isNumeric(value)) {
920 return '';
921 }
922
e7ade592 923 return Proxmox.Utils.format_size(value) + '/s';
b0a6d326
EK
924 },
925
3f633655
EK
926 render_timestamp_human_readable: function(value) {
927 return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s');
928 },
929
0bfc799f
DC
930 calculate_mem_usage: function(data) {
931 if (!Ext.isNumeric(data.mem) ||
932 data.maxmem === 0 ||
933 data.uptime < 1) {
934 return -1;
935 }
936
937 return (data.mem / data.maxmem);
938 },
939
940 render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
941 if (!Ext.isNumeric(value) || value === -1) {
942 return '';
943 }
944 if (value > 1 ) {
945 // we got no percentage but bytes
946 var mem = value;
947 var maxmem = record.data.maxmem;
948 if (!record.data.uptime ||
949 maxmem === 0 ||
950 !Ext.isNumeric(mem)) {
951 return '';
952 }
953
954 return ((mem*100)/maxmem).toFixed(1) + " %";
955 }
956 return (value*100).toFixed(1) + " %";
957 },
958
b0a6d326
EK
959 render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
960
961 var mem = value;
962 var maxmem = record.data.maxmem;
0be88ae1 963
b0a6d326
EK
964 if (!record.data.uptime) {
965 return '';
966 }
967
968 if (!(Ext.isNumeric(mem) && maxmem)) {
969 return '';
970 }
971
728f1b97 972 return PVE.Utils.render_size(value);
b0a6d326
EK
973 },
974
0bfc799f
DC
975 calculate_disk_usage: function(data) {
976
977 if (!Ext.isNumeric(data.disk) ||
978 data.type === 'qemu' ||
979 (data.type === 'lxc' && data.uptime === 0) ||
980 data.maxdisk === 0) {
981 return -1;
982 }
983
984 return (data.disk / data.maxdisk);
985 },
986
987 render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
988 if (!Ext.isNumeric(value) || value === -1) {
989 return '';
990 }
991
992 return (value * 100).toFixed(1) + " %";
993 },
994
b0a6d326
EK
995 render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
996
997 var disk = value;
998 var maxdisk = record.data.maxdisk;
728f1b97 999 var type = record.data.type;
b0a6d326 1000
728f1b97
DC
1001 if (!Ext.isNumeric(disk) ||
1002 type === 'qemu' ||
1003 maxdisk === 0 ||
1004 (type === 'lxc' && record.data.uptime === 0)) {
b0a6d326
EK
1005 return '';
1006 }
1007
728f1b97 1008 return PVE.Utils.render_size(value);
b0a6d326
EK
1009 },
1010
4dbc64a7
DC
1011 get_object_icon_class: function(type, record) {
1012 var status = '';
1013 var objType = type;
1014
1015 if (type === 'type') {
1016 // for folder view
1017 objType = record.groupbyid;
1018 } else if (record.template) {
1019 // templates
1020 objType = 'template';
1021 status = type;
1022 } else {
1023 // everything else
1024 status = record.status + ' ha-' + record.hastate;
b1d8e73d
DC
1025 }
1026
6284a48a
DC
1027 if (record.lock) {
1028 status += ' locked lock-' + record.lock;
1029 }
1030
4dbc64a7
DC
1031 var defaults = PVE.tree.ResourceTree.typeDefaults[objType];
1032 if (defaults && defaults.iconCls) {
1033 var retVal = defaults.iconCls + ' ' + status;
1034 return retVal;
b0a6d326
EK
1035 }
1036
4dbc64a7
DC
1037 return '';
1038 },
1039
1040 render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
1041
1042 var cls = PVE.Utils.get_object_icon_class(value,record.data);
2b2fe160 1043
4dbc64a7 1044 var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> ';
b1d8e73d 1045 return fa + value;
b0a6d326
EK
1046 },
1047
b0a6d326
EK
1048 render_support_level: function(value, metaData, record) {
1049 return PVE.Utils.support_level_hash[value] || '-';
1050 },
1051
0be88ae1 1052 render_upid: function(value, metaData, record) {
b0a6d326
EK
1053 var type = record.data.type;
1054 var id = record.data.id;
1055
e7ade592 1056 return Proxmox.Utils.format_task_description(type, id);
b0a6d326
EK
1057 },
1058
054ac1b8
DC
1059 /* render functions for new status panel */
1060
1061 render_usage: function(val) {
1062 return (val*100).toFixed(2) + '%';
1063 },
1064
1065 render_cpu_usage: function(val, max) {
1066 return Ext.String.format(gettext('{0}% of {1}') +
1067 ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max);
1068 },
1069
1070 render_size_usage: function(val, max) {
bab64974
DC
1071 if (max === 0) {
1072 return gettext('N/A');
1073 }
054ac1b8
DC
1074 return (val*100/max).toFixed(2) + '% '+ '(' +
1075 Ext.String.format(gettext('{0} of {1}'),
1076 PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')';
1077 },
1078
1079 /* this is different for nodes */
1080 render_node_cpu_usage: function(value, record) {
1081 return PVE.Utils.render_cpu_usage(value, record.cpus);
1082 },
1083
1084 /* this is different for nodes */
1085 render_node_size_usage: function(record) {
1086 return PVE.Utils.render_size_usage(record.used, record.total);
1087 },
1088
27809975
DC
1089 render_optional_url: function(value) {
1090 var match;
1091 if (value && (match = value.match(/^https?:\/\//)) !== null) {
cdd9b6c0 1092 return '<a target="_blank" href="' + value + '">' + value + '</a>';
27809975
DC
1093 }
1094 return value;
1095 },
1096
1097 render_san: function(value) {
1098 var names = [];
1099 if (Ext.isArray(value)) {
1100 value.forEach(function(val) {
1101 if (!Ext.isNumber(val)) {
1102 names.push(val);
1103 }
1104 });
1105 return names.join('<br>');
1106 }
1107 return value;
1108 },
1109
6ad4be69
DC
1110 render_full_name: function(firstname, metaData, record) {
1111 var first = firstname || '';
1112 var last = record.data.lastname || '';
1113 return Ext.htmlEncode(first + " " + last);
1114 },
1115
2d41c7e6
TL
1116 render_u2f_error: function(error) {
1117 var ErrorNames = {
1118 '1': gettext('Other Error'),
1119 '2': gettext('Bad Request'),
1120 '3': gettext('Configuration Unsupported'),
1121 '4': gettext('Device Ineligible'),
1122 '5': gettext('Timeout')
1123 };
1124 return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText;
1125 },
1126
aa0819a8 1127 windowHostname: function() {
e7ade592 1128 return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
aa0819a8
WB
1129 function(m, addr, offset, original) { return addr; });
1130 },
0be88ae1 1131
953f6e9b 1132 openDefaultConsoleWindow: function(consoles, consoleType, vmid, nodename, vmname, cmd) {
3438c27e 1133 var dv = PVE.Utils.defaultViewer(consoles);
953f6e9b 1134 PVE.Utils.openConsoleWindow(dv, consoleType, vmid, nodename, vmname, cmd);
b0a6d326
EK
1135 },
1136
953f6e9b
TL
1137 openConsoleWindow: function(viewer, consoleType, vmid, nodename, vmname, cmd) {
1138 if (vmid == undefined && (consoleType === 'kvm' || consoleType === 'lxc')) {
b0a6d326
EK
1139 throw "missing vmid";
1140 }
b0a6d326
EK
1141 if (!nodename) {
1142 throw "no nodename specified";
1143 }
1144
c7218ab3 1145 if (viewer === 'html5') {
953f6e9b 1146 PVE.Utils.openVNCViewer(consoleType, vmid, nodename, vmname, cmd);
c6b2336c 1147 } else if (viewer === 'xtermjs') {
953f6e9b 1148 Proxmox.Utils.openXtermJsViewer(consoleType, vmid, nodename, vmname, cmd);
b0a6d326 1149 } else if (viewer === 'vv') {
953f6e9b
TL
1150 let url = '/nodes/' + nodename + '/spiceshell';
1151 let params = {
1152 proxy: PVE.Utils.windowHostname(),
1153 };
1154 if (consoleType === 'kvm') {
b0a6d326 1155 url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
953f6e9b 1156 } else if (consoleType === 'lxc') {
9e361643 1157 url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy';
953f6e9b
TL
1158 } else if (consoleType === 'upgrade') {
1159 params.cmd = 'upgrade';
1160 } else if (consoleType === 'cmd') {
8eccc68f 1161 params.cmd = cmd;
953f6e9b
TL
1162 } else if (consoleType !== 'shell') {
1163 throw `unknown spice viewer type '${consoleType}'`;
b0a6d326 1164 }
953f6e9b 1165 PVE.Utils.openSpiceViewer(url, params);
b0a6d326 1166 } else {
953f6e9b 1167 throw `unknown viewer type '${viewer}'`;
b0a6d326
EK
1168 }
1169 },
1170
3438c27e
DC
1171 defaultViewer: function(consoles) {
1172
1173 var allowSpice, allowXtermjs;
1174
1175 if (consoles === true) {
1176 allowSpice = true;
1177 allowXtermjs = true;
1178 } else if (typeof consoles === 'object') {
1179 allowSpice = consoles.spice;
4ace5c6f 1180 allowXtermjs = !!consoles.xtermjs;
3438c27e 1181 }
da9d14cd 1182 var dv = PVE.VersionInfo.console || 'xtermjs';
f932cffa
DC
1183 if (dv === 'vv' && !allowSpice) {
1184 dv = (allowXtermjs) ? 'xtermjs' : 'html5';
1185 } else if (dv === 'xtermjs' && !allowXtermjs) {
1186 dv = (allowSpice) ? 'vv' : 'html5';
b0a6d326
EK
1187 }
1188
1189 return dv;
1190 },
1191
8eccc68f 1192 openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) {
af89f682
TL
1193 let scaling = 'off';
1194 if (Proxmox.Utils.toolkit !== 'touch') {
1195 var sp = Ext.state.Manager.getProvider();
1196 scaling = sp.get('novnc-scaling', 'off');
1197 }
8eccc68f 1198 var url = Ext.Object.toQueryString({
9e361643 1199 console: vmtype, // kvm, lxc, upgrade or shell
c7218ab3 1200 novnc: 1,
b0a6d326
EK
1201 vmid: vmid,
1202 vmname: vmname,
16e64c97 1203 node: nodename,
af89f682 1204 resize: scaling,
8eccc68f 1205 cmd: cmd
b0a6d326
EK
1206 });
1207 var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
7af1ab47
DC
1208 if (nw) {
1209 nw.focus();
1210 }
b0a6d326
EK
1211 },
1212
1213 openSpiceViewer: function(url, params){
1214
1215 var downloadWithName = function(uri, name) {
1216 var link = Ext.DomHelper.append(document.body, {
1217 tag: 'a',
1218 href: uri,
1219 css : 'display:none;visibility:hidden;height:0px;'
1220 });
1221
1222 // Note: we need to tell android the correct file name extension
1223 // but we do not set 'download' tag for other environments, because
1224 // It can have strange side effects (additional user prompt on firefox)
1225 var andriod = navigator.userAgent.match(/Android/i) ? true : false;
1226 if (andriod) {
1227 link.download = name;
1228 }
1229
1230 if (link.fireEvent) {
1231 link.fireEvent('onclick');
1232 } else {
953f6e9b
TL
1233 let evt = document.createEvent("MouseEvents");
1234 evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
b0a6d326
EK
1235 link.dispatchEvent(evt);
1236 }
1237 };
1238
e7ade592 1239 Proxmox.Utils.API2Request({
b0a6d326
EK
1240 url: url,
1241 params: params,
1242 method: 'POST',
1243 failure: function(response, opts){
1244 Ext.Msg.alert('Error', response.htmlStatus);
1245 },
1246 success: function(response, opts){
1247 var raw = "[virt-viewer]\n";
1248 Ext.Object.each(response.result.data, function(k, v) {
1249 raw += k + "=" + v + "\n";
1250 });
1251 var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
1252 encodeURIComponent(raw);
0be88ae1 1253
b0a6d326
EK
1254 downloadWithName(url, "pve-spice.vv");
1255 }
1256 });
1257 },
1258
e3129443
DC
1259 openTreeConsole: function(tree, record, item, index, e) {
1260 e.stopEvent();
1261 var nodename = record.data.node;
1262 var vmid = record.data.vmid;
1263 var vmname = record.data.name;
1264 if (record.data.type === 'qemu' && !record.data.template) {
e7ade592 1265 Proxmox.Utils.API2Request({
e3129443
DC
1266 url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
1267 failure: function(response, opts) {
1268 Ext.Msg.alert('Error', response.htmlStatus);
1269 },
1270 success: function(response, opts) {
bd9537d7 1271 let conf = response.result.data;
54453c38 1272 var consoles = {
bd9537d7
TL
1273 spice: !!conf.spice,
1274 xtermjs: !!conf.serial,
54453c38
DC
1275 };
1276 PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
e3129443
DC
1277 }
1278 });
1279 } else if (record.data.type === 'lxc' && !record.data.template) {
1280 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
1281 }
1282 },
1283
fbd60cfd
DM
1284 // test automation helper
1285 call_menu_handler: function(menu, text) {
1286
1287 var list = menu.query('menuitem');
1288
1289 Ext.Array.each(list, function(item) {
1290 if (item.text === text) {
1291 if (item.handler) {
1292 item.handler();
1293 return 1;
1294 } else {
1295 return undefined;
1296 }
1297 }
1298 });
1299 },
1300
685b7aa4
DC
1301 createCmdMenu: function(v, record, item, index, event) {
1302 event.stopEvent();
cc1a91be
DC
1303 if (!(v instanceof Ext.tree.View)) {
1304 v.select(record);
1305 }
685b7aa4 1306 var menu;
9bad05bd
DC
1307 var template = !!record.data.template;
1308 var type = record.data.type;
685b7aa4 1309
9bad05bd
DC
1310 if (template) {
1311 if (type === 'qemu' || type == 'lxc') {
1312 menu = Ext.create('PVE.menu.TemplateMenu', {
1313 pveSelNode: record
1314 });
1315 }
1316 } else if (type === 'qemu' ||
1317 type === 'lxc' ||
1318 type === 'node') {
1319 menu = Ext.create('PVE.' + type + '.CmdMenu', {
1320 pveSelNode: record,
c11ab8cb
DC
1321 nodename: record.data.node
1322 });
685b7aa4
DC
1323 } else {
1324 return;
1325 }
1326
1327 menu.showAt(event.getXY());
9f0b4e04 1328 return menu;
e7ade592 1329 },
9fa2e36d 1330
fe4f00ad
TL
1331 // helper for deleting field which are set to there default values
1332 delete_if_default: function(values, fieldname, default_val, create) {
1333 if (values[fieldname] === '' || values[fieldname] === default_val) {
1334 if (!create) {
1335 if (values['delete']) {
2db8e90d
DC
1336 if (Ext.isArray(values['delete'])) {
1337 values['delete'].push(fieldname);
1338 } else {
1339 values['delete'] += ',' + fieldname;
1340 }
fe4f00ad
TL
1341 } else {
1342 values['delete'] = fieldname;
1343 }
1344 }
1345
1346 delete values[fieldname];
1347 }
857b97a7
TL
1348 },
1349
1350 loadSSHKeyFromFile: function(file, callback) {
1351 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1352 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1353 // assume: 740*8 for max. 32kbit (5920 byte file)
1354 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1355 if (file.size > 8192) {
1356 Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
1357 return;
1358 }
1359 /*global
1360 FileReader
1361 */
1362 var reader = new FileReader();
1363 reader.onload = function(evt) {
1364 callback(evt.target.result);
1365 };
1366 reader.readAsText(file);
abe824aa
DC
1367 },
1368
7dda153c
TL
1369 loadTextFromFile: function(file, callback, maxBytes) {
1370 let maxSize = maxBytes || 8192;
1371 if (file.size > maxSize) {
1372 Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
1373 return;
1374 }
1375 /*global
1376 FileReader
1377 */
1378 let reader = new FileReader();
1379 reader.onload = evt => callback(evt.target.result);
1380 reader.readAsText(file);
1381 },
1382
8c4ec8c7
TL
1383 diskControllerMaxIDs: {
1384 ide: 4,
1385 sata: 6,
cf0d139e 1386 scsi: 31,
8c4ec8c7
TL
1387 virtio: 16,
1388 },
abe824aa
DC
1389
1390 // types is either undefined (all busses), an array of busses, or a single bus
1391 forEachBus: function(types, func) {
8c4ec8c7 1392 var busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
abe824aa
DC
1393 var i, j, count, cont;
1394
1395 if (Ext.isArray(types)) {
1396 busses = types;
1397 } else if (Ext.isDefined(types)) {
1398 busses = [ types ];
1399 }
1400
1401 // check if we only have valid busses
1402 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1403 if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) {
abe824aa
DC
1404 throw "invalid bus: '" + busses[i] + "'";
1405 }
1406 }
1407
1408 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1409 count = PVE.Utils.diskControllerMaxIDs[busses[i]];
abe824aa
DC
1410 for (j = 0; j < count; j++) {
1411 cont = func(busses[i], j);
1412 if (!cont && cont !== undefined) {
1413 return;
1414 }
1415 }
1416 }
14a845bc
DC
1417 },
1418
483bd394 1419 mp_counts: { mps: 256, unused: 256 },
14a845bc
DC
1420
1421 forEachMP: function(func, includeUnused) {
1422 var i, cont;
1423 for (i = 0; i < PVE.Utils.mp_counts.mps; i++) {
1424 cont = func('mp', i);
1425 if (!cont && cont !== undefined) {
1426 return;
1427 }
1428 }
1429
1430 if (!includeUnused) {
1431 return;
1432 }
1433
1434 for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
1435 cont = func('unused', i);
1436 if (!cont && cont !== undefined) {
1437 return;
1438 }
1439 }
b945c7c1
TM
1440 },
1441
6c1d8ead 1442 hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1 },
9d855398 1443
b945c7c1
TM
1444 cleanEmptyObjectKeys: function (obj) {
1445 var propName;
1446 for (propName in obj) {
1447 if (obj.hasOwnProperty(propName)) {
1448 if (obj[propName] === null || obj[propName] === undefined) {
1449 delete obj[propName];
1450 }
1451 }
1452 }
4616a55b
TM
1453 },
1454
eadbbb4a
DC
1455 acmedomain_count: 5,
1456
1457 add_domain_to_acme: function(acme, domain) {
1458 if (acme.domains === undefined) {
1459 acme.domains = [domain];
1460 } else {
1461 acme.domains.push(domain);
1462 acme.domains = acme.domains.filter((value, index, self) => {
1463 return self.indexOf(value) === index;
1464 });
1465 }
1466 return acme;
1467 },
1468
1469 remove_domain_from_acme: function(acme, domain) {
1470 if (acme.domains !== undefined) {
1471 acme.domains = acme.domains.filter((value, index, self) => {
1472 return self.indexOf(value) === index && value !== domain;
1473 });
1474 }
1475 return acme;
1476 },
1477
4616a55b
TM
1478 handleStoreErrorOrMask: function(me, store, regex, callback) {
1479
1480 me.mon(store, 'load', function (proxy, response, success, operation) {
1481
1482 if (success) {
1483 Proxmox.Utils.setErrorMask(me, false);
1484 return;
1485 }
1486 var msg;
1487
1488 if (operation.error.statusText) {
1489 if (operation.error.statusText.match(regex)) {
1490 callback(me, operation.error);
1491 return;
1492 } else {
1493 msg = operation.error.statusText + ' (' + operation.error.status + ')';
1494 }
1495 } else {
1496 msg = gettext('Connection error');
1497 }
1498 Proxmox.Utils.setErrorMask(me, msg);
1499 });
1500 },
1501
1502 showCephInstallOrMask: function(container, msg, nodename, callback){
1503 var regex = new RegExp("not (installed|initialized)", "i");
1504 if (msg.match(regex)) {
1505 if (Proxmox.UserName === 'root@pam') {
1506 container.el.mask();
1507 if (!container.down('pveCephInstallWindow')){
f992ef80 1508 var isInstalled = msg.match(/not initialized/i) ? true : false;
4616a55b
TM
1509 var win = Ext.create('PVE.ceph.Install', {
1510 nodename: nodename
1511 });
f992ef80 1512 win.getViewModel().set('isInstalled', isInstalled);
4616a55b
TM
1513 container.add(win);
1514 win.show();
1515 callback(win);
1516 }
1517 } else {
a7e8b87b
TL
1518 container.mask(Ext.String.format(gettext('{0} not installed.') +
1519 ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']);
4616a55b
TM
1520 }
1521 return true;
1522 } else {
1523 return false;
1524 }
49dfba72
DC
1525 },
1526
1527 propertyStringSet: function(target, source, name, value) {
1528 if (source) {
1529 if (value === undefined) {
1530 target[name] = source;
1531 } else {
1532 target[name] = value;
1533 }
1534 } else {
1535 delete target[name];
1536 }
bbc83309
DC
1537 },
1538
1539 updateColumns: function(container) {
f973c5b2
DC
1540 let mode = Ext.state.Manager.get('summarycolumns') || 'auto';
1541 let factor;
1542 if (mode !== 'auto') {
1543 factor = parseInt(mode, 10);
1544 if (Number.isNaN(factor)) {
1545 factor = 1;
1546 }
1547 } else {
1548 factor = container.getSize().width < 1400 ? 1 : 2;
1549 }
bbc83309
DC
1550
1551 if (container.oldFactor === factor) {
1552 return;
1553 }
1554
1555 let items = container.query('>'); // direct childs
1556 factor = Math.min(factor, items.length);
1557 container.oldFactor = factor;
1558
1559 items.forEach((item) => {
1560 item.columnWidth = 1 / factor;
1561 });
1562
1563 // we have to update the layout twice, since the first layout change
1564 // can trigger the scrollbar which reduces the amount of space left
1565 container.updateLayout();
1566 container.updateLayout();
1567 },
e65817a1
SR
1568
1569 forEachCorosyncLink: function(nodeinfo, cb) {
1570 let re = /(?:ring|link)(\d+)_addr/;
1571 Ext.iterate(nodeinfo, (prop, val) => {
1572 let match = re.exec(prop);
1573 if (match) {
1574 cb(Number(match[1]), val);
1575 }
1576 });
1577 },
4546808c
SR
1578
1579 cpu_vendor_map: {
1580 'default': 'QEMU',
1581 'AuthenticAMD': 'AMD',
1582 'GenuineIntel': 'Intel'
1583 },
1584
1585 cpu_vendor_order: {
1586 "AMD": 1,
1587 "Intel": 2,
1588 "QEMU": 3,
1589 "Host": 4,
1590 "_default_": 5, // includes custom models
1591 },
e7ade592 1592},
fe4f00ad 1593
9fa2e36d
EK
1594 singleton: true,
1595 constructor: function() {
1596 var me = this;
1597 Ext.apply(me, me.utilities);
d18e15dd
DC
1598
1599 Proxmox.Utils.override_task_descriptions({
1600 acmedeactivate: ['ACME Account', gettext('Deactivate')],
1601 acmenewcert: ['SRV', gettext('Order Certificate')],
1602 acmerefresh: ['ACME Account', gettext('Refresh')],
1603 acmeregister: ['ACME Account', gettext('Register')],
1604 acmerenew: ['SRV', gettext('Renew Certificate')],
1605 acmerevoke: ['SRV', gettext('Revoke Certificate')],
1606 acmeupdate: ['ACME Account', gettext('Update')],
1607 'auth-realm-sync': [gettext('Realm'), gettext('Sync')],
1608 'auth-realm-sync-test': [gettext('Realm'), gettext('Sync Preview')],
1609 cephcreatemds: ['Ceph Metadata Server', gettext('Create')],
1610 cephcreatemgr: ['Ceph Manager', gettext('Create')],
1611 cephcreatemon: ['Ceph Monitor', gettext('Create')],
1612 cephcreateosd: ['Ceph OSD', gettext('Create')],
1613 cephcreatepool: ['Ceph Pool', gettext('Create')],
1614 cephdestroymds: ['Ceph Metadata Server', gettext('Destroy')],
1615 cephdestroymgr: ['Ceph Manager', gettext('Destroy')],
1616 cephdestroymon: ['Ceph Monitor', gettext('Destroy')],
1617 cephdestroyosd: ['Ceph OSD', gettext('Destroy')],
1618 cephdestroypool: ['Ceph Pool', gettext('Destroy')],
1619 cephfscreate: ['CephFS', gettext('Create')],
1620 clustercreate: ['', gettext('Create Cluster')],
1621 clusterjoin: ['', gettext('Join Cluster')],
1622 dircreate: [gettext('Directory Storage'), gettext('Create')],
1623 dirremove: [gettext('Directory'), gettext('Remove')],
1624 download: ['', gettext('Download')],
1625 hamigrate: ['HA', gettext('Migrate')],
1626 hashutdown: ['HA', gettext('Shutdown')],
1627 hastart: ['HA', gettext('Start')],
1628 hastop: ['HA', gettext('Stop')],
1629 imgcopy: ['', gettext('Copy data')],
1630 imgdel: ['', gettext('Erase data')],
1631 lvmcreate: [gettext('LVM Storage'), gettext('Create')],
1632 lvmthincreate: [gettext('LVM-Thin Storage'), gettext('Create')],
1633 migrateall: ['', gettext('Migrate all VMs and Containers')],
1634 'move_volume': ['CT', gettext('Move Volume')],
1635 pull_file: ['CT', gettext('Pull file')],
1636 push_file: ['CT', gettext('Push file')],
1637 qmclone: ['VM', gettext('Clone')],
1638 qmconfig: ['VM', gettext('Configure')],
1639 qmcreate: ['VM', gettext('Create')],
1640 qmdelsnapshot: ['VM', gettext('Delete Snapshot')],
1641 qmdestroy: ['VM', gettext('Destroy')],
1642 qmigrate: ['VM', gettext('Migrate')],
1643 qmmove: ['VM', gettext('Move disk')],
1644 qmpause: ['VM', gettext('Pause')],
1645 qmreboot: ['VM', gettext('Reboot')],
1646 qmreset: ['VM', gettext('Reset')],
1647 qmrestore: ['VM', gettext('Restore')],
1648 qmresume: ['VM', gettext('Resume')],
1649 qmrollback: ['VM', gettext('Rollback')],
1650 qmshutdown: ['VM', gettext('Shutdown')],
1651 qmsnapshot: ['VM', gettext('Snapshot')],
1652 qmstart: ['VM', gettext('Start')],
1653 qmstop: ['VM', gettext('Stop')],
1654 qmsuspend: ['VM', gettext('Hibernate')],
1655 qmtemplate: ['VM', gettext('Convert to template')],
1656 spiceproxy: ['VM/CT', gettext('Console') + ' (Spice)'],
1657 spiceshell: ['', gettext('Shell') + ' (Spice)'],
1658 startall: ['', gettext('Start all VMs and Containers')],
1659 stopall: ['', gettext('Stop all VMs and Containers')],
1660 unknownimgdel: ['', gettext('Destroy image from unknown guest')],
1661 vncproxy: ['VM/CT', gettext('Console')],
1662 vncshell: ['', gettext('Shell')],
1663 vzclone: ['CT', gettext('Clone')],
1664 vzcreate: ['CT', gettext('Create')],
1665 vzdelsnapshot: ['CT', gettext('Delete Snapshot')],
1666 vzdestroy: ['CT', gettext('Destroy')],
1667 vzdump: (type, id) => id ? `VM/CT ${id} - ${gettext('Backup')}` : gettext('Backup Job'),
1668 vzmigrate: ['CT', gettext('Migrate')],
1669 vzmount: ['CT', gettext('Mount')],
1670 vzreboot: ['CT', gettext('Reboot')],
1671 vzrestore: ['CT', gettext('Restore')],
1672 vzresume: ['CT', gettext('Resume')],
1673 vzrollback: ['CT', gettext('Rollback')],
1674 vzshutdown: ['CT', gettext('Shutdown')],
1675 vzsnapshot: ['CT', gettext('Snapshot')],
1676 vzstart: ['CT', gettext('Start')],
1677 vzstop: ['CT', gettext('Stop')],
1678 vzsuspend: ['CT', gettext('Suspend')],
1679 vztemplate: ['CT', gettext('Convert to template')],
1680 vzumount: ['CT', gettext('Unmount')],
1681 zfscreate: [gettext('ZFS Storage'), gettext('Create')],
1682 });
685b7aa4 1683 }
e7ade592 1684
9fa2e36d 1685});