]>
Commit | Line | Data |
---|---|---|
53f669b1 TL |
1 | Ext.define('PVE.VMSummaryBase', { |
2 | extend: 'PVE.Page', | |
3 | ||
4 | nodename: undefined, | |
5 | vmid: undefined, | |
6 | vmtype: undefined, // qemu or lxc | |
7 | ||
8 | // defines the key/value config keys do display | |
9 | config_keys: undefined, | |
10 | ||
11 | vm_command: function(cmd, params) { | |
12 | var me = this; | |
13 | ||
e54ad66e | 14 | Proxmox.Utils.API2Request({ |
53f669b1 TL |
15 | params: params, |
16 | url: '/nodes/' + me.nodename + '/' + me.vmtype + '/' + me.vmid + | |
17 | '/status/' + cmd, | |
18 | method: 'POST', | |
19 | success: function(response, opts) { | |
20 | var upid = response.result.data; | |
21 | var page = 'nodes/' + me.nodename + '/tasks/' + upid; | |
22 | PVE.Workspace.gotoPage(page); | |
23 | }, | |
24 | failure: function(response, opts) { | |
25 | Ext.Msg.alert('Error', response.htmlStatus); | |
26 | } | |
27 | }); | |
28 | }, | |
29 | ||
30 | config: { | |
31 | items: [ | |
32 | { | |
33 | xtype: 'pveTitleBar' | |
34 | }, | |
35 | { | |
36 | xtype: 'component', | |
37 | itemId: 'vmstatus', | |
38 | styleHtmlContent: true, | |
39 | style: 'background-color:white;', | |
40 | tpl: [ | |
41 | '<table style="margin-bottom:0px;">', | |
42 | '<tr><td>Status:</td><td>{[this.status(values)]}</td></tr>', | |
43 | '<tr><td>Memory:</td><td>{[this.meminfo(values)]}</td></tr>', | |
44 | '<tr><td>CPU:</td><td>{[this.cpuinfo(values)]}</td></tr>', | |
e7ade592 | 45 | '<tr><td>Uptime:</td><td>{[Proxmox.Utils.format_duration_long' + |
53f669b1 TL |
46 | '(values.uptime)]}</td></tr>', |
47 | '</table>', | |
48 | { | |
49 | meminfo: function(values) { | |
50 | if (!Ext.isDefined(values.mem)) { | |
51 | return '-'; | |
52 | } | |
e7ade592 DC |
53 | return Proxmox.Utils.format_size(values.mem || 0) + " of " + |
54 | Proxmox.Utils.format_size(values.maxmem); | |
53f669b1 TL |
55 | }, |
56 | cpuinfo: function(values) { | |
57 | if (!Ext.isDefined(values.cpu)) { | |
58 | return '-'; | |
59 | } | |
60 | var per = values.cpu * 100; | |
61 | return per.toFixed(2) + "% (" + values.cpus + " CPUs)"; | |
62 | }, | |
63 | status: function(values) { | |
64 | return values.qmpstatus ? values.qmpstatus : | |
65 | values.status; | |
66 | } | |
67 | } | |
68 | ] | |
69 | }, | |
70 | { | |
71 | xtype: 'component', | |
72 | cls: 'dark', | |
73 | padding: 5, | |
74 | html: gettext('Configuration') | |
75 | }, | |
76 | { | |
77 | xtype: 'container', | |
78 | scrollable: 'both', | |
79 | flex: 1, | |
80 | styleHtmlContent: true, | |
81 | itemId: 'vmconfig', | |
82 | style: 'background-color:white;white-space:pre', | |
83 | tpl: [ | |
84 | '<table style="margin-bottom:0px;">', | |
85 | '<tpl for=".">', | |
86 | '<tr><td>{key}</td><td>{value}</td></tr>', | |
87 | '</tpl>', | |
88 | '</table>' | |
89 | ] | |
90 | } | |
91 | ] | |
92 | }, | |
93 | ||
94 | reload: function() { | |
95 | var me = this; | |
96 | ||
97 | var vm_stat = me.down('#vmstatus'); | |
98 | ||
99 | var error_handler = function(response) { | |
100 | me.setMasked({ xtype: 'loadmask', message: response.htmlStatus }); | |
101 | }; | |
102 | ||
e54ad66e | 103 | Proxmox.Utils.API2Request({ |
53f669b1 TL |
104 | url: '/nodes/' + me.nodename + '/' + me.vmtype + '/' + me.vmid + |
105 | '/status/current', | |
106 | method: 'GET', | |
107 | success: function(response) { | |
108 | var d = response.result.data; | |
109 | ||
110 | me.render_menu(d); | |
111 | ||
112 | vm_stat.setData(d); | |
113 | }, | |
114 | failure: error_handler | |
115 | }); | |
116 | ||
117 | var vm_cfg = me.down('#vmconfig'); | |
118 | ||
e54ad66e | 119 | Proxmox.Utils.API2Request({ |
53f669b1 TL |
120 | url: '/nodes/' + me.nodename + '/' + me.vmtype + '/' + me.vmid + |
121 | '/config', | |
122 | method: 'GET', | |
123 | success: function(response) { | |
124 | var d = response.result.data; | |
125 | var kv = PVE.Workspace.obj_to_kv(d, me.config_keys); | |
126 | vm_cfg.setData(kv); | |
127 | }, | |
128 | failure: error_handler | |
129 | }); | |
130 | }, | |
131 | ||
132 | render_menu: function(data) { | |
133 | var me = this; | |
134 | ||
135 | // use two item arrays for format reasons. | |
136 | // display start, stop and migrate by default | |
137 | var top_items = [ | |
138 | { | |
139 | text: gettext('Start'), | |
140 | handler: function() { | |
141 | me.vm_command("start", {}); | |
142 | } | |
143 | }, | |
144 | { | |
145 | text: gettext('Stop'), | |
146 | handler: function() { | |
147 | me.vm_command("stop", {}); | |
148 | } | |
149 | } | |
150 | ]; | |
151 | ||
152 | var bottom_items = [{ | |
153 | text: gettext('Migrate'), | |
154 | handler: function() { | |
155 | PVE.Workspace.gotoPage('nodes/' + me.nodename + '/' + me.vmtype + | |
156 | '/' + me.vmid +'/migrate'); | |
157 | } | |
158 | }]; | |
159 | ||
160 | // use qmpstatus with qemu, as it's exacter | |
161 | var vm_status = (me.vmtype === 'qemu') ? data.qmpstatus : data.status; | |
162 | ||
163 | if(vm_status === 'running') { | |
164 | ||
165 | top_items.push( | |
166 | { | |
167 | text: gettext('Shutdown'), | |
168 | handler: function() { | |
169 | me.vm_command("shutdown", {}); | |
170 | } | |
171 | }, | |
172 | { | |
173 | text: gettext('Suspend'), | |
174 | handler: function() { | |
175 | me.vm_command("suspend", {}); | |
176 | } | |
177 | } | |
178 | ); | |
179 | ||
180 | bottom_items.push({ | |
181 | text: gettext('Console'), | |
182 | handler: function() { | |
183 | var vmtype = me.vmtype === 'qemu' ? 'kvm' : me.vmtype; | |
184 | PVE.Utils.openConsoleWindow('html5', vmtype, me.vmid, | |
185 | me.nodename); | |
186 | } | |
187 | }); | |
188 | ||
189 | if(data.spice || me.vmtype==='lxc') { | |
190 | bottom_items.push({ | |
191 | text: gettext('Spice'), | |
192 | handler: function() { | |
193 | var vmtype = me.vmtype === 'qemu' ? 'kvm' : me.vmtype; | |
194 | PVE.Utils.openConsoleWindow('vv', vmtype, me.vmid, | |
195 | me.nodename); | |
196 | } | |
197 | }); | |
198 | } | |
199 | ||
200 | } else if(vm_status === 'paused') { | |
201 | top_items.push({ | |
202 | text: gettext('Resume'), | |
203 | handler: function() { | |
204 | me.vm_command("resume", {}); | |
205 | } | |
206 | }); | |
207 | } | |
208 | ||
209 | // concat our item arrays and add them to the menu | |
210 | me.down('pveMenuButton').setMenuItems(top_items.concat(bottom_items)); | |
211 | ||
212 | }, | |
213 | ||
214 | initialize: function() { | |
215 | var me = this; | |
216 | ||
217 | me.reload(); | |
218 | ||
219 | this.callParent(); | |
220 | } | |
221 | }); |