]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/Utils.js
ui: Parser: add printACME
[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',
822fb26d 573 syncipanel: 'pveAuthLDAPSyncPanel',
efff7eab
DC
574 add: true,
575 },
576 ldap: {
577 name: gettext('LDAP Server'),
578 ipanel: 'pveAuthLDAPPanel',
822fb26d 579 syncipanel: 'pveAuthLDAPSyncPanel',
efff7eab
DC
580 add: true,
581 },
582 pam: {
583 name: 'Linux PAM',
584 ipanel: 'pveAuthBasePanel',
585 add: false,
586 },
587 pve: {
588 name: 'Proxmox VE authentication server',
589 ipanel: 'pveAuthBasePanel',
590 add: false,
591 },
592 },
593
062a7f49
TL
594 storageSchema: {
595 dir: {
596 name: Proxmox.Utils.directoryText,
597 ipanel: 'DirInputPanel',
598 faIcon: 'folder'
599 },
600 lvm: {
601 name: 'LVM',
602 ipanel: 'LVMInputPanel',
603 faIcon: 'folder'
604 },
605 lvmthin: {
606 name: 'LVM-Thin',
607 ipanel: 'LvmThinInputPanel',
608 faIcon: 'folder'
609 },
610 nfs: {
611 name: 'NFS',
612 ipanel: 'NFSInputPanel',
613 faIcon: 'building'
614 },
615 cifs: {
616 name: 'CIFS',
617 ipanel: 'CIFSInputPanel',
618 faIcon: 'building'
619 },
620 glusterfs: {
621 name: 'GlusterFS',
622 ipanel: 'GlusterFsInputPanel',
623 faIcon: 'building'
624 },
625 iscsi: {
626 name: 'iSCSI',
627 ipanel: 'IScsiInputPanel',
628 faIcon: 'building'
629 },
4a4b2b6e
TL
630 cephfs: {
631 name: 'CephFS',
632 ipanel: 'CephFSInputPanel',
633 faIcon: 'building'
634 },
635 pvecephfs: {
636 name: 'CephFS (PVE)',
637 ipanel: 'CephFSInputPanel',
638 hideAdd: true,
639 faIcon: 'building'
640 },
062a7f49
TL
641 rbd: {
642 name: 'RBD',
643 ipanel: 'RBDInputPanel',
062a7f49
TL
644 faIcon: 'building'
645 },
646 pveceph: {
647 name: 'RBD (PVE)',
0d1ac958
TL
648 ipanel: 'RBDInputPanel',
649 hideAdd: true,
062a7f49
TL
650 faIcon: 'building'
651 },
652 zfs: {
653 name: 'ZFS over iSCSI',
654 ipanel: 'ZFSInputPanel',
655 faIcon: 'building'
656 },
657 zfspool: {
658 name: 'ZFS',
659 ipanel: 'ZFSPoolInputPanel',
660 faIcon: 'folder'
661 },
8b966034
TL
662 pbs: {
663 name: 'Proxmox Backup Server',
664 //ipanel: '', // TODO
665 hideAdd: true,
666 faIcon: 'database',
667 },
062a7f49
TL
668 drbd: {
669 name: 'DRBD',
8b966034
TL
670 hideAdd: true,
671 },
062a7f49
TL
672 },
673
9233148b
AD
674 sdnvnetSchema: {
675 vnet: {
676 name: 'vnet',
677 faIcon: 'folder'
678 },
679 },
680
681 sdnzoneSchema: {
682 zone: {
683 name: 'zone',
684 hideAdd: true
685 },
686 vlan: {
687 name: 'vlan',
688 ipanel: 'VlanInputPanel',
689 faIcon: 'folder'
690 },
691 qinq: {
692 name: 'qinq',
693 ipanel: 'QinQInputPanel',
694 faIcon: 'folder'
695 },
696 vxlan: {
697 name: 'vxlan',
698 ipanel: 'VxlanInputPanel',
699 faIcon: 'folder'
700 },
701 evpn: {
702 name: 'evpn',
703 ipanel: 'EvpnInputPanel',
704 faIcon: 'folder'
705 },
706 },
707
708 sdncontrollerSchema: {
709 controller: {
710 name: 'controller',
711 hideAdd: true
712 },
713 evpn: {
714 name: 'evpn',
715 ipanel: 'EvpnInputPanel',
716 faIcon: 'folder'
717 },
718 },
719
720 format_sdnvnet_type: function(value, md, record) {
721 var schema = PVE.Utils.sdnvnetSchema[value];
722 if (schema) {
723 return schema.name;
724 }
725 return Proxmox.Utils.unknownText;
726 },
727
728 format_sdnzone_type: function(value, md, record) {
729 var schema = PVE.Utils.sdnzoneSchema[value];
730 if (schema) {
34d0acbd 731 return schema.name.toUpperCase();
9233148b
AD
732 }
733 return Proxmox.Utils.unknownText;
734 },
735
736 format_sdncontroller_type: function(value, md, record) {
737 var schema = PVE.Utils.sdncontrollerSchema[value];
738 if (schema) {
739 return schema.name;
740 }
741 return Proxmox.Utils.unknownText;
742 },
743
3c23c025 744 format_storage_type: function(value, md, record) {
4a4b2b6e
TL
745 if (value === 'rbd') {
746 value = (!record || record.get('monhost') ? 'rbd' : 'pveceph');
747 } else if (value === 'cephfs') {
748 value = (!record || record.get('monhost') ? 'cephfs' : 'pvecephfs');
3c23c025 749 }
062a7f49
TL
750
751 var schema = PVE.Utils.storageSchema[value];
752 if (schema) {
753 return schema.name;
b0a6d326 754 }
062a7f49 755 return Proxmox.Utils.unknownText;
a3b8efb4
EK
756 },
757
ced1677b 758 format_ha: function(value) {
e7ade592 759 var text = Proxmox.Utils.noneText;
ced1677b
TL
760
761 if (value.managed) {
e7ade592 762 text = value.state || Proxmox.Utils.noneText;
ced1677b 763
e7ade592
DC
764 text += ', ' + Proxmox.Utils.groupText + ': ';
765 text += value.group || Proxmox.Utils.noneText;
ced1677b
TL
766 }
767
768 return text;
769 },
770
b0a6d326 771 format_content_types: function(value) {
0e244a29
DC
772 return value.split(',').sort().map(function(ct) {
773 return PVE.Utils.contentTypes[ct] || ct;
774 }).join(', ');
b0a6d326
EK
775 },
776
777 render_storage_content: function(value, metaData, record) {
778 var data = record.data;
779 if (Ext.isNumber(data.channel) &&
780 Ext.isNumber(data.id) &&
781 Ext.isNumber(data.lun)) {
0be88ae1
DC
782 return "CH " +
783 Ext.String.leftPad(data.channel,2, '0') +
b0a6d326
EK
784 " ID " + data.id + " LUN " + data.lun;
785 }
3b8f599b 786 return data.volid.replace(/^.*?:(.*?\/)?/,'');
b0a6d326
EK
787 },
788
789 render_serverity: function (value) {
790 return PVE.Utils.log_severity_hash[value] || value;
791 },
792
793 render_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
794
795 if (!(record.data.uptime && Ext.isNumeric(value))) {
796 return '';
797 }
798
799 var maxcpu = record.data.maxcpu || 1;
800
801 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
802 return '';
803 }
0be88ae1 804
b0a6d326
EK
805 var per = value * 100;
806
807 return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
808 },
809
810 render_size: function(value, metaData, record, rowIndex, colIndex, store) {
811 /*jslint confusion: true */
812
813 if (!Ext.isNumeric(value)) {
814 return '';
815 }
816
e7ade592 817 return Proxmox.Utils.format_size(value);
b0a6d326
EK
818 },
819
946730cd
DC
820 render_bandwidth: function(value) {
821 if (!Ext.isNumeric(value)) {
822 return '';
823 }
824
e7ade592 825 return Proxmox.Utils.format_size(value) + '/s';
b0a6d326
EK
826 },
827
3f633655
EK
828 render_timestamp_human_readable: function(value) {
829 return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s');
830 },
831
ddd26302
DC
832 render_duration: function(value) {
833 if (value === undefined) {
834 return '-';
835 }
836 return PVE.Utils.format_duration_short(value);
837 },
838
0bfc799f
DC
839 calculate_mem_usage: function(data) {
840 if (!Ext.isNumeric(data.mem) ||
841 data.maxmem === 0 ||
842 data.uptime < 1) {
843 return -1;
844 }
845
846 return (data.mem / data.maxmem);
847 },
848
849 render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
850 if (!Ext.isNumeric(value) || value === -1) {
851 return '';
852 }
853 if (value > 1 ) {
854 // we got no percentage but bytes
855 var mem = value;
856 var maxmem = record.data.maxmem;
857 if (!record.data.uptime ||
858 maxmem === 0 ||
859 !Ext.isNumeric(mem)) {
860 return '';
861 }
862
863 return ((mem*100)/maxmem).toFixed(1) + " %";
864 }
865 return (value*100).toFixed(1) + " %";
866 },
867
b0a6d326
EK
868 render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
869
870 var mem = value;
871 var maxmem = record.data.maxmem;
0be88ae1 872
b0a6d326
EK
873 if (!record.data.uptime) {
874 return '';
875 }
876
877 if (!(Ext.isNumeric(mem) && maxmem)) {
878 return '';
879 }
880
728f1b97 881 return PVE.Utils.render_size(value);
b0a6d326
EK
882 },
883
0bfc799f
DC
884 calculate_disk_usage: function(data) {
885
886 if (!Ext.isNumeric(data.disk) ||
887 data.type === 'qemu' ||
888 (data.type === 'lxc' && data.uptime === 0) ||
889 data.maxdisk === 0) {
890 return -1;
891 }
892
893 return (data.disk / data.maxdisk);
894 },
895
896 render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
897 if (!Ext.isNumeric(value) || value === -1) {
898 return '';
899 }
900
901 return (value * 100).toFixed(1) + " %";
902 },
903
b0a6d326
EK
904 render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
905
906 var disk = value;
907 var maxdisk = record.data.maxdisk;
728f1b97 908 var type = record.data.type;
b0a6d326 909
728f1b97
DC
910 if (!Ext.isNumeric(disk) ||
911 type === 'qemu' ||
912 maxdisk === 0 ||
913 (type === 'lxc' && record.data.uptime === 0)) {
b0a6d326
EK
914 return '';
915 }
916
728f1b97 917 return PVE.Utils.render_size(value);
b0a6d326
EK
918 },
919
4dbc64a7
DC
920 get_object_icon_class: function(type, record) {
921 var status = '';
922 var objType = type;
923
924 if (type === 'type') {
925 // for folder view
926 objType = record.groupbyid;
927 } else if (record.template) {
928 // templates
929 objType = 'template';
930 status = type;
931 } else {
932 // everything else
933 status = record.status + ' ha-' + record.hastate;
b1d8e73d
DC
934 }
935
6284a48a
DC
936 if (record.lock) {
937 status += ' locked lock-' + record.lock;
938 }
939
4dbc64a7
DC
940 var defaults = PVE.tree.ResourceTree.typeDefaults[objType];
941 if (defaults && defaults.iconCls) {
942 var retVal = defaults.iconCls + ' ' + status;
943 return retVal;
b0a6d326
EK
944 }
945
4dbc64a7
DC
946 return '';
947 },
948
949 render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
950
951 var cls = PVE.Utils.get_object_icon_class(value,record.data);
2b2fe160 952
4dbc64a7 953 var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> ';
b1d8e73d 954 return fa + value;
b0a6d326
EK
955 },
956
b0a6d326
EK
957 render_support_level: function(value, metaData, record) {
958 return PVE.Utils.support_level_hash[value] || '-';
959 },
960
0be88ae1 961 render_upid: function(value, metaData, record) {
b0a6d326
EK
962 var type = record.data.type;
963 var id = record.data.id;
964
e7ade592 965 return Proxmox.Utils.format_task_description(type, id);
b0a6d326
EK
966 },
967
054ac1b8
DC
968 /* render functions for new status panel */
969
970 render_usage: function(val) {
971 return (val*100).toFixed(2) + '%';
972 },
973
974 render_cpu_usage: function(val, max) {
975 return Ext.String.format(gettext('{0}% of {1}') +
976 ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max);
977 },
978
979 render_size_usage: function(val, max) {
bab64974
DC
980 if (max === 0) {
981 return gettext('N/A');
982 }
054ac1b8
DC
983 return (val*100/max).toFixed(2) + '% '+ '(' +
984 Ext.String.format(gettext('{0} of {1}'),
985 PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')';
986 },
987
988 /* this is different for nodes */
989 render_node_cpu_usage: function(value, record) {
990 return PVE.Utils.render_cpu_usage(value, record.cpus);
991 },
992
993 /* this is different for nodes */
994 render_node_size_usage: function(record) {
995 return PVE.Utils.render_size_usage(record.used, record.total);
996 },
997
27809975
DC
998 render_optional_url: function(value) {
999 var match;
1000 if (value && (match = value.match(/^https?:\/\//)) !== null) {
cdd9b6c0 1001 return '<a target="_blank" href="' + value + '">' + value + '</a>';
27809975
DC
1002 }
1003 return value;
1004 },
1005
1006 render_san: function(value) {
1007 var names = [];
1008 if (Ext.isArray(value)) {
1009 value.forEach(function(val) {
1010 if (!Ext.isNumber(val)) {
1011 names.push(val);
1012 }
1013 });
1014 return names.join('<br>');
1015 }
1016 return value;
1017 },
1018
6ad4be69
DC
1019 render_full_name: function(firstname, metaData, record) {
1020 var first = firstname || '';
1021 var last = record.data.lastname || '';
1022 return Ext.htmlEncode(first + " " + last);
1023 },
1024
2d41c7e6
TL
1025 render_u2f_error: function(error) {
1026 var ErrorNames = {
1027 '1': gettext('Other Error'),
1028 '2': gettext('Bad Request'),
1029 '3': gettext('Configuration Unsupported'),
1030 '4': gettext('Device Ineligible'),
1031 '5': gettext('Timeout')
1032 };
1033 return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText;
1034 },
1035
aa0819a8 1036 windowHostname: function() {
e7ade592 1037 return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
aa0819a8
WB
1038 function(m, addr, offset, original) { return addr; });
1039 },
0be88ae1 1040
8eccc68f 1041 openDefaultConsoleWindow: function(consoles, vmtype, vmid, nodename, vmname, cmd) {
3438c27e 1042 var dv = PVE.Utils.defaultViewer(consoles);
8eccc68f 1043 PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname, cmd);
b0a6d326
EK
1044 },
1045
8eccc68f 1046 openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname, cmd) {
9e361643 1047 // kvm, lxc, shell, upgrade
b0a6d326 1048
9e361643 1049 if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) {
b0a6d326
EK
1050 throw "missing vmid";
1051 }
1052
1053 if (!nodename) {
1054 throw "no nodename specified";
1055 }
1056
c7218ab3 1057 if (viewer === 'html5') {
8eccc68f 1058 PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname, cmd);
c6b2336c 1059 } else if (viewer === 'xtermjs') {
8eccc68f 1060 Proxmox.Utils.openXtermJsViewer(vmtype, vmid, nodename, vmname, cmd);
b0a6d326
EK
1061 } else if (viewer === 'vv') {
1062 var url;
aa0819a8 1063 var params = { proxy: PVE.Utils.windowHostname() };
b0a6d326
EK
1064 if (vmtype === 'kvm') {
1065 url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
1066 PVE.Utils.openSpiceViewer(url, params);
9e361643
DM
1067 } else if (vmtype === 'lxc') {
1068 url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy';
b0a6d326
EK
1069 PVE.Utils.openSpiceViewer(url, params);
1070 } else if (vmtype === 'shell') {
1071 url = '/nodes/' + nodename + '/spiceshell';
1072 PVE.Utils.openSpiceViewer(url, params);
1073 } else if (vmtype === 'upgrade') {
1074 url = '/nodes/' + nodename + '/spiceshell';
1075 params.upgrade = 1;
1076 PVE.Utils.openSpiceViewer(url, params);
8eccc68f
TM
1077 } else if (vmtype === 'cmd') {
1078 url = '/nodes/' + nodename + '/spiceshell';
1079 params.cmd = cmd;
1080 PVE.Utils.openSpiceViewer(url, params);
b0a6d326
EK
1081 }
1082 } else {
1083 throw "unknown viewer type";
1084 }
1085 },
1086
3438c27e
DC
1087 defaultViewer: function(consoles) {
1088
1089 var allowSpice, allowXtermjs;
1090
1091 if (consoles === true) {
1092 allowSpice = true;
1093 allowXtermjs = true;
1094 } else if (typeof consoles === 'object') {
1095 allowSpice = consoles.spice;
4ace5c6f 1096 allowXtermjs = !!consoles.xtermjs;
3438c27e 1097 }
da9d14cd 1098 var dv = PVE.VersionInfo.console || 'xtermjs';
f932cffa
DC
1099 if (dv === 'vv' && !allowSpice) {
1100 dv = (allowXtermjs) ? 'xtermjs' : 'html5';
1101 } else if (dv === 'xtermjs' && !allowXtermjs) {
1102 dv = (allowSpice) ? 'vv' : 'html5';
b0a6d326
EK
1103 }
1104
1105 return dv;
1106 },
1107
8eccc68f 1108 openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) {
af89f682
TL
1109 let scaling = 'off';
1110 if (Proxmox.Utils.toolkit !== 'touch') {
1111 var sp = Ext.state.Manager.getProvider();
1112 scaling = sp.get('novnc-scaling', 'off');
1113 }
8eccc68f 1114 var url = Ext.Object.toQueryString({
9e361643 1115 console: vmtype, // kvm, lxc, upgrade or shell
c7218ab3 1116 novnc: 1,
b0a6d326
EK
1117 vmid: vmid,
1118 vmname: vmname,
16e64c97 1119 node: nodename,
af89f682 1120 resize: scaling,
8eccc68f 1121 cmd: cmd
b0a6d326
EK
1122 });
1123 var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
7af1ab47
DC
1124 if (nw) {
1125 nw.focus();
1126 }
b0a6d326
EK
1127 },
1128
1129 openSpiceViewer: function(url, params){
1130
1131 var downloadWithName = function(uri, name) {
1132 var link = Ext.DomHelper.append(document.body, {
1133 tag: 'a',
1134 href: uri,
1135 css : 'display:none;visibility:hidden;height:0px;'
1136 });
1137
1138 // Note: we need to tell android the correct file name extension
1139 // but we do not set 'download' tag for other environments, because
1140 // It can have strange side effects (additional user prompt on firefox)
1141 var andriod = navigator.userAgent.match(/Android/i) ? true : false;
1142 if (andriod) {
1143 link.download = name;
1144 }
1145
1146 if (link.fireEvent) {
1147 link.fireEvent('onclick');
1148 } else {
1149 var evt = document.createEvent("MouseEvents");
1150 evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
1151 link.dispatchEvent(evt);
1152 }
1153 };
1154
e7ade592 1155 Proxmox.Utils.API2Request({
b0a6d326
EK
1156 url: url,
1157 params: params,
1158 method: 'POST',
1159 failure: function(response, opts){
1160 Ext.Msg.alert('Error', response.htmlStatus);
1161 },
1162 success: function(response, opts){
1163 var raw = "[virt-viewer]\n";
1164 Ext.Object.each(response.result.data, function(k, v) {
1165 raw += k + "=" + v + "\n";
1166 });
1167 var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
1168 encodeURIComponent(raw);
0be88ae1 1169
b0a6d326
EK
1170 downloadWithName(url, "pve-spice.vv");
1171 }
1172 });
1173 },
1174
e3129443
DC
1175 openTreeConsole: function(tree, record, item, index, e) {
1176 e.stopEvent();
1177 var nodename = record.data.node;
1178 var vmid = record.data.vmid;
1179 var vmname = record.data.name;
1180 if (record.data.type === 'qemu' && !record.data.template) {
e7ade592 1181 Proxmox.Utils.API2Request({
e3129443
DC
1182 url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
1183 failure: function(response, opts) {
1184 Ext.Msg.alert('Error', response.htmlStatus);
1185 },
1186 success: function(response, opts) {
bd9537d7 1187 let conf = response.result.data;
54453c38 1188 var consoles = {
bd9537d7
TL
1189 spice: !!conf.spice,
1190 xtermjs: !!conf.serial,
54453c38
DC
1191 };
1192 PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
e3129443
DC
1193 }
1194 });
1195 } else if (record.data.type === 'lxc' && !record.data.template) {
1196 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
1197 }
1198 },
1199
fbd60cfd
DM
1200 // test automation helper
1201 call_menu_handler: function(menu, text) {
1202
1203 var list = menu.query('menuitem');
1204
1205 Ext.Array.each(list, function(item) {
1206 if (item.text === text) {
1207 if (item.handler) {
1208 item.handler();
1209 return 1;
1210 } else {
1211 return undefined;
1212 }
1213 }
1214 });
1215 },
1216
685b7aa4
DC
1217 createCmdMenu: function(v, record, item, index, event) {
1218 event.stopEvent();
cc1a91be
DC
1219 if (!(v instanceof Ext.tree.View)) {
1220 v.select(record);
1221 }
685b7aa4 1222 var menu;
9bad05bd
DC
1223 var template = !!record.data.template;
1224 var type = record.data.type;
685b7aa4 1225
9bad05bd
DC
1226 if (template) {
1227 if (type === 'qemu' || type == 'lxc') {
1228 menu = Ext.create('PVE.menu.TemplateMenu', {
1229 pveSelNode: record
1230 });
1231 }
1232 } else if (type === 'qemu' ||
1233 type === 'lxc' ||
1234 type === 'node') {
1235 menu = Ext.create('PVE.' + type + '.CmdMenu', {
1236 pveSelNode: record,
c11ab8cb
DC
1237 nodename: record.data.node
1238 });
685b7aa4
DC
1239 } else {
1240 return;
1241 }
1242
1243 menu.showAt(event.getXY());
9f0b4e04 1244 return menu;
e7ade592 1245 },
9fa2e36d 1246
fe4f00ad
TL
1247 // helper for deleting field which are set to there default values
1248 delete_if_default: function(values, fieldname, default_val, create) {
1249 if (values[fieldname] === '' || values[fieldname] === default_val) {
1250 if (!create) {
1251 if (values['delete']) {
2db8e90d
DC
1252 if (Ext.isArray(values['delete'])) {
1253 values['delete'].push(fieldname);
1254 } else {
1255 values['delete'] += ',' + fieldname;
1256 }
fe4f00ad
TL
1257 } else {
1258 values['delete'] = fieldname;
1259 }
1260 }
1261
1262 delete values[fieldname];
1263 }
857b97a7
TL
1264 },
1265
1266 loadSSHKeyFromFile: function(file, callback) {
1267 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1268 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1269 // assume: 740*8 for max. 32kbit (5920 byte file)
1270 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1271 if (file.size > 8192) {
1272 Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
1273 return;
1274 }
1275 /*global
1276 FileReader
1277 */
1278 var reader = new FileReader();
1279 reader.onload = function(evt) {
1280 callback(evt.target.result);
1281 };
1282 reader.readAsText(file);
abe824aa
DC
1283 },
1284
8c4ec8c7
TL
1285 diskControllerMaxIDs: {
1286 ide: 4,
1287 sata: 6,
cf0d139e 1288 scsi: 31,
8c4ec8c7
TL
1289 virtio: 16,
1290 },
abe824aa
DC
1291
1292 // types is either undefined (all busses), an array of busses, or a single bus
1293 forEachBus: function(types, func) {
8c4ec8c7 1294 var busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
abe824aa
DC
1295 var i, j, count, cont;
1296
1297 if (Ext.isArray(types)) {
1298 busses = types;
1299 } else if (Ext.isDefined(types)) {
1300 busses = [ types ];
1301 }
1302
1303 // check if we only have valid busses
1304 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1305 if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) {
abe824aa
DC
1306 throw "invalid bus: '" + busses[i] + "'";
1307 }
1308 }
1309
1310 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1311 count = PVE.Utils.diskControllerMaxIDs[busses[i]];
abe824aa
DC
1312 for (j = 0; j < count; j++) {
1313 cont = func(busses[i], j);
1314 if (!cont && cont !== undefined) {
1315 return;
1316 }
1317 }
1318 }
14a845bc
DC
1319 },
1320
483bd394 1321 mp_counts: { mps: 256, unused: 256 },
14a845bc
DC
1322
1323 forEachMP: function(func, includeUnused) {
1324 var i, cont;
1325 for (i = 0; i < PVE.Utils.mp_counts.mps; i++) {
1326 cont = func('mp', i);
1327 if (!cont && cont !== undefined) {
1328 return;
1329 }
1330 }
1331
1332 if (!includeUnused) {
1333 return;
1334 }
1335
1336 for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
1337 cont = func('unused', i);
1338 if (!cont && cont !== undefined) {
1339 return;
1340 }
1341 }
b945c7c1
TM
1342 },
1343
6c1d8ead 1344 hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1 },
9d855398 1345
b945c7c1
TM
1346 cleanEmptyObjectKeys: function (obj) {
1347 var propName;
1348 for (propName in obj) {
1349 if (obj.hasOwnProperty(propName)) {
1350 if (obj[propName] === null || obj[propName] === undefined) {
1351 delete obj[propName];
1352 }
1353 }
1354 }
4616a55b
TM
1355 },
1356
1357 handleStoreErrorOrMask: function(me, store, regex, callback) {
1358
1359 me.mon(store, 'load', function (proxy, response, success, operation) {
1360
1361 if (success) {
1362 Proxmox.Utils.setErrorMask(me, false);
1363 return;
1364 }
1365 var msg;
1366
1367 if (operation.error.statusText) {
1368 if (operation.error.statusText.match(regex)) {
1369 callback(me, operation.error);
1370 return;
1371 } else {
1372 msg = operation.error.statusText + ' (' + operation.error.status + ')';
1373 }
1374 } else {
1375 msg = gettext('Connection error');
1376 }
1377 Proxmox.Utils.setErrorMask(me, msg);
1378 });
1379 },
1380
1381 showCephInstallOrMask: function(container, msg, nodename, callback){
1382 var regex = new RegExp("not (installed|initialized)", "i");
1383 if (msg.match(regex)) {
1384 if (Proxmox.UserName === 'root@pam') {
1385 container.el.mask();
1386 if (!container.down('pveCephInstallWindow')){
f992ef80 1387 var isInstalled = msg.match(/not initialized/i) ? true : false;
4616a55b
TM
1388 var win = Ext.create('PVE.ceph.Install', {
1389 nodename: nodename
1390 });
f992ef80 1391 win.getViewModel().set('isInstalled', isInstalled);
4616a55b
TM
1392 container.add(win);
1393 win.show();
1394 callback(win);
1395 }
1396 } else {
a7e8b87b
TL
1397 container.mask(Ext.String.format(gettext('{0} not installed.') +
1398 ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']);
4616a55b
TM
1399 }
1400 return true;
1401 } else {
1402 return false;
1403 }
49dfba72
DC
1404 },
1405
1406 propertyStringSet: function(target, source, name, value) {
1407 if (source) {
1408 if (value === undefined) {
1409 target[name] = source;
1410 } else {
1411 target[name] = value;
1412 }
1413 } else {
1414 delete target[name];
1415 }
bbc83309
DC
1416 },
1417
1418 updateColumns: function(container) {
f973c5b2
DC
1419 let mode = Ext.state.Manager.get('summarycolumns') || 'auto';
1420 let factor;
1421 if (mode !== 'auto') {
1422 factor = parseInt(mode, 10);
1423 if (Number.isNaN(factor)) {
1424 factor = 1;
1425 }
1426 } else {
1427 factor = container.getSize().width < 1400 ? 1 : 2;
1428 }
bbc83309
DC
1429
1430 if (container.oldFactor === factor) {
1431 return;
1432 }
1433
1434 let items = container.query('>'); // direct childs
1435 factor = Math.min(factor, items.length);
1436 container.oldFactor = factor;
1437
1438 items.forEach((item) => {
1439 item.columnWidth = 1 / factor;
1440 });
1441
1442 // we have to update the layout twice, since the first layout change
1443 // can trigger the scrollbar which reduces the amount of space left
1444 container.updateLayout();
1445 container.updateLayout();
1446 },
e65817a1
SR
1447
1448 forEachCorosyncLink: function(nodeinfo, cb) {
1449 let re = /(?:ring|link)(\d+)_addr/;
1450 Ext.iterate(nodeinfo, (prop, val) => {
1451 let match = re.exec(prop);
1452 if (match) {
1453 cb(Number(match[1]), val);
1454 }
1455 });
1456 },
e7ade592 1457},
fe4f00ad 1458
9fa2e36d
EK
1459 singleton: true,
1460 constructor: function() {
1461 var me = this;
1462 Ext.apply(me, me.utilities);
685b7aa4 1463 }
e7ade592 1464
9fa2e36d 1465});