]>
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 | ||
4d739f4a | 10 | console.log("Starting Proxmox VE Manager"); |
b0a6d326 EK |
11 | |
12 | Ext.Ajax.defaultHeaders = { | |
f6710aac | 13 | 'Accept': 'application/json', |
b0a6d326 EK |
14 | }; |
15 | ||
8058410f TL |
16 | Ext.define('PVE.Utils', { |
17 | utilities: { | |
b0a6d326 | 18 | |
9fa2e36d | 19 | // this singleton contains miscellaneous utilities |
b0a6d326 | 20 | |
0be88ae1 | 21 | toolkit: undefined, // (extjs|touch), set inside Toolkit.js |
b0a6d326 | 22 | |
98a01af2 EK |
23 | bus_match: /^(ide|sata|virtio|scsi)\d+$/, |
24 | ||
b0a6d326 EK |
25 | log_severity_hash: { |
26 | 0: "panic", | |
27 | 1: "alert", | |
28 | 2: "critical", | |
29 | 3: "error", | |
30 | 4: "warning", | |
31 | 5: "notice", | |
32 | 6: "info", | |
f6710aac | 33 | 7: "debug", |
b0a6d326 EK |
34 | }, |
35 | ||
36 | support_level_hash: { | |
37 | 'c': gettext('Community'), | |
38 | 'b': gettext('Basic'), | |
39 | 's': gettext('Standard'), | |
f6710aac | 40 | 'p': gettext('Premium'), |
b0a6d326 EK |
41 | }, |
42 | ||
301f52b1 TL |
43 | noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit ' |
44 | +'<a target="_blank" href="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">' | |
45 | +'www.proxmox.com</a> to get a list of available options.', | |
b0a6d326 EK |
46 | |
47 | kvm_ostypes: { | |
45d6c71a | 48 | 'Linux': [ |
ca71cd5d | 49 | { desc: '5.x - 2.6 Kernel', val: 'l26' }, |
f6710aac | 50 | { desc: '2.4 Kernel', val: 'l24' }, |
45d6c71a TL |
51 | ], |
52 | 'Microsoft Windows': [ | |
beb3c8a4 | 53 | { desc: '10/2016/2019', val: 'win10' }, |
45d6c71a TL |
54 | { desc: '8.x/2012/2012r2', val: 'win8' }, |
55 | { desc: '7/2008r2', val: 'win7' }, | |
56 | { desc: 'Vista/2008', val: 'w2k8' }, | |
57 | { desc: 'XP/2003', val: 'wxp' }, | |
f6710aac | 58 | { desc: '2000', val: 'w2k' }, |
45d6c71a TL |
59 | ], |
60 | 'Solaris Kernel': [ | |
8058410f | 61 | { desc: '-', val: 'solaris' }, |
45d6c71a TL |
62 | ], |
63 | 'Other': [ | |
8058410f | 64 | { desc: '-', val: 'other' }, |
f6710aac | 65 | ], |
b0a6d326 EK |
66 | }, |
67 | ||
43798244 SR |
68 | is_windows: function(ostype) { |
69 | for (let entry of PVE.Utils.kvm_ostypes['Microsoft Windows']) { | |
70 | if (entry.val === ostype) { | |
71 | return true; | |
72 | } | |
73 | } | |
74 | return false; | |
75 | }, | |
76 | ||
428bc4a2 DC |
77 | get_health_icon: function(state, circle) { |
78 | if (circle === undefined) { | |
79 | circle = false; | |
80 | } | |
81 | ||
82 | if (state === undefined) { | |
83 | state = 'uknown'; | |
84 | } | |
85 | ||
86 | var icon = 'faded fa-question'; | |
8058410f | 87 | switch (state) { |
428bc4a2 DC |
88 | case 'good': |
89 | icon = 'good fa-check'; | |
90 | break; | |
23c83a3a DC |
91 | case 'upgrade': |
92 | icon = 'warning fa-upload'; | |
93 | break; | |
aa240b29 DC |
94 | case 'old': |
95 | icon = 'warning fa-refresh'; | |
96 | break; | |
428bc4a2 DC |
97 | case 'warning': |
98 | icon = 'warning fa-exclamation'; | |
99 | break; | |
100 | case 'critical': | |
101 | icon = 'critical fa-times'; | |
102 | break; | |
103 | default: break; | |
104 | } | |
105 | ||
106 | if (circle) { | |
107 | icon += '-circle'; | |
108 | } | |
109 | ||
110 | return icon; | |
111 | }, | |
112 | ||
95d0de89 DC |
113 | parse_ceph_version: function(service) { |
114 | if (service.ceph_version_short) { | |
115 | return service.ceph_version_short; | |
116 | } | |
117 | ||
118 | if (service.ceph_version) { | |
35306f47 | 119 | var match = service.ceph_version.match(/version (\d+(\.\d+)*)/); |
95d0de89 DC |
120 | if (match) { |
121 | return match[1]; | |
122 | } | |
123 | } | |
124 | ||
125 | return undefined; | |
126 | }, | |
127 | ||
005e0a60 | 128 | compare_ceph_versions: function(a, b) { |
3a08795a DC |
129 | let avers = []; |
130 | let bvers = []; | |
131 | ||
005e0a60 DC |
132 | if (a === b) { |
133 | return 0; | |
134 | } | |
3a08795a DC |
135 | |
136 | if (Ext.isArray(a)) { | |
137 | avers = a.slice(); // copy array | |
138 | } else { | |
139 | avers = a.toString().split('.'); | |
140 | } | |
141 | ||
142 | if (Ext.isArray(b)) { | |
143 | bvers = b.slice(); // copy array | |
144 | } else { | |
145 | bvers = b.toString().split('.'); | |
146 | } | |
35306f47 | 147 | |
4d739f4a | 148 | for (;;) { |
35306f47 TL |
149 | let av = avers.shift(); |
150 | let bv = bvers.shift(); | |
151 | ||
152 | if (av === undefined && bv === undefined) { | |
153 | return 0; | |
8058410f | 154 | } else if (av === undefined) { |
35306f47 TL |
155 | return -1; |
156 | } else if (bv === undefined) { | |
157 | return 1; | |
158 | } else { | |
159 | let diff = parseInt(av, 10) - parseInt(bv, 10); | |
4d739f4a | 160 | if (diff !== 0) return diff; |
35306f47 | 161 | // else we need to look at the next parts |
005e0a60 DC |
162 | } |
163 | } | |
005e0a60 DC |
164 | }, |
165 | ||
2f5b82ae DC |
166 | get_ceph_icon_html: function(health, fw) { |
167 | var state = PVE.Utils.map_ceph_health[health]; | |
168 | var cls = PVE.Utils.get_health_icon(state); | |
169 | if (fw) { | |
170 | cls += ' fa-fw'; | |
171 | } | |
172 | return "<i class='fa " + cls + "'></i> "; | |
173 | }, | |
174 | ||
046e640c | 175 | map_ceph_health: { |
8058410f TL |
176 | 'HEALTH_OK': 'good', |
177 | 'HEALTH_UPGRADE': 'upgrade', | |
178 | 'HEALTH_OLD': 'old', | |
179 | 'HEALTH_WARN': 'warning', | |
180 | 'HEALTH_ERR': 'critical', | |
046e640c DC |
181 | }, |
182 | ||
4d739f4a | 183 | render_sdn_pending: function(rec, value, key, index) { |
1d9643f6 AD |
184 | if (rec.data.state === undefined || rec.data.state === null) { |
185 | return value; | |
186 | } | |
187 | ||
188 | if (rec.data.state === 'deleted') { | |
189 | if (value === undefined) { | |
190 | return ' '; | |
191 | } else { | |
192 | return '<div style="text-decoration: line-through;">'+ value +'</div>'; | |
193 | } | |
4d739f4a TL |
194 | } else if (rec.data.pending[key] !== undefined && rec.data.pending[key] !== null) { |
195 | if (rec.data.pending[key] === 'deleted') { | |
196 | return ' '; | |
1d9643f6 | 197 | } else { |
4d739f4a | 198 | return rec.data.pending[key]; |
1d9643f6 AD |
199 | } |
200 | } | |
201 | return value; | |
202 | }, | |
203 | ||
4d739f4a | 204 | render_sdn_pending_state: function(rec, value) { |
1d9643f6 AD |
205 | if (value === undefined || value === null) { |
206 | return ' '; | |
207 | } | |
208 | ||
209 | let icon = `<i class="fa fa-fw fa-refresh warning"></i>`; | |
210 | ||
211 | if (value === 'deleted') { | |
212 | return '<span>' + icon + value + '</span>'; | |
213 | } | |
214 | ||
4d739f4a | 215 | let tip = gettext('Pending Changes') + ': <br>'; |
1d9643f6 AD |
216 | |
217 | for (const [key, keyvalue] of Object.entries(rec.data.pending)) { | |
4d739f4a TL |
218 | if ((rec.data[key] !== undefined && rec.data.pending[key] !== rec.data[key]) || |
219 | rec.data[key] === undefined | |
220 | ) { | |
221 | tip += `${key}: ${keyvalue} <br>`; | |
1d9643f6 AD |
222 | } |
223 | } | |
224 | return '<span data-qtip="' + tip + '">'+ icon + value + '</span>'; | |
225 | }, | |
226 | ||
dfe6d184 | 227 | render_ceph_health: function(healthObj) { |
046e640c DC |
228 | var state = { |
229 | iconCls: PVE.Utils.get_health_icon(), | |
f6710aac | 230 | text: '', |
046e640c DC |
231 | }; |
232 | ||
dfe6d184 | 233 | if (!healthObj || !healthObj.status) { |
046e640c DC |
234 | return state; |
235 | } | |
236 | ||
dfe6d184 | 237 | var health = PVE.Utils.map_ceph_health[healthObj.status]; |
046e640c DC |
238 | |
239 | state.iconCls = PVE.Utils.get_health_icon(health, true); | |
dfe6d184 | 240 | state.text = healthObj.status; |
046e640c DC |
241 | |
242 | return state; | |
243 | }, | |
244 | ||
fee716d3 | 245 | render_zfs_health: function(value) { |
4d739f4a | 246 | if (typeof value === 'undefined') { |
8c8604ba TM |
247 | return ""; |
248 | } | |
fee716d3 DC |
249 | var iconCls = 'question-circle'; |
250 | switch (value) { | |
8c8604ba | 251 | case 'AVAIL': |
fee716d3 DC |
252 | case 'ONLINE': |
253 | iconCls = 'check-circle good'; | |
254 | break; | |
255 | case 'REMOVED': | |
256 | case 'DEGRADED': | |
257 | iconCls = 'exclamation-circle warning'; | |
258 | break; | |
259 | case 'UNAVAIL': | |
260 | case 'FAULTED': | |
261 | case 'OFFLINE': | |
262 | iconCls = 'times-circle critical'; | |
263 | break; | |
264 | default: //unknown | |
265 | } | |
266 | ||
267 | return '<i class="fa fa-' + iconCls + '"></i> ' + value; | |
268 | }, | |
269 | ||
14ba33fb TL |
270 | render_pbs_fingerprint: fp => fp.substring(0, 23), |
271 | ||
3003a59d TL |
272 | render_backup_encryption: function(v, meta, record) { |
273 | if (!v) { | |
274 | return gettext('No'); | |
275 | } | |
276 | ||
277 | let tip = ''; | |
278 | if (v.match(/^[a-fA-F0-9]{2}:/)) { // fingerprint | |
279 | tip = `Key fingerprint ${PVE.Utils.render_pbs_fingerprint(v)}`; | |
280 | } | |
281 | let icon = `<i class="fa fa-fw fa-lock good"></i>`; | |
282 | return `<span data-qtip="${tip}">${icon} ${gettext('Encrypted')}</span>`; | |
283 | }, | |
284 | ||
770d614f TL |
285 | render_backup_verification: function(v, meta, record) { |
286 | let i = (cls, txt) => `<i class="fa fa-fw fa-${cls}"></i> ${txt}`; | |
287 | if (v === undefined || v === null) { | |
288 | return i('question-circle-o warning', gettext('None')); | |
289 | } | |
8058410f | 290 | let tip = ""; |
770d614f TL |
291 | let txt = gettext('Failed'); |
292 | let iconCls = 'times critical'; | |
293 | if (v.state === 'ok') { | |
294 | txt = gettext('OK'); | |
295 | iconCls = 'check good'; | |
296 | let now = Date.now() / 1000; | |
297 | let task = Proxmox.Utils.parse_task_upid(v.upid); | |
298 | let verify_time = Proxmox.Utils.render_timestamp(task.starttime); | |
299 | tip = `Last verify task started on ${verify_time}`; | |
300 | if (now - v.starttime > 30 * 24 * 60 * 60) { | |
301 | tip = `Last verify task over 30 days ago: ${verify_time}`; | |
302 | iconCls = 'check warning'; | |
303 | } | |
304 | } | |
305 | return `<span data-qtip="${tip}"> ${i(iconCls, txt)} </span>`; | |
306 | }, | |
307 | ||
01ad47af | 308 | render_backup_status: function(value, meta, record) { |
4d739f4a | 309 | if (typeof value === 'undefined') { |
01ad47af AL |
310 | return ""; |
311 | } | |
312 | ||
313 | let iconCls = 'check-circle good'; | |
314 | let text = gettext('Yes'); | |
315 | ||
316 | if (!PVE.Parser.parseBoolean(value.toString())) { | |
317 | iconCls = 'times-circle critical'; | |
318 | ||
319 | text = gettext('No'); | |
320 | ||
321 | let reason = record.get('reason'); | |
322 | if (typeof reason !== 'undefined') { | |
323 | if (reason in PVE.Utils.backup_reasons_table) { | |
324 | reason = PVE.Utils.backup_reasons_table[record.get('reason')]; | |
325 | } | |
326 | text = `${text} - ${reason}`; | |
327 | } | |
328 | } | |
329 | ||
330 | return `<i class="fa fa-${iconCls}"></i> ${text}`; | |
331 | }, | |
332 | ||
7f08d0d1 AL |
333 | render_backup_days_of_week: function(val) { |
334 | var dows = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; | |
335 | var selected = []; | |
336 | var cur = -1; | |
8058410f | 337 | val.split(',').forEach(function(day) { |
7f08d0d1 AL |
338 | cur++; |
339 | var dow = (dows.indexOf(day)+6)%7; | |
340 | if (cur === dow) { | |
341 | if (selected.length === 0 || selected[selected.length-1] === 0) { | |
342 | selected.push(1); | |
343 | } else { | |
344 | selected[selected.length-1]++; | |
345 | } | |
346 | } else { | |
347 | while (cur < dow) { | |
348 | cur++; | |
349 | selected.push(0); | |
350 | } | |
351 | selected.push(1); | |
352 | } | |
353 | }); | |
354 | ||
355 | cur = -1; | |
356 | var days = []; | |
357 | selected.forEach(function(item) { | |
358 | cur++; | |
359 | if (item > 2) { | |
53e3ea84 | 360 | days.push(Ext.Date.dayNames[cur+1] + '-' + Ext.Date.dayNames[(cur+item)%7]); |
7f08d0d1 | 361 | cur += item-1; |
4d739f4a | 362 | } else if (item === 2) { |
7f08d0d1 AL |
363 | days.push(Ext.Date.dayNames[cur+1]); |
364 | days.push(Ext.Date.dayNames[(cur+2)%7]); | |
365 | cur++; | |
4d739f4a | 366 | } else if (item === 1) { |
7f08d0d1 AL |
367 | days.push(Ext.Date.dayNames[(cur+1)%7]); |
368 | } | |
369 | }); | |
370 | return days.join(', '); | |
371 | }, | |
372 | ||
373 | render_backup_selection: function(value, metaData, record) { | |
374 | let allExceptText = gettext('All except {0}'); | |
375 | let allText = '-- ' + gettext('All') + ' --'; | |
376 | if (record.data.all) { | |
377 | if (record.data.exclude) { | |
378 | return Ext.String.format(allExceptText, record.data.exclude); | |
379 | } | |
380 | return allText; | |
381 | } | |
382 | if (record.data.vmid) { | |
383 | return record.data.vmid; | |
384 | } | |
385 | ||
386 | if (record.data.pool) { | |
387 | return "Pool '"+ record.data.pool + "'"; | |
388 | } | |
389 | ||
390 | return "-"; | |
391 | }, | |
392 | ||
01ad47af AL |
393 | backup_reasons_table: { |
394 | 'backup=yes': gettext('Enabled'), | |
395 | 'backup=no': gettext('Disabled'), | |
396 | 'enabled': gettext('Enabled'), | |
397 | 'disabled': gettext('Disabled'), | |
398 | 'not a volume': gettext('Not a volume'), | |
399 | 'efidisk but no OMVF BIOS': gettext('EFI Disk without OMVF BIOS'), | |
400 | }, | |
401 | ||
45d6c71a TL |
402 | get_kvm_osinfo: function(value) { |
403 | var info = { base: 'Other' }; // default | |
404 | if (value) { | |
405 | Ext.each(Object.keys(PVE.Utils.kvm_ostypes), function(k) { | |
406 | Ext.each(PVE.Utils.kvm_ostypes[k], function(e) { | |
407 | if (e.val === value) { | |
408 | info = { desc: e.desc, base: k }; | |
409 | } | |
410 | }); | |
411 | }); | |
b0a6d326 | 412 | } |
45d6c71a TL |
413 | return info; |
414 | }, | |
415 | ||
8058410f | 416 | render_kvm_ostype: function(value) { |
45d6c71a TL |
417 | var osinfo = PVE.Utils.get_kvm_osinfo(value); |
418 | if (osinfo.desc && osinfo.desc !== '-') { | |
419 | return osinfo.base + ' ' + osinfo.desc; | |
420 | } else { | |
421 | return osinfo.base; | |
b0a6d326 | 422 | } |
b0a6d326 EK |
423 | }, |
424 | ||
8058410f | 425 | render_hotplug_features: function(value) { |
23d3881a | 426 | var fa = []; |
b0a6d326 | 427 | |
53e3ea84 | 428 | if (!value || value === '0') { |
ec99b1c3 | 429 | return gettext('Disabled'); |
b0a6d326 EK |
430 | } |
431 | ||
4dcca8a4 DC |
432 | if (value === '1') { |
433 | value = 'disk,network,usb'; | |
434 | } | |
435 | ||
b0a6d326 EK |
436 | Ext.each(value.split(','), function(el) { |
437 | if (el === 'disk') { | |
438 | fa.push(gettext('Disk')); | |
439 | } else if (el === 'network') { | |
440 | fa.push(gettext('Network')); | |
441 | } else if (el === 'usb') { | |
b9628aa5 | 442 | fa.push('USB'); |
b0a6d326 EK |
443 | } else if (el === 'memory') { |
444 | fa.push(gettext('Memory')); | |
445 | } else if (el === 'cpu') { | |
446 | fa.push(gettext('CPU')); | |
447 | } else { | |
448 | fa.push(el); | |
449 | } | |
450 | }); | |
451 | ||
452 | return fa.join(', '); | |
453 | }, | |
454 | ||
0beff18b FE |
455 | render_localtime: function(value) { |
456 | if (value === '__default__') { | |
457 | return Proxmox.Utils.defaultText + ' (' + gettext('Enabled for Windows') + ')'; | |
458 | } | |
459 | return Proxmox.Utils.format_boolean(value); | |
460 | }, | |
461 | ||
4d739f4a TL |
462 | render_qga_features: function(config) { |
463 | if (!config) { | |
8058410f | 464 | return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText + ')'; |
1662ccdb | 465 | } |
4d739f4a TL |
466 | let qga = PVE.Parser.parsePropertyString(config, 'enabled'); |
467 | if (!PVE.Parser.parseBoolean(qga.enabled)) { | |
1662ccdb SI |
468 | return Proxmox.Utils.disabledText; |
469 | } | |
4d739f4a | 470 | delete qga.enabled; |
1662ccdb | 471 | |
4d739f4a | 472 | let agentstring = Proxmox.Utils.enabledText; |
1662ccdb | 473 | |
4d739f4a TL |
474 | for (const [key, value] of Object.entries(qga)) { |
475 | let displayText = Proxmox.Utils.disabledText; | |
5a6c563c MD |
476 | if (key === 'type') { |
477 | let map = { | |
478 | isa: "ISA", | |
176a62d3 | 479 | virtio: "VirtIO", |
5a6c563c | 480 | }; |
4d739f4a TL |
481 | displayText = map[value] || Proxmox.Utils.unknownText; |
482 | } else if (PVE.Parser.parseBoolean(value)) { | |
483 | displayText = Proxmox.Utils.enabledText; | |
1662ccdb | 484 | } |
4d739f4a TL |
485 | agentstring += `, ${key}: ${displayText}`; |
486 | } | |
1662ccdb SI |
487 | |
488 | return agentstring; | |
489 | }, | |
490 | ||
a1ee14a2 | 491 | render_qemu_machine: function(value) { |
53e3ea84 | 492 | return value || Proxmox.Utils.defaultText + ' (i440fx)'; |
a1ee14a2 DC |
493 | }, |
494 | ||
17c71f27 DC |
495 | render_qemu_bios: function(value) { |
496 | if (!value) { | |
e7ade592 | 497 | return Proxmox.Utils.defaultText + ' (SeaBIOS)'; |
17c71f27 DC |
498 | } else if (value === 'seabios') { |
499 | return "SeaBIOS"; | |
500 | } else if (value === 'ovmf') { | |
501 | return "OVMF (UEFI)"; | |
502 | } else { | |
503 | return value; | |
504 | } | |
505 | }, | |
506 | ||
8f17b496 TL |
507 | render_dc_ha_opts: function(value) { |
508 | if (!value) { | |
41ca3465 | 509 | return Proxmox.Utils.defaultText; |
8f17b496 TL |
510 | } else { |
511 | return PVE.Parser.printPropertyString(value); | |
512 | } | |
513 | }, | |
bb469a11 | 514 | render_as_property_string: function(value) { |
53e3ea84 | 515 | return !value ? Proxmox.Utils.defaultText |
bb469a11 TL |
516 | : PVE.Parser.printPropertyString(value); |
517 | }, | |
8f17b496 | 518 | |
b0a6d326 EK |
519 | render_scsihw: function(value) { |
520 | if (!value) { | |
e7ade592 | 521 | return Proxmox.Utils.defaultText + ' (LSI 53C895A)'; |
b0a6d326 EK |
522 | } else if (value === 'lsi') { |
523 | return 'LSI 53C895A'; | |
524 | } else if (value === 'lsi53c810') { | |
525 | return 'LSI 53C810'; | |
526 | } else if (value === 'megasas') { | |
527 | return 'MegaRAID SAS 8708EM2'; | |
528 | } else if (value === 'virtio-scsi-pci') { | |
49f5d1ab EK |
529 | return 'VirtIO SCSI'; |
530 | } else if (value === 'virtio-scsi-single') { | |
531 | return 'VirtIO SCSI single'; | |
b0a6d326 EK |
532 | } else if (value === 'pvscsi') { |
533 | return 'VMware PVSCSI'; | |
534 | } else { | |
535 | return value; | |
536 | } | |
537 | }, | |
538 | ||
9c22da32 | 539 | render_spice_enhancements: function(values) { |
9c22da32 AL |
540 | let props = PVE.Parser.parsePropertyString(values); |
541 | if (Ext.Object.isEmpty(props)) { | |
3b0facc9 | 542 | return Proxmox.Utils.noneText; |
9c22da32 AL |
543 | } |
544 | ||
545 | let output = []; | |
546 | if (PVE.Parser.parseBoolean(props.foldersharing)) { | |
547 | output.push('Folder Sharing: ' + gettext('Enabled')); | |
548 | } | |
549 | if (props.videostreaming === 'all' || props.videostreaming === 'filter') { | |
550 | output.push('Video Streaming: ' + props.videostreaming); | |
551 | } | |
552 | return output.join(', '); | |
553 | }, | |
554 | ||
b0a6d326 EK |
555 | // fixme: auto-generate this |
556 | // for now, please keep in sync with PVE::Tools::kvmkeymaps | |
557 | kvm_keymaps: { | |
558 | //ar: 'Arabic', | |
559 | da: 'Danish', | |
0be88ae1 DC |
560 | de: 'German', |
561 | 'de-ch': 'German (Swiss)', | |
562 | 'en-gb': 'English (UK)', | |
0a5b8747 | 563 | 'en-us': 'English (USA)', |
b0a6d326 EK |
564 | es: 'Spanish', |
565 | //et: 'Estonia', | |
566 | fi: 'Finnish', | |
0be88ae1 DC |
567 | //fo: 'Faroe Islands', |
568 | fr: 'French', | |
569 | 'fr-be': 'French (Belgium)', | |
b0a6d326 EK |
570 | 'fr-ca': 'French (Canada)', |
571 | 'fr-ch': 'French (Swiss)', | |
572 | //hr: 'Croatia', | |
573 | hu: 'Hungarian', | |
574 | is: 'Icelandic', | |
0be88ae1 | 575 | it: 'Italian', |
b0a6d326 EK |
576 | ja: 'Japanese', |
577 | lt: 'Lithuanian', | |
578 | //lv: 'Latvian', | |
0be88ae1 | 579 | mk: 'Macedonian', |
b0a6d326 EK |
580 | nl: 'Dutch', |
581 | //'nl-be': 'Dutch (Belgium)', | |
0be88ae1 | 582 | no: 'Norwegian', |
b0a6d326 EK |
583 | pl: 'Polish', |
584 | pt: 'Portuguese', | |
585 | 'pt-br': 'Portuguese (Brazil)', | |
586 | //ru: 'Russian', | |
587 | sl: 'Slovenian', | |
588 | sv: 'Swedish', | |
589 | //th: 'Thai', | |
f6710aac | 590 | tr: 'Turkish', |
b0a6d326 EK |
591 | }, |
592 | ||
593 | kvm_vga_drivers: { | |
594 | std: gettext('Standard VGA'), | |
5ca366f2 | 595 | vmware: gettext('VMware compatible'), |
b0a6d326 EK |
596 | qxl: 'SPICE', |
597 | qxl2: 'SPICE dual monitor', | |
598 | qxl3: 'SPICE three monitors', | |
599 | qxl4: 'SPICE four monitors', | |
600 | serial0: gettext('Serial terminal') + ' 0', | |
601 | serial1: gettext('Serial terminal') + ' 1', | |
602 | serial2: gettext('Serial terminal') + ' 2', | |
89ae1bb1 DC |
603 | serial3: gettext('Serial terminal') + ' 3', |
604 | virtio: 'VirtIO-GPU', | |
f6710aac | 605 | none: Proxmox.Utils.noneText, |
b0a6d326 EK |
606 | }, |
607 | ||
8058410f | 608 | render_kvm_language: function(value) { |
e7ade592 DC |
609 | if (!value || value === '__default__') { |
610 | return Proxmox.Utils.defaultText; | |
b0a6d326 EK |
611 | } |
612 | var text = PVE.Utils.kvm_keymaps[value]; | |
613 | if (text) { | |
614 | return text + ' (' + value + ')'; | |
615 | } | |
616 | return value; | |
617 | }, | |
618 | ||
619 | kvm_keymap_array: function() { | |
f2782813 | 620 | var data = [['__default__', PVE.Utils.render_kvm_language('')]]; |
b0a6d326 EK |
621 | Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) { |
622 | data.push([key, PVE.Utils.render_kvm_language(value)]); | |
623 | }); | |
624 | ||
625 | return data; | |
626 | }, | |
627 | ||
3438c27e | 628 | console_map: { |
da9d14cd | 629 | '__default__': Proxmox.Utils.defaultText + ' (xterm.js)', |
3438c27e DC |
630 | 'vv': 'SPICE (remote-viewer)', |
631 | 'html5': 'HTML5 (noVNC)', | |
f6710aac | 632 | 'xtermjs': 'xterm.js', |
3438c27e DC |
633 | }, |
634 | ||
b0a6d326 | 635 | render_console_viewer: function(value) { |
3438c27e DC |
636 | value = value || '__default__'; |
637 | if (PVE.Utils.console_map[value]) { | |
638 | return PVE.Utils.console_map[value]; | |
b0a6d326 | 639 | } |
3438c27e | 640 | return value; |
b0a6d326 EK |
641 | }, |
642 | ||
755b9083 | 643 | console_viewer_array: function() { |
3438c27e | 644 | return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) { |
755b9083 TL |
645 | return [v, PVE.Utils.render_console_viewer(v)]; |
646 | }); | |
647 | }, | |
648 | ||
8058410f | 649 | render_kvm_vga_driver: function(value) { |
b0a6d326 | 650 | if (!value) { |
e7ade592 | 651 | return Proxmox.Utils.defaultText; |
b0a6d326 | 652 | } |
4f3e66d8 DC |
653 | var vga = PVE.Parser.parsePropertyString(value, 'type'); |
654 | var text = PVE.Utils.kvm_vga_drivers[vga.type]; | |
655 | if (!vga.type) { | |
656 | text = Proxmox.Utils.defaultText; | |
657 | } | |
0be88ae1 | 658 | if (text) { |
b0a6d326 EK |
659 | return text + ' (' + value + ')'; |
660 | } | |
661 | return value; | |
662 | }, | |
663 | ||
664 | kvm_vga_driver_array: function() { | |
f2782813 | 665 | var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]]; |
b0a6d326 EK |
666 | Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) { |
667 | data.push([key, PVE.Utils.render_kvm_vga_driver(value)]); | |
668 | }); | |
669 | ||
670 | return data; | |
671 | }, | |
672 | ||
673 | render_kvm_startup: function(value) { | |
674 | var startup = PVE.Parser.parseStartup(value); | |
675 | ||
676 | var res = 'order='; | |
677 | if (startup.order === undefined) { | |
678 | res += 'any'; | |
679 | } else { | |
680 | res += startup.order; | |
681 | } | |
682 | if (startup.up !== undefined) { | |
683 | res += ',up=' + startup.up; | |
684 | } | |
685 | if (startup.down !== undefined) { | |
686 | res += ',down=' + startup.down; | |
687 | } | |
688 | ||
689 | return res; | |
690 | }, | |
691 | ||
b0a6d326 EK |
692 | extractFormActionError: function(action) { |
693 | var msg; | |
694 | switch (action.failureType) { | |
695 | case Ext.form.action.Action.CLIENT_INVALID: | |
696 | msg = gettext('Form fields may not be submitted with invalid values'); | |
697 | break; | |
698 | case Ext.form.action.Action.CONNECT_FAILURE: | |
699 | msg = gettext('Connection error'); | |
700 | var resp = action.response; | |
701 | if (resp.status && resp.statusText) { | |
702 | msg += " " + resp.status + ": " + resp.statusText; | |
703 | } | |
704 | break; | |
705 | case Ext.form.action.Action.LOAD_FAILURE: | |
706 | case Ext.form.action.Action.SERVER_INVALID: | |
e7ade592 | 707 | msg = Proxmox.Utils.extractRequestError(action.result, true); |
b0a6d326 EK |
708 | break; |
709 | } | |
710 | return msg; | |
711 | }, | |
712 | ||
0e244a29 DC |
713 | contentTypes: { |
714 | 'images': gettext('Disk image'), | |
715 | 'backup': gettext('VZDump backup file'), | |
716 | 'vztmpl': gettext('Container template'), | |
717 | 'iso': gettext('ISO image'), | |
aef28e04 | 718 | 'rootdir': gettext('Container'), |
f6710aac | 719 | 'snippets': gettext('Snippets'), |
0e244a29 | 720 | }, |
b0a6d326 | 721 | |
3b8f599b DM |
722 | volume_is_qemu_backup: function(volid, format) { |
723 | return format === 'pbs-vm' || volid.match(':backup/vzdump-qemu-'); | |
724 | }, | |
725 | ||
726 | volume_is_lxc_backup: function(volid, format) { | |
727 | return format === 'pbs-ct' || volid.match(':backup/vzdump-(lxc|openvz)-'); | |
728 | }, | |
729 | ||
efff7eab DC |
730 | authSchema: { |
731 | ad: { | |
732 | name: gettext('Active Directory Server'), | |
733 | ipanel: 'pveAuthADPanel', | |
822fb26d | 734 | syncipanel: 'pveAuthLDAPSyncPanel', |
efff7eab | 735 | add: true, |
550857eb | 736 | tfa: true, |
60265958 | 737 | pwchange: true, |
efff7eab DC |
738 | }, |
739 | ldap: { | |
740 | name: gettext('LDAP Server'), | |
741 | ipanel: 'pveAuthLDAPPanel', | |
822fb26d | 742 | syncipanel: 'pveAuthLDAPSyncPanel', |
efff7eab | 743 | add: true, |
550857eb | 744 | tfa: true, |
60265958 | 745 | pwchange: true, |
efff7eab | 746 | }, |
668951e2 DC |
747 | openid: { |
748 | name: gettext('OpenID Server'), | |
749 | ipanel: 'pveAuthOpenIDPanel', | |
750 | add: true, | |
751 | tfa: false, | |
60265958 | 752 | pwchange: false, |
da25c5ac | 753 | iconCls: 'pmx-itype-icon-openid-logo', |
668951e2 | 754 | }, |
efff7eab DC |
755 | pam: { |
756 | name: 'Linux PAM', | |
757 | ipanel: 'pveAuthBasePanel', | |
758 | add: false, | |
550857eb | 759 | tfa: true, |
60265958 | 760 | pwchange: true, |
efff7eab DC |
761 | }, |
762 | pve: { | |
763 | name: 'Proxmox VE authentication server', | |
764 | ipanel: 'pveAuthBasePanel', | |
765 | add: false, | |
60265958 | 766 | pwchange: true, |
efff7eab DC |
767 | }, |
768 | }, | |
769 | ||
062a7f49 TL |
770 | storageSchema: { |
771 | dir: { | |
772 | name: Proxmox.Utils.directoryText, | |
773 | ipanel: 'DirInputPanel', | |
06c8315d DC |
774 | faIcon: 'folder', |
775 | backups: true, | |
062a7f49 TL |
776 | }, |
777 | lvm: { | |
778 | name: 'LVM', | |
779 | ipanel: 'LVMInputPanel', | |
06c8315d DC |
780 | faIcon: 'folder', |
781 | backups: false, | |
062a7f49 TL |
782 | }, |
783 | lvmthin: { | |
784 | name: 'LVM-Thin', | |
785 | ipanel: 'LvmThinInputPanel', | |
06c8315d DC |
786 | faIcon: 'folder', |
787 | backups: false, | |
062a7f49 | 788 | }, |
ffeb4f57 TL |
789 | btrfs: { |
790 | name: 'BTRFS', | |
791 | ipanel: 'BTRFSInputPanel', | |
792 | faIcon: 'folder', | |
793 | backups: true, | |
794 | }, | |
062a7f49 TL |
795 | nfs: { |
796 | name: 'NFS', | |
797 | ipanel: 'NFSInputPanel', | |
06c8315d DC |
798 | faIcon: 'building', |
799 | backups: true, | |
062a7f49 TL |
800 | }, |
801 | cifs: { | |
802 | name: 'CIFS', | |
803 | ipanel: 'CIFSInputPanel', | |
06c8315d DC |
804 | faIcon: 'building', |
805 | backups: true, | |
062a7f49 TL |
806 | }, |
807 | glusterfs: { | |
808 | name: 'GlusterFS', | |
809 | ipanel: 'GlusterFsInputPanel', | |
06c8315d DC |
810 | faIcon: 'building', |
811 | backups: true, | |
062a7f49 TL |
812 | }, |
813 | iscsi: { | |
814 | name: 'iSCSI', | |
815 | ipanel: 'IScsiInputPanel', | |
06c8315d DC |
816 | faIcon: 'building', |
817 | backups: false, | |
062a7f49 | 818 | }, |
4a4b2b6e TL |
819 | cephfs: { |
820 | name: 'CephFS', | |
821 | ipanel: 'CephFSInputPanel', | |
06c8315d DC |
822 | faIcon: 'building', |
823 | backups: true, | |
4a4b2b6e TL |
824 | }, |
825 | pvecephfs: { | |
826 | name: 'CephFS (PVE)', | |
827 | ipanel: 'CephFSInputPanel', | |
828 | hideAdd: true, | |
06c8315d DC |
829 | faIcon: 'building', |
830 | backups: true, | |
4a4b2b6e | 831 | }, |
062a7f49 TL |
832 | rbd: { |
833 | name: 'RBD', | |
834 | ipanel: 'RBDInputPanel', | |
06c8315d DC |
835 | faIcon: 'building', |
836 | backups: false, | |
062a7f49 TL |
837 | }, |
838 | pveceph: { | |
839 | name: 'RBD (PVE)', | |
0d1ac958 TL |
840 | ipanel: 'RBDInputPanel', |
841 | hideAdd: true, | |
06c8315d DC |
842 | faIcon: 'building', |
843 | backups: false, | |
062a7f49 TL |
844 | }, |
845 | zfs: { | |
846 | name: 'ZFS over iSCSI', | |
847 | ipanel: 'ZFSInputPanel', | |
06c8315d DC |
848 | faIcon: 'building', |
849 | backups: false, | |
062a7f49 TL |
850 | }, |
851 | zfspool: { | |
852 | name: 'ZFS', | |
853 | ipanel: 'ZFSPoolInputPanel', | |
06c8315d DC |
854 | faIcon: 'folder', |
855 | backups: false, | |
062a7f49 | 856 | }, |
8b966034 TL |
857 | pbs: { |
858 | name: 'Proxmox Backup Server', | |
ee19d331 TL |
859 | ipanel: 'PBSInputPanel', |
860 | faIcon: 'floppy-o', | |
06c8315d | 861 | backups: true, |
8b966034 | 862 | }, |
062a7f49 TL |
863 | drbd: { |
864 | name: 'DRBD', | |
8b966034 | 865 | hideAdd: true, |
06c8315d | 866 | backups: false, |
8b966034 | 867 | }, |
062a7f49 TL |
868 | }, |
869 | ||
9233148b AD |
870 | sdnvnetSchema: { |
871 | vnet: { | |
872 | name: 'vnet', | |
f6710aac | 873 | faIcon: 'folder', |
9233148b AD |
874 | }, |
875 | }, | |
876 | ||
877 | sdnzoneSchema: { | |
878 | zone: { | |
879 | name: 'zone', | |
f6710aac | 880 | hideAdd: true, |
9233148b | 881 | }, |
1b4cce60 AD |
882 | simple: { |
883 | name: 'Simple', | |
884 | ipanel: 'SimpleInputPanel', | |
f6710aac | 885 | faIcon: 'th', |
1b4cce60 | 886 | }, |
9233148b | 887 | vlan: { |
f3c1eac7 | 888 | name: 'VLAN', |
9233148b | 889 | ipanel: 'VlanInputPanel', |
f6710aac | 890 | faIcon: 'th', |
9233148b AD |
891 | }, |
892 | qinq: { | |
f3c1eac7 | 893 | name: 'QinQ', |
9233148b | 894 | ipanel: 'QinQInputPanel', |
f6710aac | 895 | faIcon: 'th', |
9233148b AD |
896 | }, |
897 | vxlan: { | |
f3c1eac7 | 898 | name: 'VXLAN', |
9233148b | 899 | ipanel: 'VxlanInputPanel', |
f6710aac | 900 | faIcon: 'th', |
9233148b AD |
901 | }, |
902 | evpn: { | |
f3c1eac7 | 903 | name: 'EVPN', |
9233148b | 904 | ipanel: 'EvpnInputPanel', |
f6710aac | 905 | faIcon: 'th', |
9233148b AD |
906 | }, |
907 | }, | |
908 | ||
909 | sdncontrollerSchema: { | |
910 | controller: { | |
911 | name: 'controller', | |
f6710aac | 912 | hideAdd: true, |
9233148b AD |
913 | }, |
914 | evpn: { | |
915 | name: 'evpn', | |
916 | ipanel: 'EvpnInputPanel', | |
f6710aac | 917 | faIcon: 'crosshairs', |
9233148b | 918 | }, |
1d9643f6 AD |
919 | bgp: { |
920 | name: 'bgp', | |
921 | ipanel: 'BgpInputPanel', | |
4d739f4a | 922 | faIcon: 'crosshairs', |
1d9643f6 AD |
923 | }, |
924 | }, | |
925 | ||
926 | sdnipamSchema: { | |
927 | ipam: { | |
928 | name: 'ipam', | |
4d739f4a | 929 | hideAdd: true, |
1d9643f6 AD |
930 | }, |
931 | pve: { | |
932 | name: 'PVE', | |
933 | ipanel: 'PVEIpamInputPanel', | |
934 | faIcon: 'th', | |
4d739f4a | 935 | hideAdd: true, |
1d9643f6 AD |
936 | }, |
937 | netbox: { | |
938 | name: 'Netbox', | |
939 | ipanel: 'NetboxInputPanel', | |
4d739f4a | 940 | faIcon: 'th', |
1d9643f6 AD |
941 | }, |
942 | phpipam: { | |
943 | name: 'PhpIpam', | |
944 | ipanel: 'PhpIpamInputPanel', | |
4d739f4a | 945 | faIcon: 'th', |
1d9643f6 AD |
946 | }, |
947 | }, | |
948 | ||
949 | sdndnsSchema: { | |
950 | dns: { | |
951 | name: 'dns', | |
4d739f4a | 952 | hideAdd: true, |
1d9643f6 AD |
953 | }, |
954 | powerdns: { | |
955 | name: 'powerdns', | |
956 | ipanel: 'PowerdnsInputPanel', | |
4d739f4a | 957 | faIcon: 'th', |
1d9643f6 | 958 | }, |
9233148b AD |
959 | }, |
960 | ||
961 | format_sdnvnet_type: function(value, md, record) { | |
962 | var schema = PVE.Utils.sdnvnetSchema[value]; | |
963 | if (schema) { | |
964 | return schema.name; | |
965 | } | |
966 | return Proxmox.Utils.unknownText; | |
967 | }, | |
968 | ||
969 | format_sdnzone_type: function(value, md, record) { | |
970 | var schema = PVE.Utils.sdnzoneSchema[value]; | |
971 | if (schema) { | |
f3c1eac7 | 972 | return schema.name; |
9233148b AD |
973 | } |
974 | return Proxmox.Utils.unknownText; | |
975 | }, | |
976 | ||
977 | format_sdncontroller_type: function(value, md, record) { | |
978 | var schema = PVE.Utils.sdncontrollerSchema[value]; | |
979 | if (schema) { | |
980 | return schema.name; | |
981 | } | |
982 | return Proxmox.Utils.unknownText; | |
983 | }, | |
984 | ||
1d9643f6 AD |
985 | format_sdnipam_type: function(value, md, record) { |
986 | var schema = PVE.Utils.sdnipamSchema[value]; | |
987 | if (schema) { | |
988 | return schema.name; | |
989 | } | |
990 | return Proxmox.Utils.unknownText; | |
991 | }, | |
992 | ||
993 | format_sdndns_type: function(value, md, record) { | |
994 | var schema = PVE.Utils.sdndnsSchema[value]; | |
995 | if (schema) { | |
996 | return schema.name; | |
997 | } | |
998 | return Proxmox.Utils.unknownText; | |
999 | }, | |
1000 | ||
3c23c025 | 1001 | format_storage_type: function(value, md, record) { |
4a4b2b6e | 1002 | if (value === 'rbd') { |
53e3ea84 | 1003 | value = !record || record.get('monhost') ? 'rbd' : 'pveceph'; |
4a4b2b6e | 1004 | } else if (value === 'cephfs') { |
53e3ea84 | 1005 | value = !record || record.get('monhost') ? 'cephfs' : 'pvecephfs'; |
3c23c025 | 1006 | } |
062a7f49 TL |
1007 | |
1008 | var schema = PVE.Utils.storageSchema[value]; | |
1009 | if (schema) { | |
1010 | return schema.name; | |
b0a6d326 | 1011 | } |
062a7f49 | 1012 | return Proxmox.Utils.unknownText; |
a3b8efb4 EK |
1013 | }, |
1014 | ||
ced1677b | 1015 | format_ha: function(value) { |
e7ade592 | 1016 | var text = Proxmox.Utils.noneText; |
ced1677b TL |
1017 | |
1018 | if (value.managed) { | |
e7ade592 | 1019 | text = value.state || Proxmox.Utils.noneText; |
ced1677b | 1020 | |
8058410f | 1021 | text += ', ' + Proxmox.Utils.groupText + ': '; |
e7ade592 | 1022 | text += value.group || Proxmox.Utils.noneText; |
ced1677b TL |
1023 | } |
1024 | ||
1025 | return text; | |
1026 | }, | |
1027 | ||
b0a6d326 | 1028 | format_content_types: function(value) { |
0e244a29 DC |
1029 | return value.split(',').sort().map(function(ct) { |
1030 | return PVE.Utils.contentTypes[ct] || ct; | |
1031 | }).join(', '); | |
b0a6d326 EK |
1032 | }, |
1033 | ||
1034 | render_storage_content: function(value, metaData, record) { | |
1035 | var data = record.data; | |
1036 | if (Ext.isNumber(data.channel) && | |
1037 | Ext.isNumber(data.id) && | |
1038 | Ext.isNumber(data.lun)) { | |
0be88ae1 | 1039 | return "CH " + |
f6710aac | 1040 | Ext.String.leftPad(data.channel, 2, '0') + |
b0a6d326 EK |
1041 | " ID " + data.id + " LUN " + data.lun; |
1042 | } | |
f6710aac | 1043 | return data.volid.replace(/^.*?:(.*?\/)?/, ''); |
b0a6d326 EK |
1044 | }, |
1045 | ||
8058410f | 1046 | render_serverity: function(value) { |
b0a6d326 EK |
1047 | return PVE.Utils.log_severity_hash[value] || value; |
1048 | }, | |
1049 | ||
a62ee730 | 1050 | calculate_hostcpu: function(data) { |
a62ee730 AD |
1051 | if (!(data.uptime && Ext.isNumeric(data.cpu))) { |
1052 | return -1; | |
1053 | } | |
1054 | ||
1055 | if (data.type !== 'qemu' && data.type !== 'lxc') { | |
1056 | return -1; | |
1057 | } | |
1058 | ||
1059 | var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node); | |
1060 | var node = PVE.data.ResourceStore.getAt(index); | |
1061 | if (!Ext.isDefined(node) || node === null) { | |
1062 | return -1; | |
1063 | } | |
1064 | var maxcpu = node.data.maxcpu || 1; | |
1065 | ||
1066 | if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) { | |
1067 | return -1; | |
1068 | } | |
1069 | ||
4d739f4a | 1070 | return (data.cpu/maxcpu) * data.maxcpu; |
a62ee730 AD |
1071 | }, |
1072 | ||
1073 | render_hostcpu: function(value, metaData, record, rowIndex, colIndex, store) { | |
a62ee730 AD |
1074 | if (!(record.data.uptime && Ext.isNumeric(record.data.cpu))) { |
1075 | return ''; | |
1076 | } | |
1077 | ||
1078 | if (record.data.type !== 'qemu' && record.data.type !== 'lxc') { | |
1079 | return ''; | |
1080 | } | |
1081 | ||
1082 | var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node); | |
1083 | var node = PVE.data.ResourceStore.getAt(index); | |
1084 | if (!Ext.isDefined(node) || node === null) { | |
1085 | return ''; | |
1086 | } | |
1087 | var maxcpu = node.data.maxcpu || 1; | |
1088 | ||
1089 | if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) { | |
1090 | return ''; | |
1091 | } | |
1092 | ||
1093 | var per = (record.data.cpu/maxcpu) * record.data.maxcpu * 100; | |
1094 | ||
1095 | return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU'); | |
1096 | }, | |
1097 | ||
946730cd DC |
1098 | render_bandwidth: function(value) { |
1099 | if (!Ext.isNumeric(value)) { | |
1100 | return ''; | |
1101 | } | |
1102 | ||
e7ade592 | 1103 | return Proxmox.Utils.format_size(value) + '/s'; |
b0a6d326 EK |
1104 | }, |
1105 | ||
3f633655 EK |
1106 | render_timestamp_human_readable: function(value) { |
1107 | return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s'); | |
1108 | }, | |
1109 | ||
0bfc799f DC |
1110 | calculate_mem_usage: function(data) { |
1111 | if (!Ext.isNumeric(data.mem) || | |
1112 | data.maxmem === 0 || | |
1113 | data.uptime < 1) { | |
1114 | return -1; | |
1115 | } | |
1116 | ||
53e3ea84 | 1117 | return data.mem / data.maxmem; |
0bfc799f DC |
1118 | }, |
1119 | ||
a62ee730 | 1120 | calculate_hostmem_usage: function(data) { |
a62ee730 AD |
1121 | if (data.type !== 'qemu' && data.type !== 'lxc') { |
1122 | return -1; | |
1123 | } | |
1124 | ||
1125 | var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node); | |
1126 | var node = PVE.data.ResourceStore.getAt(index); | |
1127 | ||
1128 | if (!Ext.isDefined(node) || node === null) { | |
1129 | return -1; | |
1130 | } | |
1131 | var maxmem = node.data.maxmem || 0; | |
1132 | ||
1133 | if (!Ext.isNumeric(data.mem) || | |
1134 | maxmem === 0 || | |
1135 | data.uptime < 1) { | |
1136 | return -1; | |
1137 | } | |
1138 | ||
4d739f4a | 1139 | return data.mem / maxmem; |
a62ee730 AD |
1140 | }, |
1141 | ||
0bfc799f DC |
1142 | render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { |
1143 | if (!Ext.isNumeric(value) || value === -1) { | |
1144 | return ''; | |
1145 | } | |
8058410f | 1146 | if (value > 1) { |
0bfc799f DC |
1147 | // we got no percentage but bytes |
1148 | var mem = value; | |
1149 | var maxmem = record.data.maxmem; | |
1150 | if (!record.data.uptime || | |
1151 | maxmem === 0 || | |
1152 | !Ext.isNumeric(mem)) { | |
1153 | return ''; | |
1154 | } | |
1155 | ||
53e3ea84 | 1156 | return (mem*100/maxmem).toFixed(1) + " %"; |
0bfc799f DC |
1157 | } |
1158 | return (value*100).toFixed(1) + " %"; | |
1159 | }, | |
1160 | ||
a62ee730 | 1161 | render_hostmem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { |
a62ee730 AD |
1162 | if (!Ext.isNumeric(record.data.mem) || value === -1) { |
1163 | return ''; | |
1164 | } | |
1165 | ||
1166 | if (record.data.type !== 'qemu' && record.data.type !== 'lxc') { | |
1167 | return ''; | |
1168 | } | |
1169 | ||
1170 | var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node); | |
1171 | var node = PVE.data.ResourceStore.getAt(index); | |
1172 | var maxmem = node.data.maxmem || 0; | |
1173 | ||
4d739f4a | 1174 | if (record.data.mem > 1) { |
a62ee730 AD |
1175 | // we got no percentage but bytes |
1176 | var mem = record.data.mem; | |
1177 | if (!record.data.uptime || | |
1178 | maxmem === 0 || | |
1179 | !Ext.isNumeric(mem)) { | |
1180 | return ''; | |
1181 | } | |
1182 | ||
1183 | return ((mem*100)/maxmem).toFixed(1) + " %"; | |
1184 | } | |
1185 | return (value*100).toFixed(1) + " %"; | |
1186 | }, | |
1187 | ||
b0a6d326 | 1188 | render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
b0a6d326 EK |
1189 | var mem = value; |
1190 | var maxmem = record.data.maxmem; | |
0be88ae1 | 1191 | |
b0a6d326 EK |
1192 | if (!record.data.uptime) { |
1193 | return ''; | |
1194 | } | |
1195 | ||
1196 | if (!(Ext.isNumeric(mem) && maxmem)) { | |
1197 | return ''; | |
1198 | } | |
1199 | ||
1bd7bcdb | 1200 | return Proxmox.Utils.render_size(value); |
b0a6d326 EK |
1201 | }, |
1202 | ||
0bfc799f | 1203 | calculate_disk_usage: function(data) { |
0bfc799f | 1204 | if (!Ext.isNumeric(data.disk) || |
4d739f4a TL |
1205 | ((data.type === 'qemu' || data.type === 'lxc') && data.uptime === 0) || |
1206 | data.maxdisk === 0 | |
1207 | ) { | |
0bfc799f DC |
1208 | return -1; |
1209 | } | |
1210 | ||
53e3ea84 | 1211 | return data.disk / data.maxdisk; |
0bfc799f DC |
1212 | }, |
1213 | ||
1214 | render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { | |
1215 | if (!Ext.isNumeric(value) || value === -1) { | |
1216 | return ''; | |
1217 | } | |
1218 | ||
1219 | return (value * 100).toFixed(1) + " %"; | |
1220 | }, | |
1221 | ||
b0a6d326 | 1222 | render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
b0a6d326 EK |
1223 | var disk = value; |
1224 | var maxdisk = record.data.maxdisk; | |
728f1b97 | 1225 | var type = record.data.type; |
b0a6d326 | 1226 | |
728f1b97 | 1227 | if (!Ext.isNumeric(disk) || |
728f1b97 | 1228 | maxdisk === 0 || |
4d739f4a TL |
1229 | ((type === 'qemu' || type === 'lxc') && record.data.uptime === 0) |
1230 | ) { | |
b0a6d326 EK |
1231 | return ''; |
1232 | } | |
1233 | ||
1bd7bcdb | 1234 | return Proxmox.Utils.render_size(value); |
b0a6d326 EK |
1235 | }, |
1236 | ||
4dbc64a7 DC |
1237 | get_object_icon_class: function(type, record) { |
1238 | var status = ''; | |
1239 | var objType = type; | |
1240 | ||
1241 | if (type === 'type') { | |
1242 | // for folder view | |
1243 | objType = record.groupbyid; | |
1244 | } else if (record.template) { | |
1245 | // templates | |
1246 | objType = 'template'; | |
1247 | status = type; | |
1248 | } else { | |
1249 | // everything else | |
1250 | status = record.status + ' ha-' + record.hastate; | |
b1d8e73d DC |
1251 | } |
1252 | ||
6284a48a DC |
1253 | if (record.lock) { |
1254 | status += ' locked lock-' + record.lock; | |
1255 | } | |
1256 | ||
4dbc64a7 DC |
1257 | var defaults = PVE.tree.ResourceTree.typeDefaults[objType]; |
1258 | if (defaults && defaults.iconCls) { | |
1259 | var retVal = defaults.iconCls + ' ' + status; | |
1260 | return retVal; | |
b0a6d326 EK |
1261 | } |
1262 | ||
4dbc64a7 DC |
1263 | return ''; |
1264 | }, | |
1265 | ||
1266 | render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) { | |
f6710aac | 1267 | var cls = PVE.Utils.get_object_icon_class(value, record.data); |
2b2fe160 | 1268 | |
8058410f | 1269 | var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> '; |
b1d8e73d | 1270 | return fa + value; |
b0a6d326 EK |
1271 | }, |
1272 | ||
b0a6d326 EK |
1273 | render_support_level: function(value, metaData, record) { |
1274 | return PVE.Utils.support_level_hash[value] || '-'; | |
1275 | }, | |
1276 | ||
0be88ae1 | 1277 | render_upid: function(value, metaData, record) { |
b0a6d326 EK |
1278 | var type = record.data.type; |
1279 | var id = record.data.id; | |
1280 | ||
e7ade592 | 1281 | return Proxmox.Utils.format_task_description(type, id); |
b0a6d326 EK |
1282 | }, |
1283 | ||
27809975 | 1284 | render_optional_url: function(value) { |
4d739f4a | 1285 | if (value && value.match(/^https?:\/\//)) { |
cdd9b6c0 | 1286 | return '<a target="_blank" href="' + value + '">' + value + '</a>'; |
27809975 DC |
1287 | } |
1288 | return value; | |
1289 | }, | |
1290 | ||
1291 | render_san: function(value) { | |
1292 | var names = []; | |
1293 | if (Ext.isArray(value)) { | |
1294 | value.forEach(function(val) { | |
1295 | if (!Ext.isNumber(val)) { | |
1296 | names.push(val); | |
1297 | } | |
1298 | }); | |
1299 | return names.join('<br>'); | |
1300 | } | |
1301 | return value; | |
1302 | }, | |
1303 | ||
6ad4be69 DC |
1304 | render_full_name: function(firstname, metaData, record) { |
1305 | var first = firstname || ''; | |
1306 | var last = record.data.lastname || ''; | |
1307 | return Ext.htmlEncode(first + " " + last); | |
1308 | }, | |
1309 | ||
2d41c7e6 TL |
1310 | render_u2f_error: function(error) { |
1311 | var ErrorNames = { | |
1312 | '1': gettext('Other Error'), | |
1313 | '2': gettext('Bad Request'), | |
1314 | '3': gettext('Configuration Unsupported'), | |
1315 | '4': gettext('Device Ineligible'), | |
f6710aac | 1316 | '5': gettext('Timeout'), |
2d41c7e6 | 1317 | }; |
8058410f | 1318 | return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText; |
2d41c7e6 TL |
1319 | }, |
1320 | ||
aa0819a8 | 1321 | windowHostname: function() { |
e7ade592 | 1322 | return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match, |
aa0819a8 WB |
1323 | function(m, addr, offset, original) { return addr; }); |
1324 | }, | |
0be88ae1 | 1325 | |
953f6e9b | 1326 | openDefaultConsoleWindow: function(consoles, consoleType, vmid, nodename, vmname, cmd) { |
8aac63a5 | 1327 | var dv = PVE.Utils.defaultViewer(consoles, consoleType); |
953f6e9b | 1328 | PVE.Utils.openConsoleWindow(dv, consoleType, vmid, nodename, vmname, cmd); |
b0a6d326 EK |
1329 | }, |
1330 | ||
953f6e9b | 1331 | openConsoleWindow: function(viewer, consoleType, vmid, nodename, vmname, cmd) { |
4d739f4a | 1332 | if (vmid === undefined && (consoleType === 'kvm' || consoleType === 'lxc')) { |
b0a6d326 EK |
1333 | throw "missing vmid"; |
1334 | } | |
b0a6d326 EK |
1335 | if (!nodename) { |
1336 | throw "no nodename specified"; | |
1337 | } | |
1338 | ||
c7218ab3 | 1339 | if (viewer === 'html5') { |
953f6e9b | 1340 | PVE.Utils.openVNCViewer(consoleType, vmid, nodename, vmname, cmd); |
c6b2336c | 1341 | } else if (viewer === 'xtermjs') { |
953f6e9b | 1342 | Proxmox.Utils.openXtermJsViewer(consoleType, vmid, nodename, vmname, cmd); |
b0a6d326 | 1343 | } else if (viewer === 'vv') { |
953f6e9b TL |
1344 | let url = '/nodes/' + nodename + '/spiceshell'; |
1345 | let params = { | |
1346 | proxy: PVE.Utils.windowHostname(), | |
1347 | }; | |
1348 | if (consoleType === 'kvm') { | |
b0a6d326 | 1349 | url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy'; |
953f6e9b | 1350 | } else if (consoleType === 'lxc') { |
9e361643 | 1351 | url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy'; |
953f6e9b TL |
1352 | } else if (consoleType === 'upgrade') { |
1353 | params.cmd = 'upgrade'; | |
1354 | } else if (consoleType === 'cmd') { | |
8eccc68f | 1355 | params.cmd = cmd; |
953f6e9b TL |
1356 | } else if (consoleType !== 'shell') { |
1357 | throw `unknown spice viewer type '${consoleType}'`; | |
b0a6d326 | 1358 | } |
953f6e9b | 1359 | PVE.Utils.openSpiceViewer(url, params); |
b0a6d326 | 1360 | } else { |
953f6e9b | 1361 | throw `unknown viewer type '${viewer}'`; |
b0a6d326 EK |
1362 | } |
1363 | }, | |
1364 | ||
8aac63a5 | 1365 | defaultViewer: function(consoles, type) { |
3438c27e DC |
1366 | var allowSpice, allowXtermjs; |
1367 | ||
1368 | if (consoles === true) { | |
1369 | allowSpice = true; | |
1370 | allowXtermjs = true; | |
1371 | } else if (typeof consoles === 'object') { | |
1372 | allowSpice = consoles.spice; | |
4ace5c6f | 1373 | allowXtermjs = !!consoles.xtermjs; |
3438c27e | 1374 | } |
8aac63a5 | 1375 | let dv = PVE.VersionInfo.console || (type === 'kvm' ? 'vv' : 'xtermjs'); |
f932cffa | 1376 | if (dv === 'vv' && !allowSpice) { |
53e3ea84 | 1377 | dv = allowXtermjs ? 'xtermjs' : 'html5'; |
f932cffa | 1378 | } else if (dv === 'xtermjs' && !allowXtermjs) { |
53e3ea84 | 1379 | dv = allowSpice ? 'vv' : 'html5'; |
b0a6d326 EK |
1380 | } |
1381 | ||
1382 | return dv; | |
1383 | }, | |
1384 | ||
8eccc68f | 1385 | openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) { |
af89f682 TL |
1386 | let scaling = 'off'; |
1387 | if (Proxmox.Utils.toolkit !== 'touch') { | |
1388 | var sp = Ext.state.Manager.getProvider(); | |
1389 | scaling = sp.get('novnc-scaling', 'off'); | |
1390 | } | |
8eccc68f | 1391 | var url = Ext.Object.toQueryString({ |
9e361643 | 1392 | console: vmtype, // kvm, lxc, upgrade or shell |
c7218ab3 | 1393 | novnc: 1, |
b0a6d326 EK |
1394 | vmid: vmid, |
1395 | vmname: vmname, | |
16e64c97 | 1396 | node: nodename, |
af89f682 | 1397 | resize: scaling, |
f6710aac | 1398 | cmd: cmd, |
b0a6d326 EK |
1399 | }); |
1400 | var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427"); | |
7af1ab47 DC |
1401 | if (nw) { |
1402 | nw.focus(); | |
1403 | } | |
b0a6d326 EK |
1404 | }, |
1405 | ||
8058410f | 1406 | openSpiceViewer: function(url, params) { |
b0a6d326 EK |
1407 | var downloadWithName = function(uri, name) { |
1408 | var link = Ext.DomHelper.append(document.body, { | |
1409 | tag: 'a', | |
1410 | href: uri, | |
8058410f | 1411 | css: 'display:none;visibility:hidden;height:0px;', |
b0a6d326 EK |
1412 | }); |
1413 | ||
63c22966 | 1414 | // Note: we need to tell Android and Chrome the correct file name extension |
b0a6d326 EK |
1415 | // but we do not set 'download' tag for other environments, because |
1416 | // It can have strange side effects (additional user prompt on firefox) | |
63c22966 | 1417 | if (navigator.userAgent.match(/Android|Chrome/i)) { |
b0a6d326 EK |
1418 | link.download = name; |
1419 | } | |
1420 | ||
1421 | if (link.fireEvent) { | |
1422 | link.fireEvent('onclick'); | |
1423 | } else { | |
953f6e9b TL |
1424 | let evt = document.createEvent("MouseEvents"); |
1425 | evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null); | |
b0a6d326 EK |
1426 | link.dispatchEvent(evt); |
1427 | } | |
1428 | }; | |
1429 | ||
e7ade592 | 1430 | Proxmox.Utils.API2Request({ |
b0a6d326 EK |
1431 | url: url, |
1432 | params: params, | |
1433 | method: 'POST', | |
8058410f | 1434 | failure: function(response, opts) { |
b0a6d326 EK |
1435 | Ext.Msg.alert('Error', response.htmlStatus); |
1436 | }, | |
8058410f | 1437 | success: function(response, opts) { |
4d739f4a TL |
1438 | let cfg = response.result.data; |
1439 | let raw = Object.entries(cfg).reduce((acc, [k, v]) => acc + `${k}=${v}\n`, "[virt-viewer]\n"); | |
1440 | let spiceDownload = 'data:application/x-virt-viewer;charset=UTF-8,' + encodeURIComponent(raw); | |
1441 | downloadWithName(spiceDownload, "pve-spice.vv"); | |
f6710aac | 1442 | }, |
b0a6d326 EK |
1443 | }); |
1444 | }, | |
1445 | ||
e3129443 DC |
1446 | openTreeConsole: function(tree, record, item, index, e) { |
1447 | e.stopEvent(); | |
4d739f4a TL |
1448 | let nodename = record.data.node; |
1449 | let vmid = record.data.vmid; | |
1450 | let vmname = record.data.name; | |
e3129443 | 1451 | if (record.data.type === 'qemu' && !record.data.template) { |
e7ade592 | 1452 | Proxmox.Utils.API2Request({ |
4d739f4a TL |
1453 | url: `/nodes/${nodename}/qemu/${vmid}/status/current`, |
1454 | failure: response => Ext.Msg.alert('Error', response.htmlStatus), | |
e3129443 | 1455 | success: function(response, opts) { |
bd9537d7 | 1456 | let conf = response.result.data; |
4d739f4a | 1457 | let consoles = { |
bd9537d7 TL |
1458 | spice: !!conf.spice, |
1459 | xtermjs: !!conf.serial, | |
54453c38 DC |
1460 | }; |
1461 | PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname); | |
f6710aac | 1462 | }, |
e3129443 DC |
1463 | }); |
1464 | } else if (record.data.type === 'lxc' && !record.data.template) { | |
1465 | PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname); | |
1466 | } | |
1467 | }, | |
1468 | ||
fbd60cfd DM |
1469 | // test automation helper |
1470 | call_menu_handler: function(menu, text) { | |
4d739f4a TL |
1471 | let item = menu.query('menuitem').find(el => el.text === text); |
1472 | if (item && item.handler) { | |
1473 | item.handler(); | |
1474 | } | |
fbd60cfd DM |
1475 | }, |
1476 | ||
685b7aa4 DC |
1477 | createCmdMenu: function(v, record, item, index, event) { |
1478 | event.stopEvent(); | |
cc1a91be DC |
1479 | if (!(v instanceof Ext.tree.View)) { |
1480 | v.select(record); | |
1481 | } | |
4d739f4a TL |
1482 | let menu; |
1483 | let type = record.data.type; | |
685b7aa4 | 1484 | |
4d739f4a TL |
1485 | if (record.data.template) { |
1486 | if (type === 'qemu' || type === 'lxc') { | |
9bad05bd | 1487 | menu = Ext.create('PVE.menu.TemplateMenu', { |
f6710aac | 1488 | pveSelNode: record, |
9bad05bd DC |
1489 | }); |
1490 | } | |
4d739f4a | 1491 | } else if (type === 'qemu' || type === 'lxc' || type === 'node') { |
9bad05bd DC |
1492 | menu = Ext.create('PVE.' + type + '.CmdMenu', { |
1493 | pveSelNode: record, | |
f6710aac | 1494 | nodename: record.data.node, |
c11ab8cb | 1495 | }); |
685b7aa4 | 1496 | } else { |
4d739f4a | 1497 | return undefined; |
685b7aa4 DC |
1498 | } |
1499 | ||
1500 | menu.showAt(event.getXY()); | |
9f0b4e04 | 1501 | return menu; |
e7ade592 | 1502 | }, |
9fa2e36d | 1503 | |
fe4f00ad TL |
1504 | // helper for deleting field which are set to there default values |
1505 | delete_if_default: function(values, fieldname, default_val, create) { | |
1506 | if (values[fieldname] === '' || values[fieldname] === default_val) { | |
1507 | if (!create) { | |
399ffa76 TL |
1508 | if (values.delete) { |
1509 | if (Ext.isArray(values.delete)) { | |
1510 | values.delete.push(fieldname); | |
2db8e90d | 1511 | } else { |
399ffa76 | 1512 | values.delete += ',' + fieldname; |
2db8e90d | 1513 | } |
fe4f00ad | 1514 | } else { |
399ffa76 | 1515 | values.delete = fieldname; |
fe4f00ad TL |
1516 | } |
1517 | } | |
1518 | ||
1519 | delete values[fieldname]; | |
1520 | } | |
857b97a7 TL |
1521 | }, |
1522 | ||
1523 | loadSSHKeyFromFile: function(file, callback) { | |
37f2e82c TL |
1524 | // ssh-keygen produces ~ 740 bytes for a 4096 bit RSA key, current max is 16 kbit, so assume: |
1525 | // 740 * 8 for max. 32kbit (5920 bytes), round upwards to 8192 bytes, leaves lots of comment space | |
1526 | PVE.Utils.loadFile(file, callback, 8192); | |
1527 | }, | |
1528 | ||
1529 | loadFile: function(file, callback, maxSize) { | |
1530 | maxSize = maxSize || 32 * 1024; | |
1531 | if (file.size > maxSize) { | |
1532 | Ext.Msg.alert(gettext('Error'), `${gettext("Invalid file size")}: ${file.size} > ${maxSize}`); | |
857b97a7 TL |
1533 | return; |
1534 | } | |
4d739f4a | 1535 | let reader = new FileReader(); |
37f2e82c | 1536 | reader.onload = evt => callback(evt.target.result); |
857b97a7 | 1537 | reader.readAsText(file); |
abe824aa DC |
1538 | }, |
1539 | ||
7dda153c TL |
1540 | loadTextFromFile: function(file, callback, maxBytes) { |
1541 | let maxSize = maxBytes || 8192; | |
1542 | if (file.size > maxSize) { | |
1543 | Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size); | |
1544 | return; | |
1545 | } | |
7dda153c TL |
1546 | let reader = new FileReader(); |
1547 | reader.onload = evt => callback(evt.target.result); | |
1548 | reader.readAsText(file); | |
1549 | }, | |
1550 | ||
8c4ec8c7 TL |
1551 | diskControllerMaxIDs: { |
1552 | ide: 4, | |
1553 | sata: 6, | |
cf0d139e | 1554 | scsi: 31, |
8c4ec8c7 TL |
1555 | virtio: 16, |
1556 | }, | |
abe824aa DC |
1557 | |
1558 | // types is either undefined (all busses), an array of busses, or a single bus | |
1559 | forEachBus: function(types, func) { | |
4d739f4a | 1560 | let busses = Object.keys(PVE.Utils.diskControllerMaxIDs); |
abe824aa DC |
1561 | |
1562 | if (Ext.isArray(types)) { | |
1563 | busses = types; | |
1564 | } else if (Ext.isDefined(types)) { | |
8058410f | 1565 | busses = [types]; |
abe824aa DC |
1566 | } |
1567 | ||
1568 | // check if we only have valid busses | |
4d739f4a | 1569 | for (let i = 0; i < busses.length; i++) { |
8c4ec8c7 | 1570 | if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) { |
abe824aa DC |
1571 | throw "invalid bus: '" + busses[i] + "'"; |
1572 | } | |
1573 | } | |
1574 | ||
4d739f4a TL |
1575 | for (let i = 0; i < busses.length; i++) { |
1576 | let count = PVE.Utils.diskControllerMaxIDs[busses[i]]; | |
1577 | for (let j = 0; j < count; j++) { | |
1578 | let cont = func(busses[i], j); | |
abe824aa DC |
1579 | if (!cont && cont !== undefined) { |
1580 | return; | |
1581 | } | |
1582 | } | |
1583 | } | |
14a845bc DC |
1584 | }, |
1585 | ||
4d739f4a TL |
1586 | mp_counts: { |
1587 | mps: 256, | |
1588 | unused: 256, | |
1589 | }, | |
14a845bc DC |
1590 | |
1591 | forEachMP: function(func, includeUnused) { | |
4d739f4a TL |
1592 | for (let i = 0; i < PVE.Utils.mp_counts.mps; i++) { |
1593 | let cont = func('mp', i); | |
14a845bc DC |
1594 | if (!cont && cont !== undefined) { |
1595 | return; | |
1596 | } | |
1597 | } | |
1598 | ||
1599 | if (!includeUnused) { | |
1600 | return; | |
1601 | } | |
1602 | ||
4d739f4a TL |
1603 | for (let i = 0; i < PVE.Utils.mp_counts.unused; i++) { |
1604 | let cont = func('unused', i); | |
14a845bc DC |
1605 | if (!cont && cont !== undefined) { |
1606 | return; | |
1607 | } | |
1608 | } | |
b945c7c1 TM |
1609 | }, |
1610 | ||
6c1d8ead | 1611 | hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1 }, |
9d855398 | 1612 | |
8058410f | 1613 | cleanEmptyObjectKeys: function(obj) { |
4d739f4a TL |
1614 | for (const propName of Object.keys(obj)) { |
1615 | if (obj[propName] === null || obj[propName] === undefined) { | |
1616 | delete obj[propName]; | |
b945c7c1 TM |
1617 | } |
1618 | } | |
4616a55b TM |
1619 | }, |
1620 | ||
eadbbb4a DC |
1621 | acmedomain_count: 5, |
1622 | ||
1623 | add_domain_to_acme: function(acme, domain) { | |
1624 | if (acme.domains === undefined) { | |
1625 | acme.domains = [domain]; | |
1626 | } else { | |
1627 | acme.domains.push(domain); | |
8058410f | 1628 | acme.domains = acme.domains.filter((value, index, self) => self.indexOf(value) === index); |
eadbbb4a DC |
1629 | } |
1630 | return acme; | |
1631 | }, | |
1632 | ||
1633 | remove_domain_from_acme: function(acme, domain) { | |
1634 | if (acme.domains !== undefined) { | |
4d739f4a TL |
1635 | acme.domains = acme |
1636 | .domains | |
1637 | .filter((value, index, self) => self.indexOf(value) === index && value !== domain); | |
eadbbb4a DC |
1638 | } |
1639 | return acme; | |
1640 | }, | |
1641 | ||
4d739f4a TL |
1642 | handleStoreErrorOrMask: function(view, store, regex, callback) { |
1643 | view.mon(store, 'load', function(proxy, response, success, operation) { | |
4616a55b | 1644 | if (success) { |
4d739f4a | 1645 | Proxmox.Utils.setErrorMask(view, false); |
4616a55b TM |
1646 | return; |
1647 | } | |
4d739f4a | 1648 | let msg; |
4616a55b TM |
1649 | if (operation.error.statusText) { |
1650 | if (operation.error.statusText.match(regex)) { | |
4d739f4a | 1651 | callback(view, operation.error); |
4616a55b TM |
1652 | return; |
1653 | } else { | |
1654 | msg = operation.error.statusText + ' (' + operation.error.status + ')'; | |
1655 | } | |
1656 | } else { | |
1657 | msg = gettext('Connection error'); | |
1658 | } | |
4d739f4a | 1659 | Proxmox.Utils.setErrorMask(view, msg); |
4616a55b TM |
1660 | }); |
1661 | }, | |
1662 | ||
8058410f | 1663 | showCephInstallOrMask: function(container, msg, nodename, callback) { |
13786fb0 | 1664 | if (msg.match(/not (installed|initialized)/i)) { |
4616a55b TM |
1665 | if (Proxmox.UserName === 'root@pam') { |
1666 | container.el.mask(); | |
8058410f | 1667 | if (!container.down('pveCephInstallWindow')) { |
ef725143 | 1668 | var isInstalled = !!msg.match(/not initialized/i); |
4616a55b | 1669 | var win = Ext.create('PVE.ceph.Install', { |
f6710aac | 1670 | nodename: nodename, |
4616a55b | 1671 | }); |
f992ef80 | 1672 | win.getViewModel().set('isInstalled', isInstalled); |
4616a55b TM |
1673 | container.add(win); |
1674 | win.show(); | |
1675 | callback(win); | |
1676 | } | |
1677 | } else { | |
a7e8b87b TL |
1678 | container.mask(Ext.String.format(gettext('{0} not installed.') + |
1679 | ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']); | |
4616a55b TM |
1680 | } |
1681 | return true; | |
1682 | } else { | |
1683 | return false; | |
1684 | } | |
49dfba72 DC |
1685 | }, |
1686 | ||
13786fb0 TL |
1687 | monitor_ceph_installed: function(view, rstore, nodename, maskOwnerCt) { |
1688 | PVE.Utils.handleStoreErrorOrMask( | |
1689 | view, | |
1690 | rstore, | |
1691 | /not (installed|initialized)/i, | |
1692 | (_, error) => { | |
1693 | nodename = nodename || 'localhost'; | |
1694 | let maskTarget = maskOwnerCt ? view.ownerCt : view; | |
1695 | rstore.stopUpdate(); | |
1696 | PVE.Utils.showCephInstallOrMask(maskTarget, error.statusText, nodename, win => { | |
1697 | view.mon(win, 'cephInstallWindowClosed', () => rstore.startUpdate()); | |
1698 | }); | |
1699 | }, | |
1700 | ); | |
1701 | }, | |
1702 | ||
1703 | ||
49dfba72 DC |
1704 | propertyStringSet: function(target, source, name, value) { |
1705 | if (source) { | |
1706 | if (value === undefined) { | |
1707 | target[name] = source; | |
1708 | } else { | |
1709 | target[name] = value; | |
1710 | } | |
1711 | } else { | |
1712 | delete target[name]; | |
1713 | } | |
bbc83309 DC |
1714 | }, |
1715 | ||
e65817a1 SR |
1716 | forEachCorosyncLink: function(nodeinfo, cb) { |
1717 | let re = /(?:ring|link)(\d+)_addr/; | |
1718 | Ext.iterate(nodeinfo, (prop, val) => { | |
1719 | let match = re.exec(prop); | |
1720 | if (match) { | |
1721 | cb(Number(match[1]), val); | |
1722 | } | |
1723 | }); | |
1724 | }, | |
4546808c SR |
1725 | |
1726 | cpu_vendor_map: { | |
1727 | 'default': 'QEMU', | |
1728 | 'AuthenticAMD': 'AMD', | |
f6710aac | 1729 | 'GenuineIntel': 'Intel', |
4546808c SR |
1730 | }, |
1731 | ||
1732 | cpu_vendor_order: { | |
1733 | "AMD": 1, | |
1734 | "Intel": 2, | |
1735 | "QEMU": 3, | |
1736 | "Host": 4, | |
1737 | "_default_": 5, // includes custom models | |
1738 | }, | |
5865b597 WB |
1739 | |
1740 | verify_ip64_address_list: function(value, with_suffix) { | |
1741 | for (let addr of value.split(/[ ,;]+/)) { | |
1742 | if (addr === '') { | |
1743 | continue; | |
1744 | } | |
1745 | ||
1746 | if (with_suffix) { | |
1747 | let parts = addr.split('%'); | |
1748 | addr = parts[0]; | |
1749 | ||
1750 | if (parts.length > 2) { | |
1751 | return false; | |
1752 | } | |
1753 | ||
1754 | if (parts.length > 1 && !addr.startsWith('fe80:')) { | |
1755 | return false; | |
1756 | } | |
1757 | } | |
1758 | ||
1759 | if (!Proxmox.Utils.IP64_match.test(addr)) { | |
1760 | return false; | |
1761 | } | |
1762 | } | |
1763 | ||
1764 | return true; | |
1765 | }, | |
e7ade592 | 1766 | }, |
fe4f00ad | 1767 | |
9fa2e36d EK |
1768 | singleton: true, |
1769 | constructor: function() { | |
1770 | var me = this; | |
1771 | Ext.apply(me, me.utilities); | |
d18e15dd DC |
1772 | |
1773 | Proxmox.Utils.override_task_descriptions({ | |
1774 | acmedeactivate: ['ACME Account', gettext('Deactivate')], | |
1775 | acmenewcert: ['SRV', gettext('Order Certificate')], | |
1776 | acmerefresh: ['ACME Account', gettext('Refresh')], | |
1777 | acmeregister: ['ACME Account', gettext('Register')], | |
1778 | acmerenew: ['SRV', gettext('Renew Certificate')], | |
1779 | acmerevoke: ['SRV', gettext('Revoke Certificate')], | |
1780 | acmeupdate: ['ACME Account', gettext('Update')], | |
1781 | 'auth-realm-sync': [gettext('Realm'), gettext('Sync')], | |
1782 | 'auth-realm-sync-test': [gettext('Realm'), gettext('Sync Preview')], | |
1783 | cephcreatemds: ['Ceph Metadata Server', gettext('Create')], | |
1784 | cephcreatemgr: ['Ceph Manager', gettext('Create')], | |
1785 | cephcreatemon: ['Ceph Monitor', gettext('Create')], | |
1786 | cephcreateosd: ['Ceph OSD', gettext('Create')], | |
1787 | cephcreatepool: ['Ceph Pool', gettext('Create')], | |
1788 | cephdestroymds: ['Ceph Metadata Server', gettext('Destroy')], | |
1789 | cephdestroymgr: ['Ceph Manager', gettext('Destroy')], | |
1790 | cephdestroymon: ['Ceph Monitor', gettext('Destroy')], | |
1791 | cephdestroyosd: ['Ceph OSD', gettext('Destroy')], | |
1792 | cephdestroypool: ['Ceph Pool', gettext('Destroy')], | |
1793 | cephfscreate: ['CephFS', gettext('Create')], | |
f9f81a01 TL |
1794 | cephsetpool: ['Ceph Pool', gettext('Edit')], |
1795 | cephsetflags: ['', gettext('Change global Ceph flags')], | |
d18e15dd DC |
1796 | clustercreate: ['', gettext('Create Cluster')], |
1797 | clusterjoin: ['', gettext('Join Cluster')], | |
1798 | dircreate: [gettext('Directory Storage'), gettext('Create')], | |
1799 | dirremove: [gettext('Directory'), gettext('Remove')], | |
79035e5a | 1800 | download: [gettext('File'), gettext('Download')], |
d18e15dd DC |
1801 | hamigrate: ['HA', gettext('Migrate')], |
1802 | hashutdown: ['HA', gettext('Shutdown')], | |
1803 | hastart: ['HA', gettext('Start')], | |
1804 | hastop: ['HA', gettext('Stop')], | |
1805 | imgcopy: ['', gettext('Copy data')], | |
1806 | imgdel: ['', gettext('Erase data')], | |
1807 | lvmcreate: [gettext('LVM Storage'), gettext('Create')], | |
1808 | lvmthincreate: [gettext('LVM-Thin Storage'), gettext('Create')], | |
1809 | migrateall: ['', gettext('Migrate all VMs and Containers')], | |
1810 | 'move_volume': ['CT', gettext('Move Volume')], | |
fe66076f | 1811 | 'pbs-download': ['VM/CT', gettext('File Restore Download')], |
d18e15dd DC |
1812 | pull_file: ['CT', gettext('Pull file')], |
1813 | push_file: ['CT', gettext('Push file')], | |
1814 | qmclone: ['VM', gettext('Clone')], | |
1815 | qmconfig: ['VM', gettext('Configure')], | |
1816 | qmcreate: ['VM', gettext('Create')], | |
1817 | qmdelsnapshot: ['VM', gettext('Delete Snapshot')], | |
1818 | qmdestroy: ['VM', gettext('Destroy')], | |
1819 | qmigrate: ['VM', gettext('Migrate')], | |
1820 | qmmove: ['VM', gettext('Move disk')], | |
1821 | qmpause: ['VM', gettext('Pause')], | |
1822 | qmreboot: ['VM', gettext('Reboot')], | |
1823 | qmreset: ['VM', gettext('Reset')], | |
1824 | qmrestore: ['VM', gettext('Restore')], | |
1825 | qmresume: ['VM', gettext('Resume')], | |
1826 | qmrollback: ['VM', gettext('Rollback')], | |
1827 | qmshutdown: ['VM', gettext('Shutdown')], | |
1828 | qmsnapshot: ['VM', gettext('Snapshot')], | |
1829 | qmstart: ['VM', gettext('Start')], | |
1830 | qmstop: ['VM', gettext('Stop')], | |
1831 | qmsuspend: ['VM', gettext('Hibernate')], | |
1832 | qmtemplate: ['VM', gettext('Convert to template')], | |
1833 | spiceproxy: ['VM/CT', gettext('Console') + ' (Spice)'], | |
1834 | spiceshell: ['', gettext('Shell') + ' (Spice)'], | |
1835 | startall: ['', gettext('Start all VMs and Containers')], | |
1836 | stopall: ['', gettext('Stop all VMs and Containers')], | |
1837 | unknownimgdel: ['', gettext('Destroy image from unknown guest')], | |
4d60651f | 1838 | wipedisk: ['Device', gettext('Wipe Disk')], |
d18e15dd DC |
1839 | vncproxy: ['VM/CT', gettext('Console')], |
1840 | vncshell: ['', gettext('Shell')], | |
1841 | vzclone: ['CT', gettext('Clone')], | |
1842 | vzcreate: ['CT', gettext('Create')], | |
1843 | vzdelsnapshot: ['CT', gettext('Delete Snapshot')], | |
1844 | vzdestroy: ['CT', gettext('Destroy')], | |
1845 | vzdump: (type, id) => id ? `VM/CT ${id} - ${gettext('Backup')}` : gettext('Backup Job'), | |
1846 | vzmigrate: ['CT', gettext('Migrate')], | |
1847 | vzmount: ['CT', gettext('Mount')], | |
1848 | vzreboot: ['CT', gettext('Reboot')], | |
1849 | vzrestore: ['CT', gettext('Restore')], | |
1850 | vzresume: ['CT', gettext('Resume')], | |
1851 | vzrollback: ['CT', gettext('Rollback')], | |
1852 | vzshutdown: ['CT', gettext('Shutdown')], | |
1853 | vzsnapshot: ['CT', gettext('Snapshot')], | |
1854 | vzstart: ['CT', gettext('Start')], | |
1855 | vzstop: ['CT', gettext('Stop')], | |
1856 | vzsuspend: ['CT', gettext('Suspend')], | |
1857 | vztemplate: ['CT', gettext('Convert to template')], | |
1858 | vzumount: ['CT', gettext('Unmount')], | |
1859 | zfscreate: [gettext('ZFS Storage'), gettext('Create')], | |
1860 | }); | |
f6710aac | 1861 | }, |
e7ade592 | 1862 | |
9fa2e36d | 1863 | }); |