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