]>
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 | }, | |
bb469a11 | 508 | render_as_property_string: function(value) { |
53e3ea84 | 509 | return !value ? Proxmox.Utils.defaultText |
bb469a11 TL |
510 | : PVE.Parser.printPropertyString(value); |
511 | }, | |
8f17b496 | 512 | |
b0a6d326 EK |
513 | render_scsihw: function(value) { |
514 | if (!value) { | |
e7ade592 | 515 | return Proxmox.Utils.defaultText + ' (LSI 53C895A)'; |
b0a6d326 EK |
516 | } else if (value === 'lsi') { |
517 | return 'LSI 53C895A'; | |
518 | } else if (value === 'lsi53c810') { | |
519 | return 'LSI 53C810'; | |
520 | } else if (value === 'megasas') { | |
521 | return 'MegaRAID SAS 8708EM2'; | |
522 | } else if (value === 'virtio-scsi-pci') { | |
49f5d1ab EK |
523 | return 'VirtIO SCSI'; |
524 | } else if (value === 'virtio-scsi-single') { | |
525 | return 'VirtIO SCSI single'; | |
b0a6d326 EK |
526 | } else if (value === 'pvscsi') { |
527 | return 'VMware PVSCSI'; | |
528 | } else { | |
529 | return value; | |
530 | } | |
531 | }, | |
532 | ||
9c22da32 | 533 | render_spice_enhancements: function(values) { |
9c22da32 AL |
534 | let props = PVE.Parser.parsePropertyString(values); |
535 | if (Ext.Object.isEmpty(props)) { | |
3b0facc9 | 536 | return Proxmox.Utils.noneText; |
9c22da32 AL |
537 | } |
538 | ||
539 | let output = []; | |
540 | if (PVE.Parser.parseBoolean(props.foldersharing)) { | |
541 | output.push('Folder Sharing: ' + gettext('Enabled')); | |
542 | } | |
543 | if (props.videostreaming === 'all' || props.videostreaming === 'filter') { | |
544 | output.push('Video Streaming: ' + props.videostreaming); | |
545 | } | |
546 | return output.join(', '); | |
547 | }, | |
548 | ||
b0a6d326 EK |
549 | // fixme: auto-generate this |
550 | // for now, please keep in sync with PVE::Tools::kvmkeymaps | |
551 | kvm_keymaps: { | |
552 | //ar: 'Arabic', | |
553 | da: 'Danish', | |
0be88ae1 DC |
554 | de: 'German', |
555 | 'de-ch': 'German (Swiss)', | |
556 | 'en-gb': 'English (UK)', | |
0a5b8747 | 557 | 'en-us': 'English (USA)', |
b0a6d326 EK |
558 | es: 'Spanish', |
559 | //et: 'Estonia', | |
560 | fi: 'Finnish', | |
0be88ae1 DC |
561 | //fo: 'Faroe Islands', |
562 | fr: 'French', | |
563 | 'fr-be': 'French (Belgium)', | |
b0a6d326 EK |
564 | 'fr-ca': 'French (Canada)', |
565 | 'fr-ch': 'French (Swiss)', | |
566 | //hr: 'Croatia', | |
567 | hu: 'Hungarian', | |
568 | is: 'Icelandic', | |
0be88ae1 | 569 | it: 'Italian', |
b0a6d326 EK |
570 | ja: 'Japanese', |
571 | lt: 'Lithuanian', | |
572 | //lv: 'Latvian', | |
0be88ae1 | 573 | mk: 'Macedonian', |
b0a6d326 EK |
574 | nl: 'Dutch', |
575 | //'nl-be': 'Dutch (Belgium)', | |
0be88ae1 | 576 | no: 'Norwegian', |
b0a6d326 EK |
577 | pl: 'Polish', |
578 | pt: 'Portuguese', | |
579 | 'pt-br': 'Portuguese (Brazil)', | |
580 | //ru: 'Russian', | |
581 | sl: 'Slovenian', | |
582 | sv: 'Swedish', | |
583 | //th: 'Thai', | |
f6710aac | 584 | tr: 'Turkish', |
b0a6d326 EK |
585 | }, |
586 | ||
587 | kvm_vga_drivers: { | |
588 | std: gettext('Standard VGA'), | |
5ca366f2 | 589 | vmware: gettext('VMware compatible'), |
b0a6d326 EK |
590 | qxl: 'SPICE', |
591 | qxl2: 'SPICE dual monitor', | |
592 | qxl3: 'SPICE three monitors', | |
593 | qxl4: 'SPICE four monitors', | |
594 | serial0: gettext('Serial terminal') + ' 0', | |
595 | serial1: gettext('Serial terminal') + ' 1', | |
596 | serial2: gettext('Serial terminal') + ' 2', | |
89ae1bb1 DC |
597 | serial3: gettext('Serial terminal') + ' 3', |
598 | virtio: 'VirtIO-GPU', | |
f6710aac | 599 | none: Proxmox.Utils.noneText, |
b0a6d326 EK |
600 | }, |
601 | ||
8058410f | 602 | render_kvm_language: function(value) { |
e7ade592 DC |
603 | if (!value || value === '__default__') { |
604 | return Proxmox.Utils.defaultText; | |
b0a6d326 EK |
605 | } |
606 | var text = PVE.Utils.kvm_keymaps[value]; | |
607 | if (text) { | |
608 | return text + ' (' + value + ')'; | |
609 | } | |
610 | return value; | |
611 | }, | |
612 | ||
613 | kvm_keymap_array: function() { | |
f2782813 | 614 | var data = [['__default__', PVE.Utils.render_kvm_language('')]]; |
b0a6d326 EK |
615 | Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) { |
616 | data.push([key, PVE.Utils.render_kvm_language(value)]); | |
617 | }); | |
618 | ||
619 | return data; | |
620 | }, | |
621 | ||
3438c27e | 622 | console_map: { |
da9d14cd | 623 | '__default__': Proxmox.Utils.defaultText + ' (xterm.js)', |
3438c27e DC |
624 | 'vv': 'SPICE (remote-viewer)', |
625 | 'html5': 'HTML5 (noVNC)', | |
f6710aac | 626 | 'xtermjs': 'xterm.js', |
3438c27e DC |
627 | }, |
628 | ||
b0a6d326 | 629 | render_console_viewer: function(value) { |
3438c27e DC |
630 | value = value || '__default__'; |
631 | if (PVE.Utils.console_map[value]) { | |
632 | return PVE.Utils.console_map[value]; | |
b0a6d326 | 633 | } |
3438c27e | 634 | return value; |
b0a6d326 EK |
635 | }, |
636 | ||
755b9083 | 637 | console_viewer_array: function() { |
3438c27e | 638 | return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) { |
755b9083 TL |
639 | return [v, PVE.Utils.render_console_viewer(v)]; |
640 | }); | |
641 | }, | |
642 | ||
8058410f | 643 | render_kvm_vga_driver: function(value) { |
b0a6d326 | 644 | if (!value) { |
e7ade592 | 645 | return Proxmox.Utils.defaultText; |
b0a6d326 | 646 | } |
4f3e66d8 DC |
647 | var vga = PVE.Parser.parsePropertyString(value, 'type'); |
648 | var text = PVE.Utils.kvm_vga_drivers[vga.type]; | |
649 | if (!vga.type) { | |
650 | text = Proxmox.Utils.defaultText; | |
651 | } | |
0be88ae1 | 652 | if (text) { |
b0a6d326 EK |
653 | return text + ' (' + value + ')'; |
654 | } | |
655 | return value; | |
656 | }, | |
657 | ||
658 | kvm_vga_driver_array: function() { | |
f2782813 | 659 | var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]]; |
b0a6d326 EK |
660 | Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) { |
661 | data.push([key, PVE.Utils.render_kvm_vga_driver(value)]); | |
662 | }); | |
663 | ||
664 | return data; | |
665 | }, | |
666 | ||
667 | render_kvm_startup: function(value) { | |
668 | var startup = PVE.Parser.parseStartup(value); | |
669 | ||
670 | var res = 'order='; | |
671 | if (startup.order === undefined) { | |
672 | res += 'any'; | |
673 | } else { | |
674 | res += startup.order; | |
675 | } | |
676 | if (startup.up !== undefined) { | |
677 | res += ',up=' + startup.up; | |
678 | } | |
679 | if (startup.down !== undefined) { | |
680 | res += ',down=' + startup.down; | |
681 | } | |
682 | ||
683 | return res; | |
684 | }, | |
685 | ||
b0a6d326 EK |
686 | extractFormActionError: function(action) { |
687 | var msg; | |
688 | switch (action.failureType) { | |
689 | case Ext.form.action.Action.CLIENT_INVALID: | |
690 | msg = gettext('Form fields may not be submitted with invalid values'); | |
691 | break; | |
692 | case Ext.form.action.Action.CONNECT_FAILURE: | |
693 | msg = gettext('Connection error'); | |
694 | var resp = action.response; | |
695 | if (resp.status && resp.statusText) { | |
696 | msg += " " + resp.status + ": " + resp.statusText; | |
697 | } | |
698 | break; | |
699 | case Ext.form.action.Action.LOAD_FAILURE: | |
700 | case Ext.form.action.Action.SERVER_INVALID: | |
e7ade592 | 701 | msg = Proxmox.Utils.extractRequestError(action.result, true); |
b0a6d326 EK |
702 | break; |
703 | } | |
704 | return msg; | |
705 | }, | |
706 | ||
0e244a29 DC |
707 | contentTypes: { |
708 | 'images': gettext('Disk image'), | |
709 | 'backup': gettext('VZDump backup file'), | |
710 | 'vztmpl': gettext('Container template'), | |
711 | 'iso': gettext('ISO image'), | |
aef28e04 | 712 | 'rootdir': gettext('Container'), |
f6710aac | 713 | 'snippets': gettext('Snippets'), |
0e244a29 | 714 | }, |
b0a6d326 | 715 | |
3b8f599b DM |
716 | volume_is_qemu_backup: function(volid, format) { |
717 | return format === 'pbs-vm' || volid.match(':backup/vzdump-qemu-'); | |
718 | }, | |
719 | ||
720 | volume_is_lxc_backup: function(volid, format) { | |
721 | return format === 'pbs-ct' || volid.match(':backup/vzdump-(lxc|openvz)-'); | |
722 | }, | |
723 | ||
efff7eab DC |
724 | authSchema: { |
725 | ad: { | |
726 | name: gettext('Active Directory Server'), | |
727 | ipanel: 'pveAuthADPanel', | |
822fb26d | 728 | syncipanel: 'pveAuthLDAPSyncPanel', |
efff7eab | 729 | add: true, |
550857eb | 730 | tfa: true, |
60265958 | 731 | pwchange: true, |
efff7eab DC |
732 | }, |
733 | ldap: { | |
734 | name: gettext('LDAP Server'), | |
735 | ipanel: 'pveAuthLDAPPanel', | |
822fb26d | 736 | syncipanel: 'pveAuthLDAPSyncPanel', |
efff7eab | 737 | add: true, |
550857eb | 738 | tfa: true, |
60265958 | 739 | pwchange: true, |
efff7eab | 740 | }, |
668951e2 | 741 | openid: { |
c42e3aa7 | 742 | name: gettext('OpenID Connect Server'), |
668951e2 DC |
743 | ipanel: 'pveAuthOpenIDPanel', |
744 | add: true, | |
745 | tfa: false, | |
60265958 | 746 | pwchange: false, |
da25c5ac | 747 | iconCls: 'pmx-itype-icon-openid-logo', |
668951e2 | 748 | }, |
efff7eab DC |
749 | pam: { |
750 | name: 'Linux PAM', | |
751 | ipanel: 'pveAuthBasePanel', | |
752 | add: false, | |
550857eb | 753 | tfa: true, |
60265958 | 754 | pwchange: true, |
efff7eab DC |
755 | }, |
756 | pve: { | |
757 | name: 'Proxmox VE authentication server', | |
758 | ipanel: 'pveAuthBasePanel', | |
759 | add: false, | |
f5ae7496 | 760 | tfa: true, |
60265958 | 761 | pwchange: true, |
efff7eab DC |
762 | }, |
763 | }, | |
764 | ||
062a7f49 TL |
765 | storageSchema: { |
766 | dir: { | |
767 | name: Proxmox.Utils.directoryText, | |
768 | ipanel: 'DirInputPanel', | |
06c8315d DC |
769 | faIcon: 'folder', |
770 | backups: true, | |
062a7f49 TL |
771 | }, |
772 | lvm: { | |
773 | name: 'LVM', | |
774 | ipanel: 'LVMInputPanel', | |
06c8315d DC |
775 | faIcon: 'folder', |
776 | backups: false, | |
062a7f49 TL |
777 | }, |
778 | lvmthin: { | |
779 | name: 'LVM-Thin', | |
780 | ipanel: 'LvmThinInputPanel', | |
06c8315d DC |
781 | faIcon: 'folder', |
782 | backups: false, | |
062a7f49 | 783 | }, |
ffeb4f57 TL |
784 | btrfs: { |
785 | name: 'BTRFS', | |
786 | ipanel: 'BTRFSInputPanel', | |
787 | faIcon: 'folder', | |
788 | backups: true, | |
789 | }, | |
062a7f49 TL |
790 | nfs: { |
791 | name: 'NFS', | |
792 | ipanel: 'NFSInputPanel', | |
06c8315d DC |
793 | faIcon: 'building', |
794 | backups: true, | |
062a7f49 TL |
795 | }, |
796 | cifs: { | |
3266c03d | 797 | name: 'SMB/CIFS', |
062a7f49 | 798 | ipanel: 'CIFSInputPanel', |
06c8315d DC |
799 | faIcon: 'building', |
800 | backups: true, | |
062a7f49 TL |
801 | }, |
802 | glusterfs: { | |
803 | name: 'GlusterFS', | |
804 | ipanel: 'GlusterFsInputPanel', | |
06c8315d DC |
805 | faIcon: 'building', |
806 | backups: true, | |
062a7f49 TL |
807 | }, |
808 | iscsi: { | |
809 | name: 'iSCSI', | |
810 | ipanel: 'IScsiInputPanel', | |
06c8315d DC |
811 | faIcon: 'building', |
812 | backups: false, | |
062a7f49 | 813 | }, |
4a4b2b6e TL |
814 | cephfs: { |
815 | name: 'CephFS', | |
816 | ipanel: 'CephFSInputPanel', | |
06c8315d DC |
817 | faIcon: 'building', |
818 | backups: true, | |
4a4b2b6e TL |
819 | }, |
820 | pvecephfs: { | |
821 | name: 'CephFS (PVE)', | |
822 | ipanel: 'CephFSInputPanel', | |
823 | hideAdd: true, | |
06c8315d DC |
824 | faIcon: 'building', |
825 | backups: true, | |
4a4b2b6e | 826 | }, |
062a7f49 TL |
827 | rbd: { |
828 | name: 'RBD', | |
829 | ipanel: 'RBDInputPanel', | |
06c8315d DC |
830 | faIcon: 'building', |
831 | backups: false, | |
062a7f49 TL |
832 | }, |
833 | pveceph: { | |
834 | name: 'RBD (PVE)', | |
0d1ac958 TL |
835 | ipanel: 'RBDInputPanel', |
836 | hideAdd: true, | |
06c8315d DC |
837 | faIcon: 'building', |
838 | backups: false, | |
062a7f49 TL |
839 | }, |
840 | zfs: { | |
841 | name: 'ZFS over iSCSI', | |
842 | ipanel: 'ZFSInputPanel', | |
06c8315d DC |
843 | faIcon: 'building', |
844 | backups: false, | |
062a7f49 TL |
845 | }, |
846 | zfspool: { | |
847 | name: 'ZFS', | |
848 | ipanel: 'ZFSPoolInputPanel', | |
06c8315d DC |
849 | faIcon: 'folder', |
850 | backups: false, | |
062a7f49 | 851 | }, |
8b966034 TL |
852 | pbs: { |
853 | name: 'Proxmox Backup Server', | |
ee19d331 TL |
854 | ipanel: 'PBSInputPanel', |
855 | faIcon: 'floppy-o', | |
06c8315d | 856 | backups: true, |
8b966034 | 857 | }, |
062a7f49 TL |
858 | drbd: { |
859 | name: 'DRBD', | |
8b966034 | 860 | hideAdd: true, |
06c8315d | 861 | backups: false, |
8b966034 | 862 | }, |
062a7f49 TL |
863 | }, |
864 | ||
9233148b AD |
865 | sdnvnetSchema: { |
866 | vnet: { | |
867 | name: 'vnet', | |
f6710aac | 868 | faIcon: 'folder', |
9233148b AD |
869 | }, |
870 | }, | |
871 | ||
872 | sdnzoneSchema: { | |
873 | zone: { | |
874 | name: 'zone', | |
f6710aac | 875 | hideAdd: true, |
9233148b | 876 | }, |
1b4cce60 AD |
877 | simple: { |
878 | name: 'Simple', | |
879 | ipanel: 'SimpleInputPanel', | |
f6710aac | 880 | faIcon: 'th', |
1b4cce60 | 881 | }, |
9233148b | 882 | vlan: { |
f3c1eac7 | 883 | name: 'VLAN', |
9233148b | 884 | ipanel: 'VlanInputPanel', |
f6710aac | 885 | faIcon: 'th', |
9233148b AD |
886 | }, |
887 | qinq: { | |
f3c1eac7 | 888 | name: 'QinQ', |
9233148b | 889 | ipanel: 'QinQInputPanel', |
f6710aac | 890 | faIcon: 'th', |
9233148b AD |
891 | }, |
892 | vxlan: { | |
f3c1eac7 | 893 | name: 'VXLAN', |
9233148b | 894 | ipanel: 'VxlanInputPanel', |
f6710aac | 895 | faIcon: 'th', |
9233148b AD |
896 | }, |
897 | evpn: { | |
f3c1eac7 | 898 | name: 'EVPN', |
9233148b | 899 | ipanel: 'EvpnInputPanel', |
f6710aac | 900 | faIcon: 'th', |
9233148b AD |
901 | }, |
902 | }, | |
903 | ||
904 | sdncontrollerSchema: { | |
905 | controller: { | |
906 | name: 'controller', | |
f6710aac | 907 | hideAdd: true, |
9233148b AD |
908 | }, |
909 | evpn: { | |
910 | name: 'evpn', | |
911 | ipanel: 'EvpnInputPanel', | |
f6710aac | 912 | faIcon: 'crosshairs', |
9233148b | 913 | }, |
1d9643f6 AD |
914 | bgp: { |
915 | name: 'bgp', | |
916 | ipanel: 'BgpInputPanel', | |
4d739f4a | 917 | faIcon: 'crosshairs', |
1d9643f6 AD |
918 | }, |
919 | }, | |
920 | ||
921 | sdnipamSchema: { | |
922 | ipam: { | |
923 | name: 'ipam', | |
4d739f4a | 924 | hideAdd: true, |
1d9643f6 AD |
925 | }, |
926 | pve: { | |
927 | name: 'PVE', | |
928 | ipanel: 'PVEIpamInputPanel', | |
929 | faIcon: 'th', | |
4d739f4a | 930 | hideAdd: true, |
1d9643f6 AD |
931 | }, |
932 | netbox: { | |
933 | name: 'Netbox', | |
934 | ipanel: 'NetboxInputPanel', | |
4d739f4a | 935 | faIcon: 'th', |
1d9643f6 AD |
936 | }, |
937 | phpipam: { | |
938 | name: 'PhpIpam', | |
939 | ipanel: 'PhpIpamInputPanel', | |
4d739f4a | 940 | faIcon: 'th', |
1d9643f6 AD |
941 | }, |
942 | }, | |
943 | ||
944 | sdndnsSchema: { | |
945 | dns: { | |
946 | name: 'dns', | |
4d739f4a | 947 | hideAdd: true, |
1d9643f6 AD |
948 | }, |
949 | powerdns: { | |
950 | name: 'powerdns', | |
951 | ipanel: 'PowerdnsInputPanel', | |
4d739f4a | 952 | faIcon: 'th', |
1d9643f6 | 953 | }, |
9233148b AD |
954 | }, |
955 | ||
956 | format_sdnvnet_type: function(value, md, record) { | |
957 | var schema = PVE.Utils.sdnvnetSchema[value]; | |
958 | if (schema) { | |
959 | return schema.name; | |
960 | } | |
961 | return Proxmox.Utils.unknownText; | |
962 | }, | |
963 | ||
964 | format_sdnzone_type: function(value, md, record) { | |
965 | var schema = PVE.Utils.sdnzoneSchema[value]; | |
966 | if (schema) { | |
f3c1eac7 | 967 | return schema.name; |
9233148b AD |
968 | } |
969 | return Proxmox.Utils.unknownText; | |
970 | }, | |
971 | ||
972 | format_sdncontroller_type: function(value, md, record) { | |
973 | var schema = PVE.Utils.sdncontrollerSchema[value]; | |
974 | if (schema) { | |
975 | return schema.name; | |
976 | } | |
977 | return Proxmox.Utils.unknownText; | |
978 | }, | |
979 | ||
1d9643f6 AD |
980 | format_sdnipam_type: function(value, md, record) { |
981 | var schema = PVE.Utils.sdnipamSchema[value]; | |
982 | if (schema) { | |
983 | return schema.name; | |
984 | } | |
985 | return Proxmox.Utils.unknownText; | |
986 | }, | |
987 | ||
988 | format_sdndns_type: function(value, md, record) { | |
989 | var schema = PVE.Utils.sdndnsSchema[value]; | |
990 | if (schema) { | |
991 | return schema.name; | |
992 | } | |
993 | return Proxmox.Utils.unknownText; | |
994 | }, | |
995 | ||
3c23c025 | 996 | format_storage_type: function(value, md, record) { |
4a4b2b6e | 997 | if (value === 'rbd') { |
53e3ea84 | 998 | value = !record || record.get('monhost') ? 'rbd' : 'pveceph'; |
4a4b2b6e | 999 | } else if (value === 'cephfs') { |
53e3ea84 | 1000 | value = !record || record.get('monhost') ? 'cephfs' : 'pvecephfs'; |
3c23c025 | 1001 | } |
062a7f49 TL |
1002 | |
1003 | var schema = PVE.Utils.storageSchema[value]; | |
1004 | if (schema) { | |
1005 | return schema.name; | |
b0a6d326 | 1006 | } |
062a7f49 | 1007 | return Proxmox.Utils.unknownText; |
a3b8efb4 EK |
1008 | }, |
1009 | ||
ced1677b | 1010 | format_ha: function(value) { |
e7ade592 | 1011 | var text = Proxmox.Utils.noneText; |
ced1677b TL |
1012 | |
1013 | if (value.managed) { | |
e7ade592 | 1014 | text = value.state || Proxmox.Utils.noneText; |
ced1677b | 1015 | |
8058410f | 1016 | text += ', ' + Proxmox.Utils.groupText + ': '; |
e7ade592 | 1017 | text += value.group || Proxmox.Utils.noneText; |
ced1677b TL |
1018 | } |
1019 | ||
1020 | return text; | |
1021 | }, | |
1022 | ||
b0a6d326 | 1023 | format_content_types: function(value) { |
0e244a29 DC |
1024 | return value.split(',').sort().map(function(ct) { |
1025 | return PVE.Utils.contentTypes[ct] || ct; | |
1026 | }).join(', '); | |
b0a6d326 EK |
1027 | }, |
1028 | ||
1029 | render_storage_content: function(value, metaData, record) { | |
1030 | var data = record.data; | |
1031 | if (Ext.isNumber(data.channel) && | |
1032 | Ext.isNumber(data.id) && | |
1033 | Ext.isNumber(data.lun)) { | |
0be88ae1 | 1034 | return "CH " + |
f6710aac | 1035 | Ext.String.leftPad(data.channel, 2, '0') + |
b0a6d326 EK |
1036 | " ID " + data.id + " LUN " + data.lun; |
1037 | } | |
f6710aac | 1038 | return data.volid.replace(/^.*?:(.*?\/)?/, ''); |
b0a6d326 EK |
1039 | }, |
1040 | ||
8058410f | 1041 | render_serverity: function(value) { |
b0a6d326 EK |
1042 | return PVE.Utils.log_severity_hash[value] || value; |
1043 | }, | |
1044 | ||
a62ee730 | 1045 | calculate_hostcpu: function(data) { |
a62ee730 AD |
1046 | if (!(data.uptime && Ext.isNumeric(data.cpu))) { |
1047 | return -1; | |
1048 | } | |
1049 | ||
1050 | if (data.type !== 'qemu' && data.type !== 'lxc') { | |
1051 | return -1; | |
1052 | } | |
1053 | ||
1054 | var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node); | |
1055 | var node = PVE.data.ResourceStore.getAt(index); | |
1056 | if (!Ext.isDefined(node) || node === null) { | |
1057 | return -1; | |
1058 | } | |
1059 | var maxcpu = node.data.maxcpu || 1; | |
1060 | ||
1061 | if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) { | |
1062 | return -1; | |
1063 | } | |
1064 | ||
4d739f4a | 1065 | return (data.cpu/maxcpu) * data.maxcpu; |
a62ee730 AD |
1066 | }, |
1067 | ||
1068 | render_hostcpu: function(value, metaData, record, rowIndex, colIndex, store) { | |
a62ee730 AD |
1069 | if (!(record.data.uptime && Ext.isNumeric(record.data.cpu))) { |
1070 | return ''; | |
1071 | } | |
1072 | ||
1073 | if (record.data.type !== 'qemu' && record.data.type !== 'lxc') { | |
1074 | return ''; | |
1075 | } | |
1076 | ||
1077 | var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node); | |
1078 | var node = PVE.data.ResourceStore.getAt(index); | |
1079 | if (!Ext.isDefined(node) || node === null) { | |
1080 | return ''; | |
1081 | } | |
1082 | var maxcpu = node.data.maxcpu || 1; | |
1083 | ||
1084 | if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) { | |
1085 | return ''; | |
1086 | } | |
1087 | ||
1088 | var per = (record.data.cpu/maxcpu) * record.data.maxcpu * 100; | |
1089 | ||
1090 | return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU'); | |
1091 | }, | |
1092 | ||
946730cd DC |
1093 | render_bandwidth: function(value) { |
1094 | if (!Ext.isNumeric(value)) { | |
1095 | return ''; | |
1096 | } | |
1097 | ||
e7ade592 | 1098 | return Proxmox.Utils.format_size(value) + '/s'; |
b0a6d326 EK |
1099 | }, |
1100 | ||
3f633655 EK |
1101 | render_timestamp_human_readable: function(value) { |
1102 | return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s'); | |
1103 | }, | |
1104 | ||
0bfc799f DC |
1105 | calculate_mem_usage: function(data) { |
1106 | if (!Ext.isNumeric(data.mem) || | |
1107 | data.maxmem === 0 || | |
1108 | data.uptime < 1) { | |
1109 | return -1; | |
1110 | } | |
1111 | ||
53e3ea84 | 1112 | return data.mem / data.maxmem; |
0bfc799f DC |
1113 | }, |
1114 | ||
a62ee730 | 1115 | calculate_hostmem_usage: function(data) { |
a62ee730 AD |
1116 | if (data.type !== 'qemu' && data.type !== 'lxc') { |
1117 | return -1; | |
1118 | } | |
1119 | ||
1120 | var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node); | |
1121 | var node = PVE.data.ResourceStore.getAt(index); | |
1122 | ||
1123 | if (!Ext.isDefined(node) || node === null) { | |
1124 | return -1; | |
1125 | } | |
1126 | var maxmem = node.data.maxmem || 0; | |
1127 | ||
1128 | if (!Ext.isNumeric(data.mem) || | |
1129 | maxmem === 0 || | |
1130 | data.uptime < 1) { | |
1131 | return -1; | |
1132 | } | |
1133 | ||
4d739f4a | 1134 | return data.mem / maxmem; |
a62ee730 AD |
1135 | }, |
1136 | ||
0bfc799f DC |
1137 | render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { |
1138 | if (!Ext.isNumeric(value) || value === -1) { | |
1139 | return ''; | |
1140 | } | |
8058410f | 1141 | if (value > 1) { |
0bfc799f DC |
1142 | // we got no percentage but bytes |
1143 | var mem = value; | |
1144 | var maxmem = record.data.maxmem; | |
1145 | if (!record.data.uptime || | |
1146 | maxmem === 0 || | |
1147 | !Ext.isNumeric(mem)) { | |
1148 | return ''; | |
1149 | } | |
1150 | ||
53e3ea84 | 1151 | return (mem*100/maxmem).toFixed(1) + " %"; |
0bfc799f DC |
1152 | } |
1153 | return (value*100).toFixed(1) + " %"; | |
1154 | }, | |
1155 | ||
a62ee730 | 1156 | render_hostmem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { |
a62ee730 AD |
1157 | if (!Ext.isNumeric(record.data.mem) || value === -1) { |
1158 | return ''; | |
1159 | } | |
1160 | ||
1161 | if (record.data.type !== 'qemu' && record.data.type !== 'lxc') { | |
1162 | return ''; | |
1163 | } | |
1164 | ||
1165 | var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node); | |
1166 | var node = PVE.data.ResourceStore.getAt(index); | |
1167 | var maxmem = node.data.maxmem || 0; | |
1168 | ||
4d739f4a | 1169 | if (record.data.mem > 1) { |
a62ee730 AD |
1170 | // we got no percentage but bytes |
1171 | var mem = record.data.mem; | |
1172 | if (!record.data.uptime || | |
1173 | maxmem === 0 || | |
1174 | !Ext.isNumeric(mem)) { | |
1175 | return ''; | |
1176 | } | |
1177 | ||
1178 | return ((mem*100)/maxmem).toFixed(1) + " %"; | |
1179 | } | |
1180 | return (value*100).toFixed(1) + " %"; | |
1181 | }, | |
1182 | ||
b0a6d326 | 1183 | render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
b0a6d326 EK |
1184 | var mem = value; |
1185 | var maxmem = record.data.maxmem; | |
0be88ae1 | 1186 | |
b0a6d326 EK |
1187 | if (!record.data.uptime) { |
1188 | return ''; | |
1189 | } | |
1190 | ||
1191 | if (!(Ext.isNumeric(mem) && maxmem)) { | |
1192 | return ''; | |
1193 | } | |
1194 | ||
1bd7bcdb | 1195 | return Proxmox.Utils.render_size(value); |
b0a6d326 EK |
1196 | }, |
1197 | ||
0bfc799f | 1198 | calculate_disk_usage: function(data) { |
0bfc799f | 1199 | if (!Ext.isNumeric(data.disk) || |
4d739f4a TL |
1200 | ((data.type === 'qemu' || data.type === 'lxc') && data.uptime === 0) || |
1201 | data.maxdisk === 0 | |
1202 | ) { | |
0bfc799f DC |
1203 | return -1; |
1204 | } | |
1205 | ||
53e3ea84 | 1206 | return data.disk / data.maxdisk; |
0bfc799f DC |
1207 | }, |
1208 | ||
1209 | render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { | |
1210 | if (!Ext.isNumeric(value) || value === -1) { | |
1211 | return ''; | |
1212 | } | |
1213 | ||
1214 | return (value * 100).toFixed(1) + " %"; | |
1215 | }, | |
1216 | ||
b0a6d326 | 1217 | render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
b0a6d326 EK |
1218 | var disk = value; |
1219 | var maxdisk = record.data.maxdisk; | |
728f1b97 | 1220 | var type = record.data.type; |
b0a6d326 | 1221 | |
728f1b97 | 1222 | if (!Ext.isNumeric(disk) || |
728f1b97 | 1223 | maxdisk === 0 || |
4d739f4a TL |
1224 | ((type === 'qemu' || type === 'lxc') && record.data.uptime === 0) |
1225 | ) { | |
b0a6d326 EK |
1226 | return ''; |
1227 | } | |
1228 | ||
1bd7bcdb | 1229 | return Proxmox.Utils.render_size(value); |
b0a6d326 EK |
1230 | }, |
1231 | ||
4dbc64a7 DC |
1232 | get_object_icon_class: function(type, record) { |
1233 | var status = ''; | |
1234 | var objType = type; | |
1235 | ||
1236 | if (type === 'type') { | |
1237 | // for folder view | |
1238 | objType = record.groupbyid; | |
1239 | } else if (record.template) { | |
1240 | // templates | |
1241 | objType = 'template'; | |
1242 | status = type; | |
1243 | } else { | |
1244 | // everything else | |
1245 | status = record.status + ' ha-' + record.hastate; | |
b1d8e73d DC |
1246 | } |
1247 | ||
6284a48a DC |
1248 | if (record.lock) { |
1249 | status += ' locked lock-' + record.lock; | |
1250 | } | |
1251 | ||
4dbc64a7 DC |
1252 | var defaults = PVE.tree.ResourceTree.typeDefaults[objType]; |
1253 | if (defaults && defaults.iconCls) { | |
1254 | var retVal = defaults.iconCls + ' ' + status; | |
1255 | return retVal; | |
b0a6d326 EK |
1256 | } |
1257 | ||
4dbc64a7 DC |
1258 | return ''; |
1259 | }, | |
1260 | ||
1261 | render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) { | |
f6710aac | 1262 | var cls = PVE.Utils.get_object_icon_class(value, record.data); |
2b2fe160 | 1263 | |
8058410f | 1264 | var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> '; |
b1d8e73d | 1265 | return fa + value; |
b0a6d326 EK |
1266 | }, |
1267 | ||
b0a6d326 EK |
1268 | render_support_level: function(value, metaData, record) { |
1269 | return PVE.Utils.support_level_hash[value] || '-'; | |
1270 | }, | |
1271 | ||
0be88ae1 | 1272 | render_upid: function(value, metaData, record) { |
b0a6d326 EK |
1273 | var type = record.data.type; |
1274 | var id = record.data.id; | |
1275 | ||
e7ade592 | 1276 | return Proxmox.Utils.format_task_description(type, id); |
b0a6d326 EK |
1277 | }, |
1278 | ||
27809975 | 1279 | render_optional_url: function(value) { |
4d739f4a | 1280 | if (value && value.match(/^https?:\/\//)) { |
cdd9b6c0 | 1281 | return '<a target="_blank" href="' + value + '">' + value + '</a>'; |
27809975 DC |
1282 | } |
1283 | return value; | |
1284 | }, | |
1285 | ||
1286 | render_san: function(value) { | |
1287 | var names = []; | |
1288 | if (Ext.isArray(value)) { | |
1289 | value.forEach(function(val) { | |
1290 | if (!Ext.isNumber(val)) { | |
1291 | names.push(val); | |
1292 | } | |
1293 | }); | |
1294 | return names.join('<br>'); | |
1295 | } | |
1296 | return value; | |
1297 | }, | |
1298 | ||
6ad4be69 DC |
1299 | render_full_name: function(firstname, metaData, record) { |
1300 | var first = firstname || ''; | |
1301 | var last = record.data.lastname || ''; | |
1302 | return Ext.htmlEncode(first + " " + last); | |
1303 | }, | |
1304 | ||
aa0819a8 | 1305 | windowHostname: function() { |
e7ade592 | 1306 | return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match, |
aa0819a8 WB |
1307 | function(m, addr, offset, original) { return addr; }); |
1308 | }, | |
0be88ae1 | 1309 | |
953f6e9b | 1310 | openDefaultConsoleWindow: function(consoles, consoleType, vmid, nodename, vmname, cmd) { |
8aac63a5 | 1311 | var dv = PVE.Utils.defaultViewer(consoles, consoleType); |
953f6e9b | 1312 | PVE.Utils.openConsoleWindow(dv, consoleType, vmid, nodename, vmname, cmd); |
b0a6d326 EK |
1313 | }, |
1314 | ||
953f6e9b | 1315 | openConsoleWindow: function(viewer, consoleType, vmid, nodename, vmname, cmd) { |
4d739f4a | 1316 | if (vmid === undefined && (consoleType === 'kvm' || consoleType === 'lxc')) { |
b0a6d326 EK |
1317 | throw "missing vmid"; |
1318 | } | |
b0a6d326 EK |
1319 | if (!nodename) { |
1320 | throw "no nodename specified"; | |
1321 | } | |
1322 | ||
c7218ab3 | 1323 | if (viewer === 'html5') { |
953f6e9b | 1324 | PVE.Utils.openVNCViewer(consoleType, vmid, nodename, vmname, cmd); |
c6b2336c | 1325 | } else if (viewer === 'xtermjs') { |
953f6e9b | 1326 | Proxmox.Utils.openXtermJsViewer(consoleType, vmid, nodename, vmname, cmd); |
b0a6d326 | 1327 | } else if (viewer === 'vv') { |
953f6e9b TL |
1328 | let url = '/nodes/' + nodename + '/spiceshell'; |
1329 | let params = { | |
1330 | proxy: PVE.Utils.windowHostname(), | |
1331 | }; | |
1332 | if (consoleType === 'kvm') { | |
b0a6d326 | 1333 | url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy'; |
953f6e9b | 1334 | } else if (consoleType === 'lxc') { |
9e361643 | 1335 | url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy'; |
953f6e9b TL |
1336 | } else if (consoleType === 'upgrade') { |
1337 | params.cmd = 'upgrade'; | |
1338 | } else if (consoleType === 'cmd') { | |
8eccc68f | 1339 | params.cmd = cmd; |
953f6e9b TL |
1340 | } else if (consoleType !== 'shell') { |
1341 | throw `unknown spice viewer type '${consoleType}'`; | |
b0a6d326 | 1342 | } |
953f6e9b | 1343 | PVE.Utils.openSpiceViewer(url, params); |
b0a6d326 | 1344 | } else { |
953f6e9b | 1345 | throw `unknown viewer type '${viewer}'`; |
b0a6d326 EK |
1346 | } |
1347 | }, | |
1348 | ||
8aac63a5 | 1349 | defaultViewer: function(consoles, type) { |
3438c27e DC |
1350 | var allowSpice, allowXtermjs; |
1351 | ||
1352 | if (consoles === true) { | |
1353 | allowSpice = true; | |
1354 | allowXtermjs = true; | |
1355 | } else if (typeof consoles === 'object') { | |
1356 | allowSpice = consoles.spice; | |
4ace5c6f | 1357 | allowXtermjs = !!consoles.xtermjs; |
3438c27e | 1358 | } |
8aac63a5 | 1359 | let dv = PVE.VersionInfo.console || (type === 'kvm' ? 'vv' : 'xtermjs'); |
f932cffa | 1360 | if (dv === 'vv' && !allowSpice) { |
53e3ea84 | 1361 | dv = allowXtermjs ? 'xtermjs' : 'html5'; |
f932cffa | 1362 | } else if (dv === 'xtermjs' && !allowXtermjs) { |
53e3ea84 | 1363 | dv = allowSpice ? 'vv' : 'html5'; |
b0a6d326 EK |
1364 | } |
1365 | ||
1366 | return dv; | |
1367 | }, | |
1368 | ||
8eccc68f | 1369 | openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) { |
af89f682 TL |
1370 | let scaling = 'off'; |
1371 | if (Proxmox.Utils.toolkit !== 'touch') { | |
1372 | var sp = Ext.state.Manager.getProvider(); | |
1373 | scaling = sp.get('novnc-scaling', 'off'); | |
1374 | } | |
8eccc68f | 1375 | var url = Ext.Object.toQueryString({ |
9e361643 | 1376 | console: vmtype, // kvm, lxc, upgrade or shell |
c7218ab3 | 1377 | novnc: 1, |
b0a6d326 EK |
1378 | vmid: vmid, |
1379 | vmname: vmname, | |
16e64c97 | 1380 | node: nodename, |
af89f682 | 1381 | resize: scaling, |
f6710aac | 1382 | cmd: cmd, |
b0a6d326 EK |
1383 | }); |
1384 | var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427"); | |
7af1ab47 DC |
1385 | if (nw) { |
1386 | nw.focus(); | |
1387 | } | |
b0a6d326 EK |
1388 | }, |
1389 | ||
8058410f | 1390 | openSpiceViewer: function(url, params) { |
b0a6d326 EK |
1391 | var downloadWithName = function(uri, name) { |
1392 | var link = Ext.DomHelper.append(document.body, { | |
1393 | tag: 'a', | |
1394 | href: uri, | |
8058410f | 1395 | css: 'display:none;visibility:hidden;height:0px;', |
b0a6d326 EK |
1396 | }); |
1397 | ||
63c22966 | 1398 | // Note: we need to tell Android and Chrome the correct file name extension |
b0a6d326 EK |
1399 | // but we do not set 'download' tag for other environments, because |
1400 | // It can have strange side effects (additional user prompt on firefox) | |
63c22966 | 1401 | if (navigator.userAgent.match(/Android|Chrome/i)) { |
b0a6d326 EK |
1402 | link.download = name; |
1403 | } | |
1404 | ||
1405 | if (link.fireEvent) { | |
1406 | link.fireEvent('onclick'); | |
1407 | } else { | |
953f6e9b TL |
1408 | let evt = document.createEvent("MouseEvents"); |
1409 | evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null); | |
b0a6d326 EK |
1410 | link.dispatchEvent(evt); |
1411 | } | |
1412 | }; | |
1413 | ||
e7ade592 | 1414 | Proxmox.Utils.API2Request({ |
b0a6d326 EK |
1415 | url: url, |
1416 | params: params, | |
1417 | method: 'POST', | |
8058410f | 1418 | failure: function(response, opts) { |
b0a6d326 EK |
1419 | Ext.Msg.alert('Error', response.htmlStatus); |
1420 | }, | |
8058410f | 1421 | success: function(response, opts) { |
4d739f4a TL |
1422 | let cfg = response.result.data; |
1423 | let raw = Object.entries(cfg).reduce((acc, [k, v]) => acc + `${k}=${v}\n`, "[virt-viewer]\n"); | |
1424 | let spiceDownload = 'data:application/x-virt-viewer;charset=UTF-8,' + encodeURIComponent(raw); | |
1425 | downloadWithName(spiceDownload, "pve-spice.vv"); | |
f6710aac | 1426 | }, |
b0a6d326 EK |
1427 | }); |
1428 | }, | |
1429 | ||
e3129443 DC |
1430 | openTreeConsole: function(tree, record, item, index, e) { |
1431 | e.stopEvent(); | |
4d739f4a TL |
1432 | let nodename = record.data.node; |
1433 | let vmid = record.data.vmid; | |
1434 | let vmname = record.data.name; | |
e3129443 | 1435 | if (record.data.type === 'qemu' && !record.data.template) { |
e7ade592 | 1436 | Proxmox.Utils.API2Request({ |
4d739f4a TL |
1437 | url: `/nodes/${nodename}/qemu/${vmid}/status/current`, |
1438 | failure: response => Ext.Msg.alert('Error', response.htmlStatus), | |
e3129443 | 1439 | success: function(response, opts) { |
bd9537d7 | 1440 | let conf = response.result.data; |
4d739f4a | 1441 | let consoles = { |
bd9537d7 TL |
1442 | spice: !!conf.spice, |
1443 | xtermjs: !!conf.serial, | |
54453c38 DC |
1444 | }; |
1445 | PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname); | |
f6710aac | 1446 | }, |
e3129443 DC |
1447 | }); |
1448 | } else if (record.data.type === 'lxc' && !record.data.template) { | |
1449 | PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname); | |
1450 | } | |
1451 | }, | |
1452 | ||
fbd60cfd DM |
1453 | // test automation helper |
1454 | call_menu_handler: function(menu, text) { | |
4d739f4a TL |
1455 | let item = menu.query('menuitem').find(el => el.text === text); |
1456 | if (item && item.handler) { | |
1457 | item.handler(); | |
1458 | } | |
fbd60cfd DM |
1459 | }, |
1460 | ||
685b7aa4 DC |
1461 | createCmdMenu: function(v, record, item, index, event) { |
1462 | event.stopEvent(); | |
cc1a91be DC |
1463 | if (!(v instanceof Ext.tree.View)) { |
1464 | v.select(record); | |
1465 | } | |
4d739f4a TL |
1466 | let menu; |
1467 | let type = record.data.type; | |
685b7aa4 | 1468 | |
4d739f4a TL |
1469 | if (record.data.template) { |
1470 | if (type === 'qemu' || type === 'lxc') { | |
9bad05bd | 1471 | menu = Ext.create('PVE.menu.TemplateMenu', { |
f6710aac | 1472 | pveSelNode: record, |
9bad05bd DC |
1473 | }); |
1474 | } | |
4d739f4a | 1475 | } else if (type === 'qemu' || type === 'lxc' || type === 'node') { |
9bad05bd DC |
1476 | menu = Ext.create('PVE.' + type + '.CmdMenu', { |
1477 | pveSelNode: record, | |
f6710aac | 1478 | nodename: record.data.node, |
c11ab8cb | 1479 | }); |
685b7aa4 | 1480 | } else { |
4d739f4a | 1481 | return undefined; |
685b7aa4 DC |
1482 | } |
1483 | ||
1484 | menu.showAt(event.getXY()); | |
9f0b4e04 | 1485 | return menu; |
e7ade592 | 1486 | }, |
9fa2e36d | 1487 | |
fe4f00ad TL |
1488 | // helper for deleting field which are set to there default values |
1489 | delete_if_default: function(values, fieldname, default_val, create) { | |
1490 | if (values[fieldname] === '' || values[fieldname] === default_val) { | |
1491 | if (!create) { | |
399ffa76 TL |
1492 | if (values.delete) { |
1493 | if (Ext.isArray(values.delete)) { | |
1494 | values.delete.push(fieldname); | |
2db8e90d | 1495 | } else { |
399ffa76 | 1496 | values.delete += ',' + fieldname; |
2db8e90d | 1497 | } |
fe4f00ad | 1498 | } else { |
399ffa76 | 1499 | values.delete = fieldname; |
fe4f00ad TL |
1500 | } |
1501 | } | |
1502 | ||
1503 | delete values[fieldname]; | |
1504 | } | |
857b97a7 TL |
1505 | }, |
1506 | ||
1507 | loadSSHKeyFromFile: function(file, callback) { | |
37f2e82c TL |
1508 | // ssh-keygen produces ~ 740 bytes for a 4096 bit RSA key, current max is 16 kbit, so assume: |
1509 | // 740 * 8 for max. 32kbit (5920 bytes), round upwards to 8192 bytes, leaves lots of comment space | |
1510 | PVE.Utils.loadFile(file, callback, 8192); | |
1511 | }, | |
1512 | ||
1513 | loadFile: function(file, callback, maxSize) { | |
1514 | maxSize = maxSize || 32 * 1024; | |
1515 | if (file.size > maxSize) { | |
1516 | Ext.Msg.alert(gettext('Error'), `${gettext("Invalid file size")}: ${file.size} > ${maxSize}`); | |
857b97a7 TL |
1517 | return; |
1518 | } | |
4d739f4a | 1519 | let reader = new FileReader(); |
37f2e82c | 1520 | reader.onload = evt => callback(evt.target.result); |
857b97a7 | 1521 | reader.readAsText(file); |
abe824aa DC |
1522 | }, |
1523 | ||
7dda153c TL |
1524 | loadTextFromFile: function(file, callback, maxBytes) { |
1525 | let maxSize = maxBytes || 8192; | |
1526 | if (file.size > maxSize) { | |
1527 | Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size); | |
1528 | return; | |
1529 | } | |
7dda153c TL |
1530 | let reader = new FileReader(); |
1531 | reader.onload = evt => callback(evt.target.result); | |
1532 | reader.readAsText(file); | |
1533 | }, | |
1534 | ||
8c4ec8c7 TL |
1535 | diskControllerMaxIDs: { |
1536 | ide: 4, | |
1537 | sata: 6, | |
cf0d139e | 1538 | scsi: 31, |
8c4ec8c7 TL |
1539 | virtio: 16, |
1540 | }, | |
abe824aa DC |
1541 | |
1542 | // types is either undefined (all busses), an array of busses, or a single bus | |
1543 | forEachBus: function(types, func) { | |
4d739f4a | 1544 | let busses = Object.keys(PVE.Utils.diskControllerMaxIDs); |
abe824aa DC |
1545 | |
1546 | if (Ext.isArray(types)) { | |
1547 | busses = types; | |
1548 | } else if (Ext.isDefined(types)) { | |
8058410f | 1549 | busses = [types]; |
abe824aa DC |
1550 | } |
1551 | ||
1552 | // check if we only have valid busses | |
4d739f4a | 1553 | for (let i = 0; i < busses.length; i++) { |
8c4ec8c7 | 1554 | if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) { |
abe824aa DC |
1555 | throw "invalid bus: '" + busses[i] + "'"; |
1556 | } | |
1557 | } | |
1558 | ||
4d739f4a TL |
1559 | for (let i = 0; i < busses.length; i++) { |
1560 | let count = PVE.Utils.diskControllerMaxIDs[busses[i]]; | |
1561 | for (let j = 0; j < count; j++) { | |
1562 | let cont = func(busses[i], j); | |
abe824aa DC |
1563 | if (!cont && cont !== undefined) { |
1564 | return; | |
1565 | } | |
1566 | } | |
1567 | } | |
14a845bc DC |
1568 | }, |
1569 | ||
4d739f4a TL |
1570 | mp_counts: { |
1571 | mps: 256, | |
1572 | unused: 256, | |
1573 | }, | |
14a845bc DC |
1574 | |
1575 | forEachMP: function(func, includeUnused) { | |
4d739f4a TL |
1576 | for (let i = 0; i < PVE.Utils.mp_counts.mps; i++) { |
1577 | let cont = func('mp', i); | |
14a845bc DC |
1578 | if (!cont && cont !== undefined) { |
1579 | return; | |
1580 | } | |
1581 | } | |
1582 | ||
1583 | if (!includeUnused) { | |
1584 | return; | |
1585 | } | |
1586 | ||
4d739f4a TL |
1587 | for (let i = 0; i < PVE.Utils.mp_counts.unused; i++) { |
1588 | let cont = func('unused', i); | |
14a845bc DC |
1589 | if (!cont && cont !== undefined) { |
1590 | return; | |
1591 | } | |
1592 | } | |
b945c7c1 TM |
1593 | }, |
1594 | ||
6d084964 | 1595 | hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1, tpmstate: 1 }, |
9d855398 | 1596 | |
8058410f | 1597 | cleanEmptyObjectKeys: function(obj) { |
4d739f4a TL |
1598 | for (const propName of Object.keys(obj)) { |
1599 | if (obj[propName] === null || obj[propName] === undefined) { | |
1600 | delete obj[propName]; | |
b945c7c1 TM |
1601 | } |
1602 | } | |
4616a55b TM |
1603 | }, |
1604 | ||
eadbbb4a DC |
1605 | acmedomain_count: 5, |
1606 | ||
1607 | add_domain_to_acme: function(acme, domain) { | |
1608 | if (acme.domains === undefined) { | |
1609 | acme.domains = [domain]; | |
1610 | } else { | |
1611 | acme.domains.push(domain); | |
8058410f | 1612 | acme.domains = acme.domains.filter((value, index, self) => self.indexOf(value) === index); |
eadbbb4a DC |
1613 | } |
1614 | return acme; | |
1615 | }, | |
1616 | ||
1617 | remove_domain_from_acme: function(acme, domain) { | |
1618 | if (acme.domains !== undefined) { | |
4d739f4a TL |
1619 | acme.domains = acme |
1620 | .domains | |
1621 | .filter((value, index, self) => self.indexOf(value) === index && value !== domain); | |
eadbbb4a DC |
1622 | } |
1623 | return acme; | |
1624 | }, | |
1625 | ||
4d739f4a TL |
1626 | handleStoreErrorOrMask: function(view, store, regex, callback) { |
1627 | view.mon(store, 'load', function(proxy, response, success, operation) { | |
4616a55b | 1628 | if (success) { |
4d739f4a | 1629 | Proxmox.Utils.setErrorMask(view, false); |
4616a55b TM |
1630 | return; |
1631 | } | |
4d739f4a | 1632 | let msg; |
4616a55b TM |
1633 | if (operation.error.statusText) { |
1634 | if (operation.error.statusText.match(regex)) { | |
4d739f4a | 1635 | callback(view, operation.error); |
4616a55b TM |
1636 | return; |
1637 | } else { | |
1638 | msg = operation.error.statusText + ' (' + operation.error.status + ')'; | |
1639 | } | |
1640 | } else { | |
1641 | msg = gettext('Connection error'); | |
1642 | } | |
4d739f4a | 1643 | Proxmox.Utils.setErrorMask(view, msg); |
4616a55b TM |
1644 | }); |
1645 | }, | |
1646 | ||
8058410f | 1647 | showCephInstallOrMask: function(container, msg, nodename, callback) { |
13786fb0 | 1648 | if (msg.match(/not (installed|initialized)/i)) { |
4616a55b TM |
1649 | if (Proxmox.UserName === 'root@pam') { |
1650 | container.el.mask(); | |
8058410f | 1651 | if (!container.down('pveCephInstallWindow')) { |
ef725143 | 1652 | var isInstalled = !!msg.match(/not initialized/i); |
4616a55b | 1653 | var win = Ext.create('PVE.ceph.Install', { |
f6710aac | 1654 | nodename: nodename, |
4616a55b | 1655 | }); |
f992ef80 | 1656 | win.getViewModel().set('isInstalled', isInstalled); |
4616a55b TM |
1657 | container.add(win); |
1658 | win.show(); | |
1659 | callback(win); | |
1660 | } | |
1661 | } else { | |
a7e8b87b TL |
1662 | container.mask(Ext.String.format(gettext('{0} not installed.') + |
1663 | ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']); | |
4616a55b TM |
1664 | } |
1665 | return true; | |
1666 | } else { | |
1667 | return false; | |
1668 | } | |
49dfba72 DC |
1669 | }, |
1670 | ||
13786fb0 TL |
1671 | monitor_ceph_installed: function(view, rstore, nodename, maskOwnerCt) { |
1672 | PVE.Utils.handleStoreErrorOrMask( | |
1673 | view, | |
1674 | rstore, | |
1675 | /not (installed|initialized)/i, | |
1676 | (_, error) => { | |
1677 | nodename = nodename || 'localhost'; | |
1678 | let maskTarget = maskOwnerCt ? view.ownerCt : view; | |
1679 | rstore.stopUpdate(); | |
1680 | PVE.Utils.showCephInstallOrMask(maskTarget, error.statusText, nodename, win => { | |
1681 | view.mon(win, 'cephInstallWindowClosed', () => rstore.startUpdate()); | |
1682 | }); | |
1683 | }, | |
1684 | ); | |
1685 | }, | |
1686 | ||
1687 | ||
49dfba72 DC |
1688 | propertyStringSet: function(target, source, name, value) { |
1689 | if (source) { | |
1690 | if (value === undefined) { | |
1691 | target[name] = source; | |
1692 | } else { | |
1693 | target[name] = value; | |
1694 | } | |
1695 | } else { | |
1696 | delete target[name]; | |
1697 | } | |
bbc83309 DC |
1698 | }, |
1699 | ||
e65817a1 SR |
1700 | forEachCorosyncLink: function(nodeinfo, cb) { |
1701 | let re = /(?:ring|link)(\d+)_addr/; | |
1702 | Ext.iterate(nodeinfo, (prop, val) => { | |
1703 | let match = re.exec(prop); | |
1704 | if (match) { | |
1705 | cb(Number(match[1]), val); | |
1706 | } | |
1707 | }); | |
1708 | }, | |
4546808c SR |
1709 | |
1710 | cpu_vendor_map: { | |
1711 | 'default': 'QEMU', | |
1712 | 'AuthenticAMD': 'AMD', | |
f6710aac | 1713 | 'GenuineIntel': 'Intel', |
4546808c SR |
1714 | }, |
1715 | ||
1716 | cpu_vendor_order: { | |
1717 | "AMD": 1, | |
1718 | "Intel": 2, | |
1719 | "QEMU": 3, | |
1720 | "Host": 4, | |
1721 | "_default_": 5, // includes custom models | |
1722 | }, | |
5865b597 WB |
1723 | |
1724 | verify_ip64_address_list: function(value, with_suffix) { | |
1725 | for (let addr of value.split(/[ ,;]+/)) { | |
1726 | if (addr === '') { | |
1727 | continue; | |
1728 | } | |
1729 | ||
1730 | if (with_suffix) { | |
1731 | let parts = addr.split('%'); | |
1732 | addr = parts[0]; | |
1733 | ||
1734 | if (parts.length > 2) { | |
1735 | return false; | |
1736 | } | |
1737 | ||
1738 | if (parts.length > 1 && !addr.startsWith('fe80:')) { | |
1739 | return false; | |
1740 | } | |
1741 | } | |
1742 | ||
1743 | if (!Proxmox.Utils.IP64_match.test(addr)) { | |
1744 | return false; | |
1745 | } | |
1746 | } | |
1747 | ||
1748 | return true; | |
1749 | }, | |
2aa645da DC |
1750 | |
1751 | sortByPreviousUsage: function(vmconfig, controllerList) { | |
1752 | if (!controllerList) { | |
1753 | controllerList = ['ide', 'virtio', 'scsi', 'sata']; | |
1754 | } | |
1755 | let usedControllers = {}; | |
1756 | for (const type of Object.keys(PVE.Utils.diskControllerMaxIDs)) { | |
1757 | usedControllers[type] = 0; | |
1758 | } | |
1759 | ||
1760 | for (const property of Object.keys(vmconfig)) { | |
1761 | if (property.match(PVE.Utils.bus_match) && !vmconfig[property].match(/media=cdrom/)) { | |
1762 | const foundController = property.match(PVE.Utils.bus_match)[1]; | |
1763 | usedControllers[foundController]++; | |
1764 | } | |
1765 | } | |
1766 | ||
1767 | let sortPriority = PVE.qemu.OSDefaults.getDefaults(vmconfig.ostype).busPriority; | |
1768 | ||
1769 | let sortedList = Ext.clone(controllerList); | |
1770 | sortedList.sort(function(a, b) { | |
1771 | if (usedControllers[b] === usedControllers[a]) { | |
1772 | return sortPriority[b] - sortPriority[a]; | |
1773 | } | |
1774 | return usedControllers[b] - usedControllers[a]; | |
1775 | }); | |
1776 | ||
1777 | return sortedList; | |
1778 | }, | |
1779 | ||
1780 | nextFreeDisk: function(controllers, config) { | |
1781 | for (const controller of controllers) { | |
1782 | for (let i = 0; i < PVE.Utils.diskControllerMaxIDs[controller]; i++) { | |
1783 | let confid = controller + i.toString(); | |
1784 | if (!Ext.isDefined(config[confid])) { | |
1785 | return { | |
1786 | controller, | |
1787 | id: i, | |
1788 | confid, | |
1789 | }; | |
1790 | } | |
1791 | } | |
1792 | } | |
1793 | ||
1794 | return undefined; | |
1795 | }, | |
e7ade592 | 1796 | }, |
fe4f00ad | 1797 | |
9fa2e36d EK |
1798 | singleton: true, |
1799 | constructor: function() { | |
1800 | var me = this; | |
1801 | Ext.apply(me, me.utilities); | |
d18e15dd DC |
1802 | |
1803 | Proxmox.Utils.override_task_descriptions({ | |
1804 | acmedeactivate: ['ACME Account', gettext('Deactivate')], | |
1805 | acmenewcert: ['SRV', gettext('Order Certificate')], | |
1806 | acmerefresh: ['ACME Account', gettext('Refresh')], | |
1807 | acmeregister: ['ACME Account', gettext('Register')], | |
1808 | acmerenew: ['SRV', gettext('Renew Certificate')], | |
1809 | acmerevoke: ['SRV', gettext('Revoke Certificate')], | |
1810 | acmeupdate: ['ACME Account', gettext('Update')], | |
1811 | 'auth-realm-sync': [gettext('Realm'), gettext('Sync')], | |
1812 | 'auth-realm-sync-test': [gettext('Realm'), gettext('Sync Preview')], | |
1813 | cephcreatemds: ['Ceph Metadata Server', gettext('Create')], | |
1814 | cephcreatemgr: ['Ceph Manager', gettext('Create')], | |
1815 | cephcreatemon: ['Ceph Monitor', gettext('Create')], | |
1816 | cephcreateosd: ['Ceph OSD', gettext('Create')], | |
1817 | cephcreatepool: ['Ceph Pool', gettext('Create')], | |
1818 | cephdestroymds: ['Ceph Metadata Server', gettext('Destroy')], | |
1819 | cephdestroymgr: ['Ceph Manager', gettext('Destroy')], | |
1820 | cephdestroymon: ['Ceph Monitor', gettext('Destroy')], | |
1821 | cephdestroyosd: ['Ceph OSD', gettext('Destroy')], | |
1822 | cephdestroypool: ['Ceph Pool', gettext('Destroy')], | |
1823 | cephfscreate: ['CephFS', gettext('Create')], | |
f9f81a01 TL |
1824 | cephsetpool: ['Ceph Pool', gettext('Edit')], |
1825 | cephsetflags: ['', gettext('Change global Ceph flags')], | |
d18e15dd DC |
1826 | clustercreate: ['', gettext('Create Cluster')], |
1827 | clusterjoin: ['', gettext('Join Cluster')], | |
1828 | dircreate: [gettext('Directory Storage'), gettext('Create')], | |
1829 | dirremove: [gettext('Directory'), gettext('Remove')], | |
79035e5a | 1830 | download: [gettext('File'), gettext('Download')], |
d18e15dd DC |
1831 | hamigrate: ['HA', gettext('Migrate')], |
1832 | hashutdown: ['HA', gettext('Shutdown')], | |
1833 | hastart: ['HA', gettext('Start')], | |
1834 | hastop: ['HA', gettext('Stop')], | |
1835 | imgcopy: ['', gettext('Copy data')], | |
1836 | imgdel: ['', gettext('Erase data')], | |
1837 | lvmcreate: [gettext('LVM Storage'), gettext('Create')], | |
03c4aed8 | 1838 | lvmremove: ['Volume Group', gettext('Remove')], |
d18e15dd | 1839 | lvmthincreate: [gettext('LVM-Thin Storage'), gettext('Create')], |
03c4aed8 | 1840 | lvmthinremove: ['Thinpool', gettext('Remove')], |
d18e15dd DC |
1841 | migrateall: ['', gettext('Migrate all VMs and Containers')], |
1842 | 'move_volume': ['CT', gettext('Move Volume')], | |
fe66076f | 1843 | 'pbs-download': ['VM/CT', gettext('File Restore Download')], |
d18e15dd DC |
1844 | pull_file: ['CT', gettext('Pull file')], |
1845 | push_file: ['CT', gettext('Push file')], | |
1846 | qmclone: ['VM', gettext('Clone')], | |
1847 | qmconfig: ['VM', gettext('Configure')], | |
1848 | qmcreate: ['VM', gettext('Create')], | |
1849 | qmdelsnapshot: ['VM', gettext('Delete Snapshot')], | |
1850 | qmdestroy: ['VM', gettext('Destroy')], | |
1851 | qmigrate: ['VM', gettext('Migrate')], | |
1852 | qmmove: ['VM', gettext('Move disk')], | |
1853 | qmpause: ['VM', gettext('Pause')], | |
1854 | qmreboot: ['VM', gettext('Reboot')], | |
1855 | qmreset: ['VM', gettext('Reset')], | |
1856 | qmrestore: ['VM', gettext('Restore')], | |
1857 | qmresume: ['VM', gettext('Resume')], | |
1858 | qmrollback: ['VM', gettext('Rollback')], | |
1859 | qmshutdown: ['VM', gettext('Shutdown')], | |
1860 | qmsnapshot: ['VM', gettext('Snapshot')], | |
1861 | qmstart: ['VM', gettext('Start')], | |
1862 | qmstop: ['VM', gettext('Stop')], | |
1863 | qmsuspend: ['VM', gettext('Hibernate')], | |
1864 | qmtemplate: ['VM', gettext('Convert to template')], | |
1865 | spiceproxy: ['VM/CT', gettext('Console') + ' (Spice)'], | |
1866 | spiceshell: ['', gettext('Shell') + ' (Spice)'], | |
1867 | startall: ['', gettext('Start all VMs and Containers')], | |
1868 | stopall: ['', gettext('Stop all VMs and Containers')], | |
1869 | unknownimgdel: ['', gettext('Destroy image from unknown guest')], | |
4d60651f | 1870 | wipedisk: ['Device', gettext('Wipe Disk')], |
d18e15dd DC |
1871 | vncproxy: ['VM/CT', gettext('Console')], |
1872 | vncshell: ['', gettext('Shell')], | |
1873 | vzclone: ['CT', gettext('Clone')], | |
1874 | vzcreate: ['CT', gettext('Create')], | |
1875 | vzdelsnapshot: ['CT', gettext('Delete Snapshot')], | |
1876 | vzdestroy: ['CT', gettext('Destroy')], | |
1877 | vzdump: (type, id) => id ? `VM/CT ${id} - ${gettext('Backup')}` : gettext('Backup Job'), | |
1878 | vzmigrate: ['CT', gettext('Migrate')], | |
1879 | vzmount: ['CT', gettext('Mount')], | |
1880 | vzreboot: ['CT', gettext('Reboot')], | |
1881 | vzrestore: ['CT', gettext('Restore')], | |
1882 | vzresume: ['CT', gettext('Resume')], | |
1883 | vzrollback: ['CT', gettext('Rollback')], | |
1884 | vzshutdown: ['CT', gettext('Shutdown')], | |
1885 | vzsnapshot: ['CT', gettext('Snapshot')], | |
1886 | vzstart: ['CT', gettext('Start')], | |
1887 | vzstop: ['CT', gettext('Stop')], | |
1888 | vzsuspend: ['CT', gettext('Suspend')], | |
1889 | vztemplate: ['CT', gettext('Convert to template')], | |
1890 | vzumount: ['CT', gettext('Unmount')], | |
1891 | zfscreate: [gettext('ZFS Storage'), gettext('Create')], | |
03c4aed8 | 1892 | zfsremove: ['ZFS Pool', gettext('Remove')], |
d18e15dd | 1893 | }); |
f6710aac | 1894 | }, |
e7ade592 | 1895 | |
9fa2e36d | 1896 | }); |