]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/Utils.js
ui: cifs: make user and password independent from each other
[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
8eccc68f 1019 openDefaultConsoleWindow: function(consoles, vmtype, vmid, nodename, vmname, cmd) {
3438c27e 1020 var dv = PVE.Utils.defaultViewer(consoles);
8eccc68f 1021 PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname, cmd);
b0a6d326
EK
1022 },
1023
8eccc68f 1024 openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname, cmd) {
9e361643 1025 // kvm, lxc, shell, upgrade
b0a6d326 1026
9e361643 1027 if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) {
b0a6d326
EK
1028 throw "missing vmid";
1029 }
1030
1031 if (!nodename) {
1032 throw "no nodename specified";
1033 }
1034
c7218ab3 1035 if (viewer === 'html5') {
8eccc68f 1036 PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname, cmd);
c6b2336c 1037 } else if (viewer === 'xtermjs') {
8eccc68f 1038 Proxmox.Utils.openXtermJsViewer(vmtype, vmid, nodename, vmname, cmd);
b0a6d326
EK
1039 } else if (viewer === 'vv') {
1040 var url;
aa0819a8 1041 var params = { proxy: PVE.Utils.windowHostname() };
b0a6d326
EK
1042 if (vmtype === 'kvm') {
1043 url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
1044 PVE.Utils.openSpiceViewer(url, params);
9e361643
DM
1045 } else if (vmtype === 'lxc') {
1046 url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy';
b0a6d326
EK
1047 PVE.Utils.openSpiceViewer(url, params);
1048 } else if (vmtype === 'shell') {
1049 url = '/nodes/' + nodename + '/spiceshell';
1050 PVE.Utils.openSpiceViewer(url, params);
1051 } else if (vmtype === 'upgrade') {
1052 url = '/nodes/' + nodename + '/spiceshell';
1053 params.upgrade = 1;
1054 PVE.Utils.openSpiceViewer(url, params);
8eccc68f
TM
1055 } else if (vmtype === 'cmd') {
1056 url = '/nodes/' + nodename + '/spiceshell';
1057 params.cmd = cmd;
1058 PVE.Utils.openSpiceViewer(url, params);
b0a6d326
EK
1059 }
1060 } else {
1061 throw "unknown viewer type";
1062 }
1063 },
1064
3438c27e
DC
1065 defaultViewer: function(consoles) {
1066
1067 var allowSpice, allowXtermjs;
1068
1069 if (consoles === true) {
1070 allowSpice = true;
1071 allowXtermjs = true;
1072 } else if (typeof consoles === 'object') {
1073 allowSpice = consoles.spice;
4ace5c6f 1074 allowXtermjs = !!consoles.xtermjs;
3438c27e 1075 }
da9d14cd 1076 var dv = PVE.VersionInfo.console || 'xtermjs';
f932cffa
DC
1077 if (dv === 'vv' && !allowSpice) {
1078 dv = (allowXtermjs) ? 'xtermjs' : 'html5';
1079 } else if (dv === 'xtermjs' && !allowXtermjs) {
1080 dv = (allowSpice) ? 'vv' : 'html5';
b0a6d326
EK
1081 }
1082
1083 return dv;
1084 },
1085
8eccc68f 1086 openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) {
af89f682
TL
1087 let scaling = 'off';
1088 if (Proxmox.Utils.toolkit !== 'touch') {
1089 var sp = Ext.state.Manager.getProvider();
1090 scaling = sp.get('novnc-scaling', 'off');
1091 }
8eccc68f 1092 var url = Ext.Object.toQueryString({
9e361643 1093 console: vmtype, // kvm, lxc, upgrade or shell
c7218ab3 1094 novnc: 1,
b0a6d326
EK
1095 vmid: vmid,
1096 vmname: vmname,
16e64c97 1097 node: nodename,
af89f682 1098 resize: scaling,
8eccc68f 1099 cmd: cmd
b0a6d326
EK
1100 });
1101 var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
7af1ab47
DC
1102 if (nw) {
1103 nw.focus();
1104 }
b0a6d326
EK
1105 },
1106
1107 openSpiceViewer: function(url, params){
1108
1109 var downloadWithName = function(uri, name) {
1110 var link = Ext.DomHelper.append(document.body, {
1111 tag: 'a',
1112 href: uri,
1113 css : 'display:none;visibility:hidden;height:0px;'
1114 });
1115
1116 // Note: we need to tell android the correct file name extension
1117 // but we do not set 'download' tag for other environments, because
1118 // It can have strange side effects (additional user prompt on firefox)
1119 var andriod = navigator.userAgent.match(/Android/i) ? true : false;
1120 if (andriod) {
1121 link.download = name;
1122 }
1123
1124 if (link.fireEvent) {
1125 link.fireEvent('onclick');
1126 } else {
1127 var evt = document.createEvent("MouseEvents");
1128 evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
1129 link.dispatchEvent(evt);
1130 }
1131 };
1132
e7ade592 1133 Proxmox.Utils.API2Request({
b0a6d326
EK
1134 url: url,
1135 params: params,
1136 method: 'POST',
1137 failure: function(response, opts){
1138 Ext.Msg.alert('Error', response.htmlStatus);
1139 },
1140 success: function(response, opts){
1141 var raw = "[virt-viewer]\n";
1142 Ext.Object.each(response.result.data, function(k, v) {
1143 raw += k + "=" + v + "\n";
1144 });
1145 var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
1146 encodeURIComponent(raw);
0be88ae1 1147
b0a6d326
EK
1148 downloadWithName(url, "pve-spice.vv");
1149 }
1150 });
1151 },
1152
e3129443
DC
1153 openTreeConsole: function(tree, record, item, index, e) {
1154 e.stopEvent();
1155 var nodename = record.data.node;
1156 var vmid = record.data.vmid;
1157 var vmname = record.data.name;
1158 if (record.data.type === 'qemu' && !record.data.template) {
e7ade592 1159 Proxmox.Utils.API2Request({
e3129443
DC
1160 url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
1161 failure: function(response, opts) {
1162 Ext.Msg.alert('Error', response.htmlStatus);
1163 },
1164 success: function(response, opts) {
bd9537d7 1165 let conf = response.result.data;
54453c38 1166 var consoles = {
bd9537d7
TL
1167 spice: !!conf.spice,
1168 xtermjs: !!conf.serial,
54453c38
DC
1169 };
1170 PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
e3129443
DC
1171 }
1172 });
1173 } else if (record.data.type === 'lxc' && !record.data.template) {
1174 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
1175 }
1176 },
1177
fbd60cfd
DM
1178 // test automation helper
1179 call_menu_handler: function(menu, text) {
1180
1181 var list = menu.query('menuitem');
1182
1183 Ext.Array.each(list, function(item) {
1184 if (item.text === text) {
1185 if (item.handler) {
1186 item.handler();
1187 return 1;
1188 } else {
1189 return undefined;
1190 }
1191 }
1192 });
1193 },
1194
685b7aa4
DC
1195 createCmdMenu: function(v, record, item, index, event) {
1196 event.stopEvent();
cc1a91be
DC
1197 if (!(v instanceof Ext.tree.View)) {
1198 v.select(record);
1199 }
685b7aa4 1200 var menu;
9bad05bd
DC
1201 var template = !!record.data.template;
1202 var type = record.data.type;
685b7aa4 1203
9bad05bd
DC
1204 if (template) {
1205 if (type === 'qemu' || type == 'lxc') {
1206 menu = Ext.create('PVE.menu.TemplateMenu', {
1207 pveSelNode: record
1208 });
1209 }
1210 } else if (type === 'qemu' ||
1211 type === 'lxc' ||
1212 type === 'node') {
1213 menu = Ext.create('PVE.' + type + '.CmdMenu', {
1214 pveSelNode: record,
c11ab8cb
DC
1215 nodename: record.data.node
1216 });
685b7aa4
DC
1217 } else {
1218 return;
1219 }
1220
1221 menu.showAt(event.getXY());
9f0b4e04 1222 return menu;
e7ade592 1223 },
9fa2e36d 1224
fe4f00ad
TL
1225 // helper for deleting field which are set to there default values
1226 delete_if_default: function(values, fieldname, default_val, create) {
1227 if (values[fieldname] === '' || values[fieldname] === default_val) {
1228 if (!create) {
1229 if (values['delete']) {
2db8e90d
DC
1230 if (Ext.isArray(values['delete'])) {
1231 values['delete'].push(fieldname);
1232 } else {
1233 values['delete'] += ',' + fieldname;
1234 }
fe4f00ad
TL
1235 } else {
1236 values['delete'] = fieldname;
1237 }
1238 }
1239
1240 delete values[fieldname];
1241 }
857b97a7
TL
1242 },
1243
1244 loadSSHKeyFromFile: function(file, callback) {
1245 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1246 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1247 // assume: 740*8 for max. 32kbit (5920 byte file)
1248 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1249 if (file.size > 8192) {
1250 Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
1251 return;
1252 }
1253 /*global
1254 FileReader
1255 */
1256 var reader = new FileReader();
1257 reader.onload = function(evt) {
1258 callback(evt.target.result);
1259 };
1260 reader.readAsText(file);
abe824aa
DC
1261 },
1262
8c4ec8c7
TL
1263 diskControllerMaxIDs: {
1264 ide: 4,
1265 sata: 6,
cf0d139e 1266 scsi: 31,
8c4ec8c7
TL
1267 virtio: 16,
1268 },
abe824aa
DC
1269
1270 // types is either undefined (all busses), an array of busses, or a single bus
1271 forEachBus: function(types, func) {
8c4ec8c7 1272 var busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
abe824aa
DC
1273 var i, j, count, cont;
1274
1275 if (Ext.isArray(types)) {
1276 busses = types;
1277 } else if (Ext.isDefined(types)) {
1278 busses = [ types ];
1279 }
1280
1281 // check if we only have valid busses
1282 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1283 if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) {
abe824aa
DC
1284 throw "invalid bus: '" + busses[i] + "'";
1285 }
1286 }
1287
1288 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1289 count = PVE.Utils.diskControllerMaxIDs[busses[i]];
abe824aa
DC
1290 for (j = 0; j < count; j++) {
1291 cont = func(busses[i], j);
1292 if (!cont && cont !== undefined) {
1293 return;
1294 }
1295 }
1296 }
14a845bc
DC
1297 },
1298
483bd394 1299 mp_counts: { mps: 256, unused: 256 },
14a845bc
DC
1300
1301 forEachMP: function(func, includeUnused) {
1302 var i, cont;
1303 for (i = 0; i < PVE.Utils.mp_counts.mps; i++) {
1304 cont = func('mp', i);
1305 if (!cont && cont !== undefined) {
1306 return;
1307 }
1308 }
1309
1310 if (!includeUnused) {
1311 return;
1312 }
1313
1314 for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
1315 cont = func('unused', i);
1316 if (!cont && cont !== undefined) {
1317 return;
1318 }
1319 }
b945c7c1
TM
1320 },
1321
6c1d8ead 1322 hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1 },
9d855398 1323
b945c7c1
TM
1324 cleanEmptyObjectKeys: function (obj) {
1325 var propName;
1326 for (propName in obj) {
1327 if (obj.hasOwnProperty(propName)) {
1328 if (obj[propName] === null || obj[propName] === undefined) {
1329 delete obj[propName];
1330 }
1331 }
1332 }
4616a55b
TM
1333 },
1334
eadbbb4a
DC
1335 acmedomain_count: 5,
1336
1337 add_domain_to_acme: function(acme, domain) {
1338 if (acme.domains === undefined) {
1339 acme.domains = [domain];
1340 } else {
1341 acme.domains.push(domain);
1342 acme.domains = acme.domains.filter((value, index, self) => {
1343 return self.indexOf(value) === index;
1344 });
1345 }
1346 return acme;
1347 },
1348
1349 remove_domain_from_acme: function(acme, domain) {
1350 if (acme.domains !== undefined) {
1351 acme.domains = acme.domains.filter((value, index, self) => {
1352 return self.indexOf(value) === index && value !== domain;
1353 });
1354 }
1355 return acme;
1356 },
1357
4616a55b
TM
1358 handleStoreErrorOrMask: function(me, store, regex, callback) {
1359
1360 me.mon(store, 'load', function (proxy, response, success, operation) {
1361
1362 if (success) {
1363 Proxmox.Utils.setErrorMask(me, false);
1364 return;
1365 }
1366 var msg;
1367
1368 if (operation.error.statusText) {
1369 if (operation.error.statusText.match(regex)) {
1370 callback(me, operation.error);
1371 return;
1372 } else {
1373 msg = operation.error.statusText + ' (' + operation.error.status + ')';
1374 }
1375 } else {
1376 msg = gettext('Connection error');
1377 }
1378 Proxmox.Utils.setErrorMask(me, msg);
1379 });
1380 },
1381
1382 showCephInstallOrMask: function(container, msg, nodename, callback){
1383 var regex = new RegExp("not (installed|initialized)", "i");
1384 if (msg.match(regex)) {
1385 if (Proxmox.UserName === 'root@pam') {
1386 container.el.mask();
1387 if (!container.down('pveCephInstallWindow')){
f992ef80 1388 var isInstalled = msg.match(/not initialized/i) ? true : false;
4616a55b
TM
1389 var win = Ext.create('PVE.ceph.Install', {
1390 nodename: nodename
1391 });
f992ef80 1392 win.getViewModel().set('isInstalled', isInstalled);
4616a55b
TM
1393 container.add(win);
1394 win.show();
1395 callback(win);
1396 }
1397 } else {
a7e8b87b
TL
1398 container.mask(Ext.String.format(gettext('{0} not installed.') +
1399 ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']);
4616a55b
TM
1400 }
1401 return true;
1402 } else {
1403 return false;
1404 }
49dfba72
DC
1405 },
1406
1407 propertyStringSet: function(target, source, name, value) {
1408 if (source) {
1409 if (value === undefined) {
1410 target[name] = source;
1411 } else {
1412 target[name] = value;
1413 }
1414 } else {
1415 delete target[name];
1416 }
bbc83309
DC
1417 },
1418
1419 updateColumns: function(container) {
f973c5b2
DC
1420 let mode = Ext.state.Manager.get('summarycolumns') || 'auto';
1421 let factor;
1422 if (mode !== 'auto') {
1423 factor = parseInt(mode, 10);
1424 if (Number.isNaN(factor)) {
1425 factor = 1;
1426 }
1427 } else {
1428 factor = container.getSize().width < 1400 ? 1 : 2;
1429 }
bbc83309
DC
1430
1431 if (container.oldFactor === factor) {
1432 return;
1433 }
1434
1435 let items = container.query('>'); // direct childs
1436 factor = Math.min(factor, items.length);
1437 container.oldFactor = factor;
1438
1439 items.forEach((item) => {
1440 item.columnWidth = 1 / factor;
1441 });
1442
1443 // we have to update the layout twice, since the first layout change
1444 // can trigger the scrollbar which reduces the amount of space left
1445 container.updateLayout();
1446 container.updateLayout();
1447 },
e65817a1
SR
1448
1449 forEachCorosyncLink: function(nodeinfo, cb) {
1450 let re = /(?:ring|link)(\d+)_addr/;
1451 Ext.iterate(nodeinfo, (prop, val) => {
1452 let match = re.exec(prop);
1453 if (match) {
1454 cb(Number(match[1]), val);
1455 }
1456 });
1457 },
4546808c
SR
1458
1459 cpu_vendor_map: {
1460 'default': 'QEMU',
1461 'AuthenticAMD': 'AMD',
1462 'GenuineIntel': 'Intel'
1463 },
1464
1465 cpu_vendor_order: {
1466 "AMD": 1,
1467 "Intel": 2,
1468 "QEMU": 3,
1469 "Host": 4,
1470 "_default_": 5, // includes custom models
1471 },
e7ade592 1472},
fe4f00ad 1473
9fa2e36d
EK
1474 singleton: true,
1475 constructor: function() {
1476 var me = this;
1477 Ext.apply(me, me.utilities);
685b7aa4 1478 }
e7ade592 1479
9fa2e36d 1480});