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