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