]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
ui: eslint: enforce "no-extra-parens" rule
[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 consoleName: vm.name,
203 nodename: nodename,
204 vmid: vmid,
205 });
206
207 var statusTxt = Ext.create('Ext.toolbar.TextItem', {
208 data: {
209 lock: undefined,
210 },
211 tpl: [
212 '<tpl if="lock">',
213 '<i class="fa fa-lg fa-lock"></i> ({lock})',
214 '</tpl>',
215 ],
216 });
217
218 Ext.apply(me, {
219 title: Ext.String.format(gettext("Virtual Machine {0} on node '{1}'"), vm.text, nodename),
220 hstateid: 'kvmtab',
221 tbarSpacing: false,
222 tbar: [statusTxt, '->', resumeBtn, startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn],
223 defaults: { statusStore: me.statusStore },
224 items: [
225 {
226 title: gettext('Summary'),
227 xtype: 'pveGuestSummary',
228 iconCls: 'fa fa-book',
229 itemId: 'summary',
230 },
231 ],
232 });
233
234 if (caps.vms['VM.Console'] && !template) {
235 me.items.push({
236 title: gettext('Console'),
237 itemId: 'console',
238 iconCls: 'fa fa-terminal',
239 xtype: 'pveNoVncConsole',
240 vmid: vmid,
241 consoleType: 'kvm',
242 nodename: nodename,
243 });
244 }
245
246 me.items.push(
247 {
248 title: gettext('Hardware'),
249 itemId: 'hardware',
250 iconCls: 'fa fa-desktop',
251 xtype: 'PVE.qemu.HardwareView',
252 },
253 {
254 title: 'Cloud-Init',
255 itemId: 'cloudinit',
256 iconCls: 'fa fa-cloud',
257 xtype: 'pveCiPanel',
258 },
259 {
260 title: gettext('Options'),
261 iconCls: 'fa fa-gear',
262 itemId: 'options',
263 xtype: 'PVE.qemu.Options',
264 },
265 {
266 title: gettext('Task History'),
267 itemId: 'tasks',
268 xtype: 'proxmoxNodeTasks',
269 iconCls: 'fa fa-list',
270 nodename: nodename,
271 vmidFilter: vmid,
272 },
273 );
274
275 if (caps.vms['VM.Monitor'] && !template) {
276 me.items.push({
277 title: gettext('Monitor'),
278 iconCls: 'fa fa-eye',
279 itemId: 'monitor',
280 xtype: 'pveQemuMonitor',
281 });
282 }
283
284 if (caps.vms['VM.Backup']) {
285 me.items.push({
286 title: gettext('Backup'),
287 iconCls: 'fa fa-floppy-o',
288 xtype: 'pveBackupView',
289 itemId: 'backup',
290 },
291 {
292 title: gettext('Replication'),
293 iconCls: 'fa fa-retweet',
294 xtype: 'pveReplicaView',
295 itemId: 'replication',
296 });
297 }
298
299 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback'] ||
300 caps.vms['VM.Audit']) && !template) {
301 me.items.push({
302 title: gettext('Snapshots'),
303 iconCls: 'fa fa-history',
304 type: 'qemu',
305 xtype: 'pveGuestSnapshotTree',
306 itemId: 'snapshot',
307 });
308 }
309
310 if (caps.vms['VM.Console']) {
311 me.items.push(
312 {
313 xtype: 'pveFirewallRules',
314 title: gettext('Firewall'),
315 iconCls: 'fa fa-shield',
316 allow_iface: true,
317 base_url: base_url + '/firewall/rules',
318 list_refs_url: base_url + '/firewall/refs',
319 itemId: 'firewall',
320 },
321 {
322 xtype: 'pveFirewallOptions',
323 groups: ['firewall'],
324 iconCls: 'fa fa-gear',
325 onlineHelp: 'pve_firewall_vm_container_configuration',
326 title: gettext('Options'),
327 base_url: base_url + '/firewall/options',
328 fwtype: 'vm',
329 itemId: 'firewall-options',
330 },
331 {
332 xtype: 'pveFirewallAliases',
333 title: gettext('Alias'),
334 groups: ['firewall'],
335 iconCls: 'fa fa-external-link',
336 base_url: base_url + '/firewall/aliases',
337 itemId: 'firewall-aliases',
338 },
339 {
340 xtype: 'pveIPSet',
341 title: gettext('IPSet'),
342 groups: ['firewall'],
343 iconCls: 'fa fa-list-ol',
344 base_url: base_url + '/firewall/ipset',
345 list_refs_url: base_url + '/firewall/refs',
346 itemId: 'firewall-ipset',
347 },
348 {
349 title: gettext('Log'),
350 groups: ['firewall'],
351 iconCls: 'fa fa-list',
352 onlineHelp: 'chapter_pve_firewall',
353 itemId: 'firewall-fwlog',
354 xtype: 'proxmoxLogView',
355 url: '/api2/extjs' + base_url + '/firewall/log',
356 },
357 );
358 }
359
360 if (caps.vms['Permissions.Modify']) {
361 me.items.push({
362 xtype: 'pveACLView',
363 title: gettext('Permissions'),
364 iconCls: 'fa fa-unlock',
365 itemId: 'permissions',
366 path: '/vms/' + vmid,
367 });
368 }
369
370 me.callParent();
371
372 var prevQMPStatus = 'unknown';
373 me.mon(me.statusStore, 'load', function(s, records, success) {
374 var status;
375 var qmpstatus;
376 var spice = false;
377 var xtermjs = false;
378 var lock;
379
380 if (!success) {
381 status = qmpstatus = 'unknown';
382 } else {
383 var rec = s.data.get('status');
384 status = rec ? rec.data.value : 'unknown';
385 rec = s.data.get('qmpstatus');
386 qmpstatus = rec ? rec.data.value : 'unknown';
387 rec = s.data.get('template');
388 template = rec.data.value || false;
389 rec = s.data.get('lock');
390 lock = rec ? rec.data.value : undefined;
391
392 spice = !!s.data.get('spice');
393 xtermjs = !!s.data.get('serial');
394 }
395
396 if (template) {
397 return;
398 }
399
400 var resume = ['prelaunch', 'paused', 'suspended'].indexOf(qmpstatus) !== -1;
401
402 if (resume || lock === 'suspended') {
403 startBtn.setVisible(false);
404 resumeBtn.setVisible(true);
405 } else {
406 startBtn.setVisible(true);
407 resumeBtn.setVisible(false);
408 }
409
410 consoleBtn.setEnableSpice(spice);
411 consoleBtn.setEnableXtermJS(xtermjs);
412
413 statusTxt.update({ lock: lock });
414
415 let guest_running = status === 'running' &&
416 !(qmpstatus === "shutdown" || qmpstatus === "prelaunch");
417 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || template || guest_running);
418
419 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
420 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
421 consoleBtn.setDisabled(template);
422
423 let wasStopped = ['prelaunch', 'stopped', 'suspended'].indexOf(prevQMPStatus) !== -1;
424 if (wasStopped && qmpstatus === 'running') {
425 let con = me.down('#console');
426 if (con) {
427 con.reload();
428 }
429 }
430
431 prevQMPStatus = qmpstatus;
432 });
433
434 me.on('afterrender', function() {
435 me.statusStore.startUpdate();
436 });
437
438 me.on('destroy', function() {
439 me.statusStore.stopUpdate();
440 });
441 },
442 });