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