]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/Utils.js
ui: dc/Auth*: refactor AuthEdit
[pve-manager.git] / www / manager6 / Utils.js
CommitLineData
b0a6d326
EK
1Ext.ns('PVE');
2
63b9faae
EK
3// avoid errors related to Accessible Rich Internet Applications
4// (access for people with disabilities)
0be88ae1 5// TODO reenable after all components are upgraded
63b9faae
EK
6Ext.enableAria = false;
7Ext.enableAriaButtons = false;
8Ext.enableAriaPanels = false;
9
b0a6d326 10// avoid errors when running without development tools
0be88ae1
DC
11if (!Ext.isDefined(Ext.global.console)) {
12 var console = {
0be88ae1 13 log: function() {}
b0a6d326
EK
14 };
15}
0be88ae1 16console.log("Starting PVE Manager");
b0a6d326
EK
17
18Ext.Ajax.defaultHeaders = {
19 'Accept': 'application/json'
20};
21
89ae1bb1 22/*jslint confusion: true */
9fa2e36d 23Ext.define('PVE.Utils', { utilities: {
b0a6d326 24
9fa2e36d 25 // this singleton contains miscellaneous utilities
b0a6d326 26
0be88ae1 27 toolkit: undefined, // (extjs|touch), set inside Toolkit.js
b0a6d326 28
98a01af2
EK
29 bus_match: /^(ide|sata|virtio|scsi)\d+$/,
30
b0a6d326
EK
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
8ec8af9c 49 noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.',
b0a6d326
EK
50
51 kvm_ostypes: {
45d6c71a 52 'Linux': [
ca71cd5d 53 { desc: '5.x - 2.6 Kernel', val: 'l26' },
45d6c71a
TL
54 { desc: '2.4 Kernel', val: 'l24' }
55 ],
56 'Microsoft Windows': [
beb3c8a4 57 { desc: '10/2016/2019', val: 'win10' },
45d6c71a
TL
58 { desc: '8.x/2012/2012r2', val: 'win8' },
59 { desc: '7/2008r2', val: 'win7' },
60 { desc: 'Vista/2008', val: 'w2k8' },
61 { desc: 'XP/2003', val: 'wxp' },
62 { desc: '2000', val: 'w2k' }
63 ],
64 'Solaris Kernel': [
65 { desc: '-', val: 'solaris'}
66 ],
67 'Other': [
68 { desc: '-', val: 'other'}
69 ]
b0a6d326
EK
70 },
71
428bc4a2
DC
72 get_health_icon: function(state, circle) {
73 if (circle === undefined) {
74 circle = false;
75 }
76
77 if (state === undefined) {
78 state = 'uknown';
79 }
80
81 var icon = 'faded fa-question';
82 switch(state) {
83 case 'good':
84 icon = 'good fa-check';
85 break;
23c83a3a
DC
86 case 'upgrade':
87 icon = 'warning fa-upload';
88 break;
aa240b29
DC
89 case 'old':
90 icon = 'warning fa-refresh';
91 break;
428bc4a2
DC
92 case 'warning':
93 icon = 'warning fa-exclamation';
94 break;
95 case 'critical':
96 icon = 'critical fa-times';
97 break;
98 default: break;
99 }
100
101 if (circle) {
102 icon += '-circle';
103 }
104
105 return icon;
106 },
107
95d0de89
DC
108 parse_ceph_version: function(service) {
109 if (service.ceph_version_short) {
110 return service.ceph_version_short;
111 }
112
113 if (service.ceph_version) {
35306f47 114 var match = service.ceph_version.match(/version (\d+(\.\d+)*)/);
95d0de89
DC
115 if (match) {
116 return match[1];
117 }
118 }
119
120 return undefined;
121 },
122
005e0a60 123 compare_ceph_versions: function(a, b) {
3a08795a
DC
124 let avers = [];
125 let bvers = [];
126
005e0a60
DC
127 if (a === b) {
128 return 0;
129 }
3a08795a
DC
130
131 if (Ext.isArray(a)) {
132 avers = a.slice(); // copy array
133 } else {
134 avers = a.toString().split('.');
135 }
136
137 if (Ext.isArray(b)) {
138 bvers = b.slice(); // copy array
139 } else {
140 bvers = b.toString().split('.');
141 }
35306f47
TL
142
143 while (true) {
144 let av = avers.shift();
145 let bv = bvers.shift();
146
147 if (av === undefined && bv === undefined) {
148 return 0;
149 } else if (av === undefined) {
150 return -1;
151 } else if (bv === undefined) {
152 return 1;
153 } else {
154 let diff = parseInt(av, 10) - parseInt(bv, 10);
155 if (diff != 0) return diff;
156 // else we need to look at the next parts
005e0a60
DC
157 }
158 }
159
005e0a60
DC
160 },
161
2f5b82ae
DC
162 get_ceph_icon_html: function(health, fw) {
163 var state = PVE.Utils.map_ceph_health[health];
164 var cls = PVE.Utils.get_health_icon(state);
165 if (fw) {
166 cls += ' fa-fw';
167 }
168 return "<i class='fa " + cls + "'></i> ";
169 },
170
046e640c
DC
171 map_ceph_health: {
172 'HEALTH_OK':'good',
23c83a3a 173 'HEALTH_UPGRADE':'upgrade',
aa240b29 174 'HEALTH_OLD':'old',
046e640c
DC
175 'HEALTH_WARN':'warning',
176 'HEALTH_ERR':'critical'
177 },
178
dfe6d184 179 render_ceph_health: function(healthObj) {
046e640c
DC
180 var state = {
181 iconCls: PVE.Utils.get_health_icon(),
182 text: ''
183 };
184
dfe6d184 185 if (!healthObj || !healthObj.status) {
046e640c
DC
186 return state;
187 }
188
dfe6d184 189 var health = PVE.Utils.map_ceph_health[healthObj.status];
046e640c
DC
190
191 state.iconCls = PVE.Utils.get_health_icon(health, true);
dfe6d184 192 state.text = healthObj.status;
046e640c
DC
193
194 return state;
195 },
196
fee716d3 197 render_zfs_health: function(value) {
8c8604ba
TM
198 if (typeof value == 'undefined'){
199 return "";
200 }
fee716d3
DC
201 var iconCls = 'question-circle';
202 switch (value) {
8c8604ba 203 case 'AVAIL':
fee716d3
DC
204 case 'ONLINE':
205 iconCls = 'check-circle good';
206 break;
207 case 'REMOVED':
208 case 'DEGRADED':
209 iconCls = 'exclamation-circle warning';
210 break;
211 case 'UNAVAIL':
212 case 'FAULTED':
213 case 'OFFLINE':
214 iconCls = 'times-circle critical';
215 break;
216 default: //unknown
217 }
218
219 return '<i class="fa fa-' + iconCls + '"></i> ' + value;
8c8604ba 220
fee716d3
DC
221 },
222
45d6c71a
TL
223 get_kvm_osinfo: function(value) {
224 var info = { base: 'Other' }; // default
225 if (value) {
226 Ext.each(Object.keys(PVE.Utils.kvm_ostypes), function(k) {
227 Ext.each(PVE.Utils.kvm_ostypes[k], function(e) {
228 if (e.val === value) {
229 info = { desc: e.desc, base: k };
230 }
231 });
232 });
b0a6d326 233 }
45d6c71a
TL
234 return info;
235 },
236
237 render_kvm_ostype: function (value) {
238 var osinfo = PVE.Utils.get_kvm_osinfo(value);
239 if (osinfo.desc && osinfo.desc !== '-') {
240 return osinfo.base + ' ' + osinfo.desc;
241 } else {
242 return osinfo.base;
b0a6d326 243 }
b0a6d326
EK
244 },
245
246 render_hotplug_features: function (value) {
23d3881a 247 var fa = [];
b0a6d326
EK
248
249 if (!value || (value === '0')) {
ec99b1c3 250 return gettext('Disabled');
b0a6d326
EK
251 }
252
4dcca8a4
DC
253 if (value === '1') {
254 value = 'disk,network,usb';
255 }
256
b0a6d326
EK
257 Ext.each(value.split(','), function(el) {
258 if (el === 'disk') {
259 fa.push(gettext('Disk'));
260 } else if (el === 'network') {
261 fa.push(gettext('Network'));
262 } else if (el === 'usb') {
b9628aa5 263 fa.push('USB');
b0a6d326
EK
264 } else if (el === 'memory') {
265 fa.push(gettext('Memory'));
266 } else if (el === 'cpu') {
267 fa.push(gettext('CPU'));
268 } else {
269 fa.push(el);
270 }
271 });
272
273 return fa.join(', ');
274 },
275
1662ccdb
SI
276 render_qga_features: function(value) {
277 if (!value) {
278 return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText + ')';
279 }
280 var props = PVE.Parser.parsePropertyString(value, 'enabled');
281 if (!PVE.Parser.parseBoolean(props.enabled)) {
282 return Proxmox.Utils.disabledText;
283 }
284
285 delete props.enabled;
286 var agentstring = Proxmox.Utils.enabledText;
287
288 Ext.Object.each(props, function(key, value) {
289 var keystring = '' ;
290 agentstring += ', ' + key + ': ';
291
5a6c563c
MD
292 if (key === 'type') {
293 let map = {
294 isa: "ISA",
176a62d3 295 virtio: "VirtIO",
5a6c563c
MD
296 };
297 agentstring += map[value] || Proxmox.Utils.unknownText;
1662ccdb 298 } else {
5a6c563c
MD
299 if (PVE.Parser.parseBoolean(value)) {
300 agentstring += Proxmox.Utils.enabledText;
301 } else {
302 agentstring += Proxmox.Utils.disabledText;
303 }
1662ccdb
SI
304 }
305 });
306
307 return agentstring;
308 },
309
a1ee14a2
DC
310 render_qemu_machine: function(value) {
311 return value || (Proxmox.Utils.defaultText + ' (i440fx)');
312 },
313
17c71f27
DC
314 render_qemu_bios: function(value) {
315 if (!value) {
e7ade592 316 return Proxmox.Utils.defaultText + ' (SeaBIOS)';
17c71f27
DC
317 } else if (value === 'seabios') {
318 return "SeaBIOS";
319 } else if (value === 'ovmf') {
320 return "OVMF (UEFI)";
321 } else {
322 return value;
323 }
324 },
325
8f17b496
TL
326 render_dc_ha_opts: function(value) {
327 if (!value) {
41ca3465 328 return Proxmox.Utils.defaultText;
8f17b496
TL
329 } else {
330 return PVE.Parser.printPropertyString(value);
331 }
332 },
bb469a11
TL
333 render_as_property_string: function(value) {
334 return (!value) ? Proxmox.Utils.defaultText
335 : PVE.Parser.printPropertyString(value);
336 },
8f17b496 337
b0a6d326
EK
338 render_scsihw: function(value) {
339 if (!value) {
e7ade592 340 return Proxmox.Utils.defaultText + ' (LSI 53C895A)';
b0a6d326
EK
341 } else if (value === 'lsi') {
342 return 'LSI 53C895A';
343 } else if (value === 'lsi53c810') {
344 return 'LSI 53C810';
345 } else if (value === 'megasas') {
346 return 'MegaRAID SAS 8708EM2';
347 } else if (value === 'virtio-scsi-pci') {
49f5d1ab
EK
348 return 'VirtIO SCSI';
349 } else if (value === 'virtio-scsi-single') {
350 return 'VirtIO SCSI single';
b0a6d326
EK
351 } else if (value === 'pvscsi') {
352 return 'VMware PVSCSI';
353 } else {
354 return value;
355 }
356 },
357
9c22da32 358 render_spice_enhancements: function(values) {
9c22da32
AL
359 let props = PVE.Parser.parsePropertyString(values);
360 if (Ext.Object.isEmpty(props)) {
3b0facc9 361 return Proxmox.Utils.noneText;
9c22da32
AL
362 }
363
364 let output = [];
365 if (PVE.Parser.parseBoolean(props.foldersharing)) {
366 output.push('Folder Sharing: ' + gettext('Enabled'));
367 }
368 if (props.videostreaming === 'all' || props.videostreaming === 'filter') {
369 output.push('Video Streaming: ' + props.videostreaming);
370 }
371 return output.join(', ');
372 },
373
b0a6d326
EK
374 // fixme: auto-generate this
375 // for now, please keep in sync with PVE::Tools::kvmkeymaps
376 kvm_keymaps: {
377 //ar: 'Arabic',
378 da: 'Danish',
0be88ae1
DC
379 de: 'German',
380 'de-ch': 'German (Swiss)',
381 'en-gb': 'English (UK)',
0a5b8747 382 'en-us': 'English (USA)',
b0a6d326
EK
383 es: 'Spanish',
384 //et: 'Estonia',
385 fi: 'Finnish',
0be88ae1
DC
386 //fo: 'Faroe Islands',
387 fr: 'French',
388 'fr-be': 'French (Belgium)',
b0a6d326
EK
389 'fr-ca': 'French (Canada)',
390 'fr-ch': 'French (Swiss)',
391 //hr: 'Croatia',
392 hu: 'Hungarian',
393 is: 'Icelandic',
0be88ae1 394 it: 'Italian',
b0a6d326
EK
395 ja: 'Japanese',
396 lt: 'Lithuanian',
397 //lv: 'Latvian',
0be88ae1 398 mk: 'Macedonian',
b0a6d326
EK
399 nl: 'Dutch',
400 //'nl-be': 'Dutch (Belgium)',
0be88ae1 401 no: 'Norwegian',
b0a6d326
EK
402 pl: 'Polish',
403 pt: 'Portuguese',
404 'pt-br': 'Portuguese (Brazil)',
405 //ru: 'Russian',
406 sl: 'Slovenian',
407 sv: 'Swedish',
408 //th: 'Thai',
409 tr: 'Turkish'
410 },
411
412 kvm_vga_drivers: {
413 std: gettext('Standard VGA'),
5ca366f2 414 vmware: gettext('VMware compatible'),
b0a6d326
EK
415 qxl: 'SPICE',
416 qxl2: 'SPICE dual monitor',
417 qxl3: 'SPICE three monitors',
418 qxl4: 'SPICE four monitors',
419 serial0: gettext('Serial terminal') + ' 0',
420 serial1: gettext('Serial terminal') + ' 1',
421 serial2: gettext('Serial terminal') + ' 2',
89ae1bb1
DC
422 serial3: gettext('Serial terminal') + ' 3',
423 virtio: 'VirtIO-GPU',
424 none: Proxmox.Utils.noneText
b0a6d326
EK
425 },
426
427 render_kvm_language: function (value) {
e7ade592
DC
428 if (!value || value === '__default__') {
429 return Proxmox.Utils.defaultText;
b0a6d326
EK
430 }
431 var text = PVE.Utils.kvm_keymaps[value];
432 if (text) {
433 return text + ' (' + value + ')';
434 }
435 return value;
436 },
437
438 kvm_keymap_array: function() {
f2782813 439 var data = [['__default__', PVE.Utils.render_kvm_language('')]];
b0a6d326
EK
440 Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) {
441 data.push([key, PVE.Utils.render_kvm_language(value)]);
442 });
443
444 return data;
445 },
446
3438c27e 447 console_map: {
da9d14cd 448 '__default__': Proxmox.Utils.defaultText + ' (xterm.js)',
3438c27e
DC
449 'vv': 'SPICE (remote-viewer)',
450 'html5': 'HTML5 (noVNC)',
4ace5c6f 451 'xtermjs': 'xterm.js'
3438c27e
DC
452 },
453
b0a6d326 454 render_console_viewer: function(value) {
3438c27e
DC
455 value = value || '__default__';
456 if (PVE.Utils.console_map[value]) {
457 return PVE.Utils.console_map[value];
b0a6d326 458 }
3438c27e 459 return value;
b0a6d326
EK
460 },
461
755b9083 462 console_viewer_array: function() {
3438c27e 463 return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) {
755b9083
TL
464 return [v, PVE.Utils.render_console_viewer(v)];
465 });
466 },
467
b0a6d326
EK
468 render_kvm_vga_driver: function (value) {
469 if (!value) {
e7ade592 470 return Proxmox.Utils.defaultText;
b0a6d326 471 }
4f3e66d8
DC
472 var vga = PVE.Parser.parsePropertyString(value, 'type');
473 var text = PVE.Utils.kvm_vga_drivers[vga.type];
474 if (!vga.type) {
475 text = Proxmox.Utils.defaultText;
476 }
0be88ae1 477 if (text) {
b0a6d326
EK
478 return text + ' (' + value + ')';
479 }
480 return value;
481 },
482
483 kvm_vga_driver_array: function() {
f2782813 484 var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]];
b0a6d326
EK
485 Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) {
486 data.push([key, PVE.Utils.render_kvm_vga_driver(value)]);
487 });
488
489 return data;
490 },
491
492 render_kvm_startup: function(value) {
493 var startup = PVE.Parser.parseStartup(value);
494
495 var res = 'order=';
496 if (startup.order === undefined) {
497 res += 'any';
498 } else {
499 res += startup.order;
500 }
501 if (startup.up !== undefined) {
502 res += ',up=' + startup.up;
503 }
504 if (startup.down !== undefined) {
505 res += ',down=' + startup.down;
506 }
507
508 return res;
509 },
510
b0a6d326
EK
511 extractFormActionError: function(action) {
512 var msg;
513 switch (action.failureType) {
514 case Ext.form.action.Action.CLIENT_INVALID:
515 msg = gettext('Form fields may not be submitted with invalid values');
516 break;
517 case Ext.form.action.Action.CONNECT_FAILURE:
518 msg = gettext('Connection error');
519 var resp = action.response;
520 if (resp.status && resp.statusText) {
521 msg += " " + resp.status + ": " + resp.statusText;
522 }
523 break;
524 case Ext.form.action.Action.LOAD_FAILURE:
525 case Ext.form.action.Action.SERVER_INVALID:
e7ade592 526 msg = Proxmox.Utils.extractRequestError(action.result, true);
b0a6d326
EK
527 break;
528 }
529 return msg;
530 },
531
b0a6d326 532 format_duration_short: function(ut) {
0be88ae1 533
b0a6d326 534 if (ut < 60) {
530ee6b7 535 return ut.toFixed(1) + 's';
b0a6d326
EK
536 }
537
538 if (ut < 3600) {
539 var mins = ut / 60;
530ee6b7 540 return mins.toFixed(1) + 'm';
b0a6d326
EK
541 }
542
543 if (ut < 86400) {
544 var hours = ut / 3600;
530ee6b7 545 return hours.toFixed(1) + 'h';
b0a6d326
EK
546 }
547
548 var days = ut / 86400;
530ee6b7 549 return days.toFixed(1) + 'd';
b0a6d326
EK
550 },
551
0e244a29
DC
552 contentTypes: {
553 'images': gettext('Disk image'),
554 'backup': gettext('VZDump backup file'),
555 'vztmpl': gettext('Container template'),
556 'iso': gettext('ISO image'),
aef28e04
DC
557 'rootdir': gettext('Container'),
558 'snippets': gettext('Snippets')
0e244a29 559 },
b0a6d326 560
3b8f599b
DM
561 volume_is_qemu_backup: function(volid, format) {
562 return format === 'pbs-vm' || volid.match(':backup/vzdump-qemu-');
563 },
564
565 volume_is_lxc_backup: function(volid, format) {
566 return format === 'pbs-ct' || volid.match(':backup/vzdump-(lxc|openvz)-');
567 },
568
efff7eab
DC
569 authSchema: {
570 ad: {
571 name: gettext('Active Directory Server'),
572 ipanel: 'pveAuthADPanel',
573 add: true,
574 },
575 ldap: {
576 name: gettext('LDAP Server'),
577 ipanel: 'pveAuthLDAPPanel',
578 add: true,
579 },
580 pam: {
581 name: 'Linux PAM',
582 ipanel: 'pveAuthBasePanel',
583 add: false,
584 },
585 pve: {
586 name: 'Proxmox VE authentication server',
587 ipanel: 'pveAuthBasePanel',
588 add: false,
589 },
590 },
591
062a7f49
TL
592 storageSchema: {
593 dir: {
594 name: Proxmox.Utils.directoryText,
595 ipanel: 'DirInputPanel',
596 faIcon: 'folder'
597 },
598 lvm: {
599 name: 'LVM',
600 ipanel: 'LVMInputPanel',
601 faIcon: 'folder'
602 },
603 lvmthin: {
604 name: 'LVM-Thin',
605 ipanel: 'LvmThinInputPanel',
606 faIcon: 'folder'
607 },
608 nfs: {
609 name: 'NFS',
610 ipanel: 'NFSInputPanel',
611 faIcon: 'building'
612 },
613 cifs: {
614 name: 'CIFS',
615 ipanel: 'CIFSInputPanel',
616 faIcon: 'building'
617 },
618 glusterfs: {
619 name: 'GlusterFS',
620 ipanel: 'GlusterFsInputPanel',
621 faIcon: 'building'
622 },
623 iscsi: {
624 name: 'iSCSI',
625 ipanel: 'IScsiInputPanel',
626 faIcon: 'building'
627 },
4a4b2b6e
TL
628 cephfs: {
629 name: 'CephFS',
630 ipanel: 'CephFSInputPanel',
631 faIcon: 'building'
632 },
633 pvecephfs: {
634 name: 'CephFS (PVE)',
635 ipanel: 'CephFSInputPanel',
636 hideAdd: true,
637 faIcon: 'building'
638 },
062a7f49
TL
639 rbd: {
640 name: 'RBD',
641 ipanel: 'RBDInputPanel',
062a7f49
TL
642 faIcon: 'building'
643 },
644 pveceph: {
645 name: 'RBD (PVE)',
0d1ac958
TL
646 ipanel: 'RBDInputPanel',
647 hideAdd: true,
062a7f49
TL
648 faIcon: 'building'
649 },
650 zfs: {
651 name: 'ZFS over iSCSI',
652 ipanel: 'ZFSInputPanel',
653 faIcon: 'building'
654 },
655 zfspool: {
656 name: 'ZFS',
657 ipanel: 'ZFSPoolInputPanel',
658 faIcon: 'folder'
659 },
8b966034
TL
660 pbs: {
661 name: 'Proxmox Backup Server',
662 //ipanel: '', // TODO
663 hideAdd: true,
664 faIcon: 'database',
665 },
062a7f49
TL
666 drbd: {
667 name: 'DRBD',
8b966034
TL
668 hideAdd: true,
669 },
062a7f49
TL
670 },
671
9233148b
AD
672 sdnvnetSchema: {
673 vnet: {
674 name: 'vnet',
675 faIcon: 'folder'
676 },
677 },
678
679 sdnzoneSchema: {
680 zone: {
681 name: 'zone',
682 hideAdd: true
683 },
684 vlan: {
685 name: 'vlan',
686 ipanel: 'VlanInputPanel',
687 faIcon: 'folder'
688 },
689 qinq: {
690 name: 'qinq',
691 ipanel: 'QinQInputPanel',
692 faIcon: 'folder'
693 },
694 vxlan: {
695 name: 'vxlan',
696 ipanel: 'VxlanInputPanel',
697 faIcon: 'folder'
698 },
699 evpn: {
700 name: 'evpn',
701 ipanel: 'EvpnInputPanel',
702 faIcon: 'folder'
703 },
704 },
705
706 sdncontrollerSchema: {
707 controller: {
708 name: 'controller',
709 hideAdd: true
710 },
711 evpn: {
712 name: 'evpn',
713 ipanel: 'EvpnInputPanel',
714 faIcon: 'folder'
715 },
716 },
717
718 format_sdnvnet_type: function(value, md, record) {
719 var schema = PVE.Utils.sdnvnetSchema[value];
720 if (schema) {
721 return schema.name;
722 }
723 return Proxmox.Utils.unknownText;
724 },
725
726 format_sdnzone_type: function(value, md, record) {
727 var schema = PVE.Utils.sdnzoneSchema[value];
728 if (schema) {
34d0acbd 729 return schema.name.toUpperCase();
9233148b
AD
730 }
731 return Proxmox.Utils.unknownText;
732 },
733
734 format_sdncontroller_type: function(value, md, record) {
735 var schema = PVE.Utils.sdncontrollerSchema[value];
736 if (schema) {
737 return schema.name;
738 }
739 return Proxmox.Utils.unknownText;
740 },
741
3c23c025 742 format_storage_type: function(value, md, record) {
4a4b2b6e
TL
743 if (value === 'rbd') {
744 value = (!record || record.get('monhost') ? 'rbd' : 'pveceph');
745 } else if (value === 'cephfs') {
746 value = (!record || record.get('monhost') ? 'cephfs' : 'pvecephfs');
3c23c025 747 }
062a7f49
TL
748
749 var schema = PVE.Utils.storageSchema[value];
750 if (schema) {
751 return schema.name;
b0a6d326 752 }
062a7f49 753 return Proxmox.Utils.unknownText;
a3b8efb4
EK
754 },
755
ced1677b 756 format_ha: function(value) {
e7ade592 757 var text = Proxmox.Utils.noneText;
ced1677b
TL
758
759 if (value.managed) {
e7ade592 760 text = value.state || Proxmox.Utils.noneText;
ced1677b 761
e7ade592
DC
762 text += ', ' + Proxmox.Utils.groupText + ': ';
763 text += value.group || Proxmox.Utils.noneText;
ced1677b
TL
764 }
765
766 return text;
767 },
768
b0a6d326 769 format_content_types: function(value) {
0e244a29
DC
770 return value.split(',').sort().map(function(ct) {
771 return PVE.Utils.contentTypes[ct] || ct;
772 }).join(', ');
b0a6d326
EK
773 },
774
775 render_storage_content: function(value, metaData, record) {
776 var data = record.data;
777 if (Ext.isNumber(data.channel) &&
778 Ext.isNumber(data.id) &&
779 Ext.isNumber(data.lun)) {
0be88ae1
DC
780 return "CH " +
781 Ext.String.leftPad(data.channel,2, '0') +
b0a6d326
EK
782 " ID " + data.id + " LUN " + data.lun;
783 }
3b8f599b 784 return data.volid.replace(/^.*?:(.*?\/)?/,'');
b0a6d326
EK
785 },
786
787 render_serverity: function (value) {
788 return PVE.Utils.log_severity_hash[value] || value;
789 },
790
791 render_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
792
793 if (!(record.data.uptime && Ext.isNumeric(value))) {
794 return '';
795 }
796
797 var maxcpu = record.data.maxcpu || 1;
798
799 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
800 return '';
801 }
0be88ae1 802
b0a6d326
EK
803 var per = value * 100;
804
805 return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
806 },
807
808 render_size: function(value, metaData, record, rowIndex, colIndex, store) {
809 /*jslint confusion: true */
810
811 if (!Ext.isNumeric(value)) {
812 return '';
813 }
814
e7ade592 815 return Proxmox.Utils.format_size(value);
b0a6d326
EK
816 },
817
946730cd
DC
818 render_bandwidth: function(value) {
819 if (!Ext.isNumeric(value)) {
820 return '';
821 }
822
e7ade592 823 return Proxmox.Utils.format_size(value) + '/s';
b0a6d326
EK
824 },
825
3f633655
EK
826 render_timestamp_human_readable: function(value) {
827 return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s');
828 },
829
ddd26302
DC
830 render_duration: function(value) {
831 if (value === undefined) {
832 return '-';
833 }
834 return PVE.Utils.format_duration_short(value);
835 },
836
0bfc799f
DC
837 calculate_mem_usage: function(data) {
838 if (!Ext.isNumeric(data.mem) ||
839 data.maxmem === 0 ||
840 data.uptime < 1) {
841 return -1;
842 }
843
844 return (data.mem / data.maxmem);
845 },
846
847 render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
848 if (!Ext.isNumeric(value) || value === -1) {
849 return '';
850 }
851 if (value > 1 ) {
852 // we got no percentage but bytes
853 var mem = value;
854 var maxmem = record.data.maxmem;
855 if (!record.data.uptime ||
856 maxmem === 0 ||
857 !Ext.isNumeric(mem)) {
858 return '';
859 }
860
861 return ((mem*100)/maxmem).toFixed(1) + " %";
862 }
863 return (value*100).toFixed(1) + " %";
864 },
865
b0a6d326
EK
866 render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
867
868 var mem = value;
869 var maxmem = record.data.maxmem;
0be88ae1 870
b0a6d326
EK
871 if (!record.data.uptime) {
872 return '';
873 }
874
875 if (!(Ext.isNumeric(mem) && maxmem)) {
876 return '';
877 }
878
728f1b97 879 return PVE.Utils.render_size(value);
b0a6d326
EK
880 },
881
0bfc799f
DC
882 calculate_disk_usage: function(data) {
883
884 if (!Ext.isNumeric(data.disk) ||
885 data.type === 'qemu' ||
886 (data.type === 'lxc' && data.uptime === 0) ||
887 data.maxdisk === 0) {
888 return -1;
889 }
890
891 return (data.disk / data.maxdisk);
892 },
893
894 render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
895 if (!Ext.isNumeric(value) || value === -1) {
896 return '';
897 }
898
899 return (value * 100).toFixed(1) + " %";
900 },
901
b0a6d326
EK
902 render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
903
904 var disk = value;
905 var maxdisk = record.data.maxdisk;
728f1b97 906 var type = record.data.type;
b0a6d326 907
728f1b97
DC
908 if (!Ext.isNumeric(disk) ||
909 type === 'qemu' ||
910 maxdisk === 0 ||
911 (type === 'lxc' && record.data.uptime === 0)) {
b0a6d326
EK
912 return '';
913 }
914
728f1b97 915 return PVE.Utils.render_size(value);
b0a6d326
EK
916 },
917
4dbc64a7
DC
918 get_object_icon_class: function(type, record) {
919 var status = '';
920 var objType = type;
921
922 if (type === 'type') {
923 // for folder view
924 objType = record.groupbyid;
925 } else if (record.template) {
926 // templates
927 objType = 'template';
928 status = type;
929 } else {
930 // everything else
931 status = record.status + ' ha-' + record.hastate;
b1d8e73d
DC
932 }
933
6284a48a
DC
934 if (record.lock) {
935 status += ' locked lock-' + record.lock;
936 }
937
4dbc64a7
DC
938 var defaults = PVE.tree.ResourceTree.typeDefaults[objType];
939 if (defaults && defaults.iconCls) {
940 var retVal = defaults.iconCls + ' ' + status;
941 return retVal;
b0a6d326
EK
942 }
943
4dbc64a7
DC
944 return '';
945 },
946
947 render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
948
949 var cls = PVE.Utils.get_object_icon_class(value,record.data);
2b2fe160 950
4dbc64a7 951 var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> ';
b1d8e73d 952 return fa + value;
b0a6d326
EK
953 },
954
b0a6d326
EK
955 render_support_level: function(value, metaData, record) {
956 return PVE.Utils.support_level_hash[value] || '-';
957 },
958
0be88ae1 959 render_upid: function(value, metaData, record) {
b0a6d326
EK
960 var type = record.data.type;
961 var id = record.data.id;
962
e7ade592 963 return Proxmox.Utils.format_task_description(type, id);
b0a6d326
EK
964 },
965
054ac1b8
DC
966 /* render functions for new status panel */
967
968 render_usage: function(val) {
969 return (val*100).toFixed(2) + '%';
970 },
971
972 render_cpu_usage: function(val, max) {
973 return Ext.String.format(gettext('{0}% of {1}') +
974 ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max);
975 },
976
977 render_size_usage: function(val, max) {
bab64974
DC
978 if (max === 0) {
979 return gettext('N/A');
980 }
054ac1b8
DC
981 return (val*100/max).toFixed(2) + '% '+ '(' +
982 Ext.String.format(gettext('{0} of {1}'),
983 PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')';
984 },
985
986 /* this is different for nodes */
987 render_node_cpu_usage: function(value, record) {
988 return PVE.Utils.render_cpu_usage(value, record.cpus);
989 },
990
991 /* this is different for nodes */
992 render_node_size_usage: function(record) {
993 return PVE.Utils.render_size_usage(record.used, record.total);
994 },
995
27809975
DC
996 render_optional_url: function(value) {
997 var match;
998 if (value && (match = value.match(/^https?:\/\//)) !== null) {
cdd9b6c0 999 return '<a target="_blank" href="' + value + '">' + value + '</a>';
27809975
DC
1000 }
1001 return value;
1002 },
1003
1004 render_san: function(value) {
1005 var names = [];
1006 if (Ext.isArray(value)) {
1007 value.forEach(function(val) {
1008 if (!Ext.isNumber(val)) {
1009 names.push(val);
1010 }
1011 });
1012 return names.join('<br>');
1013 }
1014 return value;
1015 },
1016
6ad4be69
DC
1017 render_full_name: function(firstname, metaData, record) {
1018 var first = firstname || '';
1019 var last = record.data.lastname || '';
1020 return Ext.htmlEncode(first + " " + last);
1021 },
1022
2d41c7e6
TL
1023 render_u2f_error: function(error) {
1024 var ErrorNames = {
1025 '1': gettext('Other Error'),
1026 '2': gettext('Bad Request'),
1027 '3': gettext('Configuration Unsupported'),
1028 '4': gettext('Device Ineligible'),
1029 '5': gettext('Timeout')
1030 };
1031 return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText;
1032 },
1033
aa0819a8 1034 windowHostname: function() {
e7ade592 1035 return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
aa0819a8
WB
1036 function(m, addr, offset, original) { return addr; });
1037 },
0be88ae1 1038
8eccc68f 1039 openDefaultConsoleWindow: function(consoles, vmtype, vmid, nodename, vmname, cmd) {
3438c27e 1040 var dv = PVE.Utils.defaultViewer(consoles);
8eccc68f 1041 PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname, cmd);
b0a6d326
EK
1042 },
1043
8eccc68f 1044 openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname, cmd) {
9e361643 1045 // kvm, lxc, shell, upgrade
b0a6d326 1046
9e361643 1047 if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) {
b0a6d326
EK
1048 throw "missing vmid";
1049 }
1050
1051 if (!nodename) {
1052 throw "no nodename specified";
1053 }
1054
c7218ab3 1055 if (viewer === 'html5') {
8eccc68f 1056 PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname, cmd);
c6b2336c 1057 } else if (viewer === 'xtermjs') {
8eccc68f 1058 Proxmox.Utils.openXtermJsViewer(vmtype, vmid, nodename, vmname, cmd);
b0a6d326
EK
1059 } else if (viewer === 'vv') {
1060 var url;
aa0819a8 1061 var params = { proxy: PVE.Utils.windowHostname() };
b0a6d326
EK
1062 if (vmtype === 'kvm') {
1063 url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
1064 PVE.Utils.openSpiceViewer(url, params);
9e361643
DM
1065 } else if (vmtype === 'lxc') {
1066 url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy';
b0a6d326
EK
1067 PVE.Utils.openSpiceViewer(url, params);
1068 } else if (vmtype === 'shell') {
1069 url = '/nodes/' + nodename + '/spiceshell';
1070 PVE.Utils.openSpiceViewer(url, params);
1071 } else if (vmtype === 'upgrade') {
1072 url = '/nodes/' + nodename + '/spiceshell';
1073 params.upgrade = 1;
1074 PVE.Utils.openSpiceViewer(url, params);
8eccc68f
TM
1075 } else if (vmtype === 'cmd') {
1076 url = '/nodes/' + nodename + '/spiceshell';
1077 params.cmd = cmd;
1078 PVE.Utils.openSpiceViewer(url, params);
b0a6d326
EK
1079 }
1080 } else {
1081 throw "unknown viewer type";
1082 }
1083 },
1084
3438c27e
DC
1085 defaultViewer: function(consoles) {
1086
1087 var allowSpice, allowXtermjs;
1088
1089 if (consoles === true) {
1090 allowSpice = true;
1091 allowXtermjs = true;
1092 } else if (typeof consoles === 'object') {
1093 allowSpice = consoles.spice;
4ace5c6f 1094 allowXtermjs = !!consoles.xtermjs;
3438c27e 1095 }
da9d14cd 1096 var dv = PVE.VersionInfo.console || 'xtermjs';
f932cffa
DC
1097 if (dv === 'vv' && !allowSpice) {
1098 dv = (allowXtermjs) ? 'xtermjs' : 'html5';
1099 } else if (dv === 'xtermjs' && !allowXtermjs) {
1100 dv = (allowSpice) ? 'vv' : 'html5';
b0a6d326
EK
1101 }
1102
1103 return dv;
1104 },
1105
8eccc68f 1106 openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) {
af89f682
TL
1107 let scaling = 'off';
1108 if (Proxmox.Utils.toolkit !== 'touch') {
1109 var sp = Ext.state.Manager.getProvider();
1110 scaling = sp.get('novnc-scaling', 'off');
1111 }
8eccc68f 1112 var url = Ext.Object.toQueryString({
9e361643 1113 console: vmtype, // kvm, lxc, upgrade or shell
c7218ab3 1114 novnc: 1,
b0a6d326
EK
1115 vmid: vmid,
1116 vmname: vmname,
16e64c97 1117 node: nodename,
af89f682 1118 resize: scaling,
8eccc68f 1119 cmd: cmd
b0a6d326
EK
1120 });
1121 var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
7af1ab47
DC
1122 if (nw) {
1123 nw.focus();
1124 }
b0a6d326
EK
1125 },
1126
1127 openSpiceViewer: function(url, params){
1128
1129 var downloadWithName = function(uri, name) {
1130 var link = Ext.DomHelper.append(document.body, {
1131 tag: 'a',
1132 href: uri,
1133 css : 'display:none;visibility:hidden;height:0px;'
1134 });
1135
1136 // Note: we need to tell android the correct file name extension
1137 // but we do not set 'download' tag for other environments, because
1138 // It can have strange side effects (additional user prompt on firefox)
1139 var andriod = navigator.userAgent.match(/Android/i) ? true : false;
1140 if (andriod) {
1141 link.download = name;
1142 }
1143
1144 if (link.fireEvent) {
1145 link.fireEvent('onclick');
1146 } else {
1147 var evt = document.createEvent("MouseEvents");
1148 evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
1149 link.dispatchEvent(evt);
1150 }
1151 };
1152
e7ade592 1153 Proxmox.Utils.API2Request({
b0a6d326
EK
1154 url: url,
1155 params: params,
1156 method: 'POST',
1157 failure: function(response, opts){
1158 Ext.Msg.alert('Error', response.htmlStatus);
1159 },
1160 success: function(response, opts){
1161 var raw = "[virt-viewer]\n";
1162 Ext.Object.each(response.result.data, function(k, v) {
1163 raw += k + "=" + v + "\n";
1164 });
1165 var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
1166 encodeURIComponent(raw);
0be88ae1 1167
b0a6d326
EK
1168 downloadWithName(url, "pve-spice.vv");
1169 }
1170 });
1171 },
1172
e3129443
DC
1173 openTreeConsole: function(tree, record, item, index, e) {
1174 e.stopEvent();
1175 var nodename = record.data.node;
1176 var vmid = record.data.vmid;
1177 var vmname = record.data.name;
1178 if (record.data.type === 'qemu' && !record.data.template) {
e7ade592 1179 Proxmox.Utils.API2Request({
e3129443
DC
1180 url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
1181 failure: function(response, opts) {
1182 Ext.Msg.alert('Error', response.htmlStatus);
1183 },
1184 success: function(response, opts) {
bd9537d7 1185 let conf = response.result.data;
54453c38 1186 var consoles = {
bd9537d7
TL
1187 spice: !!conf.spice,
1188 xtermjs: !!conf.serial,
54453c38
DC
1189 };
1190 PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
e3129443
DC
1191 }
1192 });
1193 } else if (record.data.type === 'lxc' && !record.data.template) {
1194 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
1195 }
1196 },
1197
fbd60cfd
DM
1198 // test automation helper
1199 call_menu_handler: function(menu, text) {
1200
1201 var list = menu.query('menuitem');
1202
1203 Ext.Array.each(list, function(item) {
1204 if (item.text === text) {
1205 if (item.handler) {
1206 item.handler();
1207 return 1;
1208 } else {
1209 return undefined;
1210 }
1211 }
1212 });
1213 },
1214
685b7aa4
DC
1215 createCmdMenu: function(v, record, item, index, event) {
1216 event.stopEvent();
cc1a91be
DC
1217 if (!(v instanceof Ext.tree.View)) {
1218 v.select(record);
1219 }
685b7aa4 1220 var menu;
9bad05bd
DC
1221 var template = !!record.data.template;
1222 var type = record.data.type;
685b7aa4 1223
9bad05bd
DC
1224 if (template) {
1225 if (type === 'qemu' || type == 'lxc') {
1226 menu = Ext.create('PVE.menu.TemplateMenu', {
1227 pveSelNode: record
1228 });
1229 }
1230 } else if (type === 'qemu' ||
1231 type === 'lxc' ||
1232 type === 'node') {
1233 menu = Ext.create('PVE.' + type + '.CmdMenu', {
1234 pveSelNode: record,
c11ab8cb
DC
1235 nodename: record.data.node
1236 });
685b7aa4
DC
1237 } else {
1238 return;
1239 }
1240
1241 menu.showAt(event.getXY());
9f0b4e04 1242 return menu;
e7ade592 1243 },
9fa2e36d 1244
fe4f00ad
TL
1245 // helper for deleting field which are set to there default values
1246 delete_if_default: function(values, fieldname, default_val, create) {
1247 if (values[fieldname] === '' || values[fieldname] === default_val) {
1248 if (!create) {
1249 if (values['delete']) {
1250 values['delete'] += ',' + fieldname;
1251 } else {
1252 values['delete'] = fieldname;
1253 }
1254 }
1255
1256 delete values[fieldname];
1257 }
857b97a7
TL
1258 },
1259
1260 loadSSHKeyFromFile: function(file, callback) {
1261 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1262 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1263 // assume: 740*8 for max. 32kbit (5920 byte file)
1264 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1265 if (file.size > 8192) {
1266 Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
1267 return;
1268 }
1269 /*global
1270 FileReader
1271 */
1272 var reader = new FileReader();
1273 reader.onload = function(evt) {
1274 callback(evt.target.result);
1275 };
1276 reader.readAsText(file);
abe824aa
DC
1277 },
1278
8c4ec8c7
TL
1279 diskControllerMaxIDs: {
1280 ide: 4,
1281 sata: 6,
cf0d139e 1282 scsi: 31,
8c4ec8c7
TL
1283 virtio: 16,
1284 },
abe824aa
DC
1285
1286 // types is either undefined (all busses), an array of busses, or a single bus
1287 forEachBus: function(types, func) {
8c4ec8c7 1288 var busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
abe824aa
DC
1289 var i, j, count, cont;
1290
1291 if (Ext.isArray(types)) {
1292 busses = types;
1293 } else if (Ext.isDefined(types)) {
1294 busses = [ types ];
1295 }
1296
1297 // check if we only have valid busses
1298 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1299 if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) {
abe824aa
DC
1300 throw "invalid bus: '" + busses[i] + "'";
1301 }
1302 }
1303
1304 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1305 count = PVE.Utils.diskControllerMaxIDs[busses[i]];
abe824aa
DC
1306 for (j = 0; j < count; j++) {
1307 cont = func(busses[i], j);
1308 if (!cont && cont !== undefined) {
1309 return;
1310 }
1311 }
1312 }
14a845bc
DC
1313 },
1314
483bd394 1315 mp_counts: { mps: 256, unused: 256 },
14a845bc
DC
1316
1317 forEachMP: function(func, includeUnused) {
1318 var i, cont;
1319 for (i = 0; i < PVE.Utils.mp_counts.mps; i++) {
1320 cont = func('mp', i);
1321 if (!cont && cont !== undefined) {
1322 return;
1323 }
1324 }
1325
1326 if (!includeUnused) {
1327 return;
1328 }
1329
1330 for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
1331 cont = func('unused', i);
1332 if (!cont && cont !== undefined) {
1333 return;
1334 }
1335 }
b945c7c1
TM
1336 },
1337
6c1d8ead 1338 hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1 },
9d855398 1339
b945c7c1
TM
1340 cleanEmptyObjectKeys: function (obj) {
1341 var propName;
1342 for (propName in obj) {
1343 if (obj.hasOwnProperty(propName)) {
1344 if (obj[propName] === null || obj[propName] === undefined) {
1345 delete obj[propName];
1346 }
1347 }
1348 }
4616a55b
TM
1349 },
1350
1351 handleStoreErrorOrMask: function(me, store, regex, callback) {
1352
1353 me.mon(store, 'load', function (proxy, response, success, operation) {
1354
1355 if (success) {
1356 Proxmox.Utils.setErrorMask(me, false);
1357 return;
1358 }
1359 var msg;
1360
1361 if (operation.error.statusText) {
1362 if (operation.error.statusText.match(regex)) {
1363 callback(me, operation.error);
1364 return;
1365 } else {
1366 msg = operation.error.statusText + ' (' + operation.error.status + ')';
1367 }
1368 } else {
1369 msg = gettext('Connection error');
1370 }
1371 Proxmox.Utils.setErrorMask(me, msg);
1372 });
1373 },
1374
1375 showCephInstallOrMask: function(container, msg, nodename, callback){
1376 var regex = new RegExp("not (installed|initialized)", "i");
1377 if (msg.match(regex)) {
1378 if (Proxmox.UserName === 'root@pam') {
1379 container.el.mask();
1380 if (!container.down('pveCephInstallWindow')){
f992ef80 1381 var isInstalled = msg.match(/not initialized/i) ? true : false;
4616a55b
TM
1382 var win = Ext.create('PVE.ceph.Install', {
1383 nodename: nodename
1384 });
f992ef80 1385 win.getViewModel().set('isInstalled', isInstalled);
4616a55b
TM
1386 container.add(win);
1387 win.show();
1388 callback(win);
1389 }
1390 } else {
a7e8b87b
TL
1391 container.mask(Ext.String.format(gettext('{0} not installed.') +
1392 ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']);
4616a55b
TM
1393 }
1394 return true;
1395 } else {
1396 return false;
1397 }
49dfba72
DC
1398 },
1399
1400 propertyStringSet: function(target, source, name, value) {
1401 if (source) {
1402 if (value === undefined) {
1403 target[name] = source;
1404 } else {
1405 target[name] = value;
1406 }
1407 } else {
1408 delete target[name];
1409 }
bbc83309
DC
1410 },
1411
1412 updateColumns: function(container) {
f973c5b2
DC
1413 let mode = Ext.state.Manager.get('summarycolumns') || 'auto';
1414 let factor;
1415 if (mode !== 'auto') {
1416 factor = parseInt(mode, 10);
1417 if (Number.isNaN(factor)) {
1418 factor = 1;
1419 }
1420 } else {
1421 factor = container.getSize().width < 1400 ? 1 : 2;
1422 }
bbc83309
DC
1423
1424 if (container.oldFactor === factor) {
1425 return;
1426 }
1427
1428 let items = container.query('>'); // direct childs
1429 factor = Math.min(factor, items.length);
1430 container.oldFactor = factor;
1431
1432 items.forEach((item) => {
1433 item.columnWidth = 1 / factor;
1434 });
1435
1436 // we have to update the layout twice, since the first layout change
1437 // can trigger the scrollbar which reduces the amount of space left
1438 container.updateLayout();
1439 container.updateLayout();
1440 },
e65817a1
SR
1441
1442 forEachCorosyncLink: function(nodeinfo, cb) {
1443 let re = /(?:ring|link)(\d+)_addr/;
1444 Ext.iterate(nodeinfo, (prop, val) => {
1445 let match = re.exec(prop);
1446 if (match) {
1447 cb(Number(match[1]), val);
1448 }
1449 });
1450 },
e7ade592 1451},
fe4f00ad 1452
9fa2e36d
EK
1453 singleton: true,
1454 constructor: function() {
1455 var me = this;
1456 Ext.apply(me, me.utilities);
685b7aa4 1457 }
e7ade592 1458
9fa2e36d 1459});