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