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