]>
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 | ||
046e640c DC |
102 | map_ceph_health: { |
103 | 'HEALTH_OK':'good', | |
104 | 'HEALTH_WARN':'warning', | |
105 | 'HEALTH_ERR':'critical' | |
106 | }, | |
107 | ||
108 | render_ceph_health: function(record) { | |
109 | var state = { | |
110 | iconCls: PVE.Utils.get_health_icon(), | |
111 | text: '' | |
112 | }; | |
113 | ||
114 | if (!record || !record.data) { | |
115 | return state; | |
116 | } | |
117 | ||
118 | var health = PVE.Utils.map_ceph_health[record.data.health.overall_status]; | |
119 | ||
120 | state.iconCls = PVE.Utils.get_health_icon(health, true); | |
121 | state.text = record.data.health.overall_status; | |
122 | ||
123 | return state; | |
124 | }, | |
125 | ||
b0a6d326 EK |
126 | render_kvm_ostype: function (value) { |
127 | if (!value) { | |
128 | return gettext('Other OS types'); | |
129 | } | |
130 | var text = PVE.Utils.kvm_ostypes[value]; | |
131 | if (text) { | |
b7159d8b | 132 | return text; |
b0a6d326 EK |
133 | } |
134 | return value; | |
135 | }, | |
136 | ||
137 | render_hotplug_features: function (value) { | |
23d3881a | 138 | var fa = []; |
b0a6d326 EK |
139 | |
140 | if (!value || (value === '0')) { | |
141 | return gettext('disabled'); | |
142 | } | |
143 | ||
4dcca8a4 DC |
144 | if (value === '1') { |
145 | value = 'disk,network,usb'; | |
146 | } | |
147 | ||
b0a6d326 EK |
148 | Ext.each(value.split(','), function(el) { |
149 | if (el === 'disk') { | |
150 | fa.push(gettext('Disk')); | |
151 | } else if (el === 'network') { | |
152 | fa.push(gettext('Network')); | |
153 | } else if (el === 'usb') { | |
154 | fa.push(gettext('USB')); | |
155 | } else if (el === 'memory') { | |
156 | fa.push(gettext('Memory')); | |
157 | } else if (el === 'cpu') { | |
158 | fa.push(gettext('CPU')); | |
159 | } else { | |
160 | fa.push(el); | |
161 | } | |
162 | }); | |
163 | ||
164 | return fa.join(', '); | |
165 | }, | |
166 | ||
167 | network_iface_types: { | |
168 | eth: gettext("Network Device"), | |
169 | bridge: 'Linux Bridge', | |
170 | bond: 'Linux Bond', | |
171 | OVSBridge: 'OVS Bridge', | |
172 | OVSBond: 'OVS Bond', | |
173 | OVSPort: 'OVS Port', | |
174 | OVSIntPort: 'OVS IntPort' | |
175 | }, | |
176 | ||
177 | render_network_iface_type: function(value) { | |
0be88ae1 | 178 | return PVE.Utils.network_iface_types[value] || |
b0a6d326 EK |
179 | PVE.Utils.unknownText; |
180 | }, | |
181 | ||
17c71f27 DC |
182 | render_qemu_bios: function(value) { |
183 | if (!value) { | |
184 | return PVE.Utils.defaultText + ' (SeaBIOS)'; | |
185 | } else if (value === 'seabios') { | |
186 | return "SeaBIOS"; | |
187 | } else if (value === 'ovmf') { | |
188 | return "OVMF (UEFI)"; | |
189 | } else { | |
190 | return value; | |
191 | } | |
192 | }, | |
193 | ||
b0a6d326 EK |
194 | render_scsihw: function(value) { |
195 | if (!value) { | |
196 | return PVE.Utils.defaultText + ' (LSI 53C895A)'; | |
197 | } else if (value === 'lsi') { | |
198 | return 'LSI 53C895A'; | |
199 | } else if (value === 'lsi53c810') { | |
200 | return 'LSI 53C810'; | |
201 | } else if (value === 'megasas') { | |
202 | return 'MegaRAID SAS 8708EM2'; | |
203 | } else if (value === 'virtio-scsi-pci') { | |
49f5d1ab EK |
204 | return 'VirtIO SCSI'; |
205 | } else if (value === 'virtio-scsi-single') { | |
206 | return 'VirtIO SCSI single'; | |
b0a6d326 EK |
207 | } else if (value === 'pvscsi') { |
208 | return 'VMware PVSCSI'; | |
209 | } else { | |
210 | return value; | |
211 | } | |
212 | }, | |
213 | ||
214 | // fixme: auto-generate this | |
215 | // for now, please keep in sync with PVE::Tools::kvmkeymaps | |
216 | kvm_keymaps: { | |
217 | //ar: 'Arabic', | |
218 | da: 'Danish', | |
0be88ae1 DC |
219 | de: 'German', |
220 | 'de-ch': 'German (Swiss)', | |
221 | 'en-gb': 'English (UK)', | |
0a5b8747 | 222 | 'en-us': 'English (USA)', |
b0a6d326 EK |
223 | es: 'Spanish', |
224 | //et: 'Estonia', | |
225 | fi: 'Finnish', | |
0be88ae1 DC |
226 | //fo: 'Faroe Islands', |
227 | fr: 'French', | |
228 | 'fr-be': 'French (Belgium)', | |
b0a6d326 EK |
229 | 'fr-ca': 'French (Canada)', |
230 | 'fr-ch': 'French (Swiss)', | |
231 | //hr: 'Croatia', | |
232 | hu: 'Hungarian', | |
233 | is: 'Icelandic', | |
0be88ae1 | 234 | it: 'Italian', |
b0a6d326 EK |
235 | ja: 'Japanese', |
236 | lt: 'Lithuanian', | |
237 | //lv: 'Latvian', | |
0be88ae1 | 238 | mk: 'Macedonian', |
b0a6d326 EK |
239 | nl: 'Dutch', |
240 | //'nl-be': 'Dutch (Belgium)', | |
0be88ae1 | 241 | no: 'Norwegian', |
b0a6d326 EK |
242 | pl: 'Polish', |
243 | pt: 'Portuguese', | |
244 | 'pt-br': 'Portuguese (Brazil)', | |
245 | //ru: 'Russian', | |
246 | sl: 'Slovenian', | |
247 | sv: 'Swedish', | |
248 | //th: 'Thai', | |
249 | tr: 'Turkish' | |
250 | }, | |
251 | ||
252 | kvm_vga_drivers: { | |
253 | std: gettext('Standard VGA'), | |
5ca366f2 | 254 | vmware: gettext('VMware compatible'), |
b0a6d326 EK |
255 | cirrus: 'Cirrus Logic GD5446', |
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: { | |
a36deac4 | 566 | diskinit: [ 'Disk', gettext('Initialize 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') ], | |
615 | imgcopy: ['', gettext('Copy data') ], | |
616 | imgdel: ['', gettext('Erase data') ], | |
617 | download: ['', gettext('Download') ], | |
618 | vzdump: ['', gettext('Backup') ], | |
619 | aptupdate: ['', gettext('Update package database') ], | |
620 | startall: [ '', gettext('Start all VMs and Containers') ], | |
621 | stopall: [ '', gettext('Stop all VMs and Containers') ], | |
622 | migrateall: [ '', gettext('Migrate all VMs and Containers') ] | |
623 | }, | |
624 | ||
0be88ae1 | 625 | format_task_description: function(type, id) { |
b0a6d326 EK |
626 | var farray = PVE.Utils.task_desc_table[type]; |
627 | if (!farray) { | |
628 | return type; | |
629 | } | |
630 | var prefix = farray[0]; | |
631 | var text = farray[1]; | |
632 | if (prefix) { | |
0be88ae1 | 633 | return prefix + ' ' + id + ' - ' + text; |
b0a6d326 EK |
634 | } |
635 | return text; | |
636 | }, | |
637 | ||
638 | parse_task_upid: function(upid) { | |
639 | var task = {}; | |
640 | ||
641 | 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]+):$/); | |
642 | if (!res) { | |
643 | throw "unable to parse upid '" + upid + "'"; | |
644 | } | |
645 | task.node = res[1]; | |
646 | task.pid = parseInt(res[2], 16); | |
647 | task.pstart = parseInt(res[3], 16); | |
648 | task.starttime = parseInt(res[4], 16); | |
649 | task.type = res[5]; | |
650 | task.id = res[6]; | |
651 | task.user = res[7]; | |
652 | ||
653 | task.desc = PVE.Utils.format_task_description(task.type, task.id); | |
654 | ||
655 | return task; | |
656 | }, | |
657 | ||
658 | format_size: function(size) { | |
659 | /*jslint confusion: true */ | |
660 | ||
02f47fe8 DC |
661 | var units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi']; |
662 | var num = 0; | |
b0a6d326 | 663 | |
02f47fe8 DC |
664 | while (size >= 1024 && ((num++)+1) < units.length) { |
665 | size = size / 1024; | |
b0a6d326 EK |
666 | } |
667 | ||
02f47fe8 | 668 | return size.toFixed((num > 0)?2:0) + " " + units[num] + "B"; |
b0a6d326 EK |
669 | }, |
670 | ||
671 | format_html_bar: function(per, text) { | |
672 | ||
673 | return "<div class='pve-bar-wrap'>" + text + "<div class='pve-bar-border'>" + | |
674 | "<div class='pve-bar-inner' style='width:" + per + "%;'></div>" + | |
675 | "</div></div>"; | |
0be88ae1 | 676 | |
b0a6d326 EK |
677 | }, |
678 | ||
679 | format_cpu_bar: function(per1, per2, text) { | |
680 | ||
681 | return "<div class='pve-bar-border'>" + | |
682 | "<div class='pve-bar-inner' style='width:" + per1 + "%;'></div>" + | |
683 | "<div class='pve-bar-inner2' style='width:" + per2 + "%;'></div>" + | |
0be88ae1 | 684 | "<div class='pve-bar-text'>" + text + "</div>" + |
b0a6d326 EK |
685 | "</div>"; |
686 | }, | |
687 | ||
688 | format_large_bar: function(per, text) { | |
689 | ||
690 | if (!text) { | |
691 | text = per.toFixed(1) + "%"; | |
692 | } | |
693 | ||
694 | return "<div class='pve-largebar-border'>" + | |
695 | "<div class='pve-largebar-inner' style='width:" + per + "%;'></div>" + | |
0be88ae1 | 696 | "<div class='pve-largebar-text'>" + text + "</div>" + |
b0a6d326 EK |
697 | "</div>"; |
698 | }, | |
699 | ||
700 | format_duration_long: function(ut) { | |
701 | ||
702 | var days = Math.floor(ut / 86400); | |
703 | ut -= days*86400; | |
704 | var hours = Math.floor(ut / 3600); | |
705 | ut -= hours*3600; | |
706 | var mins = Math.floor(ut / 60); | |
707 | ut -= mins*60; | |
708 | ||
709 | var hours_str = '00' + hours.toString(); | |
710 | hours_str = hours_str.substr(hours_str.length - 2); | |
711 | var mins_str = "00" + mins.toString(); | |
712 | mins_str = mins_str.substr(mins_str.length - 2); | |
713 | var ut_str = "00" + ut.toString(); | |
714 | ut_str = ut_str.substr(ut_str.length - 2); | |
715 | ||
716 | if (days) { | |
717 | var ds = days > 1 ? PVE.Utils.daysText : PVE.Utils.dayText; | |
0be88ae1 | 718 | return days.toString() + ' ' + ds + ' ' + |
b0a6d326 EK |
719 | hours_str + ':' + mins_str + ':' + ut_str; |
720 | } else { | |
721 | return hours_str + ':' + mins_str + ':' + ut_str; | |
722 | } | |
723 | }, | |
724 | ||
725 | format_duration_short: function(ut) { | |
0be88ae1 | 726 | |
b0a6d326 EK |
727 | if (ut < 60) { |
728 | return ut.toString() + 's'; | |
729 | } | |
730 | ||
731 | if (ut < 3600) { | |
732 | var mins = ut / 60; | |
733 | return mins.toFixed(0) + 'm'; | |
734 | } | |
735 | ||
736 | if (ut < 86400) { | |
737 | var hours = ut / 3600; | |
738 | return hours.toFixed(0) + 'h'; | |
739 | } | |
740 | ||
741 | var days = ut / 86400; | |
0be88ae1 | 742 | return days.toFixed(0) + 'd'; |
b0a6d326 EK |
743 | }, |
744 | ||
745 | yesText: gettext('Yes'), | |
746 | noText: gettext('No'), | |
747 | noneText: gettext('none'), | |
748 | errorText: gettext('Error'), | |
749 | unknownText: gettext('Unknown'), | |
750 | defaultText: gettext('Default'), | |
751 | daysText: gettext('days'), | |
752 | dayText: gettext('day'), | |
753 | runningText: gettext('running'), | |
754 | stoppedText: gettext('stopped'), | |
755 | neverText: gettext('never'), | |
756 | totalText: gettext('Total'), | |
757 | usedText: gettext('Used'), | |
758 | directoryText: gettext('Directory'), | |
759 | imagesText: gettext('Disk image'), | |
760 | backupFileText: gettext('VZDump backup file'), | |
2c554952 | 761 | vztmplText: gettext('Container template'), |
b0a6d326 | 762 | isoImageText: gettext('ISO image'), |
2c554952 | 763 | containersText: gettext('Container'), |
45ab85bb DM |
764 | stateText: gettext('State'), |
765 | groupText: gettext('Group'), | |
b0a6d326 EK |
766 | |
767 | format_expire: function(date) { | |
768 | if (!date) { | |
769 | return PVE.Utils.neverText; | |
770 | } | |
771 | return Ext.Date.format(date, "Y-m-d"); | |
772 | }, | |
773 | ||
774 | format_storage_type: function(value) { | |
775 | if (value === 'dir') { | |
776 | return PVE.Utils.directoryText; | |
777 | } else if (value === 'nfs') { | |
778 | return 'NFS'; | |
779 | } else if (value === 'glusterfs') { | |
780 | return 'GlusterFS'; | |
781 | } else if (value === 'lvm') { | |
782 | return 'LVM'; | |
ffd96a3b DM |
783 | } else if (value === 'lvmthin') { |
784 | return 'LVM-Thin'; | |
b0a6d326 EK |
785 | } else if (value === 'iscsi') { |
786 | return 'iSCSI'; | |
787 | } else if (value === 'rbd') { | |
788 | return 'RBD'; | |
789 | } else if (value === 'sheepdog') { | |
790 | return 'Sheepdog'; | |
791 | } else if (value === 'zfs') { | |
792 | return 'ZFS over iSCSI'; | |
793 | } else if (value === 'zfspool') { | |
794 | return 'ZFS'; | |
795 | } else if (value === 'iscsidirect') { | |
796 | return 'iSCSIDirect'; | |
ffd96a3b DM |
797 | } else if (value === 'drbd') { |
798 | return 'DRBD'; | |
b0a6d326 EK |
799 | } else { |
800 | return PVE.Utils.unknownText; | |
801 | } | |
802 | }, | |
803 | ||
804 | format_boolean_with_default: function(value) { | |
f2782813 | 805 | if (Ext.isDefined(value) && value !== '__default__') { |
b0a6d326 EK |
806 | return value ? PVE.Utils.yesText : PVE.Utils.noText; |
807 | } | |
808 | return PVE.Utils.defaultText; | |
809 | }, | |
810 | ||
811 | format_boolean: function(value) { | |
812 | return value ? PVE.Utils.yesText : PVE.Utils.noText; | |
813 | }, | |
814 | ||
815 | format_neg_boolean: function(value) { | |
816 | return !value ? PVE.Utils.yesText : PVE.Utils.noText; | |
817 | }, | |
818 | ||
ced1677b TL |
819 | format_ha: function(value) { |
820 | var text = PVE.Utils.format_boolean(value.managed); | |
821 | ||
822 | if (value.managed) { | |
45ab85bb | 823 | text += ', ' + PVE.Utils.stateText + ': '; |
f25d7c4a | 824 | text += value.state || PVE.Utils.noneText; |
ced1677b | 825 | |
45ab85bb | 826 | text += ', ' + PVE.Utils.groupText + ': '; |
f25d7c4a | 827 | text += value.group || PVE.Utils.noneText; |
ced1677b TL |
828 | } |
829 | ||
830 | return text; | |
831 | }, | |
832 | ||
b0a6d326 EK |
833 | format_content_types: function(value) { |
834 | var cta = []; | |
835 | ||
836 | Ext.each(value.split(',').sort(), function(ct) { | |
837 | if (ct === 'images') { | |
838 | cta.push(PVE.Utils.imagesText); | |
839 | } else if (ct === 'backup') { | |
840 | cta.push(PVE.Utils.backupFileText); | |
841 | } else if (ct === 'vztmpl') { | |
842 | cta.push(PVE.Utils.vztmplText); | |
843 | } else if (ct === 'iso') { | |
844 | cta.push(PVE.Utils.isoImageText); | |
845 | } else if (ct === 'rootdir') { | |
846 | cta.push(PVE.Utils.containersText); | |
847 | } | |
848 | }); | |
849 | ||
850 | return cta.join(', '); | |
851 | }, | |
852 | ||
853 | render_storage_content: function(value, metaData, record) { | |
854 | var data = record.data; | |
855 | if (Ext.isNumber(data.channel) && | |
856 | Ext.isNumber(data.id) && | |
857 | Ext.isNumber(data.lun)) { | |
0be88ae1 DC |
858 | return "CH " + |
859 | Ext.String.leftPad(data.channel,2, '0') + | |
b0a6d326 EK |
860 | " ID " + data.id + " LUN " + data.lun; |
861 | } | |
862 | return data.volid.replace(/^.*:(.*\/)?/,''); | |
863 | }, | |
864 | ||
865 | render_serverity: function (value) { | |
866 | return PVE.Utils.log_severity_hash[value] || value; | |
867 | }, | |
868 | ||
869 | render_cpu: function(value, metaData, record, rowIndex, colIndex, store) { | |
870 | ||
871 | if (!(record.data.uptime && Ext.isNumeric(value))) { | |
872 | return ''; | |
873 | } | |
874 | ||
875 | var maxcpu = record.data.maxcpu || 1; | |
876 | ||
877 | if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) { | |
878 | return ''; | |
879 | } | |
0be88ae1 | 880 | |
b0a6d326 EK |
881 | var per = value * 100; |
882 | ||
883 | return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU'); | |
884 | }, | |
885 | ||
886 | render_size: function(value, metaData, record, rowIndex, colIndex, store) { | |
887 | /*jslint confusion: true */ | |
888 | ||
889 | if (!Ext.isNumeric(value)) { | |
890 | return ''; | |
891 | } | |
892 | ||
893 | return PVE.Utils.format_size(value); | |
894 | }, | |
895 | ||
896 | render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) { | |
897 | var servertime = new Date(value * 1000); | |
898 | return Ext.Date.format(servertime, 'Y-m-d H:i:s'); | |
899 | }, | |
900 | ||
0bfc799f DC |
901 | calculate_mem_usage: function(data) { |
902 | if (!Ext.isNumeric(data.mem) || | |
903 | data.maxmem === 0 || | |
904 | data.uptime < 1) { | |
905 | return -1; | |
906 | } | |
907 | ||
908 | return (data.mem / data.maxmem); | |
909 | }, | |
910 | ||
911 | render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { | |
912 | if (!Ext.isNumeric(value) || value === -1) { | |
913 | return ''; | |
914 | } | |
915 | if (value > 1 ) { | |
916 | // we got no percentage but bytes | |
917 | var mem = value; | |
918 | var maxmem = record.data.maxmem; | |
919 | if (!record.data.uptime || | |
920 | maxmem === 0 || | |
921 | !Ext.isNumeric(mem)) { | |
922 | return ''; | |
923 | } | |
924 | ||
925 | return ((mem*100)/maxmem).toFixed(1) + " %"; | |
926 | } | |
927 | return (value*100).toFixed(1) + " %"; | |
928 | }, | |
929 | ||
b0a6d326 EK |
930 | render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
931 | ||
932 | var mem = value; | |
933 | var maxmem = record.data.maxmem; | |
0be88ae1 | 934 | |
b0a6d326 EK |
935 | if (!record.data.uptime) { |
936 | return ''; | |
937 | } | |
938 | ||
939 | if (!(Ext.isNumeric(mem) && maxmem)) { | |
940 | return ''; | |
941 | } | |
942 | ||
728f1b97 | 943 | return PVE.Utils.render_size(value); |
b0a6d326 EK |
944 | }, |
945 | ||
0bfc799f DC |
946 | calculate_disk_usage: function(data) { |
947 | ||
948 | if (!Ext.isNumeric(data.disk) || | |
949 | data.type === 'qemu' || | |
950 | (data.type === 'lxc' && data.uptime === 0) || | |
951 | data.maxdisk === 0) { | |
952 | return -1; | |
953 | } | |
954 | ||
955 | return (data.disk / data.maxdisk); | |
956 | }, | |
957 | ||
958 | render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { | |
959 | if (!Ext.isNumeric(value) || value === -1) { | |
960 | return ''; | |
961 | } | |
962 | ||
963 | return (value * 100).toFixed(1) + " %"; | |
964 | }, | |
965 | ||
b0a6d326 EK |
966 | render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
967 | ||
968 | var disk = value; | |
969 | var maxdisk = record.data.maxdisk; | |
728f1b97 | 970 | var type = record.data.type; |
b0a6d326 | 971 | |
728f1b97 DC |
972 | if (!Ext.isNumeric(disk) || |
973 | type === 'qemu' || | |
974 | maxdisk === 0 || | |
975 | (type === 'lxc' && record.data.uptime === 0)) { | |
b0a6d326 EK |
976 | return ''; |
977 | } | |
978 | ||
728f1b97 | 979 | return PVE.Utils.render_size(value); |
b0a6d326 EK |
980 | }, |
981 | ||
982 | render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) { | |
983 | ||
b1d8e73d DC |
984 | var icon = ''; |
985 | var gridcls = ''; | |
986 | ||
987 | switch (value) { | |
988 | case 'lxc': icon = 'cube'; | |
989 | gridcls = '-stopped'; | |
990 | break; | |
991 | case 'qemu': icon = 'desktop'; | |
992 | gridcls = '-stopped'; | |
993 | break; | |
994 | case 'node': icon = 'building'; | |
995 | gridcls = '-offline'; | |
996 | break; | |
997 | case 'storage': icon = 'database'; break; | |
998 | case 'pool': icon = 'tags'; break; | |
999 | default: icon = 'file'; | |
1000 | } | |
1001 | ||
1002 | if (value === 'lxc' || value === 'qemu') { | |
1003 | if (record.data.running && record.data.status !== 'paused') { | |
1004 | gridcls = '-running'; | |
1005 | } else if (record.data.running) { | |
1006 | gridcls = '-paused'; | |
1007 | } | |
1008 | if (record.data.template) { | |
1009 | icon = 'file-o'; | |
1010 | gridcls = '-template-' + value; | |
1011 | } | |
1012 | } else if (value === 'node') { | |
1013 | if (record.data.running) { | |
a764c5f7 | 1014 | gridcls = '-online'; |
b1d8e73d | 1015 | } |
b0a6d326 EK |
1016 | } |
1017 | ||
2b2fe160 DC |
1018 | // overwrite anything else |
1019 | if (record.data.hastate === 'error') { | |
1020 | gridcls = '-offline'; | |
1021 | } | |
1022 | ||
a764c5f7 | 1023 | var fa = '<i class="fa fa-fw x-fa-grid' + gridcls + ' fa-' + icon + '"></i> '; |
b1d8e73d | 1024 | return fa + value; |
b0a6d326 EK |
1025 | }, |
1026 | ||
1027 | render_uptime: function(value, metaData, record, rowIndex, colIndex, store) { | |
1028 | ||
1029 | var uptime = value; | |
1030 | ||
1031 | if (uptime === undefined) { | |
1032 | return ''; | |
1033 | } | |
0be88ae1 | 1034 | |
b0a6d326 EK |
1035 | if (uptime <= 0) { |
1036 | return '-'; | |
1037 | } | |
1038 | ||
1039 | return PVE.Utils.format_duration_long(uptime); | |
1040 | }, | |
1041 | ||
1042 | render_support_level: function(value, metaData, record) { | |
1043 | return PVE.Utils.support_level_hash[value] || '-'; | |
1044 | }, | |
1045 | ||
0be88ae1 | 1046 | render_upid: function(value, metaData, record) { |
b0a6d326 EK |
1047 | var type = record.data.type; |
1048 | var id = record.data.id; | |
1049 | ||
1050 | return PVE.Utils.format_task_description(type, id); | |
1051 | }, | |
1052 | ||
054ac1b8 DC |
1053 | /* render functions for new status panel */ |
1054 | ||
1055 | render_usage: function(val) { | |
1056 | return (val*100).toFixed(2) + '%'; | |
1057 | }, | |
1058 | ||
1059 | render_cpu_usage: function(val, max) { | |
1060 | return Ext.String.format(gettext('{0}% of {1}') + | |
1061 | ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max); | |
1062 | }, | |
1063 | ||
1064 | render_size_usage: function(val, max) { | |
bab64974 DC |
1065 | if (max === 0) { |
1066 | return gettext('N/A'); | |
1067 | } | |
054ac1b8 DC |
1068 | return (val*100/max).toFixed(2) + '% '+ '(' + |
1069 | Ext.String.format(gettext('{0} of {1}'), | |
1070 | PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')'; | |
1071 | }, | |
1072 | ||
1073 | /* this is different for nodes */ | |
1074 | render_node_cpu_usage: function(value, record) { | |
1075 | return PVE.Utils.render_cpu_usage(value, record.cpus); | |
1076 | }, | |
1077 | ||
1078 | /* this is different for nodes */ | |
1079 | render_node_size_usage: function(record) { | |
1080 | return PVE.Utils.render_size_usage(record.used, record.total); | |
1081 | }, | |
1082 | ||
b0a6d326 EK |
1083 | dialog_title: function(subject, create, isAdd) { |
1084 | if (create) { | |
1085 | if (isAdd) { | |
1086 | return gettext('Add') + ': ' + subject; | |
1087 | } else { | |
1088 | return gettext('Create') + ': ' + subject; | |
1089 | } | |
1090 | } else { | |
1091 | return gettext('Edit') + ': ' + subject; | |
1092 | } | |
1093 | }, | |
aa0819a8 WB |
1094 | |
1095 | windowHostname: function() { | |
c15c61d3 | 1096 | return window.location.hostname.replace(PVE.Utils.IP6_bracket_match, |
aa0819a8 WB |
1097 | function(m, addr, offset, original) { return addr; }); |
1098 | }, | |
0be88ae1 | 1099 | |
b0a6d326 EK |
1100 | openDefaultConsoleWindow: function(allowSpice, vmtype, vmid, nodename, vmname) { |
1101 | var dv = PVE.Utils.defaultViewer(allowSpice); | |
1102 | PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname); | |
1103 | }, | |
1104 | ||
1105 | openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname) { | |
9e361643 | 1106 | // kvm, lxc, shell, upgrade |
b0a6d326 | 1107 | |
9e361643 | 1108 | if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) { |
b0a6d326 EK |
1109 | throw "missing vmid"; |
1110 | } | |
1111 | ||
1112 | if (!nodename) { | |
1113 | throw "no nodename specified"; | |
1114 | } | |
1115 | ||
c7218ab3 DC |
1116 | if (viewer === 'html5') { |
1117 | PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname); | |
b0a6d326 EK |
1118 | } else if (viewer === 'vv') { |
1119 | var url; | |
aa0819a8 | 1120 | var params = { proxy: PVE.Utils.windowHostname() }; |
b0a6d326 EK |
1121 | if (vmtype === 'kvm') { |
1122 | url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy'; | |
1123 | PVE.Utils.openSpiceViewer(url, params); | |
9e361643 DM |
1124 | } else if (vmtype === 'lxc') { |
1125 | url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy'; | |
b0a6d326 EK |
1126 | PVE.Utils.openSpiceViewer(url, params); |
1127 | } else if (vmtype === 'shell') { | |
1128 | url = '/nodes/' + nodename + '/spiceshell'; | |
1129 | PVE.Utils.openSpiceViewer(url, params); | |
1130 | } else if (vmtype === 'upgrade') { | |
1131 | url = '/nodes/' + nodename + '/spiceshell'; | |
1132 | params.upgrade = 1; | |
1133 | PVE.Utils.openSpiceViewer(url, params); | |
1134 | } | |
1135 | } else { | |
1136 | throw "unknown viewer type"; | |
1137 | } | |
1138 | }, | |
1139 | ||
1140 | defaultViewer: function(allowSpice) { | |
1141 | var vncdefault = 'html5'; | |
1142 | var dv = PVE.VersionInfo.console || vncdefault; | |
1143 | if (dv === 'vv' && !allowSpice) { | |
1144 | dv = vncdefault; | |
1145 | } | |
1146 | ||
1147 | return dv; | |
1148 | }, | |
1149 | ||
c7218ab3 | 1150 | openVNCViewer: function(vmtype, vmid, nodename, vmname) { |
b0a6d326 | 1151 | var url = Ext.urlEncode({ |
9e361643 | 1152 | console: vmtype, // kvm, lxc, upgrade or shell |
c7218ab3 | 1153 | novnc: 1, |
b0a6d326 EK |
1154 | vmid: vmid, |
1155 | vmname: vmname, | |
1156 | node: nodename | |
1157 | }); | |
1158 | var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427"); | |
1159 | nw.focus(); | |
1160 | }, | |
1161 | ||
1162 | openSpiceViewer: function(url, params){ | |
1163 | ||
1164 | var downloadWithName = function(uri, name) { | |
1165 | var link = Ext.DomHelper.append(document.body, { | |
1166 | tag: 'a', | |
1167 | href: uri, | |
1168 | css : 'display:none;visibility:hidden;height:0px;' | |
1169 | }); | |
1170 | ||
1171 | // Note: we need to tell android the correct file name extension | |
1172 | // but we do not set 'download' tag for other environments, because | |
1173 | // It can have strange side effects (additional user prompt on firefox) | |
1174 | var andriod = navigator.userAgent.match(/Android/i) ? true : false; | |
1175 | if (andriod) { | |
1176 | link.download = name; | |
1177 | } | |
1178 | ||
1179 | if (link.fireEvent) { | |
1180 | link.fireEvent('onclick'); | |
1181 | } else { | |
1182 | var evt = document.createEvent("MouseEvents"); | |
1183 | evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null); | |
1184 | link.dispatchEvent(evt); | |
1185 | } | |
1186 | }; | |
1187 | ||
1188 | PVE.Utils.API2Request({ | |
1189 | url: url, | |
1190 | params: params, | |
1191 | method: 'POST', | |
1192 | failure: function(response, opts){ | |
1193 | Ext.Msg.alert('Error', response.htmlStatus); | |
1194 | }, | |
1195 | success: function(response, opts){ | |
1196 | var raw = "[virt-viewer]\n"; | |
1197 | Ext.Object.each(response.result.data, function(k, v) { | |
1198 | raw += k + "=" + v + "\n"; | |
1199 | }); | |
1200 | var url = 'data:application/x-virt-viewer;charset=UTF-8,' + | |
1201 | encodeURIComponent(raw); | |
0be88ae1 | 1202 | |
b0a6d326 EK |
1203 | downloadWithName(url, "pve-spice.vv"); |
1204 | } | |
1205 | }); | |
1206 | }, | |
1207 | ||
0be88ae1 | 1208 | // comp.setLoading() is buggy in ExtJS 4.0.7, so we |
b0a6d326 EK |
1209 | // use el.mask() instead |
1210 | setErrorMask: function(comp, msg) { | |
1211 | var el = comp.el; | |
1212 | if (!el) { | |
1213 | return; | |
1214 | } | |
1215 | if (!msg) { | |
1216 | el.unmask(); | |
1217 | } else { | |
1218 | if (msg === true) { | |
1219 | el.mask(gettext("Loading...")); | |
1220 | } else { | |
1221 | el.mask(msg); | |
1222 | } | |
1223 | } | |
1224 | }, | |
1225 | ||
1226 | monStoreErrors: function(me, store) { | |
1227 | me.mon(store, 'beforeload', function(s, operation, eOpts) { | |
1228 | if (!me.loadCount) { | |
1229 | me.loadCount = 0; // make sure it is numeric | |
1230 | PVE.Utils.setErrorMask(me, true); | |
1231 | } | |
1232 | }); | |
1233 | ||
1234 | // only works with 'pve' proxy | |
1235 | me.mon(store.proxy, 'afterload', function(proxy, request, success) { | |
1236 | me.loadCount++; | |
1237 | ||
1238 | if (success) { | |
1239 | PVE.Utils.setErrorMask(me, false); | |
1240 | return; | |
1241 | } | |
1242 | ||
1243 | var msg; | |
23d3881a | 1244 | /*jslint nomen: true */ |
86826854 | 1245 | var operation = request._operation; |
b0a6d326 EK |
1246 | var error = operation.getError(); |
1247 | if (error.statusText) { | |
1248 | msg = error.statusText + ' (' + error.status + ')'; | |
1249 | } else { | |
1250 | msg = gettext('Connection error'); | |
1251 | } | |
1252 | PVE.Utils.setErrorMask(me, msg); | |
1253 | }); | |
685b7aa4 | 1254 | }, |
b0a6d326 | 1255 | |
e3129443 DC |
1256 | openTreeConsole: function(tree, record, item, index, e) { |
1257 | e.stopEvent(); | |
1258 | var nodename = record.data.node; | |
1259 | var vmid = record.data.vmid; | |
1260 | var vmname = record.data.name; | |
1261 | if (record.data.type === 'qemu' && !record.data.template) { | |
1262 | PVE.Utils.API2Request({ | |
1263 | url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current', | |
1264 | failure: function(response, opts) { | |
1265 | Ext.Msg.alert('Error', response.htmlStatus); | |
1266 | }, | |
1267 | success: function(response, opts) { | |
1268 | var allowSpice = response.result.data.spice; | |
1269 | PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname); | |
1270 | } | |
1271 | }); | |
1272 | } else if (record.data.type === 'lxc' && !record.data.template) { | |
1273 | PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname); | |
1274 | } | |
1275 | }, | |
1276 | ||
fbd60cfd DM |
1277 | // test automation helper |
1278 | call_menu_handler: function(menu, text) { | |
1279 | ||
1280 | var list = menu.query('menuitem'); | |
1281 | ||
1282 | Ext.Array.each(list, function(item) { | |
1283 | if (item.text === text) { | |
1284 | if (item.handler) { | |
1285 | item.handler(); | |
1286 | return 1; | |
1287 | } else { | |
1288 | return undefined; | |
1289 | } | |
1290 | } | |
1291 | }); | |
1292 | }, | |
1293 | ||
685b7aa4 DC |
1294 | createCmdMenu: function(v, record, item, index, event) { |
1295 | event.stopEvent(); | |
cc1a91be DC |
1296 | if (!(v instanceof Ext.tree.View)) { |
1297 | v.select(record); | |
1298 | } | |
685b7aa4 DC |
1299 | var menu; |
1300 | ||
1301 | if (record.data.type === 'qemu' && !record.data.template) { | |
1302 | menu = Ext.create('PVE.qemu.CmdMenu', { | |
1303 | pveSelNode: record | |
1304 | }); | |
1305 | } else if (record.data.type === 'qemu' && record.data.template) { | |
1306 | menu = Ext.create('PVE.qemu.TemplateMenu', { | |
1307 | pveSelNode: record | |
1308 | }); | |
1309 | } else if (record.data.type === 'lxc' && !record.data.template) { | |
1310 | menu = Ext.create('PVE.lxc.CmdMenu', { | |
1311 | pveSelNode: record | |
1312 | }); | |
1313 | } else if (record.data.type === 'lxc' && record.data.template) { | |
1314 | /* since clone does not work reliably, disable for now | |
1315 | menu = Ext.create('PVE.lxc.TemplateMenu', { | |
1316 | pveSelNode: record | |
1317 | }); | |
1318 | */ | |
1319 | return; | |
1320 | } else { | |
1321 | return; | |
1322 | } | |
1323 | ||
1324 | menu.showAt(event.getXY()); | |
9fa2e36d EK |
1325 | }}, |
1326 | ||
fe4f00ad TL |
1327 | // helper for deleting field which are set to there default values |
1328 | delete_if_default: function(values, fieldname, default_val, create) { | |
1329 | if (values[fieldname] === '' || values[fieldname] === default_val) { | |
1330 | if (!create) { | |
1331 | if (values['delete']) { | |
1332 | values['delete'] += ',' + fieldname; | |
1333 | } else { | |
1334 | values['delete'] = fieldname; | |
1335 | } | |
1336 | } | |
1337 | ||
1338 | delete values[fieldname]; | |
1339 | } | |
1340 | }, | |
1341 | ||
9fa2e36d EK |
1342 | singleton: true, |
1343 | constructor: function() { | |
1344 | var me = this; | |
1345 | Ext.apply(me, me.utilities); | |
c15c61d3 EK |
1346 | |
1347 | var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])"; | |
1348 | var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")"; | |
1349 | var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})"; | |
1350 | var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")"; | |
1351 | ||
1352 | ||
1353 | me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$"); | |
1354 | me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$"); | |
1355 | ||
1356 | var IPV6_REGEXP = "(?:" + | |
1357 | "(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" + | |
1358 | "(?:(?:" + "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" + | |
1359 | "(?:(?:(?:" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" + | |
1360 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" + | |
1361 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" + | |
1362 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" + | |
1363 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" + ")" + IPV6_LS32 + ")|" + | |
1364 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" + ")" + IPV6_H16 + ")|" + | |
1365 | "(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" + ")" + ")" + | |
1366 | ")"; | |
1367 | ||
1368 | me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$"); | |
1369 | me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$"); | |
1370 | me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]"); | |
1371 | ||
1372 | me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$"); | |
1373 | ||
1374 | 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])?))"; | |
1375 | me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$"); | |
1376 | ||
1377 | me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$"); | |
1378 | me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$"); | |
1379 | me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$"); | |
685b7aa4 | 1380 | } |
9fa2e36d | 1381 | }); |
b0a6d326 | 1382 |