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