]>
Commit | Line | Data |
---|---|---|
b0a6d326 EK |
1 | Ext.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 |
6 | Ext.enableAria = false; |
7 | Ext.enableAriaButtons = false; | |
8 | Ext.enableAriaPanels = false; | |
9 | ||
b0a6d326 | 10 | // avoid errors when running without development tools |
0be88ae1 DC |
11 | if (!Ext.isDefined(Ext.global.console)) { |
12 | var console = { | |
0be88ae1 | 13 | log: function() {} |
b0a6d326 EK |
14 | }; |
15 | } | |
0be88ae1 | 16 | console.log("Starting PVE Manager"); |
b0a6d326 EK |
17 | |
18 | Ext.Ajax.defaultHeaders = { | |
19 | 'Accept': 'application/json' | |
20 | }; | |
21 | ||
89ae1bb1 | 22 | /*jslint confusion: true */ |
9fa2e36d | 23 | Ext.define('PVE.Utils', { utilities: { |
b0a6d326 | 24 | |
9fa2e36d | 25 | // this singleton contains miscellaneous utilities |
b0a6d326 | 26 | |
0be88ae1 | 27 | toolkit: undefined, // (extjs|touch), set inside Toolkit.js |
b0a6d326 | 28 | |
98a01af2 EK |
29 | bus_match: /^(ide|sata|virtio|scsi)\d+$/, |
30 | ||
b0a6d326 EK |
31 | log_severity_hash: { |
32 | 0: "panic", | |
33 | 1: "alert", | |
34 | 2: "critical", | |
35 | 3: "error", | |
36 | 4: "warning", | |
37 | 5: "notice", | |
38 | 6: "info", | |
39 | 7: "debug" | |
40 | }, | |
41 | ||
42 | support_level_hash: { | |
43 | 'c': gettext('Community'), | |
44 | 'b': gettext('Basic'), | |
45 | 's': gettext('Standard'), | |
46 | 'p': gettext('Premium') | |
47 | }, | |
48 | ||
49 | noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="http://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.', | |
50 | ||
51 | kvm_ostypes: { | |
45d6c71a TL |
52 | 'Linux': [ |
53 | { desc: '4.X/3.X/2.6 Kernel', val: 'l26' }, | |
54 | { desc: '2.4 Kernel', val: 'l24' } | |
55 | ], | |
56 | 'Microsoft Windows': [ | |
57 | { desc: '10/2016', val: 'win10' }, | |
58 | { desc: '8.x/2012/2012r2', val: 'win8' }, | |
59 | { desc: '7/2008r2', val: 'win7' }, | |
60 | { desc: 'Vista/2008', val: 'w2k8' }, | |
61 | { desc: 'XP/2003', val: 'wxp' }, | |
62 | { desc: '2000', val: 'w2k' } | |
63 | ], | |
64 | 'Solaris Kernel': [ | |
65 | { desc: '-', val: 'solaris'} | |
66 | ], | |
67 | 'Other': [ | |
68 | { desc: '-', val: 'other'} | |
69 | ] | |
b0a6d326 EK |
70 | }, |
71 | ||
428bc4a2 DC |
72 | get_health_icon: function(state, circle) { |
73 | if (circle === undefined) { | |
74 | circle = false; | |
75 | } | |
76 | ||
77 | if (state === undefined) { | |
78 | state = 'uknown'; | |
79 | } | |
80 | ||
81 | var icon = 'faded fa-question'; | |
82 | switch(state) { | |
83 | case 'good': | |
84 | icon = 'good fa-check'; | |
85 | break; | |
86 | case 'warning': | |
87 | icon = 'warning fa-exclamation'; | |
88 | break; | |
89 | case 'critical': | |
90 | icon = 'critical fa-times'; | |
91 | break; | |
92 | default: break; | |
93 | } | |
94 | ||
95 | if (circle) { | |
96 | icon += '-circle'; | |
97 | } | |
98 | ||
99 | return icon; | |
100 | }, | |
101 | ||
046e640c DC |
102 | map_ceph_health: { |
103 | 'HEALTH_OK':'good', | |
104 | 'HEALTH_WARN':'warning', | |
105 | 'HEALTH_ERR':'critical' | |
106 | }, | |
107 | ||
dfe6d184 | 108 | render_ceph_health: function(healthObj) { |
046e640c DC |
109 | var state = { |
110 | iconCls: PVE.Utils.get_health_icon(), | |
111 | text: '' | |
112 | }; | |
113 | ||
dfe6d184 | 114 | if (!healthObj || !healthObj.status) { |
046e640c DC |
115 | return state; |
116 | } | |
117 | ||
dfe6d184 | 118 | var health = PVE.Utils.map_ceph_health[healthObj.status]; |
046e640c DC |
119 | |
120 | state.iconCls = PVE.Utils.get_health_icon(health, true); | |
dfe6d184 | 121 | state.text = healthObj.status; |
046e640c DC |
122 | |
123 | return state; | |
124 | }, | |
125 | ||
fee716d3 | 126 | render_zfs_health: function(value) { |
8c8604ba TM |
127 | if (typeof value == 'undefined'){ |
128 | return ""; | |
129 | } | |
fee716d3 DC |
130 | var iconCls = 'question-circle'; |
131 | switch (value) { | |
8c8604ba | 132 | case 'AVAIL': |
fee716d3 DC |
133 | case 'ONLINE': |
134 | iconCls = 'check-circle good'; | |
135 | break; | |
136 | case 'REMOVED': | |
137 | case 'DEGRADED': | |
138 | iconCls = 'exclamation-circle warning'; | |
139 | break; | |
140 | case 'UNAVAIL': | |
141 | case 'FAULTED': | |
142 | case 'OFFLINE': | |
143 | iconCls = 'times-circle critical'; | |
144 | break; | |
145 | default: //unknown | |
146 | } | |
147 | ||
148 | return '<i class="fa fa-' + iconCls + '"></i> ' + value; | |
8c8604ba | 149 | |
fee716d3 DC |
150 | }, |
151 | ||
45d6c71a TL |
152 | get_kvm_osinfo: function(value) { |
153 | var info = { base: 'Other' }; // default | |
154 | if (value) { | |
155 | Ext.each(Object.keys(PVE.Utils.kvm_ostypes), function(k) { | |
156 | Ext.each(PVE.Utils.kvm_ostypes[k], function(e) { | |
157 | if (e.val === value) { | |
158 | info = { desc: e.desc, base: k }; | |
159 | } | |
160 | }); | |
161 | }); | |
b0a6d326 | 162 | } |
45d6c71a TL |
163 | return info; |
164 | }, | |
165 | ||
166 | render_kvm_ostype: function (value) { | |
167 | var osinfo = PVE.Utils.get_kvm_osinfo(value); | |
168 | if (osinfo.desc && osinfo.desc !== '-') { | |
169 | return osinfo.base + ' ' + osinfo.desc; | |
170 | } else { | |
171 | return osinfo.base; | |
b0a6d326 | 172 | } |
b0a6d326 EK |
173 | }, |
174 | ||
175 | render_hotplug_features: function (value) { | |
23d3881a | 176 | var fa = []; |
b0a6d326 EK |
177 | |
178 | if (!value || (value === '0')) { | |
ec99b1c3 | 179 | return gettext('Disabled'); |
b0a6d326 EK |
180 | } |
181 | ||
4dcca8a4 DC |
182 | if (value === '1') { |
183 | value = 'disk,network,usb'; | |
184 | } | |
185 | ||
b0a6d326 EK |
186 | Ext.each(value.split(','), function(el) { |
187 | if (el === 'disk') { | |
188 | fa.push(gettext('Disk')); | |
189 | } else if (el === 'network') { | |
190 | fa.push(gettext('Network')); | |
191 | } else if (el === 'usb') { | |
b9628aa5 | 192 | fa.push('USB'); |
b0a6d326 EK |
193 | } else if (el === 'memory') { |
194 | fa.push(gettext('Memory')); | |
195 | } else if (el === 'cpu') { | |
196 | fa.push(gettext('CPU')); | |
197 | } else { | |
198 | fa.push(el); | |
199 | } | |
200 | }); | |
201 | ||
202 | return fa.join(', '); | |
203 | }, | |
204 | ||
1662ccdb SI |
205 | render_qga_features: function(value) { |
206 | if (!value) { | |
207 | return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText + ')'; | |
208 | } | |
209 | var props = PVE.Parser.parsePropertyString(value, 'enabled'); | |
210 | if (!PVE.Parser.parseBoolean(props.enabled)) { | |
211 | return Proxmox.Utils.disabledText; | |
212 | } | |
213 | ||
214 | delete props.enabled; | |
215 | var agentstring = Proxmox.Utils.enabledText; | |
216 | ||
217 | Ext.Object.each(props, function(key, value) { | |
218 | var keystring = '' ; | |
219 | agentstring += ', ' + key + ': '; | |
220 | ||
221 | if (PVE.Parser.parseBoolean(value)) { | |
222 | agentstring += Proxmox.Utils.enabledText; | |
223 | } else { | |
224 | agentstring += Proxmox.Utils.disabledText; | |
225 | } | |
226 | }); | |
227 | ||
228 | return agentstring; | |
229 | }, | |
230 | ||
17c71f27 DC |
231 | render_qemu_bios: function(value) { |
232 | if (!value) { | |
e7ade592 | 233 | return Proxmox.Utils.defaultText + ' (SeaBIOS)'; |
17c71f27 DC |
234 | } else if (value === 'seabios') { |
235 | return "SeaBIOS"; | |
236 | } else if (value === 'ovmf') { | |
237 | return "OVMF (UEFI)"; | |
238 | } else { | |
239 | return value; | |
240 | } | |
241 | }, | |
242 | ||
b0a6d326 EK |
243 | render_scsihw: function(value) { |
244 | if (!value) { | |
e7ade592 | 245 | return Proxmox.Utils.defaultText + ' (LSI 53C895A)'; |
b0a6d326 EK |
246 | } else if (value === 'lsi') { |
247 | return 'LSI 53C895A'; | |
248 | } else if (value === 'lsi53c810') { | |
249 | return 'LSI 53C810'; | |
250 | } else if (value === 'megasas') { | |
251 | return 'MegaRAID SAS 8708EM2'; | |
252 | } else if (value === 'virtio-scsi-pci') { | |
49f5d1ab EK |
253 | return 'VirtIO SCSI'; |
254 | } else if (value === 'virtio-scsi-single') { | |
255 | return 'VirtIO SCSI single'; | |
b0a6d326 EK |
256 | } else if (value === 'pvscsi') { |
257 | return 'VMware PVSCSI'; | |
258 | } else { | |
259 | return value; | |
260 | } | |
261 | }, | |
262 | ||
263 | // fixme: auto-generate this | |
264 | // for now, please keep in sync with PVE::Tools::kvmkeymaps | |
265 | kvm_keymaps: { | |
266 | //ar: 'Arabic', | |
267 | da: 'Danish', | |
0be88ae1 DC |
268 | de: 'German', |
269 | 'de-ch': 'German (Swiss)', | |
270 | 'en-gb': 'English (UK)', | |
0a5b8747 | 271 | 'en-us': 'English (USA)', |
b0a6d326 EK |
272 | es: 'Spanish', |
273 | //et: 'Estonia', | |
274 | fi: 'Finnish', | |
0be88ae1 DC |
275 | //fo: 'Faroe Islands', |
276 | fr: 'French', | |
277 | 'fr-be': 'French (Belgium)', | |
b0a6d326 EK |
278 | 'fr-ca': 'French (Canada)', |
279 | 'fr-ch': 'French (Swiss)', | |
280 | //hr: 'Croatia', | |
281 | hu: 'Hungarian', | |
282 | is: 'Icelandic', | |
0be88ae1 | 283 | it: 'Italian', |
b0a6d326 EK |
284 | ja: 'Japanese', |
285 | lt: 'Lithuanian', | |
286 | //lv: 'Latvian', | |
0be88ae1 | 287 | mk: 'Macedonian', |
b0a6d326 EK |
288 | nl: 'Dutch', |
289 | //'nl-be': 'Dutch (Belgium)', | |
0be88ae1 | 290 | no: 'Norwegian', |
b0a6d326 EK |
291 | pl: 'Polish', |
292 | pt: 'Portuguese', | |
293 | 'pt-br': 'Portuguese (Brazil)', | |
294 | //ru: 'Russian', | |
295 | sl: 'Slovenian', | |
296 | sv: 'Swedish', | |
297 | //th: 'Thai', | |
298 | tr: 'Turkish' | |
299 | }, | |
300 | ||
301 | kvm_vga_drivers: { | |
302 | std: gettext('Standard VGA'), | |
5ca366f2 | 303 | vmware: gettext('VMware compatible'), |
b0a6d326 EK |
304 | qxl: 'SPICE', |
305 | qxl2: 'SPICE dual monitor', | |
306 | qxl3: 'SPICE three monitors', | |
307 | qxl4: 'SPICE four monitors', | |
308 | serial0: gettext('Serial terminal') + ' 0', | |
309 | serial1: gettext('Serial terminal') + ' 1', | |
310 | serial2: gettext('Serial terminal') + ' 2', | |
89ae1bb1 DC |
311 | serial3: gettext('Serial terminal') + ' 3', |
312 | virtio: 'VirtIO-GPU', | |
313 | none: Proxmox.Utils.noneText | |
b0a6d326 EK |
314 | }, |
315 | ||
316 | render_kvm_language: function (value) { | |
e7ade592 DC |
317 | if (!value || value === '__default__') { |
318 | return Proxmox.Utils.defaultText; | |
b0a6d326 EK |
319 | } |
320 | var text = PVE.Utils.kvm_keymaps[value]; | |
321 | if (text) { | |
322 | return text + ' (' + value + ')'; | |
323 | } | |
324 | return value; | |
325 | }, | |
326 | ||
327 | kvm_keymap_array: function() { | |
f2782813 | 328 | var data = [['__default__', PVE.Utils.render_kvm_language('')]]; |
b0a6d326 EK |
329 | Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) { |
330 | data.push([key, PVE.Utils.render_kvm_language(value)]); | |
331 | }); | |
332 | ||
333 | return data; | |
334 | }, | |
335 | ||
3438c27e DC |
336 | console_map: { |
337 | '__default__': Proxmox.Utils.defaultText + ' (HTML5)', | |
338 | 'vv': 'SPICE (remote-viewer)', | |
339 | 'html5': 'HTML5 (noVNC)', | |
4ace5c6f | 340 | 'xtermjs': 'xterm.js' |
3438c27e DC |
341 | }, |
342 | ||
b0a6d326 | 343 | render_console_viewer: function(value) { |
3438c27e DC |
344 | value = value || '__default__'; |
345 | if (PVE.Utils.console_map[value]) { | |
346 | return PVE.Utils.console_map[value]; | |
b0a6d326 | 347 | } |
3438c27e | 348 | return value; |
b0a6d326 EK |
349 | }, |
350 | ||
755b9083 | 351 | console_viewer_array: function() { |
3438c27e | 352 | return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) { |
755b9083 TL |
353 | return [v, PVE.Utils.render_console_viewer(v)]; |
354 | }); | |
355 | }, | |
356 | ||
b0a6d326 EK |
357 | render_kvm_vga_driver: function (value) { |
358 | if (!value) { | |
e7ade592 | 359 | return Proxmox.Utils.defaultText; |
b0a6d326 | 360 | } |
4f3e66d8 DC |
361 | var vga = PVE.Parser.parsePropertyString(value, 'type'); |
362 | var text = PVE.Utils.kvm_vga_drivers[vga.type]; | |
363 | if (!vga.type) { | |
364 | text = Proxmox.Utils.defaultText; | |
365 | } | |
0be88ae1 | 366 | if (text) { |
b0a6d326 EK |
367 | return text + ' (' + value + ')'; |
368 | } | |
369 | return value; | |
370 | }, | |
371 | ||
372 | kvm_vga_driver_array: function() { | |
f2782813 | 373 | var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]]; |
b0a6d326 EK |
374 | Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) { |
375 | data.push([key, PVE.Utils.render_kvm_vga_driver(value)]); | |
376 | }); | |
377 | ||
378 | return data; | |
379 | }, | |
380 | ||
381 | render_kvm_startup: function(value) { | |
382 | var startup = PVE.Parser.parseStartup(value); | |
383 | ||
384 | var res = 'order='; | |
385 | if (startup.order === undefined) { | |
386 | res += 'any'; | |
387 | } else { | |
388 | res += startup.order; | |
389 | } | |
390 | if (startup.up !== undefined) { | |
391 | res += ',up=' + startup.up; | |
392 | } | |
393 | if (startup.down !== undefined) { | |
394 | res += ',down=' + startup.down; | |
395 | } | |
396 | ||
397 | return res; | |
398 | }, | |
399 | ||
b0a6d326 EK |
400 | extractFormActionError: function(action) { |
401 | var msg; | |
402 | switch (action.failureType) { | |
403 | case Ext.form.action.Action.CLIENT_INVALID: | |
404 | msg = gettext('Form fields may not be submitted with invalid values'); | |
405 | break; | |
406 | case Ext.form.action.Action.CONNECT_FAILURE: | |
407 | msg = gettext('Connection error'); | |
408 | var resp = action.response; | |
409 | if (resp.status && resp.statusText) { | |
410 | msg += " " + resp.status + ": " + resp.statusText; | |
411 | } | |
412 | break; | |
413 | case Ext.form.action.Action.LOAD_FAILURE: | |
414 | case Ext.form.action.Action.SERVER_INVALID: | |
e7ade592 | 415 | msg = Proxmox.Utils.extractRequestError(action.result, true); |
b0a6d326 EK |
416 | break; |
417 | } | |
418 | return msg; | |
419 | }, | |
420 | ||
b0a6d326 | 421 | format_duration_short: function(ut) { |
0be88ae1 | 422 | |
b0a6d326 | 423 | if (ut < 60) { |
530ee6b7 | 424 | return ut.toFixed(1) + 's'; |
b0a6d326 EK |
425 | } |
426 | ||
427 | if (ut < 3600) { | |
428 | var mins = ut / 60; | |
530ee6b7 | 429 | return mins.toFixed(1) + 'm'; |
b0a6d326 EK |
430 | } |
431 | ||
432 | if (ut < 86400) { | |
433 | var hours = ut / 3600; | |
530ee6b7 | 434 | return hours.toFixed(1) + 'h'; |
b0a6d326 EK |
435 | } |
436 | ||
437 | var days = ut / 86400; | |
530ee6b7 | 438 | return days.toFixed(1) + 'd'; |
b0a6d326 EK |
439 | }, |
440 | ||
0e244a29 DC |
441 | contentTypes: { |
442 | 'images': gettext('Disk image'), | |
443 | 'backup': gettext('VZDump backup file'), | |
444 | 'vztmpl': gettext('Container template'), | |
445 | 'iso': gettext('ISO image'), | |
aef28e04 DC |
446 | 'rootdir': gettext('Container'), |
447 | 'snippets': gettext('Snippets') | |
0e244a29 | 448 | }, |
b0a6d326 | 449 | |
062a7f49 TL |
450 | storageSchema: { |
451 | dir: { | |
452 | name: Proxmox.Utils.directoryText, | |
453 | ipanel: 'DirInputPanel', | |
454 | faIcon: 'folder' | |
455 | }, | |
456 | lvm: { | |
457 | name: 'LVM', | |
458 | ipanel: 'LVMInputPanel', | |
459 | faIcon: 'folder' | |
460 | }, | |
461 | lvmthin: { | |
462 | name: 'LVM-Thin', | |
463 | ipanel: 'LvmThinInputPanel', | |
464 | faIcon: 'folder' | |
465 | }, | |
466 | nfs: { | |
467 | name: 'NFS', | |
468 | ipanel: 'NFSInputPanel', | |
469 | faIcon: 'building' | |
470 | }, | |
471 | cifs: { | |
472 | name: 'CIFS', | |
473 | ipanel: 'CIFSInputPanel', | |
474 | faIcon: 'building' | |
475 | }, | |
476 | glusterfs: { | |
477 | name: 'GlusterFS', | |
478 | ipanel: 'GlusterFsInputPanel', | |
479 | faIcon: 'building' | |
480 | }, | |
481 | iscsi: { | |
482 | name: 'iSCSI', | |
483 | ipanel: 'IScsiInputPanel', | |
484 | faIcon: 'building' | |
485 | }, | |
486 | sheepdog: { | |
487 | name: 'Sheepdog', | |
488 | ipanel: 'SheepdogInputPanel', | |
489 | hideAdd: true, | |
490 | faIcon: 'building' | |
491 | }, | |
4a4b2b6e TL |
492 | cephfs: { |
493 | name: 'CephFS', | |
494 | ipanel: 'CephFSInputPanel', | |
495 | faIcon: 'building' | |
496 | }, | |
497 | pvecephfs: { | |
498 | name: 'CephFS (PVE)', | |
499 | ipanel: 'CephFSInputPanel', | |
500 | hideAdd: true, | |
501 | faIcon: 'building' | |
502 | }, | |
062a7f49 TL |
503 | rbd: { |
504 | name: 'RBD', | |
505 | ipanel: 'RBDInputPanel', | |
062a7f49 TL |
506 | faIcon: 'building' |
507 | }, | |
508 | pveceph: { | |
509 | name: 'RBD (PVE)', | |
0d1ac958 TL |
510 | ipanel: 'RBDInputPanel', |
511 | hideAdd: true, | |
062a7f49 TL |
512 | faIcon: 'building' |
513 | }, | |
514 | zfs: { | |
515 | name: 'ZFS over iSCSI', | |
516 | ipanel: 'ZFSInputPanel', | |
517 | faIcon: 'building' | |
518 | }, | |
519 | zfspool: { | |
520 | name: 'ZFS', | |
521 | ipanel: 'ZFSPoolInputPanel', | |
522 | faIcon: 'folder' | |
523 | }, | |
524 | drbd: { | |
525 | name: 'DRBD', | |
526 | hideAdd: true | |
527 | } | |
528 | }, | |
529 | ||
3c23c025 | 530 | format_storage_type: function(value, md, record) { |
4a4b2b6e TL |
531 | if (value === 'rbd') { |
532 | value = (!record || record.get('monhost') ? 'rbd' : 'pveceph'); | |
533 | } else if (value === 'cephfs') { | |
534 | value = (!record || record.get('monhost') ? 'cephfs' : 'pvecephfs'); | |
3c23c025 | 535 | } |
062a7f49 TL |
536 | |
537 | var schema = PVE.Utils.storageSchema[value]; | |
538 | if (schema) { | |
539 | return schema.name; | |
b0a6d326 | 540 | } |
062a7f49 | 541 | return Proxmox.Utils.unknownText; |
a3b8efb4 EK |
542 | }, |
543 | ||
ced1677b | 544 | format_ha: function(value) { |
e7ade592 | 545 | var text = Proxmox.Utils.noneText; |
ced1677b TL |
546 | |
547 | if (value.managed) { | |
e7ade592 | 548 | text = value.state || Proxmox.Utils.noneText; |
ced1677b | 549 | |
e7ade592 DC |
550 | text += ', ' + Proxmox.Utils.groupText + ': '; |
551 | text += value.group || Proxmox.Utils.noneText; | |
ced1677b TL |
552 | } |
553 | ||
554 | return text; | |
555 | }, | |
556 | ||
b0a6d326 | 557 | format_content_types: function(value) { |
0e244a29 DC |
558 | return value.split(',').sort().map(function(ct) { |
559 | return PVE.Utils.contentTypes[ct] || ct; | |
560 | }).join(', '); | |
b0a6d326 EK |
561 | }, |
562 | ||
563 | render_storage_content: function(value, metaData, record) { | |
564 | var data = record.data; | |
565 | if (Ext.isNumber(data.channel) && | |
566 | Ext.isNumber(data.id) && | |
567 | Ext.isNumber(data.lun)) { | |
0be88ae1 DC |
568 | return "CH " + |
569 | Ext.String.leftPad(data.channel,2, '0') + | |
b0a6d326 EK |
570 | " ID " + data.id + " LUN " + data.lun; |
571 | } | |
572 | return data.volid.replace(/^.*:(.*\/)?/,''); | |
573 | }, | |
574 | ||
575 | render_serverity: function (value) { | |
576 | return PVE.Utils.log_severity_hash[value] || value; | |
577 | }, | |
578 | ||
579 | render_cpu: function(value, metaData, record, rowIndex, colIndex, store) { | |
580 | ||
581 | if (!(record.data.uptime && Ext.isNumeric(value))) { | |
582 | return ''; | |
583 | } | |
584 | ||
585 | var maxcpu = record.data.maxcpu || 1; | |
586 | ||
587 | if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) { | |
588 | return ''; | |
589 | } | |
0be88ae1 | 590 | |
b0a6d326 EK |
591 | var per = value * 100; |
592 | ||
593 | return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU'); | |
594 | }, | |
595 | ||
596 | render_size: function(value, metaData, record, rowIndex, colIndex, store) { | |
597 | /*jslint confusion: true */ | |
598 | ||
599 | if (!Ext.isNumeric(value)) { | |
600 | return ''; | |
601 | } | |
602 | ||
e7ade592 | 603 | return Proxmox.Utils.format_size(value); |
b0a6d326 EK |
604 | }, |
605 | ||
946730cd DC |
606 | render_bandwidth: function(value) { |
607 | if (!Ext.isNumeric(value)) { | |
608 | return ''; | |
609 | } | |
610 | ||
e7ade592 | 611 | return Proxmox.Utils.format_size(value) + '/s'; |
b0a6d326 EK |
612 | }, |
613 | ||
3f633655 EK |
614 | render_timestamp_human_readable: function(value) { |
615 | return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s'); | |
616 | }, | |
617 | ||
ddd26302 DC |
618 | render_duration: function(value) { |
619 | if (value === undefined) { | |
620 | return '-'; | |
621 | } | |
622 | return PVE.Utils.format_duration_short(value); | |
623 | }, | |
624 | ||
0bfc799f DC |
625 | calculate_mem_usage: function(data) { |
626 | if (!Ext.isNumeric(data.mem) || | |
627 | data.maxmem === 0 || | |
628 | data.uptime < 1) { | |
629 | return -1; | |
630 | } | |
631 | ||
632 | return (data.mem / data.maxmem); | |
633 | }, | |
634 | ||
635 | render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { | |
636 | if (!Ext.isNumeric(value) || value === -1) { | |
637 | return ''; | |
638 | } | |
639 | if (value > 1 ) { | |
640 | // we got no percentage but bytes | |
641 | var mem = value; | |
642 | var maxmem = record.data.maxmem; | |
643 | if (!record.data.uptime || | |
644 | maxmem === 0 || | |
645 | !Ext.isNumeric(mem)) { | |
646 | return ''; | |
647 | } | |
648 | ||
649 | return ((mem*100)/maxmem).toFixed(1) + " %"; | |
650 | } | |
651 | return (value*100).toFixed(1) + " %"; | |
652 | }, | |
653 | ||
b0a6d326 EK |
654 | render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
655 | ||
656 | var mem = value; | |
657 | var maxmem = record.data.maxmem; | |
0be88ae1 | 658 | |
b0a6d326 EK |
659 | if (!record.data.uptime) { |
660 | return ''; | |
661 | } | |
662 | ||
663 | if (!(Ext.isNumeric(mem) && maxmem)) { | |
664 | return ''; | |
665 | } | |
666 | ||
728f1b97 | 667 | return PVE.Utils.render_size(value); |
b0a6d326 EK |
668 | }, |
669 | ||
0bfc799f DC |
670 | calculate_disk_usage: function(data) { |
671 | ||
672 | if (!Ext.isNumeric(data.disk) || | |
673 | data.type === 'qemu' || | |
674 | (data.type === 'lxc' && data.uptime === 0) || | |
675 | data.maxdisk === 0) { | |
676 | return -1; | |
677 | } | |
678 | ||
679 | return (data.disk / data.maxdisk); | |
680 | }, | |
681 | ||
682 | render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { | |
683 | if (!Ext.isNumeric(value) || value === -1) { | |
684 | return ''; | |
685 | } | |
686 | ||
687 | return (value * 100).toFixed(1) + " %"; | |
688 | }, | |
689 | ||
b0a6d326 EK |
690 | render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
691 | ||
692 | var disk = value; | |
693 | var maxdisk = record.data.maxdisk; | |
728f1b97 | 694 | var type = record.data.type; |
b0a6d326 | 695 | |
728f1b97 DC |
696 | if (!Ext.isNumeric(disk) || |
697 | type === 'qemu' || | |
698 | maxdisk === 0 || | |
699 | (type === 'lxc' && record.data.uptime === 0)) { | |
b0a6d326 EK |
700 | return ''; |
701 | } | |
702 | ||
728f1b97 | 703 | return PVE.Utils.render_size(value); |
b0a6d326 EK |
704 | }, |
705 | ||
4dbc64a7 DC |
706 | get_object_icon_class: function(type, record) { |
707 | var status = ''; | |
708 | var objType = type; | |
709 | ||
710 | if (type === 'type') { | |
711 | // for folder view | |
712 | objType = record.groupbyid; | |
713 | } else if (record.template) { | |
714 | // templates | |
715 | objType = 'template'; | |
716 | status = type; | |
717 | } else { | |
718 | // everything else | |
719 | status = record.status + ' ha-' + record.hastate; | |
b1d8e73d DC |
720 | } |
721 | ||
4dbc64a7 DC |
722 | var defaults = PVE.tree.ResourceTree.typeDefaults[objType]; |
723 | if (defaults && defaults.iconCls) { | |
724 | var retVal = defaults.iconCls + ' ' + status; | |
725 | return retVal; | |
b0a6d326 EK |
726 | } |
727 | ||
4dbc64a7 DC |
728 | return ''; |
729 | }, | |
730 | ||
731 | render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) { | |
732 | ||
733 | var cls = PVE.Utils.get_object_icon_class(value,record.data); | |
2b2fe160 | 734 | |
4dbc64a7 | 735 | var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> '; |
b1d8e73d | 736 | return fa + value; |
b0a6d326 EK |
737 | }, |
738 | ||
b0a6d326 EK |
739 | render_support_level: function(value, metaData, record) { |
740 | return PVE.Utils.support_level_hash[value] || '-'; | |
741 | }, | |
742 | ||
0be88ae1 | 743 | render_upid: function(value, metaData, record) { |
b0a6d326 EK |
744 | var type = record.data.type; |
745 | var id = record.data.id; | |
746 | ||
e7ade592 | 747 | return Proxmox.Utils.format_task_description(type, id); |
b0a6d326 EK |
748 | }, |
749 | ||
054ac1b8 DC |
750 | /* render functions for new status panel */ |
751 | ||
752 | render_usage: function(val) { | |
753 | return (val*100).toFixed(2) + '%'; | |
754 | }, | |
755 | ||
756 | render_cpu_usage: function(val, max) { | |
757 | return Ext.String.format(gettext('{0}% of {1}') + | |
758 | ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max); | |
759 | }, | |
760 | ||
761 | render_size_usage: function(val, max) { | |
bab64974 DC |
762 | if (max === 0) { |
763 | return gettext('N/A'); | |
764 | } | |
054ac1b8 DC |
765 | return (val*100/max).toFixed(2) + '% '+ '(' + |
766 | Ext.String.format(gettext('{0} of {1}'), | |
767 | PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')'; | |
768 | }, | |
769 | ||
770 | /* this is different for nodes */ | |
771 | render_node_cpu_usage: function(value, record) { | |
772 | return PVE.Utils.render_cpu_usage(value, record.cpus); | |
773 | }, | |
774 | ||
775 | /* this is different for nodes */ | |
776 | render_node_size_usage: function(record) { | |
777 | return PVE.Utils.render_size_usage(record.used, record.total); | |
778 | }, | |
779 | ||
27809975 DC |
780 | render_optional_url: function(value) { |
781 | var match; | |
782 | if (value && (match = value.match(/^https?:\/\//)) !== null) { | |
cdd9b6c0 | 783 | return '<a target="_blank" href="' + value + '">' + value + '</a>'; |
27809975 DC |
784 | } |
785 | return value; | |
786 | }, | |
787 | ||
788 | render_san: function(value) { | |
789 | var names = []; | |
790 | if (Ext.isArray(value)) { | |
791 | value.forEach(function(val) { | |
792 | if (!Ext.isNumber(val)) { | |
793 | names.push(val); | |
794 | } | |
795 | }); | |
796 | return names.join('<br>'); | |
797 | } | |
798 | return value; | |
799 | }, | |
800 | ||
6ad4be69 DC |
801 | render_full_name: function(firstname, metaData, record) { |
802 | var first = firstname || ''; | |
803 | var last = record.data.lastname || ''; | |
804 | return Ext.htmlEncode(first + " " + last); | |
805 | }, | |
806 | ||
aa0819a8 | 807 | windowHostname: function() { |
e7ade592 | 808 | return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match, |
aa0819a8 WB |
809 | function(m, addr, offset, original) { return addr; }); |
810 | }, | |
0be88ae1 | 811 | |
3438c27e DC |
812 | openDefaultConsoleWindow: function(consoles, vmtype, vmid, nodename, vmname) { |
813 | var dv = PVE.Utils.defaultViewer(consoles); | |
b0a6d326 EK |
814 | PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname); |
815 | }, | |
816 | ||
817 | openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname) { | |
9e361643 | 818 | // kvm, lxc, shell, upgrade |
b0a6d326 | 819 | |
9e361643 | 820 | if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) { |
b0a6d326 EK |
821 | throw "missing vmid"; |
822 | } | |
823 | ||
824 | if (!nodename) { | |
825 | throw "no nodename specified"; | |
826 | } | |
827 | ||
c7218ab3 DC |
828 | if (viewer === 'html5') { |
829 | PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname); | |
c6b2336c | 830 | } else if (viewer === 'xtermjs') { |
e7ade592 | 831 | Proxmox.Utils.openXtermJsViewer(vmtype, vmid, nodename, vmname); |
b0a6d326 EK |
832 | } else if (viewer === 'vv') { |
833 | var url; | |
aa0819a8 | 834 | var params = { proxy: PVE.Utils.windowHostname() }; |
b0a6d326 EK |
835 | if (vmtype === 'kvm') { |
836 | url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy'; | |
837 | PVE.Utils.openSpiceViewer(url, params); | |
9e361643 DM |
838 | } else if (vmtype === 'lxc') { |
839 | url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy'; | |
b0a6d326 EK |
840 | PVE.Utils.openSpiceViewer(url, params); |
841 | } else if (vmtype === 'shell') { | |
842 | url = '/nodes/' + nodename + '/spiceshell'; | |
843 | PVE.Utils.openSpiceViewer(url, params); | |
844 | } else if (vmtype === 'upgrade') { | |
845 | url = '/nodes/' + nodename + '/spiceshell'; | |
846 | params.upgrade = 1; | |
847 | PVE.Utils.openSpiceViewer(url, params); | |
848 | } | |
849 | } else { | |
850 | throw "unknown viewer type"; | |
851 | } | |
852 | }, | |
853 | ||
3438c27e DC |
854 | defaultViewer: function(consoles) { |
855 | ||
856 | var allowSpice, allowXtermjs; | |
857 | ||
858 | if (consoles === true) { | |
859 | allowSpice = true; | |
860 | allowXtermjs = true; | |
861 | } else if (typeof consoles === 'object') { | |
862 | allowSpice = consoles.spice; | |
4ace5c6f | 863 | allowXtermjs = !!consoles.xtermjs; |
3438c27e | 864 | } |
b0a6d326 EK |
865 | var vncdefault = 'html5'; |
866 | var dv = PVE.VersionInfo.console || vncdefault; | |
3438c27e | 867 | if ((dv === 'vv' && !allowSpice) || (dv === 'xtermjs' && !allowXtermjs)) { |
b0a6d326 EK |
868 | dv = vncdefault; |
869 | } | |
870 | ||
871 | return dv; | |
872 | }, | |
873 | ||
c7218ab3 | 874 | openVNCViewer: function(vmtype, vmid, nodename, vmname) { |
b0a6d326 | 875 | var url = Ext.urlEncode({ |
9e361643 | 876 | console: vmtype, // kvm, lxc, upgrade or shell |
c7218ab3 | 877 | novnc: 1, |
b0a6d326 EK |
878 | vmid: vmid, |
879 | vmname: vmname, | |
16e64c97 DC |
880 | node: nodename, |
881 | resize: 'off' | |
b0a6d326 EK |
882 | }); |
883 | var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427"); | |
7af1ab47 DC |
884 | if (nw) { |
885 | nw.focus(); | |
886 | } | |
b0a6d326 EK |
887 | }, |
888 | ||
889 | openSpiceViewer: function(url, params){ | |
890 | ||
891 | var downloadWithName = function(uri, name) { | |
892 | var link = Ext.DomHelper.append(document.body, { | |
893 | tag: 'a', | |
894 | href: uri, | |
895 | css : 'display:none;visibility:hidden;height:0px;' | |
896 | }); | |
897 | ||
898 | // Note: we need to tell android the correct file name extension | |
899 | // but we do not set 'download' tag for other environments, because | |
900 | // It can have strange side effects (additional user prompt on firefox) | |
901 | var andriod = navigator.userAgent.match(/Android/i) ? true : false; | |
902 | if (andriod) { | |
903 | link.download = name; | |
904 | } | |
905 | ||
906 | if (link.fireEvent) { | |
907 | link.fireEvent('onclick'); | |
908 | } else { | |
909 | var evt = document.createEvent("MouseEvents"); | |
910 | evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null); | |
911 | link.dispatchEvent(evt); | |
912 | } | |
913 | }; | |
914 | ||
e7ade592 | 915 | Proxmox.Utils.API2Request({ |
b0a6d326 EK |
916 | url: url, |
917 | params: params, | |
918 | method: 'POST', | |
919 | failure: function(response, opts){ | |
920 | Ext.Msg.alert('Error', response.htmlStatus); | |
921 | }, | |
922 | success: function(response, opts){ | |
923 | var raw = "[virt-viewer]\n"; | |
924 | Ext.Object.each(response.result.data, function(k, v) { | |
925 | raw += k + "=" + v + "\n"; | |
926 | }); | |
927 | var url = 'data:application/x-virt-viewer;charset=UTF-8,' + | |
928 | encodeURIComponent(raw); | |
0be88ae1 | 929 | |
b0a6d326 EK |
930 | downloadWithName(url, "pve-spice.vv"); |
931 | } | |
932 | }); | |
933 | }, | |
934 | ||
e3129443 DC |
935 | openTreeConsole: function(tree, record, item, index, e) { |
936 | e.stopEvent(); | |
937 | var nodename = record.data.node; | |
938 | var vmid = record.data.vmid; | |
939 | var vmname = record.data.name; | |
940 | if (record.data.type === 'qemu' && !record.data.template) { | |
e7ade592 | 941 | Proxmox.Utils.API2Request({ |
e3129443 DC |
942 | url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current', |
943 | failure: function(response, opts) { | |
944 | Ext.Msg.alert('Error', response.htmlStatus); | |
945 | }, | |
946 | success: function(response, opts) { | |
ab9f0fe1 | 947 | var allowSpice = !!response.result.data.spice; |
e3129443 DC |
948 | PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname); |
949 | } | |
950 | }); | |
951 | } else if (record.data.type === 'lxc' && !record.data.template) { | |
952 | PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname); | |
953 | } | |
954 | }, | |
955 | ||
fbd60cfd DM |
956 | // test automation helper |
957 | call_menu_handler: function(menu, text) { | |
958 | ||
959 | var list = menu.query('menuitem'); | |
960 | ||
961 | Ext.Array.each(list, function(item) { | |
962 | if (item.text === text) { | |
963 | if (item.handler) { | |
964 | item.handler(); | |
965 | return 1; | |
966 | } else { | |
967 | return undefined; | |
968 | } | |
969 | } | |
970 | }); | |
971 | }, | |
972 | ||
685b7aa4 DC |
973 | createCmdMenu: function(v, record, item, index, event) { |
974 | event.stopEvent(); | |
cc1a91be DC |
975 | if (!(v instanceof Ext.tree.View)) { |
976 | v.select(record); | |
977 | } | |
685b7aa4 | 978 | var menu; |
9bad05bd DC |
979 | var template = !!record.data.template; |
980 | var type = record.data.type; | |
685b7aa4 | 981 | |
9bad05bd DC |
982 | if (template) { |
983 | if (type === 'qemu' || type == 'lxc') { | |
984 | menu = Ext.create('PVE.menu.TemplateMenu', { | |
985 | pveSelNode: record | |
986 | }); | |
987 | } | |
988 | } else if (type === 'qemu' || | |
989 | type === 'lxc' || | |
990 | type === 'node') { | |
991 | menu = Ext.create('PVE.' + type + '.CmdMenu', { | |
992 | pveSelNode: record, | |
c11ab8cb DC |
993 | nodename: record.data.node |
994 | }); | |
685b7aa4 DC |
995 | } else { |
996 | return; | |
997 | } | |
998 | ||
999 | menu.showAt(event.getXY()); | |
9f0b4e04 | 1000 | return menu; |
e7ade592 | 1001 | }, |
9fa2e36d | 1002 | |
fe4f00ad TL |
1003 | // helper for deleting field which are set to there default values |
1004 | delete_if_default: function(values, fieldname, default_val, create) { | |
1005 | if (values[fieldname] === '' || values[fieldname] === default_val) { | |
1006 | if (!create) { | |
1007 | if (values['delete']) { | |
1008 | values['delete'] += ',' + fieldname; | |
1009 | } else { | |
1010 | values['delete'] = fieldname; | |
1011 | } | |
1012 | } | |
1013 | ||
1014 | delete values[fieldname]; | |
1015 | } | |
857b97a7 TL |
1016 | }, |
1017 | ||
1018 | loadSSHKeyFromFile: function(file, callback) { | |
1019 | // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with | |
1020 | // a user@host comment, 1420 for 8192 bits; current max is 16kbit | |
1021 | // assume: 740*8 for max. 32kbit (5920 byte file) | |
1022 | // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space | |
1023 | if (file.size > 8192) { | |
1024 | Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size); | |
1025 | return; | |
1026 | } | |
1027 | /*global | |
1028 | FileReader | |
1029 | */ | |
1030 | var reader = new FileReader(); | |
1031 | reader.onload = function(evt) { | |
1032 | callback(evt.target.result); | |
1033 | }; | |
1034 | reader.readAsText(file); | |
abe824aa DC |
1035 | }, |
1036 | ||
1037 | bus_counts: { ide: 4, sata: 6, scsi: 16, virtio: 16 }, | |
1038 | ||
1039 | // types is either undefined (all busses), an array of busses, or a single bus | |
1040 | forEachBus: function(types, func) { | |
1041 | var busses = Object.keys(PVE.Utils.bus_counts); | |
1042 | var i, j, count, cont; | |
1043 | ||
1044 | if (Ext.isArray(types)) { | |
1045 | busses = types; | |
1046 | } else if (Ext.isDefined(types)) { | |
1047 | busses = [ types ]; | |
1048 | } | |
1049 | ||
1050 | // check if we only have valid busses | |
1051 | for (i = 0; i < busses.length; i++) { | |
1052 | if (!PVE.Utils.bus_counts[busses[i]]) { | |
1053 | throw "invalid bus: '" + busses[i] + "'"; | |
1054 | } | |
1055 | } | |
1056 | ||
1057 | for (i = 0; i < busses.length; i++) { | |
1058 | count = PVE.Utils.bus_counts[busses[i]]; | |
1059 | for (j = 0; j < count; j++) { | |
1060 | cont = func(busses[i], j); | |
1061 | if (!cont && cont !== undefined) { | |
1062 | return; | |
1063 | } | |
1064 | } | |
1065 | } | |
14a845bc DC |
1066 | }, |
1067 | ||
483bd394 | 1068 | mp_counts: { mps: 256, unused: 256 }, |
14a845bc DC |
1069 | |
1070 | forEachMP: function(func, includeUnused) { | |
1071 | var i, cont; | |
1072 | for (i = 0; i < PVE.Utils.mp_counts.mps; i++) { | |
1073 | cont = func('mp', i); | |
1074 | if (!cont && cont !== undefined) { | |
1075 | return; | |
1076 | } | |
1077 | } | |
1078 | ||
1079 | if (!includeUnused) { | |
1080 | return; | |
1081 | } | |
1082 | ||
1083 | for (i = 0; i < PVE.Utils.mp_counts.unused; i++) { | |
1084 | cont = func('unused', i); | |
1085 | if (!cont && cont !== undefined) { | |
1086 | return; | |
1087 | } | |
1088 | } | |
e7ade592 DC |
1089 | } |
1090 | }, | |
fe4f00ad | 1091 | |
9fa2e36d EK |
1092 | singleton: true, |
1093 | constructor: function() { | |
1094 | var me = this; | |
1095 | Ext.apply(me, me.utilities); | |
685b7aa4 | 1096 | } |
e7ade592 | 1097 | |
9fa2e36d | 1098 | }); |
b0a6d326 | 1099 |