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