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