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