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