]>
Commit | Line | Data |
---|---|---|
7a2a8d56 DM |
1 | Ext.define('PVE.qemu.Monitor', { |
2 | extend: 'Ext.panel.Panel', | |
3 | ||
4 | alias: 'widget.pveQemuMonitor', | |
5 | ||
6 | maxLines: 500, | |
7 | ||
8 | initComponent : function() { | |
9 | var me = this; | |
10 | ||
11 | var nodename = me.pveSelNode.data.node; | |
12 | if (!nodename) { | |
13 | throw "no node name specified"; | |
14 | } | |
15 | ||
16 | var vmid = me.pveSelNode.data.vmid; | |
17 | if (!vmid) { | |
18 | throw "no VM ID specified"; | |
19 | } | |
20 | ||
7f0b90e9 DC |
21 | var history = []; |
22 | var histNum = -1; | |
7a2a8d56 DM |
23 | var lines = []; |
24 | ||
25 | var textbox = Ext.createWidget('panel', { | |
26 | region: 'center', | |
27 | xtype: 'panel', | |
28 | autoScroll: true, | |
29 | border: true, | |
30 | margins: '5 5 5 5', | |
f6710aac | 31 | bodyStyle: 'font-family: monospace;', |
7a2a8d56 DM |
32 | }); |
33 | ||
34 | var scrollToEnd = function() { | |
35 | var el = textbox.getTargetEl(); | |
36 | var dom = Ext.getDom(el); | |
37 | ||
38 | var clientHeight = dom.clientHeight; | |
39 | // BrowserBug: clientHeight reports 0 in IE9 StrictMode | |
40 | // Instead we are using offsetHeight and hardcoding borders | |
41 | if (Ext.isIE9 && Ext.isStrict) { | |
42 | clientHeight = dom.offsetHeight + 2; | |
43 | } | |
44 | dom.scrollTop = dom.scrollHeight - clientHeight; | |
45 | }; | |
46 | ||
47 | var refresh = function() { | |
48 | textbox.update('<pre>' + lines.join('\n') + '</pre>'); | |
49 | scrollToEnd(); | |
50 | }; | |
51 | ||
52 | var addLine = function(line) { | |
53 | lines.push(line); | |
54 | if (lines.length > me.maxLines) { | |
55 | lines.shift(); | |
56 | } | |
57 | }; | |
58 | ||
59 | var executeCmd = function(cmd) { | |
60 | addLine("# " + Ext.htmlEncode(cmd)); | |
7f0b90e9 DC |
61 | if (cmd) { |
62 | history.unshift(cmd); | |
63 | if (history.length > 20) { | |
64 | history.splice(20); | |
65 | } | |
66 | } | |
67 | histNum = -1; | |
68 | ||
7a2a8d56 | 69 | refresh(); |
e7ade592 | 70 | Proxmox.Utils.API2Request({ |
7a2a8d56 DM |
71 | params: { command: cmd }, |
72 | url: '/nodes/' + nodename + '/qemu/' + vmid + "/monitor", | |
73 | method: 'POST', | |
74 | waitMsgTarget: me, | |
75 | success: function(response, opts) { | |
2a4971d8 | 76 | var res = response.result.data; |
7a2a8d56 DM |
77 | Ext.Array.each(res.split('\n'), function(line) { |
78 | addLine(Ext.htmlEncode(line)); | |
79 | }); | |
80 | refresh(); | |
81 | }, | |
82 | failure: function(response, opts) { | |
83 | Ext.Msg.alert('Error', response.htmlStatus); | |
f6710aac | 84 | }, |
7a2a8d56 DM |
85 | }); |
86 | }; | |
87 | ||
88 | Ext.apply(me, { | |
89 | layout: { type: 'border' }, | |
90 | border: false, | |
91 | items: [ | |
92 | textbox, | |
93 | { | |
94 | region: 'south', | |
95 | margins:'0 5 5 5', | |
96 | border: false, | |
97 | xtype: 'textfield', | |
98 | name: 'cmd', | |
99 | value: '', | |
100 | fieldStyle: 'font-family: monospace;', | |
101 | allowBlank: true, | |
102 | listeners: { | |
103 | afterrender: function(f) { | |
104 | f.focus(false); | |
105 | addLine("Type 'help' for help."); | |
106 | refresh(); | |
107 | }, | |
108 | specialkey: function(f, e) { | |
7f0b90e9 DC |
109 | var key = e.getKey(); |
110 | switch (key) { | |
111 | case e.ENTER: | |
112 | var cmd = f.getValue(); | |
113 | f.setValue(''); | |
114 | executeCmd(cmd); | |
115 | break; | |
116 | case e.PAGE_UP: | |
117 | textbox.scrollBy(0, -0.9*textbox.getHeight(), false); | |
118 | break; | |
119 | case e.PAGE_DOWN: | |
120 | textbox.scrollBy(0, 0.9*textbox.getHeight(), false); | |
121 | break; | |
122 | case e.UP: | |
123 | if (histNum + 1 < history.length) { | |
124 | f.setValue(history[++histNum]); | |
125 | } | |
126 | e.preventDefault(); | |
127 | break; | |
128 | case e.DOWN: | |
129 | if (histNum > 0) { | |
130 | f.setValue(history[--histNum]); | |
131 | } | |
132 | e.preventDefault(); | |
133 | break; | |
134 | default: | |
135 | break; | |
7a2a8d56 | 136 | } |
f6710aac TL |
137 | }, |
138 | }, | |
139 | }, | |
7a2a8d56 DM |
140 | ], |
141 | listeners: { | |
142 | show: function() { | |
143 | var field = me.query('textfield[name="cmd"]')[0]; | |
144 | field.focus(false, true); | |
f6710aac TL |
145 | }, |
146 | }, | |
2a4971d8 | 147 | }); |
7a2a8d56 DM |
148 | |
149 | me.callParent(); | |
f6710aac | 150 | }, |
7a2a8d56 | 151 | }); |