]>
Commit | Line | Data |
---|---|---|
1 | Ext.define('PVE.qemu.Config', { | |
2 | extend: 'PVE.panel.Config', | |
3 | alias: 'widget.PVE.qemu.Config', | |
4 | ||
5 | onlineHelp: 'chapter_virtual_machines', | |
6 | ||
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 | } | |
19 | ||
20 | var template = !!me.pveSelNode.data.template; | |
21 | ||
22 | var running = !!me.pveSelNode.data.uptime; | |
23 | ||
24 | var caps = Ext.state.Manager.get('GuiCap'); | |
25 | ||
26 | var base_url = '/nodes/' + nodename + "/qemu/" + vmid; | |
27 | ||
28 | me.statusStore = Ext.create('PVE.data.ObjectStore', { | |
29 | url: '/api2/json' + base_url + '/status/current', | |
30 | interval: 1000 | |
31 | }); | |
32 | ||
33 | var vm_command = function(cmd, params) { | |
34 | Proxmox.Utils.API2Request({ | |
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 | ||
45 | var resumeBtn = Ext.create('Ext.Button', { | |
46 | text: gettext('Resume'), | |
47 | disabled: !caps.vms['VM.PowerMgmt'], | |
48 | hidden: true, | |
49 | handler: function() { | |
50 | vm_command('resume'); | |
51 | }, | |
52 | iconCls: 'fa fa-play' | |
53 | }); | |
54 | ||
55 | var startBtn = Ext.create('Ext.Button', { | |
56 | text: gettext('Start'), | |
57 | disabled: !caps.vms['VM.PowerMgmt'] || running, | |
58 | hidden: template, | |
59 | handler: function() { | |
60 | vm_command('start'); | |
61 | }, | |
62 | iconCls: 'fa fa-play' | |
63 | }); | |
64 | ||
65 | var migrateBtn = Ext.create('Ext.Button', { | |
66 | text: gettext('Migrate'), | |
67 | disabled: !caps.vms['VM.Migrate'], | |
68 | hidden: PVE.data.ResourceStore.getNodes().length < 2, | |
69 | handler: function() { | |
70 | var win = Ext.create('PVE.window.Migrate', { | |
71 | vmtype: 'qemu', | |
72 | nodename: nodename, | |
73 | vmid: vmid | |
74 | }); | |
75 | win.show(); | |
76 | }, | |
77 | iconCls: 'fa fa-send-o' | |
78 | }); | |
79 | ||
80 | var moreBtn = Ext.create('Proxmox.button.Button', { | |
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() { | |
88 | PVE.window.Clone.wrap(nodename, vmid, template); | |
89 | } | |
90 | }, | |
91 | { | |
92 | text: gettext('Convert to template'), | |
93 | disabled: template, | |
94 | xtype: 'pveMenuItem', | |
95 | iconCls: 'fa fa-fw fa-file-o', | |
96 | hidden: caps.vms['VM.Allocate'] ? false : true, | |
97 | confirmMsg: Proxmox.Utils.format_task_description('qmtemplate', vmid), | |
98 | handler: function() { | |
99 | Proxmox.Utils.API2Request({ | |
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 | } | |
108 | }, | |
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 | }, | |
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 | ]} | |
134 | }); | |
135 | ||
136 | var shutdownBtn = Ext.create('PVE.button.Split', { | |
137 | text: gettext('Shutdown'), | |
138 | disabled: !caps.vms['VM.PowerMgmt'] || !running, | |
139 | hidden: template, | |
140 | confirmMsg: Proxmox.Utils.format_task_description('qmshutdown', vmid), | |
141 | handler: function() { | |
142 | vm_command('shutdown'); | |
143 | }, | |
144 | menu: { | |
145 | items: [{ | |
146 | text: gettext('Stop'), | |
147 | disabled: !caps.vms['VM.PowerMgmt'], | |
148 | dangerous: true, | |
149 | confirmMsg: Proxmox.Utils.format_task_description('qmstop', vmid), | |
150 | handler: function() { | |
151 | vm_command("stop", { timeout: 30 }); | |
152 | }, | |
153 | iconCls: 'fa fa-stop' | |
154 | },{ | |
155 | text: gettext('Reset'), | |
156 | disabled: !caps.vms['VM.PowerMgmt'], | |
157 | confirmMsg: Proxmox.Utils.format_task_description('qmreset', vmid), | |
158 | handler: function() { | |
159 | vm_command("reset"); | |
160 | }, | |
161 | iconCls: 'fa fa-bolt' | |
162 | }] | |
163 | }, | |
164 | iconCls: 'fa fa-power-off' | |
165 | }); | |
166 | ||
167 | var vm = me.pveSelNode.data; | |
168 | ||
169 | var consoleBtn = Ext.create('PVE.button.ConsoleButton', { | |
170 | disabled: !caps.vms['VM.Console'], | |
171 | hidden: template, | |
172 | consoleType: 'kvm', | |
173 | consoleName: vm.name, | |
174 | nodename: nodename, | |
175 | vmid: vmid | |
176 | }); | |
177 | ||
178 | Ext.apply(me, { | |
179 | title: Ext.String.format(gettext("Virtual Machine {0} on node '{1}'"), vm.text, nodename), | |
180 | hstateid: 'kvmtab', | |
181 | tbar: [ resumeBtn, startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn ], | |
182 | defaults: { statusStore: me.statusStore }, | |
183 | items: [ | |
184 | { | |
185 | title: gettext('Summary'), | |
186 | xtype: 'pveQemuSummary', | |
187 | iconCls: 'fa fa-book', | |
188 | itemId: 'summary' | |
189 | } | |
190 | ] | |
191 | }); | |
192 | ||
193 | if (caps.vms['VM.Console'] && !template) { | |
194 | me.items.push({ | |
195 | title: gettext('Console'), | |
196 | itemId: 'console', | |
197 | iconCls: 'fa fa-terminal', | |
198 | xtype: 'pveNoVncConsole', | |
199 | vmid: vmid, | |
200 | consoleType: 'kvm', | |
201 | nodename: nodename | |
202 | }); | |
203 | } | |
204 | ||
205 | me.items.push( | |
206 | { | |
207 | title: gettext('Hardware'), | |
208 | itemId: 'hardware', | |
209 | iconCls: 'fa fa-desktop', | |
210 | xtype: 'PVE.qemu.HardwareView' | |
211 | }, | |
212 | { | |
213 | title: gettext('Options'), | |
214 | iconCls: 'fa fa-gear', | |
215 | itemId: 'options', | |
216 | xtype: 'PVE.qemu.Options' | |
217 | }, | |
218 | { | |
219 | title: gettext('Task History'), | |
220 | itemId: 'tasks', | |
221 | xtype: 'proxmoxNodeTasks', | |
222 | iconCls: 'fa fa-list', | |
223 | nodename: nodename, | |
224 | vmidFilter: vmid | |
225 | } | |
226 | ); | |
227 | ||
228 | if (caps.vms['VM.Monitor'] && !template) { | |
229 | me.items.push({ | |
230 | title: gettext('Monitor'), | |
231 | iconCls: 'fa fa-eye', | |
232 | itemId: 'monitor', | |
233 | xtype: 'pveQemuMonitor' | |
234 | }); | |
235 | } | |
236 | ||
237 | if (caps.vms['VM.Backup']) { | |
238 | me.items.push({ | |
239 | title: gettext('Backup'), | |
240 | iconCls: 'fa fa-floppy-o', | |
241 | xtype: 'pveBackupView', | |
242 | itemId: 'backup' | |
243 | }, | |
244 | { | |
245 | title: gettext('Replication'), | |
246 | iconCls: 'fa fa-retweet', | |
247 | xtype: 'pveReplicaView', | |
248 | itemId: 'replication' | |
249 | }); | |
250 | } | |
251 | ||
252 | if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback']) && !template) { | |
253 | me.items.push({ | |
254 | title: gettext('Snapshots'), | |
255 | iconCls: 'fa fa-history', | |
256 | xtype: 'pveQemuSnapshotTree', | |
257 | itemId: 'snapshot' | |
258 | }); | |
259 | } | |
260 | ||
261 | if (caps.vms['VM.Console']) { | |
262 | me.items.push( | |
263 | { | |
264 | xtype: 'pveFirewallRules', | |
265 | title: gettext('Firewall'), | |
266 | iconCls: 'fa fa-shield', | |
267 | allow_iface: true, | |
268 | base_url: base_url + '/firewall/rules', | |
269 | list_refs_url: base_url + '/firewall/refs', | |
270 | itemId: 'firewall' | |
271 | }, | |
272 | { | |
273 | xtype: 'pveFirewallOptions', | |
274 | groups: ['firewall'], | |
275 | iconCls: 'fa fa-gear', | |
276 | onlineHelp: 'pve_firewall_vm_container_configuration', | |
277 | title: gettext('Options'), | |
278 | base_url: base_url + '/firewall/options', | |
279 | fwtype: 'vm', | |
280 | itemId: 'firewall-options' | |
281 | }, | |
282 | { | |
283 | xtype: 'pveFirewallAliases', | |
284 | title: gettext('Alias'), | |
285 | groups: ['firewall'], | |
286 | iconCls: 'fa fa-external-link', | |
287 | base_url: base_url + '/firewall/aliases', | |
288 | itemId: 'firewall-aliases' | |
289 | }, | |
290 | { | |
291 | xtype: 'pveIPSet', | |
292 | title: gettext('IPSet'), | |
293 | groups: ['firewall'], | |
294 | iconCls: 'fa fa-list-ol', | |
295 | base_url: base_url + '/firewall/ipset', | |
296 | list_refs_url: base_url + '/firewall/refs', | |
297 | itemId: 'firewall-ipset' | |
298 | }, | |
299 | { | |
300 | title: gettext('Log'), | |
301 | groups: ['firewall'], | |
302 | iconCls: 'fa fa-list', | |
303 | onlineHelp: 'chapter_pve_firewall', | |
304 | itemId: 'firewall-fwlog', | |
305 | xtype: 'pveLogView', | |
306 | url: '/api2/extjs' + base_url + '/firewall/log' | |
307 | } | |
308 | ); | |
309 | } | |
310 | ||
311 | if (caps.vms['Permissions.Modify']) { | |
312 | me.items.push({ | |
313 | xtype: 'pveACLView', | |
314 | title: gettext('Permissions'), | |
315 | iconCls: 'fa fa-unlock', | |
316 | itemId: 'permissions', | |
317 | path: '/vms/' + vmid | |
318 | }); | |
319 | } | |
320 | ||
321 | me.callParent(); | |
322 | ||
323 | me.mon(me.statusStore, 'load', function(s, records, success) { | |
324 | var status; | |
325 | var qmpstatus; | |
326 | var spice = false; | |
327 | ||
328 | if (!success) { | |
329 | status = qmpstatus = 'unknown'; | |
330 | } else { | |
331 | var rec = s.data.get('status'); | |
332 | status = rec ? rec.data.value : 'unknown'; | |
333 | rec = s.data.get('qmpstatus'); | |
334 | qmpstatus = rec ? rec.data.value : 'unknown'; | |
335 | rec = s.data.get('template'); | |
336 | template = rec.data.value || false; | |
337 | ||
338 | spice = s.data.get('spice') ? true : false; | |
339 | ||
340 | } | |
341 | ||
342 | if (template) { | |
343 | return; | |
344 | } | |
345 | ||
346 | if (qmpstatus === 'prelaunch' || qmpstatus === 'paused' || qmpstatus === 'suspended') { | |
347 | startBtn.setVisible(false); | |
348 | resumeBtn.setVisible(true); | |
349 | } else { | |
350 | startBtn.setVisible(true); | |
351 | resumeBtn.setVisible(false); | |
352 | } | |
353 | ||
354 | consoleBtn.setEnableSpice(spice); | |
355 | ||
356 | startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template); | |
357 | shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); | |
358 | me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped'); | |
359 | consoleBtn.setDisabled(template); | |
360 | }); | |
361 | ||
362 | me.on('afterrender', function() { | |
363 | me.statusStore.startUpdate(); | |
364 | }); | |
365 | ||
366 | me.on('destroy', function() { | |
367 | me.statusStore.stopUpdate(); | |
368 | }); | |
369 | } | |
370 | }); |