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