]>
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 = { | |
13 | dir: function() {}, | |
14 | log: function() {} | |
b0a6d326 EK |
15 | }; |
16 | } | |
0be88ae1 | 17 | console.log("Starting PVE Manager"); |
b0a6d326 EK |
18 | |
19 | Ext.Ajax.defaultHeaders = { | |
20 | 'Accept': 'application/json' | |
21 | }; | |
22 | ||
23 | Ext.Ajax.on('beforerequest', function(conn, options) { | |
24 | if (PVE.CSRFPreventionToken) { | |
0be88ae1 | 25 | if (!options.headers) { |
b0a6d326 EK |
26 | options.headers = {}; |
27 | } | |
28 | options.headers.CSRFPreventionToken = PVE.CSRFPreventionToken; | |
29 | } | |
30 | }); | |
31 | ||
9fa2e36d | 32 | Ext.define('PVE.Utils', { utilities: { |
b0a6d326 | 33 | |
9fa2e36d | 34 | // this singleton contains miscellaneous utilities |
b0a6d326 | 35 | |
0be88ae1 | 36 | toolkit: undefined, // (extjs|touch), set inside Toolkit.js |
b0a6d326 | 37 | |
98a01af2 EK |
38 | bus_match: /^(ide|sata|virtio|scsi)\d+$/, |
39 | ||
b0a6d326 EK |
40 | log_severity_hash: { |
41 | 0: "panic", | |
42 | 1: "alert", | |
43 | 2: "critical", | |
44 | 3: "error", | |
45 | 4: "warning", | |
46 | 5: "notice", | |
47 | 6: "info", | |
48 | 7: "debug" | |
49 | }, | |
50 | ||
51 | support_level_hash: { | |
52 | 'c': gettext('Community'), | |
53 | 'b': gettext('Basic'), | |
54 | 's': gettext('Standard'), | |
55 | 'p': gettext('Premium') | |
56 | }, | |
57 | ||
58 | noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="http://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.', | |
59 | ||
60 | kvm_ostypes: { | |
61 | other: gettext('Other OS types'), | |
62 | wxp: 'Microsoft Windows XP/2003', | |
63 | w2k: 'Microsoft Windows 2000', | |
64 | w2k8: 'Microsoft Windows Vista/2008', | |
65 | win7: 'Microsoft Windows 7/2008r2', | |
2b9e8828 EK |
66 | win8: 'Microsoft Windows 8.x/2012/2012r2', |
67 | win10: 'Microsoft Windows 10/2016', | |
b0a6d326 | 68 | l24: 'Linux 2.4 Kernel', |
5a4ba3c2 | 69 | l26: 'Linux 4.X/3.X/2.6 Kernel', |
b0a6d326 EK |
70 | solaris: 'Solaris Kernel' |
71 | }, | |
72 | ||
428bc4a2 DC |
73 | get_health_icon: function(state, circle) { |
74 | if (circle === undefined) { | |
75 | circle = false; | |
76 | } | |
77 | ||
78 | if (state === undefined) { | |
79 | state = 'uknown'; | |
80 | } | |
81 | ||
82 | var icon = 'faded fa-question'; | |
83 | switch(state) { | |
84 | case 'good': | |
85 | icon = 'good fa-check'; | |
86 | break; | |
87 | case 'warning': | |
88 | icon = 'warning fa-exclamation'; | |
89 | break; | |
90 | case 'critical': | |
91 | icon = 'critical fa-times'; | |
92 | break; | |
93 | default: break; | |
94 | } | |
95 | ||
96 | if (circle) { | |
97 | icon += '-circle'; | |
98 | } | |
99 | ||
100 | return icon; | |
101 | }, | |
102 | ||
046e640c DC |
103 | map_ceph_health: { |
104 | 'HEALTH_OK':'good', | |
105 | 'HEALTH_WARN':'warning', | |
106 | 'HEALTH_ERR':'critical' | |
107 | }, | |
108 | ||
dfe6d184 | 109 | render_ceph_health: function(healthObj) { |
046e640c DC |
110 | var state = { |
111 | iconCls: PVE.Utils.get_health_icon(), | |
112 | text: '' | |
113 | }; | |
114 | ||
dfe6d184 | 115 | if (!healthObj || !healthObj.status) { |
046e640c DC |
116 | return state; |
117 | } | |
118 | ||
dfe6d184 | 119 | var health = PVE.Utils.map_ceph_health[healthObj.status]; |
046e640c DC |
120 | |
121 | state.iconCls = PVE.Utils.get_health_icon(health, true); | |
dfe6d184 | 122 | state.text = healthObj.status; |
046e640c DC |
123 | |
124 | return state; | |
125 | }, | |
126 | ||
b0a6d326 EK |
127 | render_kvm_ostype: function (value) { |
128 | if (!value) { | |
129 | return gettext('Other OS types'); | |
130 | } | |
131 | var text = PVE.Utils.kvm_ostypes[value]; | |
132 | if (text) { | |
b7159d8b | 133 | return text; |
b0a6d326 EK |
134 | } |
135 | return value; | |
136 | }, | |
137 | ||
138 | render_hotplug_features: function (value) { | |
23d3881a | 139 | var fa = []; |
b0a6d326 EK |
140 | |
141 | if (!value || (value === '0')) { | |
ec99b1c3 | 142 | return gettext('Disabled'); |
b0a6d326 EK |
143 | } |
144 | ||
4dcca8a4 DC |
145 | if (value === '1') { |
146 | value = 'disk,network,usb'; | |
147 | } | |
148 | ||
b0a6d326 EK |
149 | Ext.each(value.split(','), function(el) { |
150 | if (el === 'disk') { | |
151 | fa.push(gettext('Disk')); | |
152 | } else if (el === 'network') { | |
153 | fa.push(gettext('Network')); | |
154 | } else if (el === 'usb') { | |
b9628aa5 | 155 | fa.push('USB'); |
b0a6d326 EK |
156 | } else if (el === 'memory') { |
157 | fa.push(gettext('Memory')); | |
158 | } else if (el === 'cpu') { | |
159 | fa.push(gettext('CPU')); | |
160 | } else { | |
161 | fa.push(el); | |
162 | } | |
163 | }); | |
164 | ||
165 | return fa.join(', '); | |
166 | }, | |
167 | ||
168 | network_iface_types: { | |
169 | eth: gettext("Network Device"), | |
170 | bridge: 'Linux Bridge', | |
171 | bond: 'Linux Bond', | |
172 | OVSBridge: 'OVS Bridge', | |
173 | OVSBond: 'OVS Bond', | |
174 | OVSPort: 'OVS Port', | |
175 | OVSIntPort: 'OVS IntPort' | |
176 | }, | |
177 | ||
178 | render_network_iface_type: function(value) { | |
0be88ae1 | 179 | return PVE.Utils.network_iface_types[value] || |
b0a6d326 EK |
180 | PVE.Utils.unknownText; |
181 | }, | |
182 | ||
17c71f27 DC |
183 | render_qemu_bios: function(value) { |
184 | if (!value) { | |
185 | return PVE.Utils.defaultText + ' (SeaBIOS)'; | |
186 | } else if (value === 'seabios') { | |
187 | return "SeaBIOS"; | |
188 | } else if (value === 'ovmf') { | |
189 | return "OVMF (UEFI)"; | |
190 | } else { | |
191 | return value; | |
192 | } | |
193 | }, | |
194 | ||
b0a6d326 EK |
195 | render_scsihw: function(value) { |
196 | if (!value) { | |
197 | return PVE.Utils.defaultText + ' (LSI 53C895A)'; | |
198 | } else if (value === 'lsi') { | |
199 | return 'LSI 53C895A'; | |
200 | } else if (value === 'lsi53c810') { | |
201 | return 'LSI 53C810'; | |
202 | } else if (value === 'megasas') { | |
203 | return 'MegaRAID SAS 8708EM2'; | |
204 | } else if (value === 'virtio-scsi-pci') { | |
49f5d1ab EK |
205 | return 'VirtIO SCSI'; |
206 | } else if (value === 'virtio-scsi-single') { | |
207 | return 'VirtIO SCSI single'; | |
b0a6d326 EK |
208 | } else if (value === 'pvscsi') { |
209 | return 'VMware PVSCSI'; | |
210 | } else { | |
211 | return value; | |
212 | } | |
213 | }, | |
214 | ||
215 | // fixme: auto-generate this | |
216 | // for now, please keep in sync with PVE::Tools::kvmkeymaps | |
217 | kvm_keymaps: { | |
218 | //ar: 'Arabic', | |
219 | da: 'Danish', | |
0be88ae1 DC |
220 | de: 'German', |
221 | 'de-ch': 'German (Swiss)', | |
222 | 'en-gb': 'English (UK)', | |
0a5b8747 | 223 | 'en-us': 'English (USA)', |
b0a6d326 EK |
224 | es: 'Spanish', |
225 | //et: 'Estonia', | |
226 | fi: 'Finnish', | |
0be88ae1 DC |
227 | //fo: 'Faroe Islands', |
228 | fr: 'French', | |
229 | 'fr-be': 'French (Belgium)', | |
b0a6d326 EK |
230 | 'fr-ca': 'French (Canada)', |
231 | 'fr-ch': 'French (Swiss)', | |
232 | //hr: 'Croatia', | |
233 | hu: 'Hungarian', | |
234 | is: 'Icelandic', | |
0be88ae1 | 235 | it: 'Italian', |
b0a6d326 EK |
236 | ja: 'Japanese', |
237 | lt: 'Lithuanian', | |
238 | //lv: 'Latvian', | |
0be88ae1 | 239 | mk: 'Macedonian', |
b0a6d326 EK |
240 | nl: 'Dutch', |
241 | //'nl-be': 'Dutch (Belgium)', | |
0be88ae1 | 242 | no: 'Norwegian', |
b0a6d326 EK |
243 | pl: 'Polish', |
244 | pt: 'Portuguese', | |
245 | 'pt-br': 'Portuguese (Brazil)', | |
246 | //ru: 'Russian', | |
247 | sl: 'Slovenian', | |
248 | sv: 'Swedish', | |
249 | //th: 'Thai', | |
250 | tr: 'Turkish' | |
251 | }, | |
252 | ||
253 | kvm_vga_drivers: { | |
254 | std: gettext('Standard VGA'), | |
5ca366f2 | 255 | vmware: gettext('VMware compatible'), |
b0a6d326 EK |
256 | qxl: 'SPICE', |
257 | qxl2: 'SPICE dual monitor', | |
258 | qxl3: 'SPICE three monitors', | |
259 | qxl4: 'SPICE four monitors', | |
260 | serial0: gettext('Serial terminal') + ' 0', | |
261 | serial1: gettext('Serial terminal') + ' 1', | |
262 | serial2: gettext('Serial terminal') + ' 2', | |
263 | serial3: gettext('Serial terminal') + ' 3' | |
264 | }, | |
265 | ||
266 | render_kvm_language: function (value) { | |
267 | if (!value) { | |
268 | return PVE.Utils.defaultText; | |
269 | } | |
270 | var text = PVE.Utils.kvm_keymaps[value]; | |
271 | if (text) { | |
272 | return text + ' (' + value + ')'; | |
273 | } | |
274 | return value; | |
275 | }, | |
276 | ||
277 | kvm_keymap_array: function() { | |
f2782813 | 278 | var data = [['__default__', PVE.Utils.render_kvm_language('')]]; |
b0a6d326 EK |
279 | Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) { |
280 | data.push([key, PVE.Utils.render_kvm_language(value)]); | |
281 | }); | |
282 | ||
283 | return data; | |
284 | }, | |
285 | ||
286 | render_console_viewer: function(value) { | |
f2782813 | 287 | if (!value || value === '__default__') { |
b0a6d326 | 288 | return PVE.Utils.defaultText + ' (HTML5)'; |
b0a6d326 EK |
289 | } else if (value === 'vv') { |
290 | return 'SPICE (remote-viewer)'; | |
291 | } else if (value === 'html5') { | |
292 | return 'HTML5 (noVNC)'; | |
293 | } else { | |
294 | return value; | |
295 | } | |
296 | }, | |
297 | ||
298 | language_map: { | |
299 | zh_CN: 'Chinese', | |
300 | ca: 'Catalan', | |
301 | da: 'Danish', | |
302 | en: 'English', | |
303 | eu: 'Euskera (Basque)', | |
304 | fr: 'French', | |
305 | de: 'German', | |
306 | it: 'Italian', | |
307 | ja: 'Japanese', | |
308 | nb: 'Norwegian (Bokmal)', | |
309 | nn: 'Norwegian (Nynorsk)', | |
310 | fa: 'Persian (Farsi)', | |
311 | pl: 'Polish', | |
312 | pt_BR: 'Portuguese (Brazil)', | |
313 | ru: 'Russian', | |
314 | sl: 'Slovenian', | |
315 | es: 'Spanish', | |
316 | sv: 'Swedish', | |
317 | tr: 'Turkish' | |
318 | }, | |
319 | ||
320 | render_language: function (value) { | |
321 | if (!value) { | |
322 | return PVE.Utils.defaultText + ' (English)'; | |
323 | } | |
324 | var text = PVE.Utils.language_map[value]; | |
325 | if (text) { | |
326 | return text + ' (' + value + ')'; | |
327 | } | |
328 | return value; | |
329 | }, | |
330 | ||
331 | language_array: function() { | |
d98a2c3c | 332 | var data = [['__default__', PVE.Utils.render_language('')]]; |
b0a6d326 EK |
333 | Ext.Object.each(PVE.Utils.language_map, function(key, value) { |
334 | data.push([key, PVE.Utils.render_language(value)]); | |
335 | }); | |
336 | ||
337 | return data; | |
338 | }, | |
339 | ||
340 | render_kvm_vga_driver: function (value) { | |
341 | if (!value) { | |
342 | return PVE.Utils.defaultText; | |
343 | } | |
344 | var text = PVE.Utils.kvm_vga_drivers[value]; | |
0be88ae1 | 345 | if (text) { |
b0a6d326 EK |
346 | return text + ' (' + value + ')'; |
347 | } | |
348 | return value; | |
349 | }, | |
350 | ||
351 | kvm_vga_driver_array: function() { | |
f2782813 | 352 | var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]]; |
b0a6d326 EK |
353 | Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) { |
354 | data.push([key, PVE.Utils.render_kvm_vga_driver(value)]); | |
355 | }); | |
356 | ||
357 | return data; | |
358 | }, | |
359 | ||
360 | render_kvm_startup: function(value) { | |
361 | var startup = PVE.Parser.parseStartup(value); | |
362 | ||
363 | var res = 'order='; | |
364 | if (startup.order === undefined) { | |
365 | res += 'any'; | |
366 | } else { | |
367 | res += startup.order; | |
368 | } | |
369 | if (startup.up !== undefined) { | |
370 | res += ',up=' + startup.up; | |
371 | } | |
372 | if (startup.down !== undefined) { | |
373 | res += ',down=' + startup.down; | |
374 | } | |
375 | ||
376 | return res; | |
377 | }, | |
378 | ||
379 | authOK: function() { | |
380 | return Ext.util.Cookies.get('PVEAuthCookie'); | |
381 | }, | |
382 | ||
383 | authClear: function() { | |
384 | Ext.util.Cookies.clear("PVEAuthCookie"); | |
385 | }, | |
386 | ||
387 | // fixme: remove - not needed? | |
388 | gridLineHeigh: function() { | |
389 | return 21; | |
0be88ae1 | 390 | |
b0a6d326 EK |
391 | //if (Ext.isGecko) |
392 | //return 23; | |
393 | //return 21; | |
394 | }, | |
395 | ||
396 | extractRequestError: function(result, verbose) { | |
397 | var msg = gettext('Successful'); | |
398 | ||
399 | if (!result.success) { | |
400 | msg = gettext("Unknown error"); | |
401 | if (result.message) { | |
402 | msg = result.message; | |
403 | if (result.status) { | |
404 | msg += ' (' + result.status + ')'; | |
405 | } | |
406 | } | |
407 | if (verbose && Ext.isObject(result.errors)) { | |
408 | msg += "<br>"; | |
409 | Ext.Object.each(result.errors, function(prop, desc) { | |
0be88ae1 | 410 | msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " + |
b0a6d326 EK |
411 | Ext.htmlEncode(desc); |
412 | }); | |
0be88ae1 | 413 | } |
b0a6d326 EK |
414 | } |
415 | ||
416 | return msg; | |
417 | }, | |
418 | ||
419 | extractFormActionError: function(action) { | |
420 | var msg; | |
421 | switch (action.failureType) { | |
422 | case Ext.form.action.Action.CLIENT_INVALID: | |
423 | msg = gettext('Form fields may not be submitted with invalid values'); | |
424 | break; | |
425 | case Ext.form.action.Action.CONNECT_FAILURE: | |
426 | msg = gettext('Connection error'); | |
427 | var resp = action.response; | |
428 | if (resp.status && resp.statusText) { | |
429 | msg += " " + resp.status + ": " + resp.statusText; | |
430 | } | |
431 | break; | |
432 | case Ext.form.action.Action.LOAD_FAILURE: | |
433 | case Ext.form.action.Action.SERVER_INVALID: | |
434 | msg = PVE.Utils.extractRequestError(action.result, true); | |
435 | break; | |
436 | } | |
437 | return msg; | |
438 | }, | |
439 | ||
440 | // Ext.Ajax.request | |
441 | API2Request: function(reqOpts) { | |
442 | ||
443 | var newopts = Ext.apply({ | |
444 | waitMsg: gettext('Please wait...') | |
445 | }, reqOpts); | |
446 | ||
447 | if (!newopts.url.match(/^\/api2/)) { | |
448 | newopts.url = '/api2/extjs' + newopts.url; | |
449 | } | |
450 | delete newopts.callback; | |
451 | ||
452 | var createWrapper = function(successFn, callbackFn, failureFn) { | |
453 | Ext.apply(newopts, { | |
454 | success: function(response, options) { | |
455 | if (options.waitMsgTarget) { | |
456 | if (PVE.Utils.toolkit === 'touch') { | |
457 | options.waitMsgTarget.setMasked(false); | |
458 | } else { | |
459 | options.waitMsgTarget.setLoading(false); | |
460 | } | |
461 | } | |
462 | var result = Ext.decode(response.responseText); | |
463 | response.result = result; | |
464 | if (!result.success) { | |
465 | response.htmlStatus = PVE.Utils.extractRequestError(result, true); | |
466 | Ext.callback(callbackFn, options.scope, [options, false, response]); | |
467 | Ext.callback(failureFn, options.scope, [response, options]); | |
468 | return; | |
469 | } | |
470 | Ext.callback(callbackFn, options.scope, [options, true, response]); | |
471 | Ext.callback(successFn, options.scope, [response, options]); | |
472 | }, | |
473 | failure: function(response, options) { | |
474 | if (options.waitMsgTarget) { | |
475 | if (PVE.Utils.toolkit === 'touch') { | |
476 | options.waitMsgTarget.setMasked(false); | |
477 | } else { | |
478 | options.waitMsgTarget.setLoading(false); | |
479 | } | |
480 | } | |
481 | response.result = {}; | |
482 | try { | |
483 | response.result = Ext.decode(response.responseText); | |
484 | } catch(e) {} | |
485 | var msg = gettext('Connection error') + ' - server offline?'; | |
486 | if (response.aborted) { | |
487 | msg = gettext('Connection error') + ' - aborted.'; | |
488 | } else if (response.timedout) { | |
489 | msg = gettext('Connection error') + ' - Timeout.'; | |
490 | } else if (response.status && response.statusText) { | |
491 | msg = gettext('Connection error') + ' ' + response.status + ': ' + response.statusText; | |
492 | } | |
493 | response.htmlStatus = msg; | |
494 | Ext.callback(callbackFn, options.scope, [options, false, response]); | |
495 | Ext.callback(failureFn, options.scope, [response, options]); | |
496 | } | |
497 | }); | |
498 | }; | |
499 | ||
500 | createWrapper(reqOpts.success, reqOpts.callback, reqOpts.failure); | |
501 | ||
502 | var target = newopts.waitMsgTarget; | |
503 | if (target) { | |
504 | if (PVE.Utils.toolkit === 'touch') { | |
505 | target.setMasked({ xtype: 'loadmask', message: newopts.waitMsg} ); | |
506 | } else { | |
507 | // Note: ExtJS bug - this does not work when component is not rendered | |
508 | target.setLoading(newopts.waitMsg); | |
509 | } | |
510 | } | |
511 | Ext.Ajax.request(newopts); | |
512 | }, | |
513 | ||
514 | assemble_field_data: function(values, data) { | |
515 | if (Ext.isObject(data)) { | |
516 | Ext.Object.each(data, function(name, val) { | |
517 | if (values.hasOwnProperty(name)) { | |
518 | var bucket = values[name]; | |
519 | if (!Ext.isArray(bucket)) { | |
520 | bucket = values[name] = [bucket]; | |
521 | } | |
522 | if (Ext.isArray(val)) { | |
523 | values[name] = bucket.concat(val); | |
524 | } else { | |
525 | bucket.push(val); | |
526 | } | |
527 | } else { | |
528 | values[name] = val; | |
529 | } | |
530 | }); | |
531 | } | |
532 | }, | |
533 | ||
534 | checked_command: function(orig_cmd) { | |
535 | PVE.Utils.API2Request({ | |
536 | url: '/nodes/localhost/subscription', | |
537 | method: 'GET', | |
538 | //waitMsgTarget: me, | |
539 | failure: function(response, opts) { | |
540 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
541 | }, | |
542 | success: function(response, opts) { | |
543 | var data = response.result.data; | |
544 | ||
545 | if (data.status !== 'Active') { | |
546 | Ext.Msg.show({ | |
547 | title: gettext('No valid subscription'), | |
548 | icon: Ext.Msg.WARNING, | |
549 | msg: PVE.Utils.noSubKeyHtml, | |
550 | buttons: Ext.Msg.OK, | |
551 | callback: function(btn) { | |
552 | if (btn !== 'ok') { | |
553 | return; | |
554 | } | |
555 | orig_cmd(); | |
556 | } | |
557 | }); | |
558 | } else { | |
559 | orig_cmd(); | |
560 | } | |
561 | } | |
562 | }); | |
563 | }, | |
564 | ||
565 | task_desc_table: { | |
b9628aa5 | 566 | diskinit: [ 'Disk', gettext('Initialize Disk with GPT') ], |
b0a6d326 EK |
567 | vncproxy: [ 'VM/CT', gettext('Console') ], |
568 | spiceproxy: [ 'VM/CT', gettext('Console') + ' (Spice)' ], | |
569 | vncshell: [ '', gettext('Shell') ], | |
570 | spiceshell: [ '', gettext('Shell') + ' (Spice)' ], | |
571 | qmsnapshot: [ 'VM', gettext('Snapshot') ], | |
572 | qmrollback: [ 'VM', gettext('Rollback') ], | |
573 | qmdelsnapshot: [ 'VM', gettext('Delete Snapshot') ], | |
574 | qmcreate: [ 'VM', gettext('Create') ], | |
575 | qmrestore: [ 'VM', gettext('Restore') ], | |
576 | qmdestroy: [ 'VM', gettext('Destroy') ], | |
577 | qmigrate: [ 'VM', gettext('Migrate') ], | |
578 | qmclone: [ 'VM', gettext('Clone') ], | |
579 | qmmove: [ 'VM', gettext('Move disk') ], | |
580 | qmtemplate: [ 'VM', gettext('Convert to template') ], | |
581 | qmstart: [ 'VM', gettext('Start') ], | |
582 | qmstop: [ 'VM', gettext('Stop') ], | |
583 | qmreset: [ 'VM', gettext('Reset') ], | |
584 | qmshutdown: [ 'VM', gettext('Shutdown') ], | |
585 | qmsuspend: [ 'VM', gettext('Suspend') ], | |
586 | qmresume: [ 'VM', gettext('Resume') ], | |
587 | qmconfig: [ 'VM', gettext('Configure') ], | |
16152937 DM |
588 | vzsnapshot: [ 'CT', gettext('Snapshot') ], |
589 | vzrollback: [ 'CT', gettext('Rollback') ], | |
590 | vzdelsnapshot: [ 'CT', gettext('Delete Snapshot') ], | |
b0a6d326 EK |
591 | vzcreate: ['CT', gettext('Create') ], |
592 | vzrestore: ['CT', gettext('Restore') ], | |
593 | vzdestroy: ['CT', gettext('Destroy') ], | |
594 | vzmigrate: [ 'CT', gettext('Migrate') ], | |
bfade4b4 DM |
595 | vzclone: [ 'CT', gettext('Clone') ], |
596 | vztemplate: [ 'CT', gettext('Convert to template') ], | |
b0a6d326 EK |
597 | vzstart: ['CT', gettext('Start') ], |
598 | vzstop: ['CT', gettext('Stop') ], | |
599 | vzmount: ['CT', gettext('Mount') ], | |
600 | vzumount: ['CT', gettext('Unmount') ], | |
601 | vzshutdown: ['CT', gettext('Shutdown') ], | |
602 | vzsuspend: [ 'CT', gettext('Suspend') ], | |
603 | vzresume: [ 'CT', gettext('Resume') ], | |
604 | hamigrate: [ 'HA', gettext('Migrate') ], | |
605 | hastart: [ 'HA', gettext('Start') ], | |
606 | hastop: [ 'HA', gettext('Stop') ], | |
607 | srvstart: ['SRV', gettext('Start') ], | |
608 | srvstop: ['SRV', gettext('Stop') ], | |
609 | srvrestart: ['SRV', gettext('Restart') ], | |
610 | srvreload: ['SRV', gettext('Reload') ], | |
611 | cephcreatemon: ['Ceph Monitor', gettext('Create') ], | |
612 | cephdestroymon: ['Ceph Monitor', gettext('Destroy') ], | |
613 | cephcreateosd: ['Ceph OSD', gettext('Create') ], | |
614 | cephdestroyosd: ['Ceph OSD', gettext('Destroy') ], | |
fe15d330 | 615 | cephcreatepool: ['Ceph Pool', gettext('Create') ], |
2125c18a | 616 | cephdestroypool: ['Ceph Pool', gettext('Destroy') ], |
b0a6d326 EK |
617 | imgcopy: ['', gettext('Copy data') ], |
618 | imgdel: ['', gettext('Erase data') ], | |
619 | download: ['', gettext('Download') ], | |
620 | vzdump: ['', gettext('Backup') ], | |
621 | aptupdate: ['', gettext('Update package database') ], | |
622 | startall: [ '', gettext('Start all VMs and Containers') ], | |
623 | stopall: [ '', gettext('Stop all VMs and Containers') ], | |
624 | migrateall: [ '', gettext('Migrate all VMs and Containers') ] | |
625 | }, | |
626 | ||
0be88ae1 | 627 | format_task_description: function(type, id) { |
b0a6d326 EK |
628 | var farray = PVE.Utils.task_desc_table[type]; |
629 | if (!farray) { | |
630 | return type; | |
631 | } | |
632 | var prefix = farray[0]; | |
633 | var text = farray[1]; | |
634 | if (prefix) { | |
0be88ae1 | 635 | return prefix + ' ' + id + ' - ' + text; |
b0a6d326 EK |
636 | } |
637 | return text; | |
638 | }, | |
639 | ||
640 | parse_task_upid: function(upid) { | |
641 | var task = {}; | |
642 | ||
643 | var res = upid.match(/^UPID:(\S+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/); | |
644 | if (!res) { | |
645 | throw "unable to parse upid '" + upid + "'"; | |
646 | } | |
647 | task.node = res[1]; | |
648 | task.pid = parseInt(res[2], 16); | |
649 | task.pstart = parseInt(res[3], 16); | |
650 | task.starttime = parseInt(res[4], 16); | |
651 | task.type = res[5]; | |
652 | task.id = res[6]; | |
653 | task.user = res[7]; | |
654 | ||
655 | task.desc = PVE.Utils.format_task_description(task.type, task.id); | |
656 | ||
657 | return task; | |
658 | }, | |
659 | ||
660 | format_size: function(size) { | |
661 | /*jslint confusion: true */ | |
662 | ||
02f47fe8 DC |
663 | var units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi']; |
664 | var num = 0; | |
b0a6d326 | 665 | |
02f47fe8 DC |
666 | while (size >= 1024 && ((num++)+1) < units.length) { |
667 | size = size / 1024; | |
b0a6d326 EK |
668 | } |
669 | ||
02f47fe8 | 670 | return size.toFixed((num > 0)?2:0) + " " + units[num] + "B"; |
b0a6d326 EK |
671 | }, |
672 | ||
673 | format_html_bar: function(per, text) { | |
674 | ||
675 | return "<div class='pve-bar-wrap'>" + text + "<div class='pve-bar-border'>" + | |
676 | "<div class='pve-bar-inner' style='width:" + per + "%;'></div>" + | |
677 | "</div></div>"; | |
0be88ae1 | 678 | |
b0a6d326 EK |
679 | }, |
680 | ||
681 | format_cpu_bar: function(per1, per2, text) { | |
682 | ||
683 | return "<div class='pve-bar-border'>" + | |
684 | "<div class='pve-bar-inner' style='width:" + per1 + "%;'></div>" + | |
685 | "<div class='pve-bar-inner2' style='width:" + per2 + "%;'></div>" + | |
0be88ae1 | 686 | "<div class='pve-bar-text'>" + text + "</div>" + |
b0a6d326 EK |
687 | "</div>"; |
688 | }, | |
689 | ||
690 | format_large_bar: function(per, text) { | |
691 | ||
692 | if (!text) { | |
693 | text = per.toFixed(1) + "%"; | |
694 | } | |
695 | ||
696 | return "<div class='pve-largebar-border'>" + | |
697 | "<div class='pve-largebar-inner' style='width:" + per + "%;'></div>" + | |
0be88ae1 | 698 | "<div class='pve-largebar-text'>" + text + "</div>" + |
b0a6d326 EK |
699 | "</div>"; |
700 | }, | |
701 | ||
702 | format_duration_long: function(ut) { | |
703 | ||
704 | var days = Math.floor(ut / 86400); | |
705 | ut -= days*86400; | |
706 | var hours = Math.floor(ut / 3600); | |
707 | ut -= hours*3600; | |
708 | var mins = Math.floor(ut / 60); | |
709 | ut -= mins*60; | |
710 | ||
711 | var hours_str = '00' + hours.toString(); | |
712 | hours_str = hours_str.substr(hours_str.length - 2); | |
713 | var mins_str = "00" + mins.toString(); | |
714 | mins_str = mins_str.substr(mins_str.length - 2); | |
715 | var ut_str = "00" + ut.toString(); | |
716 | ut_str = ut_str.substr(ut_str.length - 2); | |
717 | ||
718 | if (days) { | |
719 | var ds = days > 1 ? PVE.Utils.daysText : PVE.Utils.dayText; | |
0be88ae1 | 720 | return days.toString() + ' ' + ds + ' ' + |
b0a6d326 EK |
721 | hours_str + ':' + mins_str + ':' + ut_str; |
722 | } else { | |
723 | return hours_str + ':' + mins_str + ':' + ut_str; | |
724 | } | |
725 | }, | |
726 | ||
727 | format_duration_short: function(ut) { | |
0be88ae1 | 728 | |
b0a6d326 | 729 | if (ut < 60) { |
530ee6b7 | 730 | return ut.toFixed(1) + 's'; |
b0a6d326 EK |
731 | } |
732 | ||
733 | if (ut < 3600) { | |
734 | var mins = ut / 60; | |
530ee6b7 | 735 | return mins.toFixed(1) + 'm'; |
b0a6d326 EK |
736 | } |
737 | ||
738 | if (ut < 86400) { | |
739 | var hours = ut / 3600; | |
530ee6b7 | 740 | return hours.toFixed(1) + 'h'; |
b0a6d326 EK |
741 | } |
742 | ||
743 | var days = ut / 86400; | |
530ee6b7 | 744 | return days.toFixed(1) + 'd'; |
b0a6d326 EK |
745 | }, |
746 | ||
747 | yesText: gettext('Yes'), | |
748 | noText: gettext('No'), | |
a3b8efb4 EK |
749 | enabledText: gettext('Enabled'), |
750 | disabledText: gettext('Disabled'), | |
b0a6d326 EK |
751 | noneText: gettext('none'), |
752 | errorText: gettext('Error'), | |
753 | unknownText: gettext('Unknown'), | |
754 | defaultText: gettext('Default'), | |
755 | daysText: gettext('days'), | |
756 | dayText: gettext('day'), | |
757 | runningText: gettext('running'), | |
758 | stoppedText: gettext('stopped'), | |
759 | neverText: gettext('never'), | |
760 | totalText: gettext('Total'), | |
761 | usedText: gettext('Used'), | |
762 | directoryText: gettext('Directory'), | |
763 | imagesText: gettext('Disk image'), | |
764 | backupFileText: gettext('VZDump backup file'), | |
2c554952 | 765 | vztmplText: gettext('Container template'), |
b0a6d326 | 766 | isoImageText: gettext('ISO image'), |
2c554952 | 767 | containersText: gettext('Container'), |
45ab85bb DM |
768 | stateText: gettext('State'), |
769 | groupText: gettext('Group'), | |
b0a6d326 EK |
770 | |
771 | format_expire: function(date) { | |
772 | if (!date) { | |
773 | return PVE.Utils.neverText; | |
774 | } | |
775 | return Ext.Date.format(date, "Y-m-d"); | |
776 | }, | |
777 | ||
3c23c025 | 778 | format_storage_type: function(value, md, record) { |
6760ab92 DC |
779 | if (value === 'rbd' && record) { |
780 | value = (record.get('monhost')?'rbd_ext':'pveceph'); | |
3c23c025 | 781 | } |
b0a6d326 EK |
782 | if (value === 'dir') { |
783 | return PVE.Utils.directoryText; | |
784 | } else if (value === 'nfs') { | |
785 | return 'NFS'; | |
786 | } else if (value === 'glusterfs') { | |
787 | return 'GlusterFS'; | |
788 | } else if (value === 'lvm') { | |
789 | return 'LVM'; | |
ffd96a3b DM |
790 | } else if (value === 'lvmthin') { |
791 | return 'LVM-Thin'; | |
b0a6d326 EK |
792 | } else if (value === 'iscsi') { |
793 | return 'iSCSI'; | |
794 | } else if (value === 'rbd') { | |
6760ab92 DC |
795 | return 'RBD'; |
796 | } else if (value === 'rbd_ext') { | |
3c23c025 DC |
797 | return 'RBD (external)'; |
798 | } else if (value === 'pveceph') { | |
799 | return 'RBD (PVE)'; | |
b0a6d326 EK |
800 | } else if (value === 'sheepdog') { |
801 | return 'Sheepdog'; | |
802 | } else if (value === 'zfs') { | |
803 | return 'ZFS over iSCSI'; | |
804 | } else if (value === 'zfspool') { | |
805 | return 'ZFS'; | |
806 | } else if (value === 'iscsidirect') { | |
807 | return 'iSCSIDirect'; | |
ffd96a3b DM |
808 | } else if (value === 'drbd') { |
809 | return 'DRBD'; | |
b0a6d326 EK |
810 | } else { |
811 | return PVE.Utils.unknownText; | |
812 | } | |
813 | }, | |
814 | ||
815 | format_boolean_with_default: function(value) { | |
f2782813 | 816 | if (Ext.isDefined(value) && value !== '__default__') { |
b0a6d326 EK |
817 | return value ? PVE.Utils.yesText : PVE.Utils.noText; |
818 | } | |
819 | return PVE.Utils.defaultText; | |
820 | }, | |
821 | ||
822 | format_boolean: function(value) { | |
823 | return value ? PVE.Utils.yesText : PVE.Utils.noText; | |
824 | }, | |
825 | ||
826 | format_neg_boolean: function(value) { | |
827 | return !value ? PVE.Utils.yesText : PVE.Utils.noText; | |
828 | }, | |
829 | ||
a3b8efb4 EK |
830 | format_enabled_toggle: function(value) { |
831 | return value ? PVE.Utils.enabledText :PVE.Utils.disabledText; | |
832 | }, | |
833 | ||
ced1677b TL |
834 | format_ha: function(value) { |
835 | var text = PVE.Utils.format_boolean(value.managed); | |
836 | ||
837 | if (value.managed) { | |
45ab85bb | 838 | text += ', ' + PVE.Utils.stateText + ': '; |
f25d7c4a | 839 | text += value.state || PVE.Utils.noneText; |
ced1677b | 840 | |
45ab85bb | 841 | text += ', ' + PVE.Utils.groupText + ': '; |
f25d7c4a | 842 | text += value.group || PVE.Utils.noneText; |
ced1677b TL |
843 | } |
844 | ||
845 | return text; | |
846 | }, | |
847 | ||
b0a6d326 EK |
848 | format_content_types: function(value) { |
849 | var cta = []; | |
850 | ||
851 | Ext.each(value.split(',').sort(), function(ct) { | |
852 | if (ct === 'images') { | |
853 | cta.push(PVE.Utils.imagesText); | |
854 | } else if (ct === 'backup') { | |
855 | cta.push(PVE.Utils.backupFileText); | |
856 | } else if (ct === 'vztmpl') { | |
857 | cta.push(PVE.Utils.vztmplText); | |
858 | } else if (ct === 'iso') { | |
859 | cta.push(PVE.Utils.isoImageText); | |
860 | } else if (ct === 'rootdir') { | |
861 | cta.push(PVE.Utils.containersText); | |
862 | } | |
863 | }); | |
864 | ||
865 | return cta.join(', '); | |
866 | }, | |
867 | ||
868 | render_storage_content: function(value, metaData, record) { | |
869 | var data = record.data; | |
870 | if (Ext.isNumber(data.channel) && | |
871 | Ext.isNumber(data.id) && | |
872 | Ext.isNumber(data.lun)) { | |
0be88ae1 DC |
873 | return "CH " + |
874 | Ext.String.leftPad(data.channel,2, '0') + | |
b0a6d326 EK |
875 | " ID " + data.id + " LUN " + data.lun; |
876 | } | |
877 | return data.volid.replace(/^.*:(.*\/)?/,''); | |
878 | }, | |
879 | ||
880 | render_serverity: function (value) { | |
881 | return PVE.Utils.log_severity_hash[value] || value; | |
882 | }, | |
883 | ||
884 | render_cpu: function(value, metaData, record, rowIndex, colIndex, store) { | |
885 | ||
886 | if (!(record.data.uptime && Ext.isNumeric(value))) { | |
887 | return ''; | |
888 | } | |
889 | ||
890 | var maxcpu = record.data.maxcpu || 1; | |
891 | ||
892 | if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) { | |
893 | return ''; | |
894 | } | |
0be88ae1 | 895 | |
b0a6d326 EK |
896 | var per = value * 100; |
897 | ||
898 | return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU'); | |
899 | }, | |
900 | ||
901 | render_size: function(value, metaData, record, rowIndex, colIndex, store) { | |
902 | /*jslint confusion: true */ | |
903 | ||
904 | if (!Ext.isNumeric(value)) { | |
905 | return ''; | |
906 | } | |
907 | ||
908 | return PVE.Utils.format_size(value); | |
909 | }, | |
910 | ||
946730cd DC |
911 | render_bandwidth: function(value) { |
912 | if (!Ext.isNumeric(value)) { | |
913 | return ''; | |
914 | } | |
915 | ||
916 | return PVE.Utils.format_size(value) + '/s'; | |
917 | }, | |
918 | ||
b0a6d326 EK |
919 | render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) { |
920 | var servertime = new Date(value * 1000); | |
921 | return Ext.Date.format(servertime, 'Y-m-d H:i:s'); | |
922 | }, | |
923 | ||
3f633655 EK |
924 | render_timestamp_human_readable: function(value) { |
925 | return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s'); | |
926 | }, | |
927 | ||
ddd26302 DC |
928 | render_duration: function(value) { |
929 | if (value === undefined) { | |
930 | return '-'; | |
931 | } | |
932 | return PVE.Utils.format_duration_short(value); | |
933 | }, | |
934 | ||
0bfc799f DC |
935 | calculate_mem_usage: function(data) { |
936 | if (!Ext.isNumeric(data.mem) || | |
937 | data.maxmem === 0 || | |
938 | data.uptime < 1) { | |
939 | return -1; | |
940 | } | |
941 | ||
942 | return (data.mem / data.maxmem); | |
943 | }, | |
944 | ||
945 | render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { | |
946 | if (!Ext.isNumeric(value) || value === -1) { | |
947 | return ''; | |
948 | } | |
949 | if (value > 1 ) { | |
950 | // we got no percentage but bytes | |
951 | var mem = value; | |
952 | var maxmem = record.data.maxmem; | |
953 | if (!record.data.uptime || | |
954 | maxmem === 0 || | |
955 | !Ext.isNumeric(mem)) { | |
956 | return ''; | |
957 | } | |
958 | ||
959 | return ((mem*100)/maxmem).toFixed(1) + " %"; | |
960 | } | |
961 | return (value*100).toFixed(1) + " %"; | |
962 | }, | |
963 | ||
b0a6d326 EK |
964 | render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
965 | ||
966 | var mem = value; | |
967 | var maxmem = record.data.maxmem; | |
0be88ae1 | 968 | |
b0a6d326 EK |
969 | if (!record.data.uptime) { |
970 | return ''; | |
971 | } | |
972 | ||
973 | if (!(Ext.isNumeric(mem) && maxmem)) { | |
974 | return ''; | |
975 | } | |
976 | ||
728f1b97 | 977 | return PVE.Utils.render_size(value); |
b0a6d326 EK |
978 | }, |
979 | ||
0bfc799f DC |
980 | calculate_disk_usage: function(data) { |
981 | ||
982 | if (!Ext.isNumeric(data.disk) || | |
983 | data.type === 'qemu' || | |
984 | (data.type === 'lxc' && data.uptime === 0) || | |
985 | data.maxdisk === 0) { | |
986 | return -1; | |
987 | } | |
988 | ||
989 | return (data.disk / data.maxdisk); | |
990 | }, | |
991 | ||
992 | render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { | |
993 | if (!Ext.isNumeric(value) || value === -1) { | |
994 | return ''; | |
995 | } | |
996 | ||
997 | return (value * 100).toFixed(1) + " %"; | |
998 | }, | |
999 | ||
b0a6d326 EK |
1000 | render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
1001 | ||
1002 | var disk = value; | |
1003 | var maxdisk = record.data.maxdisk; | |
728f1b97 | 1004 | var type = record.data.type; |
b0a6d326 | 1005 | |
728f1b97 DC |
1006 | if (!Ext.isNumeric(disk) || |
1007 | type === 'qemu' || | |
1008 | maxdisk === 0 || | |
1009 | (type === 'lxc' && record.data.uptime === 0)) { | |
b0a6d326 EK |
1010 | return ''; |
1011 | } | |
1012 | ||
728f1b97 | 1013 | return PVE.Utils.render_size(value); |
b0a6d326 EK |
1014 | }, |
1015 | ||
1016 | render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) { | |
1017 | ||
b1d8e73d DC |
1018 | var icon = ''; |
1019 | var gridcls = ''; | |
1020 | ||
1021 | switch (value) { | |
1022 | case 'lxc': icon = 'cube'; | |
1023 | gridcls = '-stopped'; | |
1024 | break; | |
1025 | case 'qemu': icon = 'desktop'; | |
1026 | gridcls = '-stopped'; | |
1027 | break; | |
1028 | case 'node': icon = 'building'; | |
1029 | gridcls = '-offline'; | |
1030 | break; | |
1031 | case 'storage': icon = 'database'; break; | |
1032 | case 'pool': icon = 'tags'; break; | |
1033 | default: icon = 'file'; | |
1034 | } | |
1035 | ||
1036 | if (value === 'lxc' || value === 'qemu') { | |
1037 | if (record.data.running && record.data.status !== 'paused') { | |
1038 | gridcls = '-running'; | |
1039 | } else if (record.data.running) { | |
1040 | gridcls = '-paused'; | |
1041 | } | |
1042 | if (record.data.template) { | |
1043 | icon = 'file-o'; | |
1044 | gridcls = '-template-' + value; | |
1045 | } | |
1046 | } else if (value === 'node') { | |
1047 | if (record.data.running) { | |
a764c5f7 | 1048 | gridcls = '-online'; |
b1d8e73d | 1049 | } |
b0a6d326 EK |
1050 | } |
1051 | ||
2b2fe160 DC |
1052 | // overwrite anything else |
1053 | if (record.data.hastate === 'error') { | |
1054 | gridcls = '-offline'; | |
1055 | } | |
1056 | ||
a764c5f7 | 1057 | var fa = '<i class="fa fa-fw x-fa-grid' + gridcls + ' fa-' + icon + '"></i> '; |
b1d8e73d | 1058 | return fa + value; |
b0a6d326 EK |
1059 | }, |
1060 | ||
1061 | render_uptime: function(value, metaData, record, rowIndex, colIndex, store) { | |
1062 | ||
1063 | var uptime = value; | |
1064 | ||
1065 | if (uptime === undefined) { | |
1066 | return ''; | |
1067 | } | |
0be88ae1 | 1068 | |
b0a6d326 EK |
1069 | if (uptime <= 0) { |
1070 | return '-'; | |
1071 | } | |
1072 | ||
1073 | return PVE.Utils.format_duration_long(uptime); | |
1074 | }, | |
1075 | ||
1076 | render_support_level: function(value, metaData, record) { | |
1077 | return PVE.Utils.support_level_hash[value] || '-'; | |
1078 | }, | |
1079 | ||
0be88ae1 | 1080 | render_upid: function(value, metaData, record) { |
b0a6d326 EK |
1081 | var type = record.data.type; |
1082 | var id = record.data.id; | |
1083 | ||
1084 | return PVE.Utils.format_task_description(type, id); | |
1085 | }, | |
1086 | ||
054ac1b8 DC |
1087 | /* render functions for new status panel */ |
1088 | ||
1089 | render_usage: function(val) { | |
1090 | return (val*100).toFixed(2) + '%'; | |
1091 | }, | |
1092 | ||
1093 | render_cpu_usage: function(val, max) { | |
1094 | return Ext.String.format(gettext('{0}% of {1}') + | |
1095 | ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max); | |
1096 | }, | |
1097 | ||
1098 | render_size_usage: function(val, max) { | |
bab64974 DC |
1099 | if (max === 0) { |
1100 | return gettext('N/A'); | |
1101 | } | |
054ac1b8 DC |
1102 | return (val*100/max).toFixed(2) + '% '+ '(' + |
1103 | Ext.String.format(gettext('{0} of {1}'), | |
1104 | PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')'; | |
1105 | }, | |
1106 | ||
1107 | /* this is different for nodes */ | |
1108 | render_node_cpu_usage: function(value, record) { | |
1109 | return PVE.Utils.render_cpu_usage(value, record.cpus); | |
1110 | }, | |
1111 | ||
1112 | /* this is different for nodes */ | |
1113 | render_node_size_usage: function(record) { | |
1114 | return PVE.Utils.render_size_usage(record.used, record.total); | |
1115 | }, | |
1116 | ||
b0a6d326 EK |
1117 | dialog_title: function(subject, create, isAdd) { |
1118 | if (create) { | |
1119 | if (isAdd) { | |
1120 | return gettext('Add') + ': ' + subject; | |
1121 | } else { | |
1122 | return gettext('Create') + ': ' + subject; | |
1123 | } | |
1124 | } else { | |
1125 | return gettext('Edit') + ': ' + subject; | |
1126 | } | |
1127 | }, | |
aa0819a8 WB |
1128 | |
1129 | windowHostname: function() { | |
c15c61d3 | 1130 | return window.location.hostname.replace(PVE.Utils.IP6_bracket_match, |
aa0819a8 WB |
1131 | function(m, addr, offset, original) { return addr; }); |
1132 | }, | |
0be88ae1 | 1133 | |
b0a6d326 EK |
1134 | openDefaultConsoleWindow: function(allowSpice, vmtype, vmid, nodename, vmname) { |
1135 | var dv = PVE.Utils.defaultViewer(allowSpice); | |
1136 | PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname); | |
1137 | }, | |
1138 | ||
1139 | openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname) { | |
9e361643 | 1140 | // kvm, lxc, shell, upgrade |
b0a6d326 | 1141 | |
9e361643 | 1142 | if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) { |
b0a6d326 EK |
1143 | throw "missing vmid"; |
1144 | } | |
1145 | ||
1146 | if (!nodename) { | |
1147 | throw "no nodename specified"; | |
1148 | } | |
1149 | ||
c7218ab3 DC |
1150 | if (viewer === 'html5') { |
1151 | PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname); | |
b0a6d326 EK |
1152 | } else if (viewer === 'vv') { |
1153 | var url; | |
aa0819a8 | 1154 | var params = { proxy: PVE.Utils.windowHostname() }; |
b0a6d326 EK |
1155 | if (vmtype === 'kvm') { |
1156 | url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy'; | |
1157 | PVE.Utils.openSpiceViewer(url, params); | |
9e361643 DM |
1158 | } else if (vmtype === 'lxc') { |
1159 | url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy'; | |
b0a6d326 EK |
1160 | PVE.Utils.openSpiceViewer(url, params); |
1161 | } else if (vmtype === 'shell') { | |
1162 | url = '/nodes/' + nodename + '/spiceshell'; | |
1163 | PVE.Utils.openSpiceViewer(url, params); | |
1164 | } else if (vmtype === 'upgrade') { | |
1165 | url = '/nodes/' + nodename + '/spiceshell'; | |
1166 | params.upgrade = 1; | |
1167 | PVE.Utils.openSpiceViewer(url, params); | |
1168 | } | |
1169 | } else { | |
1170 | throw "unknown viewer type"; | |
1171 | } | |
1172 | }, | |
1173 | ||
1174 | defaultViewer: function(allowSpice) { | |
1175 | var vncdefault = 'html5'; | |
1176 | var dv = PVE.VersionInfo.console || vncdefault; | |
1177 | if (dv === 'vv' && !allowSpice) { | |
1178 | dv = vncdefault; | |
1179 | } | |
1180 | ||
1181 | return dv; | |
1182 | }, | |
1183 | ||
c7218ab3 | 1184 | openVNCViewer: function(vmtype, vmid, nodename, vmname) { |
b0a6d326 | 1185 | var url = Ext.urlEncode({ |
9e361643 | 1186 | console: vmtype, // kvm, lxc, upgrade or shell |
c7218ab3 | 1187 | novnc: 1, |
b0a6d326 EK |
1188 | vmid: vmid, |
1189 | vmname: vmname, | |
1190 | node: nodename | |
1191 | }); | |
1192 | var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427"); | |
1193 | nw.focus(); | |
1194 | }, | |
1195 | ||
1196 | openSpiceViewer: function(url, params){ | |
1197 | ||
1198 | var downloadWithName = function(uri, name) { | |
1199 | var link = Ext.DomHelper.append(document.body, { | |
1200 | tag: 'a', | |
1201 | href: uri, | |
1202 | css : 'display:none;visibility:hidden;height:0px;' | |
1203 | }); | |
1204 | ||
1205 | // Note: we need to tell android the correct file name extension | |
1206 | // but we do not set 'download' tag for other environments, because | |
1207 | // It can have strange side effects (additional user prompt on firefox) | |
1208 | var andriod = navigator.userAgent.match(/Android/i) ? true : false; | |
1209 | if (andriod) { | |
1210 | link.download = name; | |
1211 | } | |
1212 | ||
1213 | if (link.fireEvent) { | |
1214 | link.fireEvent('onclick'); | |
1215 | } else { | |
1216 | var evt = document.createEvent("MouseEvents"); | |
1217 | evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null); | |
1218 | link.dispatchEvent(evt); | |
1219 | } | |
1220 | }; | |
1221 | ||
1222 | PVE.Utils.API2Request({ | |
1223 | url: url, | |
1224 | params: params, | |
1225 | method: 'POST', | |
1226 | failure: function(response, opts){ | |
1227 | Ext.Msg.alert('Error', response.htmlStatus); | |
1228 | }, | |
1229 | success: function(response, opts){ | |
1230 | var raw = "[virt-viewer]\n"; | |
1231 | Ext.Object.each(response.result.data, function(k, v) { | |
1232 | raw += k + "=" + v + "\n"; | |
1233 | }); | |
1234 | var url = 'data:application/x-virt-viewer;charset=UTF-8,' + | |
1235 | encodeURIComponent(raw); | |
0be88ae1 | 1236 | |
b0a6d326 EK |
1237 | downloadWithName(url, "pve-spice.vv"); |
1238 | } | |
1239 | }); | |
1240 | }, | |
1241 | ||
0be88ae1 | 1242 | // comp.setLoading() is buggy in ExtJS 4.0.7, so we |
b0a6d326 EK |
1243 | // use el.mask() instead |
1244 | setErrorMask: function(comp, msg) { | |
1245 | var el = comp.el; | |
1246 | if (!el) { | |
1247 | return; | |
1248 | } | |
1249 | if (!msg) { | |
1250 | el.unmask(); | |
1251 | } else { | |
1252 | if (msg === true) { | |
1253 | el.mask(gettext("Loading...")); | |
1254 | } else { | |
1255 | el.mask(msg); | |
1256 | } | |
1257 | } | |
1258 | }, | |
1259 | ||
1260 | monStoreErrors: function(me, store) { | |
1261 | me.mon(store, 'beforeload', function(s, operation, eOpts) { | |
1262 | if (!me.loadCount) { | |
1263 | me.loadCount = 0; // make sure it is numeric | |
1264 | PVE.Utils.setErrorMask(me, true); | |
1265 | } | |
1266 | }); | |
1267 | ||
1268 | // only works with 'pve' proxy | |
1269 | me.mon(store.proxy, 'afterload', function(proxy, request, success) { | |
1270 | me.loadCount++; | |
1271 | ||
1272 | if (success) { | |
1273 | PVE.Utils.setErrorMask(me, false); | |
1274 | return; | |
1275 | } | |
1276 | ||
1277 | var msg; | |
23d3881a | 1278 | /*jslint nomen: true */ |
86826854 | 1279 | var operation = request._operation; |
b0a6d326 EK |
1280 | var error = operation.getError(); |
1281 | if (error.statusText) { | |
1282 | msg = error.statusText + ' (' + error.status + ')'; | |
1283 | } else { | |
1284 | msg = gettext('Connection error'); | |
1285 | } | |
1286 | PVE.Utils.setErrorMask(me, msg); | |
1287 | }); | |
685b7aa4 | 1288 | }, |
b0a6d326 | 1289 | |
e3129443 DC |
1290 | openTreeConsole: function(tree, record, item, index, e) { |
1291 | e.stopEvent(); | |
1292 | var nodename = record.data.node; | |
1293 | var vmid = record.data.vmid; | |
1294 | var vmname = record.data.name; | |
1295 | if (record.data.type === 'qemu' && !record.data.template) { | |
1296 | PVE.Utils.API2Request({ | |
1297 | url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current', | |
1298 | failure: function(response, opts) { | |
1299 | Ext.Msg.alert('Error', response.htmlStatus); | |
1300 | }, | |
1301 | success: function(response, opts) { | |
1302 | var allowSpice = response.result.data.spice; | |
1303 | PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname); | |
1304 | } | |
1305 | }); | |
1306 | } else if (record.data.type === 'lxc' && !record.data.template) { | |
1307 | PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname); | |
1308 | } | |
1309 | }, | |
1310 | ||
fbd60cfd DM |
1311 | // test automation helper |
1312 | call_menu_handler: function(menu, text) { | |
1313 | ||
1314 | var list = menu.query('menuitem'); | |
1315 | ||
1316 | Ext.Array.each(list, function(item) { | |
1317 | if (item.text === text) { | |
1318 | if (item.handler) { | |
1319 | item.handler(); | |
1320 | return 1; | |
1321 | } else { | |
1322 | return undefined; | |
1323 | } | |
1324 | } | |
1325 | }); | |
1326 | }, | |
1327 | ||
685b7aa4 DC |
1328 | createCmdMenu: function(v, record, item, index, event) { |
1329 | event.stopEvent(); | |
cc1a91be DC |
1330 | if (!(v instanceof Ext.tree.View)) { |
1331 | v.select(record); | |
1332 | } | |
685b7aa4 DC |
1333 | var menu; |
1334 | ||
1335 | if (record.data.type === 'qemu' && !record.data.template) { | |
1336 | menu = Ext.create('PVE.qemu.CmdMenu', { | |
1337 | pveSelNode: record | |
1338 | }); | |
1339 | } else if (record.data.type === 'qemu' && record.data.template) { | |
1340 | menu = Ext.create('PVE.qemu.TemplateMenu', { | |
1341 | pveSelNode: record | |
1342 | }); | |
1343 | } else if (record.data.type === 'lxc' && !record.data.template) { | |
1344 | menu = Ext.create('PVE.lxc.CmdMenu', { | |
1345 | pveSelNode: record | |
1346 | }); | |
1347 | } else if (record.data.type === 'lxc' && record.data.template) { | |
1348 | /* since clone does not work reliably, disable for now | |
1349 | menu = Ext.create('PVE.lxc.TemplateMenu', { | |
1350 | pveSelNode: record | |
1351 | }); | |
1352 | */ | |
1353 | return; | |
c11ab8cb DC |
1354 | |
1355 | } else if (record.data.type === 'node' ){ | |
1356 | menu = Ext.create('PVE.node.CmdMenu', { | |
1357 | nodename: record.data.node | |
1358 | }); | |
1359 | ||
685b7aa4 DC |
1360 | } else { |
1361 | return; | |
1362 | } | |
1363 | ||
1364 | menu.showAt(event.getXY()); | |
9fa2e36d EK |
1365 | }}, |
1366 | ||
fe4f00ad TL |
1367 | // helper for deleting field which are set to there default values |
1368 | delete_if_default: function(values, fieldname, default_val, create) { | |
1369 | if (values[fieldname] === '' || values[fieldname] === default_val) { | |
1370 | if (!create) { | |
1371 | if (values['delete']) { | |
1372 | values['delete'] += ',' + fieldname; | |
1373 | } else { | |
1374 | values['delete'] = fieldname; | |
1375 | } | |
1376 | } | |
1377 | ||
1378 | delete values[fieldname]; | |
1379 | } | |
1380 | }, | |
1381 | ||
9fa2e36d EK |
1382 | singleton: true, |
1383 | constructor: function() { | |
1384 | var me = this; | |
1385 | Ext.apply(me, me.utilities); | |
c15c61d3 EK |
1386 | |
1387 | var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])"; | |
1388 | var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")"; | |
1389 | var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})"; | |
1390 | var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")"; | |
1391 | ||
1392 | ||
1393 | me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$"); | |
1394 | me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$"); | |
1395 | ||
1396 | var IPV6_REGEXP = "(?:" + | |
1397 | "(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" + | |
1398 | "(?:(?:" + "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" + | |
1399 | "(?:(?:(?:" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" + | |
1400 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" + | |
1401 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" + | |
1402 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" + | |
1403 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" + ")" + IPV6_LS32 + ")|" + | |
1404 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" + ")" + IPV6_H16 + ")|" + | |
1405 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" + ")" + ")" + | |
1406 | ")"; | |
1407 | ||
1408 | me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$"); | |
1409 | me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$"); | |
1410 | me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]"); | |
1411 | ||
1412 | me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$"); | |
1413 | ||
1414 | var DnsName_REGEXP = "(?:(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*([A-Za-z0-9]([A-Za-z0-9\\-]*[A-Za-z0-9])?))"; | |
1415 | me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$"); | |
1416 | ||
1417 | me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$"); | |
1418 | me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$"); | |
1419 | me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$"); | |
685b7aa4 | 1420 | } |
9fa2e36d | 1421 | }); |
b0a6d326 | 1422 |