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