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