]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
ui: qemu/Config: disable xtermjs and spice until status is loaded
[pve-manager.git] / www / manager6 / qemu / Config.js
1 Ext.define('PVE.qemu.Config', {
2 extend: 'PVE.panel.Config',
3 alias: 'widget.PVE.qemu.Config',
4
5 onlineHelp: 'chapter_virtual_machines',
6
7 initComponent: function() {
8 var me = this;
9 var vm = me.pveSelNode.data;
10
11 var nodename = vm.node;
12 if (!nodename) {
13 throw "no node name specified";
14 }
15
16 var vmid = vm.vmid;
17 if (!vmid) {
18 throw "no VM ID specified";
19 }
20
21 var template = !!vm.template;
22
23 var running = !!vm.uptime;
24
25 var caps = Ext.state.Manager.get('GuiCap');
26
27 var base_url = '/nodes/' + nodename + "/qemu/" + vmid;
28
29 me.statusStore = Ext.create('Proxmox.data.ObjectStore', {
30 url: '/api2/json' + base_url + '/status/current',
31 interval: 1000,
32 });
33
34 var vm_command = function(cmd, params) {
35 Proxmox.Utils.API2Request({
36 params: params,
37 url: base_url + '/status/' + cmd,
38 waitMsgTarget: me,
39 method: 'POST',
40 failure: function(response, opts) {
41 Ext.Msg.alert('Error', response.htmlStatus);
42 },
43 });
44 };
45
46 var resumeBtn = Ext.create('Ext.Button', {
47 text: gettext('Resume'),
48 disabled: !caps.vms['VM.PowerMgmt'],
49 hidden: true,
50 handler: function() {
51 vm_command('resume');
52 },
53 iconCls: 'fa fa-play',
54 });
55
56 var startBtn = Ext.create('Ext.Button', {
57 text: gettext('Start'),
58 disabled: !caps.vms['VM.PowerMgmt'] || running,
59 hidden: template,
60 handler: function() {
61 vm_command('start');
62 },
63 iconCls: 'fa fa-play',
64 });
65
66 var migrateBtn = Ext.create('Ext.Button', {
67 text: gettext('Migrate'),
68 disabled: !caps.vms['VM.Migrate'],
69 hidden: PVE.data.ResourceStore.getNodes().length < 2,
70 handler: function() {
71 var win = Ext.create('PVE.window.Migrate', {
72 vmtype: 'qemu',
73 nodename: nodename,
74 vmid: vmid,
75 });
76 win.show();
77 },
78 iconCls: 'fa fa-send-o',
79 });
80
81 var moreBtn = Ext.create('Proxmox.button.Button', {
82 text: gettext('More'),
83 menu: {
84 items: [
85 {
86 text: gettext('Clone'),
87 iconCls: 'fa fa-fw fa-clone',
88 hidden: !caps.vms['VM.Clone'],
89 handler: function() {
90 PVE.window.Clone.wrap(nodename, vmid, template, 'qemu');
91 },
92 },
93 {
94 text: gettext('Convert to template'),
95 disabled: template,
96 xtype: 'pveMenuItem',
97 iconCls: 'fa fa-fw fa-file-o',
98 hidden: !caps.vms['VM.Allocate'],
99 confirmMsg: Proxmox.Utils.format_task_description('qmtemplate', vmid),
100 handler: function() {
101 Proxmox.Utils.API2Request({
102 url: base_url + '/template',
103 waitMsgTarget: me,
104 method: 'POST',
105 failure: function(response, opts) {
106 Ext.Msg.alert('Error', response.htmlStatus);
107 },
108 });
109 },
110 },
111 {
112 iconCls: 'fa fa-heartbeat ',
113 hidden: !caps.nodes['Sys.Console'],
114 text: gettext('Manage HA'),
115 handler: function() {
116 var ha = vm.hastate;
117 Ext.create('PVE.ha.VMResourceEdit', {
118 vmid: vmid,
119 isCreate: !ha || ha === 'unmanaged',
120 }).show();
121 },
122 },
123 {
124 text: gettext('Remove'),
125 itemId: 'removeBtn',
126 disabled: !caps.vms['VM.Allocate'],
127 handler: function() {
128 Ext.create('PVE.window.SafeDestroy', {
129 url: base_url,
130 item: { type: 'VM', id: vmid },
131 }).show();
132 },
133 iconCls: 'fa fa-trash-o',
134 },
135 ],
136 },
137 });
138
139 var shutdownBtn = Ext.create('PVE.button.Split', {
140 text: gettext('Shutdown'),
141 disabled: !caps.vms['VM.PowerMgmt'] || !running,
142 hidden: template,
143 confirmMsg: Proxmox.Utils.format_task_description('qmshutdown', vmid),
144 handler: function() {
145 vm_command('shutdown');
146 },
147 menu: {
148 items: [{
149 text: gettext('Reboot'),
150 disabled: !caps.vms['VM.PowerMgmt'],
151 tooltip: Ext.String.format(gettext('Shutdown, apply pending changes and reboot {0}'), 'VM'),
152 confirmMsg: Proxmox.Utils.format_task_description('qmreboot', vmid),
153 handler: function() {
154 vm_command("reboot");
155 },
156 iconCls: 'fa fa-refresh',
157 }, {
158 text: gettext('Pause'),
159 disabled: !caps.vms['VM.PowerMgmt'],
160 confirmMsg: Proxmox.Utils.format_task_description('qmpause', vmid),
161 handler: function() {
162 vm_command("suspend");
163 },
164 iconCls: 'fa fa-pause',
165 }, {
166 text: gettext('Hibernate'),
167 disabled: !caps.vms['VM.PowerMgmt'],
168 confirmMsg: Proxmox.Utils.format_task_description('qmsuspend', vmid),
169 tooltip: gettext('Suspend to disk'),
170 handler: function() {
171 vm_command("suspend", { todisk: 1 });
172 },
173 iconCls: 'fa fa-download',
174 }, {
175 text: gettext('Stop'),
176 disabled: !caps.vms['VM.PowerMgmt'],
177 dangerous: true,
178 tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'VM'),
179 confirmMsg: Proxmox.Utils.format_task_description('qmstop', vmid),
180 handler: function() {
181 vm_command("stop", { timeout: 30 });
182 },
183 iconCls: 'fa fa-stop',
184 }, {
185 text: gettext('Reset'),
186 disabled: !caps.vms['VM.PowerMgmt'],
187 tooltip: Ext.String.format(gettext('Reset {0} immediately'), 'VM'),
188 confirmMsg: Proxmox.Utils.format_task_description('qmreset', vmid),
189 handler: function() {
190 vm_command("reset");
191 },
192 iconCls: 'fa fa-bolt',
193 }],
194 },
195 iconCls: 'fa fa-power-off',
196 });
197
198 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
199 disabled: !caps.vms['VM.Console'],
200 hidden: template,
201 consoleType: 'kvm',
202 enableSpice: false,
203 enableXtermjs: false,
204 consoleName: vm.name,
205 nodename: nodename,
206 vmid: vmid,
207 });
208
209 var statusTxt = Ext.create('Ext.toolbar.TextItem', {
210 data: {
211 lock: undefined,
212 },
213 tpl: [
214 '<tpl if="lock">',
215 '<i class="fa fa-lg fa-lock"></i> ({lock})',
216 '</tpl>',
217 ],
218 });
219
220 Ext.apply(me, {
221 title: Ext.String.format(gettext("Virtual Machine {0} on node '{1}'"), vm.text, nodename),
222 hstateid: 'kvmtab',
223 tbarSpacing: false,
224 tbar: [statusTxt, '->', resumeBtn, startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn],
225 defaults: { statusStore: me.statusStore },
226 items: [
227 {
228 title: gettext('Summary'),
229 xtype: 'pveGuestSummary',
230 iconCls: 'fa fa-book',
231 itemId: 'summary',
232 },
233 ],
234 });
235
236 if (caps.vms['VM.Console'] && !template) {
237 me.items.push({
238 title: gettext('Console'),
239 itemId: 'console',
240 iconCls: 'fa fa-terminal',
241 xtype: 'pveNoVncConsole',
242 vmid: vmid,
243 consoleType: 'kvm',
244 nodename: nodename,
245 });
246 }
247
248 me.items.push(
249 {
250 title: gettext('Hardware'),
251 itemId: 'hardware',
252 iconCls: 'fa fa-desktop',
253 xtype: 'PVE.qemu.HardwareView',
254 },
255 {
256 title: 'Cloud-Init',
257 itemId: 'cloudinit',
258 iconCls: 'fa fa-cloud',
259 xtype: 'pveCiPanel',
260 },
261 {
262 title: gettext('Options'),
263 iconCls: 'fa fa-gear',
264 itemId: 'options',
265 xtype: 'PVE.qemu.Options',
266 },
267 {
268 title: gettext('Task History'),
269 itemId: 'tasks',
270 xtype: 'proxmoxNodeTasks',
271 iconCls: 'fa fa-list',
272 nodename: nodename,
273 vmidFilter: vmid,
274 },
275 );
276
277 if (caps.vms['VM.Monitor'] && !template) {
278 me.items.push({
279 title: gettext('Monitor'),
280 iconCls: 'fa fa-eye',
281 itemId: 'monitor',
282 xtype: 'pveQemuMonitor',
283 });
284 }
285
286 if (caps.vms['VM.Backup']) {
287 me.items.push({
288 title: gettext('Backup'),
289 iconCls: 'fa fa-floppy-o',
290 xtype: 'pveBackupView',
291 itemId: 'backup',
292 },
293 {
294 title: gettext('Replication'),
295 iconCls: 'fa fa-retweet',
296 xtype: 'pveReplicaView',
297 itemId: 'replication',
298 });
299 }
300
301 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback'] ||
302 caps.vms['VM.Audit']) && !template) {
303 me.items.push({
304 title: gettext('Snapshots'),
305 iconCls: 'fa fa-history',
306 type: 'qemu',
307 xtype: 'pveGuestSnapshotTree',
308 itemId: 'snapshot',
309 });
310 }
311
312 if (caps.vms['VM.Console']) {
313 me.items.push(
314 {
315 xtype: 'pveFirewallRules',
316 title: gettext('Firewall'),
317 iconCls: 'fa fa-shield',
318 allow_iface: true,
319 base_url: base_url + '/firewall/rules',
320 list_refs_url: base_url + '/firewall/refs',
321 itemId: 'firewall',
322 },
323 {
324 xtype: 'pveFirewallOptions',
325 groups: ['firewall'],
326 iconCls: 'fa fa-gear',
327 onlineHelp: 'pve_firewall_vm_container_configuration',
328 title: gettext('Options'),
329 base_url: base_url + '/firewall/options',
330 fwtype: 'vm',
331 itemId: 'firewall-options',
332 },
333 {
334 xtype: 'pveFirewallAliases',
335 title: gettext('Alias'),
336 groups: ['firewall'],
337 iconCls: 'fa fa-external-link',
338 base_url: base_url + '/firewall/aliases',
339 itemId: 'firewall-aliases',
340 },
341 {
342 xtype: 'pveIPSet',
343 title: gettext('IPSet'),
344 groups: ['firewall'],
345 iconCls: 'fa fa-list-ol',
346 base_url: base_url + '/firewall/ipset',
347 list_refs_url: base_url + '/firewall/refs',
348 itemId: 'firewall-ipset',
349 },
350 {
351 title: gettext('Log'),
352 groups: ['firewall'],
353 iconCls: 'fa fa-list',
354 onlineHelp: 'chapter_pve_firewall',
355 itemId: 'firewall-fwlog',
356 xtype: 'proxmoxLogView',
357 url: '/api2/extjs' + base_url + '/firewall/log',
358 },
359 );
360 }
361
362 if (caps.vms['Permissions.Modify']) {
363 me.items.push({
364 xtype: 'pveACLView',
365 title: gettext('Permissions'),
366 iconCls: 'fa fa-unlock',
367 itemId: 'permissions',
368 path: '/vms/' + vmid,
369 });
370 }
371
372 me.callParent();
373
374 var prevQMPStatus = 'unknown';
375 me.mon(me.statusStore, 'load', function(s, records, success) {
376 var status;
377 var qmpstatus;
378 var spice = false;
379 var xtermjs = false;
380 var lock;
381
382 if (!success) {
383 status = qmpstatus = 'unknown';
384 } else {
385 var rec = s.data.get('status');
386 status = rec ? rec.data.value : 'unknown';
387 rec = s.data.get('qmpstatus');
388 qmpstatus = rec ? rec.data.value : 'unknown';
389 rec = s.data.get('template');
390 template = rec ? rec.data.value : false;
391 rec = s.data.get('lock');
392 lock = rec ? rec.data.value : undefined;
393
394 spice = !!s.data.get('spice');
395 xtermjs = !!s.data.get('serial');
396 }
397
398 if (template) {
399 return;
400 }
401
402 var resume = ['prelaunch', 'paused', 'suspended'].indexOf(qmpstatus) !== -1;
403
404 if (resume || lock === 'suspended') {
405 startBtn.setVisible(false);
406 resumeBtn.setVisible(true);
407 } else {
408 startBtn.setVisible(true);
409 resumeBtn.setVisible(false);
410 }
411
412 consoleBtn.setEnableSpice(spice);
413 consoleBtn.setEnableXtermJS(xtermjs);
414
415 statusTxt.update({ lock: lock });
416
417 let guest_running = status === 'running' &&
418 !(qmpstatus === "shutdown" || qmpstatus === "prelaunch");
419 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || template || guest_running);
420
421 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
422 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
423 consoleBtn.setDisabled(template);
424
425 let wasStopped = ['prelaunch', 'stopped', 'suspended'].indexOf(prevQMPStatus) !== -1;
426 if (wasStopped && qmpstatus === 'running') {
427 let con = me.down('#console');
428 if (con) {
429 con.reload();
430 }
431 }
432
433 prevQMPStatus = qmpstatus;
434 });
435
436 me.on('afterrender', function() {
437 me.statusStore.startUpdate();
438 });
439
440 me.on('destroy', function() {
441 me.statusStore.stopUpdate();
442 });
443 },
444 });