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