]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/Utils.js
ui: storage: base: allow adding extra tab panels
[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
01ad47af
AL
222 render_backup_status: function(value, meta, record) {
223 if (typeof value == 'undefined') {
224 return "";
225 }
226
227 let iconCls = 'check-circle good';
228 let text = gettext('Yes');
229
230 if (!PVE.Parser.parseBoolean(value.toString())) {
231 iconCls = 'times-circle critical';
232
233 text = gettext('No');
234
235 let reason = record.get('reason');
236 if (typeof reason !== 'undefined') {
237 if (reason in PVE.Utils.backup_reasons_table) {
238 reason = PVE.Utils.backup_reasons_table[record.get('reason')];
239 }
240 text = `${text} - ${reason}`;
241 }
242 }
243
244 return `<i class="fa fa-${iconCls}"></i> ${text}`;
245 },
246
7f08d0d1
AL
247 render_backup_days_of_week: function(val) {
248 var dows = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
249 var selected = [];
250 var cur = -1;
251 val.split(',').forEach(function(day){
252 cur++;
253 var dow = (dows.indexOf(day)+6)%7;
254 if (cur === dow) {
255 if (selected.length === 0 || selected[selected.length-1] === 0) {
256 selected.push(1);
257 } else {
258 selected[selected.length-1]++;
259 }
260 } else {
261 while (cur < dow) {
262 cur++;
263 selected.push(0);
264 }
265 selected.push(1);
266 }
267 });
268
269 cur = -1;
270 var days = [];
271 selected.forEach(function(item) {
272 cur++;
273 if (item > 2) {
274 days.push(Ext.Date.dayNames[(cur+1)] + '-' + Ext.Date.dayNames[(cur+item)%7]);
275 cur += item-1;
276 } else if (item == 2) {
277 days.push(Ext.Date.dayNames[cur+1]);
278 days.push(Ext.Date.dayNames[(cur+2)%7]);
279 cur++;
280 } else if (item == 1) {
281 days.push(Ext.Date.dayNames[(cur+1)%7]);
282 }
283 });
284 return days.join(', ');
285 },
286
287 render_backup_selection: function(value, metaData, record) {
288 let allExceptText = gettext('All except {0}');
289 let allText = '-- ' + gettext('All') + ' --';
290 if (record.data.all) {
291 if (record.data.exclude) {
292 return Ext.String.format(allExceptText, record.data.exclude);
293 }
294 return allText;
295 }
296 if (record.data.vmid) {
297 return record.data.vmid;
298 }
299
300 if (record.data.pool) {
301 return "Pool '"+ record.data.pool + "'";
302 }
303
304 return "-";
305 },
306
01ad47af
AL
307 backup_reasons_table: {
308 'backup=yes': gettext('Enabled'),
309 'backup=no': gettext('Disabled'),
310 'enabled': gettext('Enabled'),
311 'disabled': gettext('Disabled'),
312 'not a volume': gettext('Not a volume'),
313 'efidisk but no OMVF BIOS': gettext('EFI Disk without OMVF BIOS'),
314 },
315
45d6c71a
TL
316 get_kvm_osinfo: function(value) {
317 var info = { base: 'Other' }; // default
318 if (value) {
319 Ext.each(Object.keys(PVE.Utils.kvm_ostypes), function(k) {
320 Ext.each(PVE.Utils.kvm_ostypes[k], function(e) {
321 if (e.val === value) {
322 info = { desc: e.desc, base: k };
323 }
324 });
325 });
b0a6d326 326 }
45d6c71a
TL
327 return info;
328 },
329
330 render_kvm_ostype: function (value) {
331 var osinfo = PVE.Utils.get_kvm_osinfo(value);
332 if (osinfo.desc && osinfo.desc !== '-') {
333 return osinfo.base + ' ' + osinfo.desc;
334 } else {
335 return osinfo.base;
b0a6d326 336 }
b0a6d326
EK
337 },
338
339 render_hotplug_features: function (value) {
23d3881a 340 var fa = [];
b0a6d326
EK
341
342 if (!value || (value === '0')) {
ec99b1c3 343 return gettext('Disabled');
b0a6d326
EK
344 }
345
4dcca8a4
DC
346 if (value === '1') {
347 value = 'disk,network,usb';
348 }
349
b0a6d326
EK
350 Ext.each(value.split(','), function(el) {
351 if (el === 'disk') {
352 fa.push(gettext('Disk'));
353 } else if (el === 'network') {
354 fa.push(gettext('Network'));
355 } else if (el === 'usb') {
b9628aa5 356 fa.push('USB');
b0a6d326
EK
357 } else if (el === 'memory') {
358 fa.push(gettext('Memory'));
359 } else if (el === 'cpu') {
360 fa.push(gettext('CPU'));
361 } else {
362 fa.push(el);
363 }
364 });
365
366 return fa.join(', ');
367 },
368
0beff18b
FE
369 render_localtime: function(value) {
370 if (value === '__default__') {
371 return Proxmox.Utils.defaultText + ' (' + gettext('Enabled for Windows') + ')';
372 }
373 return Proxmox.Utils.format_boolean(value);
374 },
375
1662ccdb
SI
376 render_qga_features: function(value) {
377 if (!value) {
378 return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText + ')';
379 }
380 var props = PVE.Parser.parsePropertyString(value, 'enabled');
381 if (!PVE.Parser.parseBoolean(props.enabled)) {
382 return Proxmox.Utils.disabledText;
383 }
384
385 delete props.enabled;
386 var agentstring = Proxmox.Utils.enabledText;
387
388 Ext.Object.each(props, function(key, value) {
389 var keystring = '' ;
390 agentstring += ', ' + key + ': ';
391
5a6c563c
MD
392 if (key === 'type') {
393 let map = {
394 isa: "ISA",
176a62d3 395 virtio: "VirtIO",
5a6c563c
MD
396 };
397 agentstring += map[value] || Proxmox.Utils.unknownText;
1662ccdb 398 } else {
5a6c563c
MD
399 if (PVE.Parser.parseBoolean(value)) {
400 agentstring += Proxmox.Utils.enabledText;
401 } else {
402 agentstring += Proxmox.Utils.disabledText;
403 }
1662ccdb
SI
404 }
405 });
406
407 return agentstring;
408 },
409
a1ee14a2
DC
410 render_qemu_machine: function(value) {
411 return value || (Proxmox.Utils.defaultText + ' (i440fx)');
412 },
413
17c71f27
DC
414 render_qemu_bios: function(value) {
415 if (!value) {
e7ade592 416 return Proxmox.Utils.defaultText + ' (SeaBIOS)';
17c71f27
DC
417 } else if (value === 'seabios') {
418 return "SeaBIOS";
419 } else if (value === 'ovmf') {
420 return "OVMF (UEFI)";
421 } else {
422 return value;
423 }
424 },
425
8f17b496
TL
426 render_dc_ha_opts: function(value) {
427 if (!value) {
41ca3465 428 return Proxmox.Utils.defaultText;
8f17b496
TL
429 } else {
430 return PVE.Parser.printPropertyString(value);
431 }
432 },
bb469a11
TL
433 render_as_property_string: function(value) {
434 return (!value) ? Proxmox.Utils.defaultText
435 : PVE.Parser.printPropertyString(value);
436 },
8f17b496 437
b0a6d326
EK
438 render_scsihw: function(value) {
439 if (!value) {
e7ade592 440 return Proxmox.Utils.defaultText + ' (LSI 53C895A)';
b0a6d326
EK
441 } else if (value === 'lsi') {
442 return 'LSI 53C895A';
443 } else if (value === 'lsi53c810') {
444 return 'LSI 53C810';
445 } else if (value === 'megasas') {
446 return 'MegaRAID SAS 8708EM2';
447 } else if (value === 'virtio-scsi-pci') {
49f5d1ab
EK
448 return 'VirtIO SCSI';
449 } else if (value === 'virtio-scsi-single') {
450 return 'VirtIO SCSI single';
b0a6d326
EK
451 } else if (value === 'pvscsi') {
452 return 'VMware PVSCSI';
453 } else {
454 return value;
455 }
456 },
457
9c22da32 458 render_spice_enhancements: function(values) {
9c22da32
AL
459 let props = PVE.Parser.parsePropertyString(values);
460 if (Ext.Object.isEmpty(props)) {
3b0facc9 461 return Proxmox.Utils.noneText;
9c22da32
AL
462 }
463
464 let output = [];
465 if (PVE.Parser.parseBoolean(props.foldersharing)) {
466 output.push('Folder Sharing: ' + gettext('Enabled'));
467 }
468 if (props.videostreaming === 'all' || props.videostreaming === 'filter') {
469 output.push('Video Streaming: ' + props.videostreaming);
470 }
471 return output.join(', ');
472 },
473
b0a6d326
EK
474 // fixme: auto-generate this
475 // for now, please keep in sync with PVE::Tools::kvmkeymaps
476 kvm_keymaps: {
477 //ar: 'Arabic',
478 da: 'Danish',
0be88ae1
DC
479 de: 'German',
480 'de-ch': 'German (Swiss)',
481 'en-gb': 'English (UK)',
0a5b8747 482 'en-us': 'English (USA)',
b0a6d326
EK
483 es: 'Spanish',
484 //et: 'Estonia',
485 fi: 'Finnish',
0be88ae1
DC
486 //fo: 'Faroe Islands',
487 fr: 'French',
488 'fr-be': 'French (Belgium)',
b0a6d326
EK
489 'fr-ca': 'French (Canada)',
490 'fr-ch': 'French (Swiss)',
491 //hr: 'Croatia',
492 hu: 'Hungarian',
493 is: 'Icelandic',
0be88ae1 494 it: 'Italian',
b0a6d326
EK
495 ja: 'Japanese',
496 lt: 'Lithuanian',
497 //lv: 'Latvian',
0be88ae1 498 mk: 'Macedonian',
b0a6d326
EK
499 nl: 'Dutch',
500 //'nl-be': 'Dutch (Belgium)',
0be88ae1 501 no: 'Norwegian',
b0a6d326
EK
502 pl: 'Polish',
503 pt: 'Portuguese',
504 'pt-br': 'Portuguese (Brazil)',
505 //ru: 'Russian',
506 sl: 'Slovenian',
507 sv: 'Swedish',
508 //th: 'Thai',
509 tr: 'Turkish'
510 },
511
512 kvm_vga_drivers: {
513 std: gettext('Standard VGA'),
5ca366f2 514 vmware: gettext('VMware compatible'),
b0a6d326
EK
515 qxl: 'SPICE',
516 qxl2: 'SPICE dual monitor',
517 qxl3: 'SPICE three monitors',
518 qxl4: 'SPICE four monitors',
519 serial0: gettext('Serial terminal') + ' 0',
520 serial1: gettext('Serial terminal') + ' 1',
521 serial2: gettext('Serial terminal') + ' 2',
89ae1bb1
DC
522 serial3: gettext('Serial terminal') + ' 3',
523 virtio: 'VirtIO-GPU',
524 none: Proxmox.Utils.noneText
b0a6d326
EK
525 },
526
527 render_kvm_language: function (value) {
e7ade592
DC
528 if (!value || value === '__default__') {
529 return Proxmox.Utils.defaultText;
b0a6d326
EK
530 }
531 var text = PVE.Utils.kvm_keymaps[value];
532 if (text) {
533 return text + ' (' + value + ')';
534 }
535 return value;
536 },
537
538 kvm_keymap_array: function() {
f2782813 539 var data = [['__default__', PVE.Utils.render_kvm_language('')]];
b0a6d326
EK
540 Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) {
541 data.push([key, PVE.Utils.render_kvm_language(value)]);
542 });
543
544 return data;
545 },
546
3438c27e 547 console_map: {
da9d14cd 548 '__default__': Proxmox.Utils.defaultText + ' (xterm.js)',
3438c27e
DC
549 'vv': 'SPICE (remote-viewer)',
550 'html5': 'HTML5 (noVNC)',
4ace5c6f 551 'xtermjs': 'xterm.js'
3438c27e
DC
552 },
553
b0a6d326 554 render_console_viewer: function(value) {
3438c27e
DC
555 value = value || '__default__';
556 if (PVE.Utils.console_map[value]) {
557 return PVE.Utils.console_map[value];
b0a6d326 558 }
3438c27e 559 return value;
b0a6d326
EK
560 },
561
755b9083 562 console_viewer_array: function() {
3438c27e 563 return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) {
755b9083
TL
564 return [v, PVE.Utils.render_console_viewer(v)];
565 });
566 },
567
b0a6d326
EK
568 render_kvm_vga_driver: function (value) {
569 if (!value) {
e7ade592 570 return Proxmox.Utils.defaultText;
b0a6d326 571 }
4f3e66d8
DC
572 var vga = PVE.Parser.parsePropertyString(value, 'type');
573 var text = PVE.Utils.kvm_vga_drivers[vga.type];
574 if (!vga.type) {
575 text = Proxmox.Utils.defaultText;
576 }
0be88ae1 577 if (text) {
b0a6d326
EK
578 return text + ' (' + value + ')';
579 }
580 return value;
581 },
582
583 kvm_vga_driver_array: function() {
f2782813 584 var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]];
b0a6d326
EK
585 Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) {
586 data.push([key, PVE.Utils.render_kvm_vga_driver(value)]);
587 });
588
589 return data;
590 },
591
592 render_kvm_startup: function(value) {
593 var startup = PVE.Parser.parseStartup(value);
594
595 var res = 'order=';
596 if (startup.order === undefined) {
597 res += 'any';
598 } else {
599 res += startup.order;
600 }
601 if (startup.up !== undefined) {
602 res += ',up=' + startup.up;
603 }
604 if (startup.down !== undefined) {
605 res += ',down=' + startup.down;
606 }
607
608 return res;
609 },
610
b0a6d326
EK
611 extractFormActionError: function(action) {
612 var msg;
613 switch (action.failureType) {
614 case Ext.form.action.Action.CLIENT_INVALID:
615 msg = gettext('Form fields may not be submitted with invalid values');
616 break;
617 case Ext.form.action.Action.CONNECT_FAILURE:
618 msg = gettext('Connection error');
619 var resp = action.response;
620 if (resp.status && resp.statusText) {
621 msg += " " + resp.status + ": " + resp.statusText;
622 }
623 break;
624 case Ext.form.action.Action.LOAD_FAILURE:
625 case Ext.form.action.Action.SERVER_INVALID:
e7ade592 626 msg = Proxmox.Utils.extractRequestError(action.result, true);
b0a6d326
EK
627 break;
628 }
629 return msg;
630 },
631
0e244a29
DC
632 contentTypes: {
633 'images': gettext('Disk image'),
634 'backup': gettext('VZDump backup file'),
635 'vztmpl': gettext('Container template'),
636 'iso': gettext('ISO image'),
aef28e04
DC
637 'rootdir': gettext('Container'),
638 'snippets': gettext('Snippets')
0e244a29 639 },
b0a6d326 640
3b8f599b
DM
641 volume_is_qemu_backup: function(volid, format) {
642 return format === 'pbs-vm' || volid.match(':backup/vzdump-qemu-');
643 },
644
645 volume_is_lxc_backup: function(volid, format) {
646 return format === 'pbs-ct' || volid.match(':backup/vzdump-(lxc|openvz)-');
647 },
648
efff7eab
DC
649 authSchema: {
650 ad: {
651 name: gettext('Active Directory Server'),
652 ipanel: 'pveAuthADPanel',
822fb26d 653 syncipanel: 'pveAuthLDAPSyncPanel',
efff7eab
DC
654 add: true,
655 },
656 ldap: {
657 name: gettext('LDAP Server'),
658 ipanel: 'pveAuthLDAPPanel',
822fb26d 659 syncipanel: 'pveAuthLDAPSyncPanel',
efff7eab
DC
660 add: true,
661 },
662 pam: {
663 name: 'Linux PAM',
664 ipanel: 'pveAuthBasePanel',
665 add: false,
666 },
667 pve: {
668 name: 'Proxmox VE authentication server',
669 ipanel: 'pveAuthBasePanel',
670 add: false,
671 },
672 },
673
062a7f49
TL
674 storageSchema: {
675 dir: {
676 name: Proxmox.Utils.directoryText,
677 ipanel: 'DirInputPanel',
678 faIcon: 'folder'
679 },
680 lvm: {
681 name: 'LVM',
682 ipanel: 'LVMInputPanel',
683 faIcon: 'folder'
684 },
685 lvmthin: {
686 name: 'LVM-Thin',
687 ipanel: 'LvmThinInputPanel',
688 faIcon: 'folder'
689 },
690 nfs: {
691 name: 'NFS',
692 ipanel: 'NFSInputPanel',
693 faIcon: 'building'
694 },
695 cifs: {
696 name: 'CIFS',
697 ipanel: 'CIFSInputPanel',
698 faIcon: 'building'
699 },
700 glusterfs: {
701 name: 'GlusterFS',
702 ipanel: 'GlusterFsInputPanel',
703 faIcon: 'building'
704 },
705 iscsi: {
706 name: 'iSCSI',
707 ipanel: 'IScsiInputPanel',
708 faIcon: 'building'
709 },
4a4b2b6e
TL
710 cephfs: {
711 name: 'CephFS',
712 ipanel: 'CephFSInputPanel',
713 faIcon: 'building'
714 },
715 pvecephfs: {
716 name: 'CephFS (PVE)',
717 ipanel: 'CephFSInputPanel',
718 hideAdd: true,
719 faIcon: 'building'
720 },
062a7f49
TL
721 rbd: {
722 name: 'RBD',
723 ipanel: 'RBDInputPanel',
062a7f49
TL
724 faIcon: 'building'
725 },
726 pveceph: {
727 name: 'RBD (PVE)',
0d1ac958
TL
728 ipanel: 'RBDInputPanel',
729 hideAdd: true,
062a7f49
TL
730 faIcon: 'building'
731 },
732 zfs: {
733 name: 'ZFS over iSCSI',
734 ipanel: 'ZFSInputPanel',
735 faIcon: 'building'
736 },
737 zfspool: {
738 name: 'ZFS',
739 ipanel: 'ZFSPoolInputPanel',
740 faIcon: 'folder'
741 },
8b966034
TL
742 pbs: {
743 name: 'Proxmox Backup Server',
ee19d331
TL
744 ipanel: 'PBSInputPanel',
745 faIcon: 'floppy-o',
8b966034 746 },
062a7f49
TL
747 drbd: {
748 name: 'DRBD',
8b966034
TL
749 hideAdd: true,
750 },
062a7f49
TL
751 },
752
9233148b
AD
753 sdnvnetSchema: {
754 vnet: {
755 name: 'vnet',
756 faIcon: 'folder'
757 },
758 },
759
760 sdnzoneSchema: {
761 zone: {
762 name: 'zone',
763 hideAdd: true
764 },
1b4cce60
AD
765 simple: {
766 name: 'Simple',
767 ipanel: 'SimpleInputPanel',
768 faIcon: 'th'
769 },
9233148b 770 vlan: {
f3c1eac7 771 name: 'VLAN',
9233148b 772 ipanel: 'VlanInputPanel',
f3c1eac7 773 faIcon: 'th'
9233148b
AD
774 },
775 qinq: {
f3c1eac7 776 name: 'QinQ',
9233148b 777 ipanel: 'QinQInputPanel',
f3c1eac7 778 faIcon: 'th'
9233148b
AD
779 },
780 vxlan: {
f3c1eac7 781 name: 'VXLAN',
9233148b 782 ipanel: 'VxlanInputPanel',
f3c1eac7 783 faIcon: 'th'
9233148b
AD
784 },
785 evpn: {
f3c1eac7 786 name: 'EVPN',
9233148b 787 ipanel: 'EvpnInputPanel',
f3c1eac7 788 faIcon: 'th'
9233148b
AD
789 },
790 },
791
792 sdncontrollerSchema: {
793 controller: {
794 name: 'controller',
795 hideAdd: true
796 },
797 evpn: {
798 name: 'evpn',
799 ipanel: 'EvpnInputPanel',
f3c1eac7 800 faIcon: 'crosshairs'
9233148b
AD
801 },
802 },
803
804 format_sdnvnet_type: function(value, md, record) {
805 var schema = PVE.Utils.sdnvnetSchema[value];
806 if (schema) {
807 return schema.name;
808 }
809 return Proxmox.Utils.unknownText;
810 },
811
812 format_sdnzone_type: function(value, md, record) {
813 var schema = PVE.Utils.sdnzoneSchema[value];
814 if (schema) {
f3c1eac7 815 return schema.name;
9233148b
AD
816 }
817 return Proxmox.Utils.unknownText;
818 },
819
820 format_sdncontroller_type: function(value, md, record) {
821 var schema = PVE.Utils.sdncontrollerSchema[value];
822 if (schema) {
823 return schema.name;
824 }
825 return Proxmox.Utils.unknownText;
826 },
827
3c23c025 828 format_storage_type: function(value, md, record) {
4a4b2b6e
TL
829 if (value === 'rbd') {
830 value = (!record || record.get('monhost') ? 'rbd' : 'pveceph');
831 } else if (value === 'cephfs') {
832 value = (!record || record.get('monhost') ? 'cephfs' : 'pvecephfs');
3c23c025 833 }
062a7f49
TL
834
835 var schema = PVE.Utils.storageSchema[value];
836 if (schema) {
837 return schema.name;
b0a6d326 838 }
062a7f49 839 return Proxmox.Utils.unknownText;
a3b8efb4
EK
840 },
841
ced1677b 842 format_ha: function(value) {
e7ade592 843 var text = Proxmox.Utils.noneText;
ced1677b
TL
844
845 if (value.managed) {
e7ade592 846 text = value.state || Proxmox.Utils.noneText;
ced1677b 847
e7ade592
DC
848 text += ', ' + Proxmox.Utils.groupText + ': ';
849 text += value.group || Proxmox.Utils.noneText;
ced1677b
TL
850 }
851
852 return text;
853 },
854
b0a6d326 855 format_content_types: function(value) {
0e244a29
DC
856 return value.split(',').sort().map(function(ct) {
857 return PVE.Utils.contentTypes[ct] || ct;
858 }).join(', ');
b0a6d326
EK
859 },
860
861 render_storage_content: function(value, metaData, record) {
862 var data = record.data;
863 if (Ext.isNumber(data.channel) &&
864 Ext.isNumber(data.id) &&
865 Ext.isNumber(data.lun)) {
0be88ae1
DC
866 return "CH " +
867 Ext.String.leftPad(data.channel,2, '0') +
b0a6d326
EK
868 " ID " + data.id + " LUN " + data.lun;
869 }
3b8f599b 870 return data.volid.replace(/^.*?:(.*?\/)?/,'');
b0a6d326
EK
871 },
872
873 render_serverity: function (value) {
874 return PVE.Utils.log_severity_hash[value] || value;
875 },
876
877 render_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
878
879 if (!(record.data.uptime && Ext.isNumeric(value))) {
880 return '';
881 }
882
883 var maxcpu = record.data.maxcpu || 1;
884
885 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
886 return '';
887 }
0be88ae1 888
b0a6d326
EK
889 var per = value * 100;
890
891 return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
892 },
893
894 render_size: function(value, metaData, record, rowIndex, colIndex, store) {
b0a6d326
EK
895
896 if (!Ext.isNumeric(value)) {
897 return '';
898 }
899
e7ade592 900 return Proxmox.Utils.format_size(value);
b0a6d326
EK
901 },
902
946730cd
DC
903 render_bandwidth: function(value) {
904 if (!Ext.isNumeric(value)) {
905 return '';
906 }
907
e7ade592 908 return Proxmox.Utils.format_size(value) + '/s';
b0a6d326
EK
909 },
910
3f633655
EK
911 render_timestamp_human_readable: function(value) {
912 return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s');
913 },
914
0bfc799f
DC
915 calculate_mem_usage: function(data) {
916 if (!Ext.isNumeric(data.mem) ||
917 data.maxmem === 0 ||
918 data.uptime < 1) {
919 return -1;
920 }
921
922 return (data.mem / data.maxmem);
923 },
924
925 render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
926 if (!Ext.isNumeric(value) || value === -1) {
927 return '';
928 }
929 if (value > 1 ) {
930 // we got no percentage but bytes
931 var mem = value;
932 var maxmem = record.data.maxmem;
933 if (!record.data.uptime ||
934 maxmem === 0 ||
935 !Ext.isNumeric(mem)) {
936 return '';
937 }
938
939 return ((mem*100)/maxmem).toFixed(1) + " %";
940 }
941 return (value*100).toFixed(1) + " %";
942 },
943
b0a6d326
EK
944 render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
945
946 var mem = value;
947 var maxmem = record.data.maxmem;
0be88ae1 948
b0a6d326
EK
949 if (!record.data.uptime) {
950 return '';
951 }
952
953 if (!(Ext.isNumeric(mem) && maxmem)) {
954 return '';
955 }
956
728f1b97 957 return PVE.Utils.render_size(value);
b0a6d326
EK
958 },
959
0bfc799f
DC
960 calculate_disk_usage: function(data) {
961
962 if (!Ext.isNumeric(data.disk) ||
963 data.type === 'qemu' ||
964 (data.type === 'lxc' && data.uptime === 0) ||
965 data.maxdisk === 0) {
966 return -1;
967 }
968
969 return (data.disk / data.maxdisk);
970 },
971
972 render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
973 if (!Ext.isNumeric(value) || value === -1) {
974 return '';
975 }
976
977 return (value * 100).toFixed(1) + " %";
978 },
979
b0a6d326
EK
980 render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
981
982 var disk = value;
983 var maxdisk = record.data.maxdisk;
728f1b97 984 var type = record.data.type;
b0a6d326 985
728f1b97
DC
986 if (!Ext.isNumeric(disk) ||
987 type === 'qemu' ||
988 maxdisk === 0 ||
989 (type === 'lxc' && record.data.uptime === 0)) {
b0a6d326
EK
990 return '';
991 }
992
728f1b97 993 return PVE.Utils.render_size(value);
b0a6d326
EK
994 },
995
4dbc64a7
DC
996 get_object_icon_class: function(type, record) {
997 var status = '';
998 var objType = type;
999
1000 if (type === 'type') {
1001 // for folder view
1002 objType = record.groupbyid;
1003 } else if (record.template) {
1004 // templates
1005 objType = 'template';
1006 status = type;
1007 } else {
1008 // everything else
1009 status = record.status + ' ha-' + record.hastate;
b1d8e73d
DC
1010 }
1011
6284a48a
DC
1012 if (record.lock) {
1013 status += ' locked lock-' + record.lock;
1014 }
1015
4dbc64a7
DC
1016 var defaults = PVE.tree.ResourceTree.typeDefaults[objType];
1017 if (defaults && defaults.iconCls) {
1018 var retVal = defaults.iconCls + ' ' + status;
1019 return retVal;
b0a6d326
EK
1020 }
1021
4dbc64a7
DC
1022 return '';
1023 },
1024
1025 render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
1026
1027 var cls = PVE.Utils.get_object_icon_class(value,record.data);
2b2fe160 1028
4dbc64a7 1029 var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> ';
b1d8e73d 1030 return fa + value;
b0a6d326
EK
1031 },
1032
b0a6d326
EK
1033 render_support_level: function(value, metaData, record) {
1034 return PVE.Utils.support_level_hash[value] || '-';
1035 },
1036
0be88ae1 1037 render_upid: function(value, metaData, record) {
b0a6d326
EK
1038 var type = record.data.type;
1039 var id = record.data.id;
1040
e7ade592 1041 return Proxmox.Utils.format_task_description(type, id);
b0a6d326
EK
1042 },
1043
054ac1b8
DC
1044 /* render functions for new status panel */
1045
1046 render_usage: function(val) {
1047 return (val*100).toFixed(2) + '%';
1048 },
1049
1050 render_cpu_usage: function(val, max) {
1051 return Ext.String.format(gettext('{0}% of {1}') +
1052 ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max);
1053 },
1054
1055 render_size_usage: function(val, max) {
bab64974
DC
1056 if (max === 0) {
1057 return gettext('N/A');
1058 }
054ac1b8
DC
1059 return (val*100/max).toFixed(2) + '% '+ '(' +
1060 Ext.String.format(gettext('{0} of {1}'),
1061 PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')';
1062 },
1063
1064 /* this is different for nodes */
1065 render_node_cpu_usage: function(value, record) {
1066 return PVE.Utils.render_cpu_usage(value, record.cpus);
1067 },
1068
1069 /* this is different for nodes */
1070 render_node_size_usage: function(record) {
1071 return PVE.Utils.render_size_usage(record.used, record.total);
1072 },
1073
27809975
DC
1074 render_optional_url: function(value) {
1075 var match;
1076 if (value && (match = value.match(/^https?:\/\//)) !== null) {
cdd9b6c0 1077 return '<a target="_blank" href="' + value + '">' + value + '</a>';
27809975
DC
1078 }
1079 return value;
1080 },
1081
1082 render_san: function(value) {
1083 var names = [];
1084 if (Ext.isArray(value)) {
1085 value.forEach(function(val) {
1086 if (!Ext.isNumber(val)) {
1087 names.push(val);
1088 }
1089 });
1090 return names.join('<br>');
1091 }
1092 return value;
1093 },
1094
6ad4be69
DC
1095 render_full_name: function(firstname, metaData, record) {
1096 var first = firstname || '';
1097 var last = record.data.lastname || '';
1098 return Ext.htmlEncode(first + " " + last);
1099 },
1100
2d41c7e6
TL
1101 render_u2f_error: function(error) {
1102 var ErrorNames = {
1103 '1': gettext('Other Error'),
1104 '2': gettext('Bad Request'),
1105 '3': gettext('Configuration Unsupported'),
1106 '4': gettext('Device Ineligible'),
1107 '5': gettext('Timeout')
1108 };
1109 return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText;
1110 },
1111
aa0819a8 1112 windowHostname: function() {
e7ade592 1113 return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
aa0819a8
WB
1114 function(m, addr, offset, original) { return addr; });
1115 },
0be88ae1 1116
953f6e9b 1117 openDefaultConsoleWindow: function(consoles, consoleType, vmid, nodename, vmname, cmd) {
3438c27e 1118 var dv = PVE.Utils.defaultViewer(consoles);
953f6e9b 1119 PVE.Utils.openConsoleWindow(dv, consoleType, vmid, nodename, vmname, cmd);
b0a6d326
EK
1120 },
1121
953f6e9b
TL
1122 openConsoleWindow: function(viewer, consoleType, vmid, nodename, vmname, cmd) {
1123 if (vmid == undefined && (consoleType === 'kvm' || consoleType === 'lxc')) {
b0a6d326
EK
1124 throw "missing vmid";
1125 }
b0a6d326
EK
1126 if (!nodename) {
1127 throw "no nodename specified";
1128 }
1129
c7218ab3 1130 if (viewer === 'html5') {
953f6e9b 1131 PVE.Utils.openVNCViewer(consoleType, vmid, nodename, vmname, cmd);
c6b2336c 1132 } else if (viewer === 'xtermjs') {
953f6e9b 1133 Proxmox.Utils.openXtermJsViewer(consoleType, vmid, nodename, vmname, cmd);
b0a6d326 1134 } else if (viewer === 'vv') {
953f6e9b
TL
1135 let url = '/nodes/' + nodename + '/spiceshell';
1136 let params = {
1137 proxy: PVE.Utils.windowHostname(),
1138 };
1139 if (consoleType === 'kvm') {
b0a6d326 1140 url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
953f6e9b 1141 } else if (consoleType === 'lxc') {
9e361643 1142 url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy';
953f6e9b
TL
1143 } else if (consoleType === 'upgrade') {
1144 params.cmd = 'upgrade';
1145 } else if (consoleType === 'cmd') {
8eccc68f 1146 params.cmd = cmd;
953f6e9b
TL
1147 } else if (consoleType !== 'shell') {
1148 throw `unknown spice viewer type '${consoleType}'`;
b0a6d326 1149 }
953f6e9b 1150 PVE.Utils.openSpiceViewer(url, params);
b0a6d326 1151 } else {
953f6e9b 1152 throw `unknown viewer type '${viewer}'`;
b0a6d326
EK
1153 }
1154 },
1155
3438c27e
DC
1156 defaultViewer: function(consoles) {
1157
1158 var allowSpice, allowXtermjs;
1159
1160 if (consoles === true) {
1161 allowSpice = true;
1162 allowXtermjs = true;
1163 } else if (typeof consoles === 'object') {
1164 allowSpice = consoles.spice;
4ace5c6f 1165 allowXtermjs = !!consoles.xtermjs;
3438c27e 1166 }
da9d14cd 1167 var dv = PVE.VersionInfo.console || 'xtermjs';
f932cffa
DC
1168 if (dv === 'vv' && !allowSpice) {
1169 dv = (allowXtermjs) ? 'xtermjs' : 'html5';
1170 } else if (dv === 'xtermjs' && !allowXtermjs) {
1171 dv = (allowSpice) ? 'vv' : 'html5';
b0a6d326
EK
1172 }
1173
1174 return dv;
1175 },
1176
8eccc68f 1177 openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) {
af89f682
TL
1178 let scaling = 'off';
1179 if (Proxmox.Utils.toolkit !== 'touch') {
1180 var sp = Ext.state.Manager.getProvider();
1181 scaling = sp.get('novnc-scaling', 'off');
1182 }
8eccc68f 1183 var url = Ext.Object.toQueryString({
9e361643 1184 console: vmtype, // kvm, lxc, upgrade or shell
c7218ab3 1185 novnc: 1,
b0a6d326
EK
1186 vmid: vmid,
1187 vmname: vmname,
16e64c97 1188 node: nodename,
af89f682 1189 resize: scaling,
8eccc68f 1190 cmd: cmd
b0a6d326
EK
1191 });
1192 var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
7af1ab47
DC
1193 if (nw) {
1194 nw.focus();
1195 }
b0a6d326
EK
1196 },
1197
1198 openSpiceViewer: function(url, params){
1199
1200 var downloadWithName = function(uri, name) {
1201 var link = Ext.DomHelper.append(document.body, {
1202 tag: 'a',
1203 href: uri,
1204 css : 'display:none;visibility:hidden;height:0px;'
1205 });
1206
1207 // Note: we need to tell android the correct file name extension
1208 // but we do not set 'download' tag for other environments, because
1209 // It can have strange side effects (additional user prompt on firefox)
1210 var andriod = navigator.userAgent.match(/Android/i) ? true : false;
1211 if (andriod) {
1212 link.download = name;
1213 }
1214
1215 if (link.fireEvent) {
1216 link.fireEvent('onclick');
1217 } else {
953f6e9b
TL
1218 let evt = document.createEvent("MouseEvents");
1219 evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
b0a6d326
EK
1220 link.dispatchEvent(evt);
1221 }
1222 };
1223
e7ade592 1224 Proxmox.Utils.API2Request({
b0a6d326
EK
1225 url: url,
1226 params: params,
1227 method: 'POST',
1228 failure: function(response, opts){
1229 Ext.Msg.alert('Error', response.htmlStatus);
1230 },
1231 success: function(response, opts){
1232 var raw = "[virt-viewer]\n";
1233 Ext.Object.each(response.result.data, function(k, v) {
1234 raw += k + "=" + v + "\n";
1235 });
1236 var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
1237 encodeURIComponent(raw);
0be88ae1 1238
b0a6d326
EK
1239 downloadWithName(url, "pve-spice.vv");
1240 }
1241 });
1242 },
1243
e3129443
DC
1244 openTreeConsole: function(tree, record, item, index, e) {
1245 e.stopEvent();
1246 var nodename = record.data.node;
1247 var vmid = record.data.vmid;
1248 var vmname = record.data.name;
1249 if (record.data.type === 'qemu' && !record.data.template) {
e7ade592 1250 Proxmox.Utils.API2Request({
e3129443
DC
1251 url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
1252 failure: function(response, opts) {
1253 Ext.Msg.alert('Error', response.htmlStatus);
1254 },
1255 success: function(response, opts) {
bd9537d7 1256 let conf = response.result.data;
54453c38 1257 var consoles = {
bd9537d7
TL
1258 spice: !!conf.spice,
1259 xtermjs: !!conf.serial,
54453c38
DC
1260 };
1261 PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
e3129443
DC
1262 }
1263 });
1264 } else if (record.data.type === 'lxc' && !record.data.template) {
1265 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
1266 }
1267 },
1268
fbd60cfd
DM
1269 // test automation helper
1270 call_menu_handler: function(menu, text) {
1271
1272 var list = menu.query('menuitem');
1273
1274 Ext.Array.each(list, function(item) {
1275 if (item.text === text) {
1276 if (item.handler) {
1277 item.handler();
1278 return 1;
1279 } else {
1280 return undefined;
1281 }
1282 }
1283 });
1284 },
1285
685b7aa4
DC
1286 createCmdMenu: function(v, record, item, index, event) {
1287 event.stopEvent();
cc1a91be
DC
1288 if (!(v instanceof Ext.tree.View)) {
1289 v.select(record);
1290 }
685b7aa4 1291 var menu;
9bad05bd
DC
1292 var template = !!record.data.template;
1293 var type = record.data.type;
685b7aa4 1294
9bad05bd
DC
1295 if (template) {
1296 if (type === 'qemu' || type == 'lxc') {
1297 menu = Ext.create('PVE.menu.TemplateMenu', {
1298 pveSelNode: record
1299 });
1300 }
1301 } else if (type === 'qemu' ||
1302 type === 'lxc' ||
1303 type === 'node') {
1304 menu = Ext.create('PVE.' + type + '.CmdMenu', {
1305 pveSelNode: record,
c11ab8cb
DC
1306 nodename: record.data.node
1307 });
685b7aa4
DC
1308 } else {
1309 return;
1310 }
1311
1312 menu.showAt(event.getXY());
9f0b4e04 1313 return menu;
e7ade592 1314 },
9fa2e36d 1315
fe4f00ad
TL
1316 // helper for deleting field which are set to there default values
1317 delete_if_default: function(values, fieldname, default_val, create) {
1318 if (values[fieldname] === '' || values[fieldname] === default_val) {
1319 if (!create) {
1320 if (values['delete']) {
2db8e90d
DC
1321 if (Ext.isArray(values['delete'])) {
1322 values['delete'].push(fieldname);
1323 } else {
1324 values['delete'] += ',' + fieldname;
1325 }
fe4f00ad
TL
1326 } else {
1327 values['delete'] = fieldname;
1328 }
1329 }
1330
1331 delete values[fieldname];
1332 }
857b97a7
TL
1333 },
1334
1335 loadSSHKeyFromFile: function(file, callback) {
1336 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1337 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1338 // assume: 740*8 for max. 32kbit (5920 byte file)
1339 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1340 if (file.size > 8192) {
1341 Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
1342 return;
1343 }
1344 /*global
1345 FileReader
1346 */
1347 var reader = new FileReader();
1348 reader.onload = function(evt) {
1349 callback(evt.target.result);
1350 };
1351 reader.readAsText(file);
abe824aa
DC
1352 },
1353
8c4ec8c7
TL
1354 diskControllerMaxIDs: {
1355 ide: 4,
1356 sata: 6,
cf0d139e 1357 scsi: 31,
8c4ec8c7
TL
1358 virtio: 16,
1359 },
abe824aa
DC
1360
1361 // types is either undefined (all busses), an array of busses, or a single bus
1362 forEachBus: function(types, func) {
8c4ec8c7 1363 var busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
abe824aa
DC
1364 var i, j, count, cont;
1365
1366 if (Ext.isArray(types)) {
1367 busses = types;
1368 } else if (Ext.isDefined(types)) {
1369 busses = [ types ];
1370 }
1371
1372 // check if we only have valid busses
1373 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1374 if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) {
abe824aa
DC
1375 throw "invalid bus: '" + busses[i] + "'";
1376 }
1377 }
1378
1379 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1380 count = PVE.Utils.diskControllerMaxIDs[busses[i]];
abe824aa
DC
1381 for (j = 0; j < count; j++) {
1382 cont = func(busses[i], j);
1383 if (!cont && cont !== undefined) {
1384 return;
1385 }
1386 }
1387 }
14a845bc
DC
1388 },
1389
483bd394 1390 mp_counts: { mps: 256, unused: 256 },
14a845bc
DC
1391
1392 forEachMP: function(func, includeUnused) {
1393 var i, cont;
1394 for (i = 0; i < PVE.Utils.mp_counts.mps; i++) {
1395 cont = func('mp', i);
1396 if (!cont && cont !== undefined) {
1397 return;
1398 }
1399 }
1400
1401 if (!includeUnused) {
1402 return;
1403 }
1404
1405 for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
1406 cont = func('unused', i);
1407 if (!cont && cont !== undefined) {
1408 return;
1409 }
1410 }
b945c7c1
TM
1411 },
1412
6c1d8ead 1413 hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1 },
9d855398 1414
b945c7c1
TM
1415 cleanEmptyObjectKeys: function (obj) {
1416 var propName;
1417 for (propName in obj) {
1418 if (obj.hasOwnProperty(propName)) {
1419 if (obj[propName] === null || obj[propName] === undefined) {
1420 delete obj[propName];
1421 }
1422 }
1423 }
4616a55b
TM
1424 },
1425
eadbbb4a
DC
1426 acmedomain_count: 5,
1427
1428 add_domain_to_acme: function(acme, domain) {
1429 if (acme.domains === undefined) {
1430 acme.domains = [domain];
1431 } else {
1432 acme.domains.push(domain);
1433 acme.domains = acme.domains.filter((value, index, self) => {
1434 return self.indexOf(value) === index;
1435 });
1436 }
1437 return acme;
1438 },
1439
1440 remove_domain_from_acme: function(acme, domain) {
1441 if (acme.domains !== undefined) {
1442 acme.domains = acme.domains.filter((value, index, self) => {
1443 return self.indexOf(value) === index && value !== domain;
1444 });
1445 }
1446 return acme;
1447 },
1448
4616a55b
TM
1449 handleStoreErrorOrMask: function(me, store, regex, callback) {
1450
1451 me.mon(store, 'load', function (proxy, response, success, operation) {
1452
1453 if (success) {
1454 Proxmox.Utils.setErrorMask(me, false);
1455 return;
1456 }
1457 var msg;
1458
1459 if (operation.error.statusText) {
1460 if (operation.error.statusText.match(regex)) {
1461 callback(me, operation.error);
1462 return;
1463 } else {
1464 msg = operation.error.statusText + ' (' + operation.error.status + ')';
1465 }
1466 } else {
1467 msg = gettext('Connection error');
1468 }
1469 Proxmox.Utils.setErrorMask(me, msg);
1470 });
1471 },
1472
1473 showCephInstallOrMask: function(container, msg, nodename, callback){
1474 var regex = new RegExp("not (installed|initialized)", "i");
1475 if (msg.match(regex)) {
1476 if (Proxmox.UserName === 'root@pam') {
1477 container.el.mask();
1478 if (!container.down('pveCephInstallWindow')){
f992ef80 1479 var isInstalled = msg.match(/not initialized/i) ? true : false;
4616a55b
TM
1480 var win = Ext.create('PVE.ceph.Install', {
1481 nodename: nodename
1482 });
f992ef80 1483 win.getViewModel().set('isInstalled', isInstalled);
4616a55b
TM
1484 container.add(win);
1485 win.show();
1486 callback(win);
1487 }
1488 } else {
a7e8b87b
TL
1489 container.mask(Ext.String.format(gettext('{0} not installed.') +
1490 ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']);
4616a55b
TM
1491 }
1492 return true;
1493 } else {
1494 return false;
1495 }
49dfba72
DC
1496 },
1497
1498 propertyStringSet: function(target, source, name, value) {
1499 if (source) {
1500 if (value === undefined) {
1501 target[name] = source;
1502 } else {
1503 target[name] = value;
1504 }
1505 } else {
1506 delete target[name];
1507 }
bbc83309
DC
1508 },
1509
1510 updateColumns: function(container) {
f973c5b2
DC
1511 let mode = Ext.state.Manager.get('summarycolumns') || 'auto';
1512 let factor;
1513 if (mode !== 'auto') {
1514 factor = parseInt(mode, 10);
1515 if (Number.isNaN(factor)) {
1516 factor = 1;
1517 }
1518 } else {
1519 factor = container.getSize().width < 1400 ? 1 : 2;
1520 }
bbc83309
DC
1521
1522 if (container.oldFactor === factor) {
1523 return;
1524 }
1525
1526 let items = container.query('>'); // direct childs
1527 factor = Math.min(factor, items.length);
1528 container.oldFactor = factor;
1529
1530 items.forEach((item) => {
1531 item.columnWidth = 1 / factor;
1532 });
1533
1534 // we have to update the layout twice, since the first layout change
1535 // can trigger the scrollbar which reduces the amount of space left
1536 container.updateLayout();
1537 container.updateLayout();
1538 },
e65817a1
SR
1539
1540 forEachCorosyncLink: function(nodeinfo, cb) {
1541 let re = /(?:ring|link)(\d+)_addr/;
1542 Ext.iterate(nodeinfo, (prop, val) => {
1543 let match = re.exec(prop);
1544 if (match) {
1545 cb(Number(match[1]), val);
1546 }
1547 });
1548 },
4546808c
SR
1549
1550 cpu_vendor_map: {
1551 'default': 'QEMU',
1552 'AuthenticAMD': 'AMD',
1553 'GenuineIntel': 'Intel'
1554 },
1555
1556 cpu_vendor_order: {
1557 "AMD": 1,
1558 "Intel": 2,
1559 "QEMU": 3,
1560 "Host": 4,
1561 "_default_": 5, // includes custom models
1562 },
e7ade592 1563},
fe4f00ad 1564
9fa2e36d
EK
1565 singleton: true,
1566 constructor: function() {
1567 var me = this;
1568 Ext.apply(me, me.utilities);
d18e15dd
DC
1569
1570 Proxmox.Utils.override_task_descriptions({
1571 acmedeactivate: ['ACME Account', gettext('Deactivate')],
1572 acmenewcert: ['SRV', gettext('Order Certificate')],
1573 acmerefresh: ['ACME Account', gettext('Refresh')],
1574 acmeregister: ['ACME Account', gettext('Register')],
1575 acmerenew: ['SRV', gettext('Renew Certificate')],
1576 acmerevoke: ['SRV', gettext('Revoke Certificate')],
1577 acmeupdate: ['ACME Account', gettext('Update')],
1578 'auth-realm-sync': [gettext('Realm'), gettext('Sync')],
1579 'auth-realm-sync-test': [gettext('Realm'), gettext('Sync Preview')],
1580 cephcreatemds: ['Ceph Metadata Server', gettext('Create')],
1581 cephcreatemgr: ['Ceph Manager', gettext('Create')],
1582 cephcreatemon: ['Ceph Monitor', gettext('Create')],
1583 cephcreateosd: ['Ceph OSD', gettext('Create')],
1584 cephcreatepool: ['Ceph Pool', gettext('Create')],
1585 cephdestroymds: ['Ceph Metadata Server', gettext('Destroy')],
1586 cephdestroymgr: ['Ceph Manager', gettext('Destroy')],
1587 cephdestroymon: ['Ceph Monitor', gettext('Destroy')],
1588 cephdestroyosd: ['Ceph OSD', gettext('Destroy')],
1589 cephdestroypool: ['Ceph Pool', gettext('Destroy')],
1590 cephfscreate: ['CephFS', gettext('Create')],
1591 clustercreate: ['', gettext('Create Cluster')],
1592 clusterjoin: ['', gettext('Join Cluster')],
1593 dircreate: [gettext('Directory Storage'), gettext('Create')],
1594 dirremove: [gettext('Directory'), gettext('Remove')],
1595 download: ['', gettext('Download')],
1596 hamigrate: ['HA', gettext('Migrate')],
1597 hashutdown: ['HA', gettext('Shutdown')],
1598 hastart: ['HA', gettext('Start')],
1599 hastop: ['HA', gettext('Stop')],
1600 imgcopy: ['', gettext('Copy data')],
1601 imgdel: ['', gettext('Erase data')],
1602 lvmcreate: [gettext('LVM Storage'), gettext('Create')],
1603 lvmthincreate: [gettext('LVM-Thin Storage'), gettext('Create')],
1604 migrateall: ['', gettext('Migrate all VMs and Containers')],
1605 'move_volume': ['CT', gettext('Move Volume')],
1606 pull_file: ['CT', gettext('Pull file')],
1607 push_file: ['CT', gettext('Push file')],
1608 qmclone: ['VM', gettext('Clone')],
1609 qmconfig: ['VM', gettext('Configure')],
1610 qmcreate: ['VM', gettext('Create')],
1611 qmdelsnapshot: ['VM', gettext('Delete Snapshot')],
1612 qmdestroy: ['VM', gettext('Destroy')],
1613 qmigrate: ['VM', gettext('Migrate')],
1614 qmmove: ['VM', gettext('Move disk')],
1615 qmpause: ['VM', gettext('Pause')],
1616 qmreboot: ['VM', gettext('Reboot')],
1617 qmreset: ['VM', gettext('Reset')],
1618 qmrestore: ['VM', gettext('Restore')],
1619 qmresume: ['VM', gettext('Resume')],
1620 qmrollback: ['VM', gettext('Rollback')],
1621 qmshutdown: ['VM', gettext('Shutdown')],
1622 qmsnapshot: ['VM', gettext('Snapshot')],
1623 qmstart: ['VM', gettext('Start')],
1624 qmstop: ['VM', gettext('Stop')],
1625 qmsuspend: ['VM', gettext('Hibernate')],
1626 qmtemplate: ['VM', gettext('Convert to template')],
1627 spiceproxy: ['VM/CT', gettext('Console') + ' (Spice)'],
1628 spiceshell: ['', gettext('Shell') + ' (Spice)'],
1629 startall: ['', gettext('Start all VMs and Containers')],
1630 stopall: ['', gettext('Stop all VMs and Containers')],
1631 unknownimgdel: ['', gettext('Destroy image from unknown guest')],
1632 vncproxy: ['VM/CT', gettext('Console')],
1633 vncshell: ['', gettext('Shell')],
1634 vzclone: ['CT', gettext('Clone')],
1635 vzcreate: ['CT', gettext('Create')],
1636 vzdelsnapshot: ['CT', gettext('Delete Snapshot')],
1637 vzdestroy: ['CT', gettext('Destroy')],
1638 vzdump: (type, id) => id ? `VM/CT ${id} - ${gettext('Backup')}` : gettext('Backup Job'),
1639 vzmigrate: ['CT', gettext('Migrate')],
1640 vzmount: ['CT', gettext('Mount')],
1641 vzreboot: ['CT', gettext('Reboot')],
1642 vzrestore: ['CT', gettext('Restore')],
1643 vzresume: ['CT', gettext('Resume')],
1644 vzrollback: ['CT', gettext('Rollback')],
1645 vzshutdown: ['CT', gettext('Shutdown')],
1646 vzsnapshot: ['CT', gettext('Snapshot')],
1647 vzstart: ['CT', gettext('Start')],
1648 vzstop: ['CT', gettext('Stop')],
1649 vzsuspend: ['CT', gettext('Suspend')],
1650 vztemplate: ['CT', gettext('Convert to template')],
1651 vzumount: ['CT', gettext('Unmount')],
1652 zfscreate: [gettext('ZFS Storage'), gettext('Create')],
1653 });
685b7aa4 1654 }
e7ade592 1655
9fa2e36d 1656});