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