]>
Commit | Line | Data |
---|---|---|
156095db DM |
1 | Ext.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'], | |
833b048f | 179 | tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'VM'), |
889c7083 | 180 | handler: function() { |
e8b411f1 FW |
181 | Ext.create('PVE.GuestStop', { |
182 | nodename: nodename, | |
183 | vm: vm, | |
184 | autoShow: true, | |
185 | }); | |
d4333933 | 186 | }, |
f6710aac TL |
187 | iconCls: 'fa fa-stop', |
188 | }, { | |
f2fa05d1 DC |
189 | text: gettext('Reset'), |
190 | disabled: !caps.vms['VM.PowerMgmt'], | |
f07d8e60 | 191 | tooltip: Ext.String.format(gettext('Reset {0} immediately'), 'VM'), |
e7ade592 | 192 | confirmMsg: Proxmox.Utils.format_task_description('qmreset', vmid), |
f2fa05d1 DC |
193 | handler: function() { |
194 | vm_command("reset"); | |
195 | }, | |
f6710aac TL |
196 | iconCls: 'fa fa-bolt', |
197 | }], | |
d4333933 | 198 | }, |
f6710aac | 199 | iconCls: 'fa fa-power-off', |
156095db DM |
200 | }); |
201 | ||
156095db DM |
202 | var consoleBtn = Ext.create('PVE.button.ConsoleButton', { |
203 | disabled: !caps.vms['VM.Console'], | |
6ecdb340 | 204 | hidden: template, |
156095db | 205 | consoleType: 'kvm', |
27cc48c2 | 206 | // disable spice/xterm for default action until status api call succeeded |
d7518964 DC |
207 | enableSpice: false, |
208 | enableXtermjs: false, | |
4ad508ef | 209 | consoleName: vm.name, |
156095db | 210 | nodename: nodename, |
f6710aac | 211 | vmid: vmid, |
156095db DM |
212 | }); |
213 | ||
375d2918 DC |
214 | var statusTxt = Ext.create('Ext.toolbar.TextItem', { |
215 | data: { | |
f6710aac | 216 | lock: undefined, |
375d2918 DC |
217 | }, |
218 | tpl: [ | |
219 | '<tpl if="lock">', | |
220 | '<i class="fa fa-lg fa-lock"></i> ({lock})', | |
f6710aac TL |
221 | '</tpl>', |
222 | ], | |
375d2918 DC |
223 | }); |
224 | ||
d70be8cd DC |
225 | let tagsContainer = Ext.create('PVE.panel.TagEditContainer', { |
226 | tags: vm.tags, | |
1b48b8b7 | 227 | canEdit: !!caps.vms['VM.Config.Options'], |
d70be8cd DC |
228 | listeners: { |
229 | change: function(tags) { | |
230 | Proxmox.Utils.API2Request({ | |
231 | url: base_url + '/config', | |
232 | method: 'PUT', | |
233 | params: { | |
234 | tags, | |
235 | }, | |
236 | success: function() { | |
237 | me.statusStore.load(); | |
238 | }, | |
239 | failure: function(response) { | |
240 | Ext.Msg.alert('Error', response.htmlStatus); | |
241 | me.statusStore.load(); | |
242 | }, | |
243 | }); | |
244 | }, | |
245 | }, | |
246 | }); | |
247 | ||
366558a7 DC |
248 | let vm_text = `${vm.vmid} (${vm.name})`; |
249 | ||
156095db | 250 | Ext.apply(me, { |
366558a7 | 251 | title: Ext.String.format(gettext("Virtual Machine {0} on node '{1}'"), vm_text, nodename), |
156095db | 252 | hstateid: 'kvmtab', |
375d2918 | 253 | tbarSpacing: false, |
d70be8cd | 254 | tbar: [statusTxt, tagsContainer, '->', resumeBtn, startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn], |
156095db DM |
255 | defaults: { statusStore: me.statusStore }, |
256 | items: [ | |
257 | { | |
6f68dcbe | 258 | title: gettext('Summary'), |
df0875c2 | 259 | xtype: 'pveGuestSummary', |
c284be32 | 260 | iconCls: 'fa fa-book', |
f6710aac TL |
261 | itemId: 'summary', |
262 | }, | |
263 | ], | |
156095db | 264 | }); |
c5ccc8d0 | 265 | |
1939a006 DC |
266 | if (caps.vms['VM.Console'] && !template) { |
267 | me.items.push({ | |
268 | title: gettext('Console'), | |
269 | itemId: 'console', | |
270 | iconCls: 'fa fa-terminal', | |
271 | xtype: 'pveNoVncConsole', | |
272 | vmid: vmid, | |
273 | consoleType: 'kvm', | |
f6710aac | 274 | nodename: nodename, |
1939a006 DC |
275 | }); |
276 | } | |
277 | ||
278 | me.items.push( | |
279 | { | |
280 | title: gettext('Hardware'), | |
281 | itemId: 'hardware', | |
282 | iconCls: 'fa fa-desktop', | |
f6710aac | 283 | xtype: 'PVE.qemu.HardwareView', |
1939a006 | 284 | }, |
4c507192 DC |
285 | { |
286 | title: 'Cloud-Init', | |
287 | itemId: 'cloudinit', | |
288 | iconCls: 'fa fa-cloud', | |
f6710aac | 289 | xtype: 'pveCiPanel', |
4c507192 | 290 | }, |
1939a006 DC |
291 | { |
292 | title: gettext('Options'), | |
293 | iconCls: 'fa fa-gear', | |
294 | itemId: 'options', | |
f6710aac | 295 | xtype: 'PVE.qemu.Options', |
1939a006 DC |
296 | }, |
297 | { | |
298 | title: gettext('Task History'), | |
299 | itemId: 'tasks', | |
6c60ab5e | 300 | xtype: 'proxmoxNodeTasks', |
56bc50b8 | 301 | iconCls: 'fa fa-list-alt', |
6c60ab5e | 302 | nodename: nodename, |
c313af0f DC |
303 | preFilter: { |
304 | vmid, | |
305 | }, | |
f6710aac | 306 | }, |
1939a006 DC |
307 | ); |
308 | ||
156095db DM |
309 | if (caps.vms['VM.Monitor'] && !template) { |
310 | me.items.push({ | |
311 | title: gettext('Monitor'), | |
c284be32 | 312 | iconCls: 'fa fa-eye', |
156095db | 313 | itemId: 'monitor', |
f6710aac | 314 | xtype: 'pveQemuMonitor', |
156095db DM |
315 | }); |
316 | } | |
317 | ||
318 | if (caps.vms['VM.Backup']) { | |
319 | me.items.push({ | |
320 | title: gettext('Backup'), | |
c284be32 | 321 | iconCls: 'fa fa-floppy-o', |
156095db | 322 | xtype: 'pveBackupView', |
f6710aac | 323 | itemId: 'backup', |
cb6df20c DC |
324 | }, |
325 | { | |
326 | title: gettext('Replication'), | |
327 | iconCls: 'fa fa-retweet', | |
328 | xtype: 'pveReplicaView', | |
f6710aac | 329 | itemId: 'replication', |
156095db DM |
330 | }); |
331 | } | |
332 | ||
b06d011e DC |
333 | if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback'] || |
334 | caps.vms['VM.Audit']) && !template) { | |
156095db DM |
335 | me.items.push({ |
336 | title: gettext('Snapshots'), | |
c284be32 | 337 | iconCls: 'fa fa-history', |
5b1b9360 DC |
338 | type: 'qemu', |
339 | xtype: 'pveGuestSnapshotTree', | |
f6710aac | 340 | itemId: 'snapshot', |
156095db DM |
341 | }); |
342 | } | |
343 | ||
2c123488 | 344 | if (caps.vms['VM.Audit']) { |
a2f35eb2 | 345 | me.items.push( |
156095db | 346 | { |
c284be32 | 347 | xtype: 'pveFirewallRules', |
156095db | 348 | title: gettext('Firewall'), |
c284be32 DC |
349 | iconCls: 'fa fa-shield', |
350 | allow_iface: true, | |
351 | base_url: base_url + '/firewall/rules', | |
816b62b0 | 352 | list_refs_url: base_url + '/firewall/refs', |
f6710aac | 353 | itemId: 'firewall', |
c284be32 DC |
354 | }, |
355 | { | |
356 | xtype: 'pveFirewallOptions', | |
357 | groups: ['firewall'], | |
358 | iconCls: 'fa fa-gear', | |
c8802a60 | 359 | onlineHelp: 'pve_firewall_vm_container_configuration', |
c284be32 DC |
360 | title: gettext('Options'), |
361 | base_url: base_url + '/firewall/options', | |
362 | fwtype: 'vm', | |
f6710aac | 363 | itemId: 'firewall-options', |
c284be32 DC |
364 | }, |
365 | { | |
366 | xtype: 'pveFirewallAliases', | |
367 | title: gettext('Alias'), | |
368 | groups: ['firewall'], | |
369 | iconCls: 'fa fa-external-link', | |
370 | base_url: base_url + '/firewall/aliases', | |
f6710aac | 371 | itemId: 'firewall-aliases', |
c284be32 DC |
372 | }, |
373 | { | |
374 | xtype: 'pveIPSet', | |
375 | title: gettext('IPSet'), | |
376 | groups: ['firewall'], | |
377 | iconCls: 'fa fa-list-ol', | |
378 | base_url: base_url + '/firewall/ipset', | |
816b62b0 | 379 | list_refs_url: base_url + '/firewall/refs', |
f6710aac | 380 | itemId: 'firewall-ipset', |
c284be32 | 381 | }, |
2c123488 AD |
382 | ); |
383 | } | |
384 | ||
385 | if (caps.vms['VM.Console']) { | |
386 | me.items.push( | |
387 | { | |
c284be32 DC |
388 | title: gettext('Log'), |
389 | groups: ['firewall'], | |
390 | iconCls: 'fa fa-list', | |
c8802a60 | 391 | onlineHelp: 'chapter_pve_firewall', |
c284be32 | 392 | itemId: 'firewall-fwlog', |
0ee5a21e | 393 | xtype: 'proxmoxLogView', |
f6710aac | 394 | url: '/api2/extjs' + base_url + '/firewall/log', |
038e94bb CE |
395 | log_select_timespan: true, |
396 | submitFormat: 'U', | |
f6710aac | 397 | }, |
a2f35eb2 | 398 | ); |
156095db DM |
399 | } |
400 | ||
401 | if (caps.vms['Permissions.Modify']) { | |
402 | me.items.push({ | |
403 | xtype: 'pveACLView', | |
404 | title: gettext('Permissions'), | |
c284be32 | 405 | iconCls: 'fa fa-unlock', |
156095db | 406 | itemId: 'permissions', |
f6710aac | 407 | path: '/vms/' + vmid, |
156095db DM |
408 | }); |
409 | } | |
c5ccc8d0 | 410 | |
156095db DM |
411 | me.callParent(); |
412 | ||
5d7c0d97 | 413 | var prevQMPStatus = 'unknown'; |
540fdc8b | 414 | me.mon(me.statusStore, 'load', function(s, records, success) { |
156095db DM |
415 | var status; |
416 | var qmpstatus; | |
417 | var spice = false; | |
a71b4398 | 418 | var xtermjs = false; |
375d2918 | 419 | var lock; |
d70be8cd | 420 | var rec; |
156095db DM |
421 | |
422 | if (!success) { | |
156095db DM |
423 | status = qmpstatus = 'unknown'; |
424 | } else { | |
d70be8cd | 425 | rec = s.data.get('status'); |
156095db DM |
426 | status = rec ? rec.data.value : 'unknown'; |
427 | rec = s.data.get('qmpstatus'); | |
428 | qmpstatus = rec ? rec.data.value : 'unknown'; | |
429 | rec = s.data.get('template'); | |
23b596dc | 430 | template = rec ? rec.data.value : false; |
375d2918 DC |
431 | rec = s.data.get('lock'); |
432 | lock = rec ? rec.data.value : undefined; | |
2a727273 | 433 | |
ef725143 TL |
434 | spice = !!s.data.get('spice'); |
435 | xtermjs = !!s.data.get('serial'); | |
156095db DM |
436 | } |
437 | ||
d70be8cd DC |
438 | rec = s.data.get('tags'); |
439 | tagsContainer.loadTags(rec?.data?.value); | |
440 | ||
6ecdb340 DC |
441 | if (template) { |
442 | return; | |
443 | } | |
444 | ||
53e3ea84 | 445 | var resume = ['prelaunch', 'paused', 'suspended'].indexOf(qmpstatus) !== -1; |
38f75802 DC |
446 | |
447 | if (resume || lock === 'suspended') { | |
156095db DM |
448 | startBtn.setVisible(false); |
449 | resumeBtn.setVisible(true); | |
450 | } else { | |
451 | startBtn.setVisible(true); | |
452 | resumeBtn.setVisible(false); | |
453 | } | |
454 | ||
455 | consoleBtn.setEnableSpice(spice); | |
a71b4398 | 456 | consoleBtn.setEnableXtermJS(xtermjs); |
156095db | 457 | |
375d2918 DC |
458 | statusTxt.update({ lock: lock }); |
459 | ||
6a073b92 SR |
460 | let guest_running = status === 'running' && |
461 | !(qmpstatus === "shutdown" || qmpstatus === "prelaunch"); | |
462 | startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || template || guest_running); | |
463 | ||
156095db | 464 | shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); |
757f4362 | 465 | me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped'); |
4365549d | 466 | consoleBtn.setDisabled(template); |
c17ecca2 | 467 | |
5d7c0d97 TL |
468 | let wasStopped = ['prelaunch', 'stopped', 'suspended'].indexOf(prevQMPStatus) !== -1; |
469 | if (wasStopped && qmpstatus === 'running') { | |
470 | let con = me.down('#console'); | |
c17ecca2 | 471 | if (con) { |
5d7c0d97 | 472 | con.reload(); |
c17ecca2 SR |
473 | } |
474 | } | |
475 | ||
5d7c0d97 | 476 | prevQMPStatus = qmpstatus; |
156095db DM |
477 | }); |
478 | ||
479 | me.on('afterrender', function() { | |
480 | me.statusStore.startUpdate(); | |
481 | }); | |
482 | ||
483 | me.on('destroy', function() { | |
484 | me.statusStore.stopUpdate(); | |
485 | }); | |
f6710aac | 486 | }, |
156095db | 487 | }); |