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