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