]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/Utils.js
update shipped appliance info index
[pve-manager.git] / www / manager6 / Utils.js
1 Ext.ns('PVE');
2
3 console.log("Starting Proxmox VE Manager");
4
5 Ext.Ajax.defaultHeaders = {
6 'Accept': 'application/json',
7 };
8
9 Ext.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 //ar: 'Arabic',
550 da: 'Danish',
551 de: 'German',
552 'de-ch': 'German (Swiss)',
553 'en-gb': 'English (UK)',
554 'en-us': 'English (USA)',
555 es: 'Spanish',
556 //et: 'Estonia',
557 fi: 'Finnish',
558 //fo: 'Faroe Islands',
559 fr: 'French',
560 'fr-be': 'French (Belgium)',
561 'fr-ca': 'French (Canada)',
562 'fr-ch': 'French (Swiss)',
563 //hr: 'Croatia',
564 hu: 'Hungarian',
565 is: 'Icelandic',
566 it: 'Italian',
567 ja: 'Japanese',
568 lt: 'Lithuanian',
569 //lv: 'Latvian',
570 mk: 'Macedonian',
571 nl: 'Dutch',
572 //'nl-be': 'Dutch (Belgium)',
573 no: 'Norwegian',
574 pl: 'Polish',
575 pt: 'Portuguese',
576 'pt-br': 'Portuguese (Brazil)',
577 //ru: 'Russian',
578 sl: 'Slovenian',
579 sv: 'Swedish',
580 //th: 'Thai',
581 tr: 'Turkish',
582 },
583
584 kvm_vga_drivers: {
585 std: gettext('Standard VGA'),
586 vmware: gettext('VMware compatible'),
587 qxl: 'SPICE',
588 qxl2: 'SPICE dual monitor',
589 qxl3: 'SPICE three monitors',
590 qxl4: 'SPICE four monitors',
591 serial0: gettext('Serial terminal') + ' 0',
592 serial1: gettext('Serial terminal') + ' 1',
593 serial2: gettext('Serial terminal') + ' 2',
594 serial3: gettext('Serial terminal') + ' 3',
595 virtio: 'VirtIO-GPU',
596 none: Proxmox.Utils.noneText,
597 },
598
599 render_kvm_language: function(value) {
600 if (!value || value === '__default__') {
601 return Proxmox.Utils.defaultText;
602 }
603 var text = PVE.Utils.kvm_keymaps[value];
604 if (text) {
605 return text + ' (' + value + ')';
606 }
607 return value;
608 },
609
610 kvm_keymap_array: function() {
611 var data = [['__default__', PVE.Utils.render_kvm_language('')]];
612 Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) {
613 data.push([key, PVE.Utils.render_kvm_language(value)]);
614 });
615
616 return data;
617 },
618
619 console_map: {
620 '__default__': Proxmox.Utils.defaultText + ' (xterm.js)',
621 'vv': 'SPICE (remote-viewer)',
622 'html5': 'HTML5 (noVNC)',
623 'xtermjs': 'xterm.js',
624 },
625
626 render_console_viewer: function(value) {
627 value = value || '__default__';
628 if (PVE.Utils.console_map[value]) {
629 return PVE.Utils.console_map[value];
630 }
631 return value;
632 },
633
634 console_viewer_array: function() {
635 return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) {
636 return [v, PVE.Utils.render_console_viewer(v)];
637 });
638 },
639
640 render_kvm_vga_driver: function(value) {
641 if (!value) {
642 return Proxmox.Utils.defaultText;
643 }
644 var vga = PVE.Parser.parsePropertyString(value, 'type');
645 var text = PVE.Utils.kvm_vga_drivers[vga.type];
646 if (!vga.type) {
647 text = Proxmox.Utils.defaultText;
648 }
649 if (text) {
650 return text + ' (' + value + ')';
651 }
652 return value;
653 },
654
655 kvm_vga_driver_array: function() {
656 var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]];
657 Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) {
658 data.push([key, PVE.Utils.render_kvm_vga_driver(value)]);
659 });
660
661 return data;
662 },
663
664 render_kvm_startup: function(value) {
665 var startup = PVE.Parser.parseStartup(value);
666
667 var res = 'order=';
668 if (startup.order === undefined) {
669 res += 'any';
670 } else {
671 res += startup.order;
672 }
673 if (startup.up !== undefined) {
674 res += ',up=' + startup.up;
675 }
676 if (startup.down !== undefined) {
677 res += ',down=' + startup.down;
678 }
679
680 return res;
681 },
682
683 extractFormActionError: function(action) {
684 var msg;
685 switch (action.failureType) {
686 case Ext.form.action.Action.CLIENT_INVALID:
687 msg = gettext('Form fields may not be submitted with invalid values');
688 break;
689 case Ext.form.action.Action.CONNECT_FAILURE:
690 msg = gettext('Connection error');
691 var resp = action.response;
692 if (resp.status && resp.statusText) {
693 msg += " " + resp.status + ": " + resp.statusText;
694 }
695 break;
696 case Ext.form.action.Action.LOAD_FAILURE:
697 case Ext.form.action.Action.SERVER_INVALID:
698 msg = Proxmox.Utils.extractRequestError(action.result, true);
699 break;
700 }
701 return msg;
702 },
703
704 contentTypes: {
705 'images': gettext('Disk image'),
706 'backup': gettext('VZDump backup file'),
707 'vztmpl': gettext('Container template'),
708 'iso': gettext('ISO image'),
709 'rootdir': gettext('Container'),
710 'snippets': gettext('Snippets'),
711 },
712
713 volume_is_qemu_backup: function(volid, format) {
714 return format === 'pbs-vm' || volid.match(':backup/vzdump-qemu-');
715 },
716
717 volume_is_lxc_backup: function(volid, format) {
718 return format === 'pbs-ct' || volid.match(':backup/vzdump-(lxc|openvz)-');
719 },
720
721 authSchema: {
722 ad: {
723 name: gettext('Active Directory Server'),
724 ipanel: 'pveAuthADPanel',
725 syncipanel: 'pveAuthLDAPSyncPanel',
726 add: true,
727 tfa: true,
728 pwchange: true,
729 },
730 ldap: {
731 name: gettext('LDAP Server'),
732 ipanel: 'pveAuthLDAPPanel',
733 syncipanel: 'pveAuthLDAPSyncPanel',
734 add: true,
735 tfa: true,
736 pwchange: true,
737 },
738 openid: {
739 name: gettext('OpenID Connect Server'),
740 ipanel: 'pveAuthOpenIDPanel',
741 add: true,
742 tfa: false,
743 pwchange: false,
744 iconCls: 'pmx-itype-icon-openid-logo',
745 },
746 pam: {
747 name: 'Linux PAM',
748 ipanel: 'pveAuthBasePanel',
749 add: false,
750 tfa: true,
751 pwchange: true,
752 },
753 pve: {
754 name: 'Proxmox VE authentication server',
755 ipanel: 'pveAuthBasePanel',
756 add: false,
757 tfa: true,
758 pwchange: true,
759 },
760 },
761
762 storageSchema: {
763 dir: {
764 name: Proxmox.Utils.directoryText,
765 ipanel: 'DirInputPanel',
766 faIcon: 'folder',
767 backups: true,
768 },
769 lvm: {
770 name: 'LVM',
771 ipanel: 'LVMInputPanel',
772 faIcon: 'folder',
773 backups: false,
774 },
775 lvmthin: {
776 name: 'LVM-Thin',
777 ipanel: 'LvmThinInputPanel',
778 faIcon: 'folder',
779 backups: false,
780 },
781 btrfs: {
782 name: 'BTRFS',
783 ipanel: 'BTRFSInputPanel',
784 faIcon: 'folder',
785 backups: true,
786 },
787 nfs: {
788 name: 'NFS',
789 ipanel: 'NFSInputPanel',
790 faIcon: 'building',
791 backups: true,
792 },
793 cifs: {
794 name: 'SMB/CIFS',
795 ipanel: 'CIFSInputPanel',
796 faIcon: 'building',
797 backups: true,
798 },
799 glusterfs: {
800 name: 'GlusterFS',
801 ipanel: 'GlusterFsInputPanel',
802 faIcon: 'building',
803 backups: true,
804 },
805 iscsi: {
806 name: 'iSCSI',
807 ipanel: 'IScsiInputPanel',
808 faIcon: 'building',
809 backups: false,
810 },
811 cephfs: {
812 name: 'CephFS',
813 ipanel: 'CephFSInputPanel',
814 faIcon: 'building',
815 backups: true,
816 },
817 pvecephfs: {
818 name: 'CephFS (PVE)',
819 ipanel: 'CephFSInputPanel',
820 hideAdd: true,
821 faIcon: 'building',
822 backups: true,
823 },
824 rbd: {
825 name: 'RBD',
826 ipanel: 'RBDInputPanel',
827 faIcon: 'building',
828 backups: false,
829 },
830 pveceph: {
831 name: 'RBD (PVE)',
832 ipanel: 'RBDInputPanel',
833 hideAdd: true,
834 faIcon: 'building',
835 backups: false,
836 },
837 zfs: {
838 name: 'ZFS over iSCSI',
839 ipanel: 'ZFSInputPanel',
840 faIcon: 'building',
841 backups: false,
842 },
843 zfspool: {
844 name: 'ZFS',
845 ipanel: 'ZFSPoolInputPanel',
846 faIcon: 'folder',
847 backups: false,
848 },
849 pbs: {
850 name: 'Proxmox Backup Server',
851 ipanel: 'PBSInputPanel',
852 faIcon: 'floppy-o',
853 backups: true,
854 },
855 drbd: {
856 name: 'DRBD',
857 hideAdd: true,
858 backups: false,
859 },
860 },
861
862 sdnvnetSchema: {
863 vnet: {
864 name: 'vnet',
865 faIcon: 'folder',
866 },
867 },
868
869 sdnzoneSchema: {
870 zone: {
871 name: 'zone',
872 hideAdd: true,
873 },
874 simple: {
875 name: 'Simple',
876 ipanel: 'SimpleInputPanel',
877 faIcon: 'th',
878 },
879 vlan: {
880 name: 'VLAN',
881 ipanel: 'VlanInputPanel',
882 faIcon: 'th',
883 },
884 qinq: {
885 name: 'QinQ',
886 ipanel: 'QinQInputPanel',
887 faIcon: 'th',
888 },
889 vxlan: {
890 name: 'VXLAN',
891 ipanel: 'VxlanInputPanel',
892 faIcon: 'th',
893 },
894 evpn: {
895 name: 'EVPN',
896 ipanel: 'EvpnInputPanel',
897 faIcon: 'th',
898 },
899 },
900
901 sdncontrollerSchema: {
902 controller: {
903 name: 'controller',
904 hideAdd: true,
905 },
906 evpn: {
907 name: 'evpn',
908 ipanel: 'EvpnInputPanel',
909 faIcon: 'crosshairs',
910 },
911 bgp: {
912 name: 'bgp',
913 ipanel: 'BgpInputPanel',
914 faIcon: 'crosshairs',
915 },
916 },
917
918 sdnipamSchema: {
919 ipam: {
920 name: 'ipam',
921 hideAdd: true,
922 },
923 pve: {
924 name: 'PVE',
925 ipanel: 'PVEIpamInputPanel',
926 faIcon: 'th',
927 hideAdd: true,
928 },
929 netbox: {
930 name: 'Netbox',
931 ipanel: 'NetboxInputPanel',
932 faIcon: 'th',
933 },
934 phpipam: {
935 name: 'PhpIpam',
936 ipanel: 'PhpIpamInputPanel',
937 faIcon: 'th',
938 },
939 },
940
941 sdndnsSchema: {
942 dns: {
943 name: 'dns',
944 hideAdd: true,
945 },
946 powerdns: {
947 name: 'powerdns',
948 ipanel: 'PowerdnsInputPanel',
949 faIcon: 'th',
950 },
951 },
952
953 format_sdnvnet_type: function(value, md, record) {
954 var schema = PVE.Utils.sdnvnetSchema[value];
955 if (schema) {
956 return schema.name;
957 }
958 return Proxmox.Utils.unknownText;
959 },
960
961 format_sdnzone_type: function(value, md, record) {
962 var schema = PVE.Utils.sdnzoneSchema[value];
963 if (schema) {
964 return schema.name;
965 }
966 return Proxmox.Utils.unknownText;
967 },
968
969 format_sdncontroller_type: function(value, md, record) {
970 var schema = PVE.Utils.sdncontrollerSchema[value];
971 if (schema) {
972 return schema.name;
973 }
974 return Proxmox.Utils.unknownText;
975 },
976
977 format_sdnipam_type: function(value, md, record) {
978 var schema = PVE.Utils.sdnipamSchema[value];
979 if (schema) {
980 return schema.name;
981 }
982 return Proxmox.Utils.unknownText;
983 },
984
985 format_sdndns_type: function(value, md, record) {
986 var schema = PVE.Utils.sdndnsSchema[value];
987 if (schema) {
988 return schema.name;
989 }
990 return Proxmox.Utils.unknownText;
991 },
992
993 format_storage_type: function(value, md, record) {
994 if (value === 'rbd') {
995 value = !record || record.get('monhost') ? 'rbd' : 'pveceph';
996 } else if (value === 'cephfs') {
997 value = !record || record.get('monhost') ? 'cephfs' : 'pvecephfs';
998 }
999
1000 var schema = PVE.Utils.storageSchema[value];
1001 if (schema) {
1002 return schema.name;
1003 }
1004 return Proxmox.Utils.unknownText;
1005 },
1006
1007 format_ha: function(value) {
1008 var text = Proxmox.Utils.noneText;
1009
1010 if (value.managed) {
1011 text = value.state || Proxmox.Utils.noneText;
1012
1013 text += ', ' + Proxmox.Utils.groupText + ': ';
1014 text += value.group || Proxmox.Utils.noneText;
1015 }
1016
1017 return text;
1018 },
1019
1020 format_content_types: function(value) {
1021 return value.split(',').sort().map(function(ct) {
1022 return PVE.Utils.contentTypes[ct] || ct;
1023 }).join(', ');
1024 },
1025
1026 render_storage_content: function(value, metaData, record) {
1027 var data = record.data;
1028 if (Ext.isNumber(data.channel) &&
1029 Ext.isNumber(data.id) &&
1030 Ext.isNumber(data.lun)) {
1031 return "CH " +
1032 Ext.String.leftPad(data.channel, 2, '0') +
1033 " ID " + data.id + " LUN " + data.lun;
1034 }
1035 return data.volid.replace(/^.*?:(.*?\/)?/, '');
1036 },
1037
1038 render_serverity: function(value) {
1039 return PVE.Utils.log_severity_hash[value] || value;
1040 },
1041
1042 calculate_hostcpu: function(data) {
1043 if (!(data.uptime && Ext.isNumeric(data.cpu))) {
1044 return -1;
1045 }
1046
1047 if (data.type !== 'qemu' && data.type !== 'lxc') {
1048 return -1;
1049 }
1050
1051 var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node);
1052 var node = PVE.data.ResourceStore.getAt(index);
1053 if (!Ext.isDefined(node) || node === null) {
1054 return -1;
1055 }
1056 var maxcpu = node.data.maxcpu || 1;
1057
1058 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
1059 return -1;
1060 }
1061
1062 return (data.cpu/maxcpu) * data.maxcpu;
1063 },
1064
1065 render_hostcpu: function(value, metaData, record, rowIndex, colIndex, store) {
1066 if (!(record.data.uptime && Ext.isNumeric(record.data.cpu))) {
1067 return '';
1068 }
1069
1070 if (record.data.type !== 'qemu' && record.data.type !== 'lxc') {
1071 return '';
1072 }
1073
1074 var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node);
1075 var node = PVE.data.ResourceStore.getAt(index);
1076 if (!Ext.isDefined(node) || node === null) {
1077 return '';
1078 }
1079 var maxcpu = node.data.maxcpu || 1;
1080
1081 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
1082 return '';
1083 }
1084
1085 var per = (record.data.cpu/maxcpu) * record.data.maxcpu * 100;
1086
1087 return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
1088 },
1089
1090 render_bandwidth: function(value) {
1091 if (!Ext.isNumeric(value)) {
1092 return '';
1093 }
1094
1095 return Proxmox.Utils.format_size(value) + '/s';
1096 },
1097
1098 render_timestamp_human_readable: function(value) {
1099 return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s');
1100 },
1101
1102 // render a timestamp or pending
1103 render_next_event: function(value) {
1104 if (!value) {
1105 return '-';
1106 }
1107 let now = new Date(), next = new Date(value * 1000);
1108 if (next < now) {
1109 return gettext('pending');
1110 }
1111 return Proxmox.Utils.render_timestamp(value);
1112 },
1113
1114 calculate_mem_usage: function(data) {
1115 if (!Ext.isNumeric(data.mem) ||
1116 data.maxmem === 0 ||
1117 data.uptime < 1) {
1118 return -1;
1119 }
1120
1121 return data.mem / data.maxmem;
1122 },
1123
1124 calculate_hostmem_usage: function(data) {
1125 if (data.type !== 'qemu' && data.type !== 'lxc') {
1126 return -1;
1127 }
1128
1129 var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node);
1130 var node = PVE.data.ResourceStore.getAt(index);
1131
1132 if (!Ext.isDefined(node) || node === null) {
1133 return -1;
1134 }
1135 var maxmem = node.data.maxmem || 0;
1136
1137 if (!Ext.isNumeric(data.mem) ||
1138 maxmem === 0 ||
1139 data.uptime < 1) {
1140 return -1;
1141 }
1142
1143 return data.mem / maxmem;
1144 },
1145
1146 render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
1147 if (!Ext.isNumeric(value) || value === -1) {
1148 return '';
1149 }
1150 if (value > 1) {
1151 // we got no percentage but bytes
1152 var mem = value;
1153 var maxmem = record.data.maxmem;
1154 if (!record.data.uptime ||
1155 maxmem === 0 ||
1156 !Ext.isNumeric(mem)) {
1157 return '';
1158 }
1159
1160 return (mem*100/maxmem).toFixed(1) + " %";
1161 }
1162 return (value*100).toFixed(1) + " %";
1163 },
1164
1165 render_hostmem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
1166 if (!Ext.isNumeric(record.data.mem) || value === -1) {
1167 return '';
1168 }
1169
1170 if (record.data.type !== 'qemu' && record.data.type !== 'lxc') {
1171 return '';
1172 }
1173
1174 var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node);
1175 var node = PVE.data.ResourceStore.getAt(index);
1176 var maxmem = node.data.maxmem || 0;
1177
1178 if (record.data.mem > 1) {
1179 // we got no percentage but bytes
1180 var mem = record.data.mem;
1181 if (!record.data.uptime ||
1182 maxmem === 0 ||
1183 !Ext.isNumeric(mem)) {
1184 return '';
1185 }
1186
1187 return ((mem*100)/maxmem).toFixed(1) + " %";
1188 }
1189 return (value*100).toFixed(1) + " %";
1190 },
1191
1192 render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
1193 var mem = value;
1194 var maxmem = record.data.maxmem;
1195
1196 if (!record.data.uptime) {
1197 return '';
1198 }
1199
1200 if (!(Ext.isNumeric(mem) && maxmem)) {
1201 return '';
1202 }
1203
1204 return Proxmox.Utils.render_size(value);
1205 },
1206
1207 calculate_disk_usage: function(data) {
1208 if (!Ext.isNumeric(data.disk) ||
1209 ((data.type === 'qemu' || data.type === 'lxc') && data.uptime === 0) ||
1210 data.maxdisk === 0
1211 ) {
1212 return -1;
1213 }
1214
1215 return data.disk / data.maxdisk;
1216 },
1217
1218 render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
1219 if (!Ext.isNumeric(value) || value === -1) {
1220 return '';
1221 }
1222
1223 return (value * 100).toFixed(1) + " %";
1224 },
1225
1226 render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
1227 var disk = value;
1228 var maxdisk = record.data.maxdisk;
1229 var type = record.data.type;
1230
1231 if (!Ext.isNumeric(disk) ||
1232 maxdisk === 0 ||
1233 ((type === 'qemu' || type === 'lxc') && record.data.uptime === 0)
1234 ) {
1235 return '';
1236 }
1237
1238 return Proxmox.Utils.render_size(value);
1239 },
1240
1241 get_object_icon_class: function(type, record) {
1242 var status = '';
1243 var objType = type;
1244
1245 if (type === 'type') {
1246 // for folder view
1247 objType = record.groupbyid;
1248 } else if (record.template) {
1249 // templates
1250 objType = 'template';
1251 status = type;
1252 } else {
1253 // everything else
1254 status = record.status + ' ha-' + record.hastate;
1255 }
1256
1257 if (record.lock) {
1258 status += ' locked lock-' + record.lock;
1259 }
1260
1261 var defaults = PVE.tree.ResourceTree.typeDefaults[objType];
1262 if (defaults && defaults.iconCls) {
1263 var retVal = defaults.iconCls + ' ' + status;
1264 return retVal;
1265 }
1266
1267 return '';
1268 },
1269
1270 render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
1271 var cls = PVE.Utils.get_object_icon_class(value, record.data);
1272
1273 var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> ';
1274 return fa + value;
1275 },
1276
1277 render_support_level: function(value, metaData, record) {
1278 return PVE.Utils.support_level_hash[value] || '-';
1279 },
1280
1281 render_upid: function(value, metaData, record) {
1282 var type = record.data.type;
1283 var id = record.data.id;
1284
1285 return Proxmox.Utils.format_task_description(type, id);
1286 },
1287
1288 render_optional_url: function(value) {
1289 if (value && value.match(/^https?:\/\//)) {
1290 return '<a target="_blank" href="' + value + '">' + value + '</a>';
1291 }
1292 return value;
1293 },
1294
1295 render_san: function(value) {
1296 var names = [];
1297 if (Ext.isArray(value)) {
1298 value.forEach(function(val) {
1299 if (!Ext.isNumber(val)) {
1300 names.push(val);
1301 }
1302 });
1303 return names.join('<br>');
1304 }
1305 return value;
1306 },
1307
1308 render_full_name: function(firstname, metaData, record) {
1309 var first = firstname || '';
1310 var last = record.data.lastname || '';
1311 return Ext.htmlEncode(first + " " + last);
1312 },
1313
1314 windowHostname: function() {
1315 return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
1316 function(m, addr, offset, original) { return addr; });
1317 },
1318
1319 openDefaultConsoleWindow: function(consoles, consoleType, vmid, nodename, vmname, cmd) {
1320 var dv = PVE.Utils.defaultViewer(consoles, consoleType);
1321 PVE.Utils.openConsoleWindow(dv, consoleType, vmid, nodename, vmname, cmd);
1322 },
1323
1324 openConsoleWindow: function(viewer, consoleType, vmid, nodename, vmname, cmd) {
1325 if (vmid === undefined && (consoleType === 'kvm' || consoleType === 'lxc')) {
1326 throw "missing vmid";
1327 }
1328 if (!nodename) {
1329 throw "no nodename specified";
1330 }
1331
1332 if (viewer === 'html5') {
1333 PVE.Utils.openVNCViewer(consoleType, vmid, nodename, vmname, cmd);
1334 } else if (viewer === 'xtermjs') {
1335 Proxmox.Utils.openXtermJsViewer(consoleType, vmid, nodename, vmname, cmd);
1336 } else if (viewer === 'vv') {
1337 let url = '/nodes/' + nodename + '/spiceshell';
1338 let params = {
1339 proxy: PVE.Utils.windowHostname(),
1340 };
1341 if (consoleType === 'kvm') {
1342 url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
1343 } else if (consoleType === 'lxc') {
1344 url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy';
1345 } else if (consoleType === 'upgrade') {
1346 params.cmd = 'upgrade';
1347 } else if (consoleType === 'cmd') {
1348 params.cmd = cmd;
1349 } else if (consoleType !== 'shell') {
1350 throw `unknown spice viewer type '${consoleType}'`;
1351 }
1352 PVE.Utils.openSpiceViewer(url, params);
1353 } else {
1354 throw `unknown viewer type '${viewer}'`;
1355 }
1356 },
1357
1358 defaultViewer: function(consoles, type) {
1359 var allowSpice, allowXtermjs;
1360
1361 if (consoles === true) {
1362 allowSpice = true;
1363 allowXtermjs = true;
1364 } else if (typeof consoles === 'object') {
1365 allowSpice = consoles.spice;
1366 allowXtermjs = !!consoles.xtermjs;
1367 }
1368 let dv = PVE.VersionInfo.console || (type === 'kvm' ? 'vv' : 'xtermjs');
1369 if (dv === 'vv' && !allowSpice) {
1370 dv = allowXtermjs ? 'xtermjs' : 'html5';
1371 } else if (dv === 'xtermjs' && !allowXtermjs) {
1372 dv = allowSpice ? 'vv' : 'html5';
1373 }
1374
1375 return dv;
1376 },
1377
1378 openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) {
1379 let scaling = 'off';
1380 if (Proxmox.Utils.toolkit !== 'touch') {
1381 var sp = Ext.state.Manager.getProvider();
1382 scaling = sp.get('novnc-scaling', 'off');
1383 }
1384 var url = Ext.Object.toQueryString({
1385 console: vmtype, // kvm, lxc, upgrade or shell
1386 novnc: 1,
1387 vmid: vmid,
1388 vmname: vmname,
1389 node: nodename,
1390 resize: scaling,
1391 cmd: cmd,
1392 });
1393 var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
1394 if (nw) {
1395 nw.focus();
1396 }
1397 },
1398
1399 openSpiceViewer: function(url, params) {
1400 var downloadWithName = function(uri, name) {
1401 var link = Ext.DomHelper.append(document.body, {
1402 tag: 'a',
1403 href: uri,
1404 css: 'display:none;visibility:hidden;height:0px;',
1405 });
1406
1407 // Note: we need to tell Android and Chrome the correct file name extension
1408 // but we do not set 'download' tag for other environments, because
1409 // It can have strange side effects (additional user prompt on firefox)
1410 if (navigator.userAgent.match(/Android|Chrome/i)) {
1411 link.download = name;
1412 }
1413
1414 if (link.fireEvent) {
1415 link.fireEvent('onclick');
1416 } else {
1417 let evt = document.createEvent("MouseEvents");
1418 evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
1419 link.dispatchEvent(evt);
1420 }
1421 };
1422
1423 Proxmox.Utils.API2Request({
1424 url: url,
1425 params: params,
1426 method: 'POST',
1427 failure: function(response, opts) {
1428 Ext.Msg.alert('Error', response.htmlStatus);
1429 },
1430 success: function(response, opts) {
1431 let cfg = response.result.data;
1432 let raw = Object.entries(cfg).reduce((acc, [k, v]) => acc + `${k}=${v}\n`, "[virt-viewer]\n");
1433 let spiceDownload = 'data:application/x-virt-viewer;charset=UTF-8,' + encodeURIComponent(raw);
1434 downloadWithName(spiceDownload, "pve-spice.vv");
1435 },
1436 });
1437 },
1438
1439 openTreeConsole: function(tree, record, item, index, e) {
1440 e.stopEvent();
1441 let nodename = record.data.node;
1442 let vmid = record.data.vmid;
1443 let vmname = record.data.name;
1444 if (record.data.type === 'qemu' && !record.data.template) {
1445 Proxmox.Utils.API2Request({
1446 url: `/nodes/${nodename}/qemu/${vmid}/status/current`,
1447 failure: response => Ext.Msg.alert('Error', response.htmlStatus),
1448 success: function(response, opts) {
1449 let conf = response.result.data;
1450 let consoles = {
1451 spice: !!conf.spice,
1452 xtermjs: !!conf.serial,
1453 };
1454 PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
1455 },
1456 });
1457 } else if (record.data.type === 'lxc' && !record.data.template) {
1458 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
1459 }
1460 },
1461
1462 // test automation helper
1463 call_menu_handler: function(menu, text) {
1464 let item = menu.query('menuitem').find(el => el.text === text);
1465 if (item && item.handler) {
1466 item.handler();
1467 }
1468 },
1469
1470 createCmdMenu: function(v, record, item, index, event) {
1471 event.stopEvent();
1472 if (!(v instanceof Ext.tree.View)) {
1473 v.select(record);
1474 }
1475 let menu;
1476 let type = record.data.type;
1477
1478 if (record.data.template) {
1479 if (type === 'qemu' || type === 'lxc') {
1480 menu = Ext.create('PVE.menu.TemplateMenu', {
1481 pveSelNode: record,
1482 });
1483 }
1484 } else if (type === 'qemu' || type === 'lxc' || type === 'node') {
1485 menu = Ext.create('PVE.' + type + '.CmdMenu', {
1486 pveSelNode: record,
1487 nodename: record.data.node,
1488 });
1489 } else {
1490 return undefined;
1491 }
1492
1493 menu.showAt(event.getXY());
1494 return menu;
1495 },
1496
1497 // helper for deleting field which are set to there default values
1498 delete_if_default: function(values, fieldname, default_val, create) {
1499 if (values[fieldname] === '' || values[fieldname] === default_val) {
1500 if (!create) {
1501 if (values.delete) {
1502 if (Ext.isArray(values.delete)) {
1503 values.delete.push(fieldname);
1504 } else {
1505 values.delete += ',' + fieldname;
1506 }
1507 } else {
1508 values.delete = fieldname;
1509 }
1510 }
1511
1512 delete values[fieldname];
1513 }
1514 },
1515
1516 loadSSHKeyFromFile: function(file, callback) {
1517 // ssh-keygen produces ~ 740 bytes for a 4096 bit RSA key, current max is 16 kbit, so assume:
1518 // 740 * 8 for max. 32kbit (5920 bytes), round upwards to 8192 bytes, leaves lots of comment space
1519 PVE.Utils.loadFile(file, callback, 8192);
1520 },
1521
1522 loadFile: function(file, callback, maxSize) {
1523 maxSize = maxSize || 32 * 1024;
1524 if (file.size > maxSize) {
1525 Ext.Msg.alert(gettext('Error'), `${gettext("Invalid file size")}: ${file.size} > ${maxSize}`);
1526 return;
1527 }
1528 let reader = new FileReader();
1529 reader.onload = evt => callback(evt.target.result);
1530 reader.readAsText(file);
1531 },
1532
1533 loadTextFromFile: function(file, callback, maxBytes) {
1534 let maxSize = maxBytes || 8192;
1535 if (file.size > maxSize) {
1536 Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
1537 return;
1538 }
1539 let reader = new FileReader();
1540 reader.onload = evt => callback(evt.target.result);
1541 reader.readAsText(file);
1542 },
1543
1544 diskControllerMaxIDs: {
1545 ide: 4,
1546 sata: 6,
1547 scsi: 31,
1548 virtio: 16,
1549 unused: 256,
1550 },
1551
1552 // types is either undefined (all busses), an array of busses, or a single bus
1553 forEachBus: function(types, func) {
1554 let busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
1555
1556 if (Ext.isArray(types)) {
1557 busses = types;
1558 } else if (Ext.isDefined(types)) {
1559 busses = [types];
1560 }
1561
1562 // check if we only have valid busses
1563 for (let i = 0; i < busses.length; i++) {
1564 if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) {
1565 throw "invalid bus: '" + busses[i] + "'";
1566 }
1567 }
1568
1569 for (let i = 0; i < busses.length; i++) {
1570 let count = PVE.Utils.diskControllerMaxIDs[busses[i]];
1571 for (let j = 0; j < count; j++) {
1572 let cont = func(busses[i], j);
1573 if (!cont && cont !== undefined) {
1574 return;
1575 }
1576 }
1577 }
1578 },
1579
1580 mp_counts: {
1581 mps: 256,
1582 unused: 256,
1583 },
1584
1585 forEachMP: function(func, includeUnused) {
1586 for (let i = 0; i < PVE.Utils.mp_counts.mps; i++) {
1587 let cont = func('mp', i);
1588 if (!cont && cont !== undefined) {
1589 return;
1590 }
1591 }
1592
1593 if (!includeUnused) {
1594 return;
1595 }
1596
1597 for (let i = 0; i < PVE.Utils.mp_counts.unused; i++) {
1598 let cont = func('unused', i);
1599 if (!cont && cont !== undefined) {
1600 return;
1601 }
1602 }
1603 },
1604
1605 hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1, tpmstate: 1 },
1606
1607 cleanEmptyObjectKeys: function(obj) {
1608 for (const propName of Object.keys(obj)) {
1609 if (obj[propName] === null || obj[propName] === undefined) {
1610 delete obj[propName];
1611 }
1612 }
1613 },
1614
1615 acmedomain_count: 5,
1616
1617 add_domain_to_acme: function(acme, domain) {
1618 if (acme.domains === undefined) {
1619 acme.domains = [domain];
1620 } else {
1621 acme.domains.push(domain);
1622 acme.domains = acme.domains.filter((value, index, self) => self.indexOf(value) === index);
1623 }
1624 return acme;
1625 },
1626
1627 remove_domain_from_acme: function(acme, domain) {
1628 if (acme.domains !== undefined) {
1629 acme.domains = acme
1630 .domains
1631 .filter((value, index, self) => self.indexOf(value) === index && value !== domain);
1632 }
1633 return acme;
1634 },
1635
1636 handleStoreErrorOrMask: function(view, store, regex, callback) {
1637 view.mon(store, 'load', function(proxy, response, success, operation) {
1638 if (success) {
1639 Proxmox.Utils.setErrorMask(view, false);
1640 return;
1641 }
1642 let msg;
1643 if (operation.error.statusText) {
1644 if (operation.error.statusText.match(regex)) {
1645 callback(view, operation.error);
1646 return;
1647 } else {
1648 msg = operation.error.statusText + ' (' + operation.error.status + ')';
1649 }
1650 } else {
1651 msg = gettext('Connection error');
1652 }
1653 Proxmox.Utils.setErrorMask(view, msg);
1654 });
1655 },
1656
1657 showCephInstallOrMask: function(container, msg, nodename, callback) {
1658 if (msg.match(/not (installed|initialized)/i)) {
1659 if (Proxmox.UserName === 'root@pam') {
1660 container.el.mask();
1661 if (!container.down('pveCephInstallWindow')) {
1662 var isInstalled = !!msg.match(/not initialized/i);
1663 var win = Ext.create('PVE.ceph.Install', {
1664 nodename: nodename,
1665 });
1666 win.getViewModel().set('isInstalled', isInstalled);
1667 container.add(win);
1668 win.show();
1669 callback(win);
1670 }
1671 } else {
1672 container.mask(Ext.String.format(gettext('{0} not installed.') +
1673 ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']);
1674 }
1675 return true;
1676 } else {
1677 return false;
1678 }
1679 },
1680
1681 monitor_ceph_installed: function(view, rstore, nodename, maskOwnerCt) {
1682 PVE.Utils.handleStoreErrorOrMask(
1683 view,
1684 rstore,
1685 /not (installed|initialized)/i,
1686 (_, error) => {
1687 nodename = nodename || 'localhost';
1688 let maskTarget = maskOwnerCt ? view.ownerCt : view;
1689 rstore.stopUpdate();
1690 PVE.Utils.showCephInstallOrMask(maskTarget, error.statusText, nodename, win => {
1691 view.mon(win, 'cephInstallWindowClosed', () => rstore.startUpdate());
1692 });
1693 },
1694 );
1695 },
1696
1697
1698 propertyStringSet: function(target, source, name, value) {
1699 if (source) {
1700 if (value === undefined) {
1701 target[name] = source;
1702 } else {
1703 target[name] = value;
1704 }
1705 } else {
1706 delete target[name];
1707 }
1708 },
1709
1710 forEachCorosyncLink: function(nodeinfo, cb) {
1711 let re = /(?:ring|link)(\d+)_addr/;
1712 Ext.iterate(nodeinfo, (prop, val) => {
1713 let match = re.exec(prop);
1714 if (match) {
1715 cb(Number(match[1]), val);
1716 }
1717 });
1718 },
1719
1720 cpu_vendor_map: {
1721 'default': 'QEMU',
1722 'AuthenticAMD': 'AMD',
1723 'GenuineIntel': 'Intel',
1724 },
1725
1726 cpu_vendor_order: {
1727 "AMD": 1,
1728 "Intel": 2,
1729 "QEMU": 3,
1730 "Host": 4,
1731 "_default_": 5, // includes custom models
1732 },
1733
1734 verify_ip64_address_list: function(value, with_suffix) {
1735 for (let addr of value.split(/[ ,;]+/)) {
1736 if (addr === '') {
1737 continue;
1738 }
1739
1740 if (with_suffix) {
1741 let parts = addr.split('%');
1742 addr = parts[0];
1743
1744 if (parts.length > 2) {
1745 return false;
1746 }
1747
1748 if (parts.length > 1 && !addr.startsWith('fe80:')) {
1749 return false;
1750 }
1751 }
1752
1753 if (!Proxmox.Utils.IP64_match.test(addr)) {
1754 return false;
1755 }
1756 }
1757
1758 return true;
1759 },
1760
1761 sortByPreviousUsage: function(vmconfig, controllerList) {
1762 if (!controllerList) {
1763 controllerList = ['ide', 'virtio', 'scsi', 'sata'];
1764 }
1765 let usedControllers = {};
1766 for (const type of Object.keys(PVE.Utils.diskControllerMaxIDs)) {
1767 usedControllers[type] = 0;
1768 }
1769
1770 for (const property of Object.keys(vmconfig)) {
1771 if (property.match(PVE.Utils.bus_match) && !vmconfig[property].match(/media=cdrom/)) {
1772 const foundController = property.match(PVE.Utils.bus_match)[1];
1773 usedControllers[foundController]++;
1774 }
1775 }
1776
1777 let sortPriority = PVE.qemu.OSDefaults.getDefaults(vmconfig.ostype).busPriority;
1778
1779 let sortedList = Ext.clone(controllerList);
1780 sortedList.sort(function(a, b) {
1781 if (usedControllers[b] === usedControllers[a]) {
1782 return sortPriority[b] - sortPriority[a];
1783 }
1784 return usedControllers[b] - usedControllers[a];
1785 });
1786
1787 return sortedList;
1788 },
1789
1790 nextFreeDisk: function(controllers, config) {
1791 for (const controller of controllers) {
1792 for (let i = 0; i < PVE.Utils.diskControllerMaxIDs[controller]; i++) {
1793 let confid = controller + i.toString();
1794 if (!Ext.isDefined(config[confid])) {
1795 return {
1796 controller,
1797 id: i,
1798 confid,
1799 };
1800 }
1801 }
1802 }
1803
1804 return undefined;
1805 },
1806 },
1807
1808 singleton: true,
1809 constructor: function() {
1810 var me = this;
1811 Ext.apply(me, me.utilities);
1812
1813 Proxmox.Utils.override_task_descriptions({
1814 acmedeactivate: ['ACME Account', gettext('Deactivate')],
1815 acmenewcert: ['SRV', gettext('Order Certificate')],
1816 acmerefresh: ['ACME Account', gettext('Refresh')],
1817 acmeregister: ['ACME Account', gettext('Register')],
1818 acmerenew: ['SRV', gettext('Renew Certificate')],
1819 acmerevoke: ['SRV', gettext('Revoke Certificate')],
1820 acmeupdate: ['ACME Account', gettext('Update')],
1821 'auth-realm-sync': [gettext('Realm'), gettext('Sync')],
1822 'auth-realm-sync-test': [gettext('Realm'), gettext('Sync Preview')],
1823 cephcreatemds: ['Ceph Metadata Server', gettext('Create')],
1824 cephcreatemgr: ['Ceph Manager', gettext('Create')],
1825 cephcreatemon: ['Ceph Monitor', gettext('Create')],
1826 cephcreateosd: ['Ceph OSD', gettext('Create')],
1827 cephcreatepool: ['Ceph Pool', gettext('Create')],
1828 cephdestroymds: ['Ceph Metadata Server', gettext('Destroy')],
1829 cephdestroymgr: ['Ceph Manager', gettext('Destroy')],
1830 cephdestroymon: ['Ceph Monitor', gettext('Destroy')],
1831 cephdestroyosd: ['Ceph OSD', gettext('Destroy')],
1832 cephdestroypool: ['Ceph Pool', gettext('Destroy')],
1833 cephdestroyfs: ['CephFS', gettext('Destroy')],
1834 cephfscreate: ['CephFS', gettext('Create')],
1835 cephsetpool: ['Ceph Pool', gettext('Edit')],
1836 cephsetflags: ['', gettext('Change global Ceph flags')],
1837 clustercreate: ['', gettext('Create Cluster')],
1838 clusterjoin: ['', gettext('Join Cluster')],
1839 dircreate: [gettext('Directory Storage'), gettext('Create')],
1840 dirremove: [gettext('Directory'), gettext('Remove')],
1841 download: [gettext('File'), gettext('Download')],
1842 hamigrate: ['HA', gettext('Migrate')],
1843 hashutdown: ['HA', gettext('Shutdown')],
1844 hastart: ['HA', gettext('Start')],
1845 hastop: ['HA', gettext('Stop')],
1846 imgcopy: ['', gettext('Copy data')],
1847 imgdel: ['', gettext('Erase data')],
1848 lvmcreate: [gettext('LVM Storage'), gettext('Create')],
1849 lvmremove: ['Volume Group', gettext('Remove')],
1850 lvmthincreate: [gettext('LVM-Thin Storage'), gettext('Create')],
1851 lvmthinremove: ['Thinpool', gettext('Remove')],
1852 migrateall: ['', gettext('Migrate all VMs and Containers')],
1853 'move_volume': ['CT', gettext('Move Volume')],
1854 'pbs-download': ['VM/CT', gettext('File Restore Download')],
1855 pull_file: ['CT', gettext('Pull file')],
1856 push_file: ['CT', gettext('Push file')],
1857 qmclone: ['VM', gettext('Clone')],
1858 qmconfig: ['VM', gettext('Configure')],
1859 qmcreate: ['VM', gettext('Create')],
1860 qmdelsnapshot: ['VM', gettext('Delete Snapshot')],
1861 qmdestroy: ['VM', gettext('Destroy')],
1862 qmigrate: ['VM', gettext('Migrate')],
1863 qmmove: ['VM', gettext('Move disk')],
1864 qmpause: ['VM', gettext('Pause')],
1865 qmreboot: ['VM', gettext('Reboot')],
1866 qmreset: ['VM', gettext('Reset')],
1867 qmrestore: ['VM', gettext('Restore')],
1868 qmresume: ['VM', gettext('Resume')],
1869 qmrollback: ['VM', gettext('Rollback')],
1870 qmshutdown: ['VM', gettext('Shutdown')],
1871 qmsnapshot: ['VM', gettext('Snapshot')],
1872 qmstart: ['VM', gettext('Start')],
1873 qmstop: ['VM', gettext('Stop')],
1874 qmsuspend: ['VM', gettext('Hibernate')],
1875 qmtemplate: ['VM', gettext('Convert to template')],
1876 spiceproxy: ['VM/CT', gettext('Console') + ' (Spice)'],
1877 spiceshell: ['', gettext('Shell') + ' (Spice)'],
1878 startall: ['', gettext('Start all VMs and Containers')],
1879 stopall: ['', gettext('Stop all VMs and Containers')],
1880 unknownimgdel: ['', gettext('Destroy image from unknown guest')],
1881 wipedisk: ['Device', gettext('Wipe Disk')],
1882 vncproxy: ['VM/CT', gettext('Console')],
1883 vncshell: ['', gettext('Shell')],
1884 vzclone: ['CT', gettext('Clone')],
1885 vzcreate: ['CT', gettext('Create')],
1886 vzdelsnapshot: ['CT', gettext('Delete Snapshot')],
1887 vzdestroy: ['CT', gettext('Destroy')],
1888 vzdump: (type, id) => id ? `VM/CT ${id} - ${gettext('Backup')}` : gettext('Backup Job'),
1889 vzmigrate: ['CT', gettext('Migrate')],
1890 vzmount: ['CT', gettext('Mount')],
1891 vzreboot: ['CT', gettext('Reboot')],
1892 vzrestore: ['CT', gettext('Restore')],
1893 vzresume: ['CT', gettext('Resume')],
1894 vzrollback: ['CT', gettext('Rollback')],
1895 vzshutdown: ['CT', gettext('Shutdown')],
1896 vzsnapshot: ['CT', gettext('Snapshot')],
1897 vzstart: ['CT', gettext('Start')],
1898 vzstop: ['CT', gettext('Stop')],
1899 vzsuspend: ['CT', gettext('Suspend')],
1900 vztemplate: ['CT', gettext('Convert to template')],
1901 vzumount: ['CT', gettext('Unmount')],
1902 zfscreate: [gettext('ZFS Storage'), gettext('Create')],
1903 zfsremove: ['ZFS Pool', gettext('Remove')],
1904 });
1905 },
1906
1907 });