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