]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
gui: refactor {lxc, qemu}/Summary to panel/GuestSummary
[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 tooltip: Ext.String.format(gettext('Shutdown, apply pending changes and reboot {0}'), 'VM'),
149 confirmMsg: Proxmox.Utils.format_task_description('qmreboot', vmid),
150 handler: function() {
151 vm_command("reboot");
152 },
153 iconCls: 'fa fa-refresh'
154 },{
155 text: gettext('Pause'),
156 disabled: !caps.vms['VM.PowerMgmt'],
157 confirmMsg: Proxmox.Utils.format_task_description('qmpause', vmid),
158 handler: function() {
159 vm_command("suspend");
160 },
161 iconCls: 'fa fa-pause'
162 },{
163 text: gettext('Hibernate'),
164 disabled: !caps.vms['VM.PowerMgmt'],
165 confirmMsg: Proxmox.Utils.format_task_description('qmsuspend', vmid),
166 tooltip: gettext('Suspend to disk'),
167 handler: function() {
168 vm_command("suspend", { todisk: 1 });
169 },
170 iconCls: 'fa fa-download'
171 },{
172 text: gettext('Stop'),
173 disabled: !caps.vms['VM.PowerMgmt'],
174 dangerous: true,
175 tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'VM'),
176 confirmMsg: Proxmox.Utils.format_task_description('qmstop', vmid),
177 handler: function() {
178 vm_command("stop", { timeout: 30 });
179 },
180 iconCls: 'fa fa-stop'
181 },{
182 text: gettext('Reset'),
183 disabled: !caps.vms['VM.PowerMgmt'],
184 tooltip: Ext.String.format(gettext('Reset {0} immediately'), 'VM'),
185 confirmMsg: Proxmox.Utils.format_task_description('qmreset', vmid),
186 handler: function() {
187 vm_command("reset");
188 },
189 iconCls: 'fa fa-bolt'
190 }]
191 },
192 iconCls: 'fa fa-power-off'
193 });
194
195 var vm = me.pveSelNode.data;
196
197 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
198 disabled: !caps.vms['VM.Console'],
199 hidden: template,
200 consoleType: 'kvm',
201 consoleName: vm.name,
202 nodename: nodename,
203 vmid: vmid
204 });
205
206 var statusTxt = Ext.create('Ext.toolbar.TextItem', {
207 data: {
208 lock: undefined
209 },
210 tpl: [
211 '<tpl if="lock">',
212 '<i class="fa fa-lg fa-lock"></i> ({lock})',
213 '</tpl>'
214 ]
215 });
216
217 Ext.apply(me, {
218 title: Ext.String.format(gettext("Virtual Machine {0} on node '{1}'"), vm.text, nodename),
219 hstateid: 'kvmtab',
220 tbarSpacing: false,
221 tbar: [ statusTxt, '->', resumeBtn, startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn ],
222 defaults: { statusStore: me.statusStore },
223 items: [
224 {
225 title: gettext('Summary'),
226 xtype: 'pveGuestSummary',
227 iconCls: 'fa fa-book',
228 itemId: 'summary'
229 }
230 ]
231 });
232
233 if (caps.vms['VM.Console'] && !template) {
234 me.items.push({
235 title: gettext('Console'),
236 itemId: 'console',
237 iconCls: 'fa fa-terminal',
238 xtype: 'pveNoVncConsole',
239 vmid: vmid,
240 consoleType: 'kvm',
241 nodename: nodename
242 });
243 }
244
245 me.items.push(
246 {
247 title: gettext('Hardware'),
248 itemId: 'hardware',
249 iconCls: 'fa fa-desktop',
250 xtype: 'PVE.qemu.HardwareView'
251 },
252 {
253 title: 'Cloud-Init',
254 itemId: 'cloudinit',
255 iconCls: 'fa fa-cloud',
256 xtype: 'pveCiPanel'
257 },
258 {
259 title: gettext('Options'),
260 iconCls: 'fa fa-gear',
261 itemId: 'options',
262 xtype: 'PVE.qemu.Options'
263 },
264 {
265 title: gettext('Task History'),
266 itemId: 'tasks',
267 xtype: 'proxmoxNodeTasks',
268 iconCls: 'fa fa-list',
269 nodename: nodename,
270 vmidFilter: vmid
271 }
272 );
273
274 if (caps.vms['VM.Monitor'] && !template) {
275 me.items.push({
276 title: gettext('Monitor'),
277 iconCls: 'fa fa-eye',
278 itemId: 'monitor',
279 xtype: 'pveQemuMonitor'
280 });
281 }
282
283 if (caps.vms['VM.Backup']) {
284 me.items.push({
285 title: gettext('Backup'),
286 iconCls: 'fa fa-floppy-o',
287 xtype: 'pveBackupView',
288 itemId: 'backup'
289 },
290 {
291 title: gettext('Replication'),
292 iconCls: 'fa fa-retweet',
293 xtype: 'pveReplicaView',
294 itemId: 'replication'
295 });
296 }
297
298 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback']) && !template) {
299 me.items.push({
300 title: gettext('Snapshots'),
301 iconCls: 'fa fa-history',
302 xtype: 'pveQemuSnapshotTree',
303 itemId: 'snapshot'
304 });
305 }
306
307 if (caps.vms['VM.Console']) {
308 me.items.push(
309 {
310 xtype: 'pveFirewallRules',
311 title: gettext('Firewall'),
312 iconCls: 'fa fa-shield',
313 allow_iface: true,
314 base_url: base_url + '/firewall/rules',
315 list_refs_url: base_url + '/firewall/refs',
316 itemId: 'firewall'
317 },
318 {
319 xtype: 'pveFirewallOptions',
320 groups: ['firewall'],
321 iconCls: 'fa fa-gear',
322 onlineHelp: 'pve_firewall_vm_container_configuration',
323 title: gettext('Options'),
324 base_url: base_url + '/firewall/options',
325 fwtype: 'vm',
326 itemId: 'firewall-options'
327 },
328 {
329 xtype: 'pveFirewallAliases',
330 title: gettext('Alias'),
331 groups: ['firewall'],
332 iconCls: 'fa fa-external-link',
333 base_url: base_url + '/firewall/aliases',
334 itemId: 'firewall-aliases'
335 },
336 {
337 xtype: 'pveIPSet',
338 title: gettext('IPSet'),
339 groups: ['firewall'],
340 iconCls: 'fa fa-list-ol',
341 base_url: base_url + '/firewall/ipset',
342 list_refs_url: base_url + '/firewall/refs',
343 itemId: 'firewall-ipset'
344 },
345 {
346 title: gettext('Log'),
347 groups: ['firewall'],
348 iconCls: 'fa fa-list',
349 onlineHelp: 'chapter_pve_firewall',
350 itemId: 'firewall-fwlog',
351 xtype: 'proxmoxLogView',
352 url: '/api2/extjs' + base_url + '/firewall/log'
353 }
354 );
355 }
356
357 if (caps.vms['Permissions.Modify']) {
358 me.items.push({
359 xtype: 'pveACLView',
360 title: gettext('Permissions'),
361 iconCls: 'fa fa-unlock',
362 itemId: 'permissions',
363 path: '/vms/' + vmid
364 });
365 }
366
367 me.callParent();
368
369 me.mon(me.statusStore, 'load', function(s, records, success) {
370 var status;
371 var qmpstatus;
372 var spice = false;
373 var xtermjs = false;
374 var lock;
375
376 if (!success) {
377 status = qmpstatus = 'unknown';
378 } else {
379 var rec = s.data.get('status');
380 status = rec ? rec.data.value : 'unknown';
381 rec = s.data.get('qmpstatus');
382 qmpstatus = rec ? rec.data.value : 'unknown';
383 rec = s.data.get('template');
384 template = rec.data.value || false;
385 rec = s.data.get('lock');
386 lock = rec ? rec.data.value : undefined;
387
388 spice = s.data.get('spice') ? true : false;
389 xtermjs = s.data.get('serial') ? true : false;
390
391 }
392
393 if (template) {
394 return;
395 }
396
397 var resume = (['prelaunch', 'paused', 'suspended'].indexOf(qmpstatus) !== -1);
398
399 if (resume || lock === 'suspended') {
400 startBtn.setVisible(false);
401 resumeBtn.setVisible(true);
402 } else {
403 startBtn.setVisible(true);
404 resumeBtn.setVisible(false);
405 }
406
407 consoleBtn.setEnableSpice(spice);
408 consoleBtn.setEnableXtermJS(xtermjs);
409
410 statusTxt.update({ lock: lock });
411
412 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
413 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
414 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
415 consoleBtn.setDisabled(template);
416 });
417
418 me.on('afterrender', function() {
419 me.statusStore.startUpdate();
420 });
421
422 me.on('destroy', function() {
423 me.statusStore.stopUpdate();
424 });
425 }
426 });