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