]>
Commit | Line | Data |
---|---|---|
156095db DM |
1 | Ext.define('PVE.qemu.Config', { |
2 | extend: 'PVE.panel.Config', | |
3 | alias: 'widget.PVE.qemu.Config', | |
4 | ||
5 | initComponent: function() { | |
6 | var me = this; | |
7 | ||
8 | var nodename = me.pveSelNode.data.node; | |
9 | if (!nodename) { | |
10 | throw "no node name specified"; | |
11 | } | |
12 | ||
13 | var vmid = me.pveSelNode.data.vmid; | |
14 | if (!vmid) { | |
15 | throw "no VM ID specified"; | |
16 | } | |
540fdc8b | 17 | |
156095db DM |
18 | var template = me.pveSelNode.data.template; |
19 | ||
20 | var caps = Ext.state.Manager.get('GuiCap'); | |
21 | ||
22 | var base_url = '/nodes/' + nodename + "/qemu/" + vmid; | |
540fdc8b | 23 | |
156095db DM |
24 | me.statusStore = Ext.create('PVE.data.ObjectStore', { |
25 | url: '/api2/json' + base_url + '/status/current', | |
26 | interval: 1000 | |
27 | }); | |
28 | ||
29 | var vm_command = function(cmd, params) { | |
30 | PVE.Utils.API2Request({ | |
31 | params: params, | |
32 | url: base_url + '/status/' + cmd, | |
33 | waitMsgTarget: me, | |
34 | method: 'POST', | |
35 | failure: function(response, opts) { | |
36 | Ext.Msg.alert('Error', response.htmlStatus); | |
37 | } | |
38 | }); | |
39 | }; | |
40 | ||
540fdc8b | 41 | var resumeBtn = Ext.create('Ext.Button', { |
156095db DM |
42 | text: gettext('Resume'), |
43 | disabled: !caps.vms['VM.PowerMgmt'], | |
394a9983 | 44 | hidden: true, |
156095db DM |
45 | handler: function() { |
46 | vm_command('resume'); | |
d4333933 DC |
47 | }, |
48 | iconCls: 'fa fa-play' | |
540fdc8b | 49 | }); |
156095db | 50 | |
540fdc8b | 51 | var startBtn = Ext.create('Ext.Button', { |
156095db DM |
52 | text: gettext('Start'), |
53 | disabled: !caps.vms['VM.PowerMgmt'], | |
54 | handler: function() { | |
55 | vm_command('start'); | |
d4333933 | 56 | }, |
22f2f9d6 | 57 | iconCls: 'fa fa-play' |
540fdc8b DC |
58 | }); |
59 | ||
540fdc8b | 60 | var migrateBtn = Ext.create('Ext.Button', { |
156095db DM |
61 | text: gettext('Migrate'), |
62 | disabled: !caps.vms['VM.Migrate'], | |
63 | handler: function() { | |
64 | var win = Ext.create('PVE.window.Migrate', { | |
65 | vmtype: 'qemu', | |
66 | nodename: nodename, | |
67 | vmid: vmid | |
68 | }); | |
69 | win.show(); | |
d4333933 DC |
70 | }, |
71 | iconCls: 'fa fa-send-o' | |
156095db | 72 | }); |
540fdc8b | 73 | |
156095db DM |
74 | var resetBtn = Ext.create('PVE.button.Button', { |
75 | text: gettext('Reset'), | |
76 | disabled: !caps.vms['VM.PowerMgmt'], | |
16152937 | 77 | confirmMsg: PVE.Utils.format_task_description('qmreset', vmid), |
540fdc8b | 78 | handler: function() { |
156095db | 79 | vm_command("reset"); |
d4333933 DC |
80 | }, |
81 | iconCls: 'fa fa-bolt' | |
156095db DM |
82 | }); |
83 | ||
889c7083 | 84 | var shutdownBtn = Ext.create('PVE.button.Split', { |
156095db DM |
85 | text: gettext('Shutdown'), |
86 | disabled: !caps.vms['VM.PowerMgmt'], | |
16152937 | 87 | confirmMsg: PVE.Utils.format_task_description('qmshutdown', vmid), |
156095db DM |
88 | handler: function() { |
89 | vm_command('shutdown'); | |
889c7083 DC |
90 | }, |
91 | menu: { | |
92 | items: [{ | |
93 | text: gettext('Stop'), | |
94 | disabled: !caps.vms['VM.PowerMgmt'], | |
95 | dangerous: true, | |
96 | confirmMsg: PVE.Utils.format_task_description('qmstop', vmid), | |
97 | handler: function() { | |
98 | vm_command("stop", { timeout: 30 }); | |
d4333933 | 99 | }, |
22f2f9d6 | 100 | iconCls: 'fa fa-stop' |
889c7083 | 101 | }] |
d4333933 DC |
102 | }, |
103 | iconCls: 'fa fa-power-off' | |
156095db DM |
104 | }); |
105 | ||
106 | var removeBtn = Ext.create('PVE.button.Button', { | |
107 | text: gettext('Remove'), | |
108 | disabled: !caps.vms['VM.Allocate'], | |
156095db | 109 | handler: function() { |
32f469f3 | 110 | Ext.create('PVE.window.SafeDestroy', { |
bcecf280 DM |
111 | url: base_url, |
112 | item: { type: 'VM', id: vmid } | |
32f469f3 | 113 | }).show(); |
d4333933 DC |
114 | }, |
115 | iconCls: 'fa fa-trash-o' | |
156095db DM |
116 | }); |
117 | ||
118 | var vmname = me.pveSelNode.data.name; | |
119 | ||
120 | var consoleBtn = Ext.create('PVE.button.ConsoleButton', { | |
121 | disabled: !caps.vms['VM.Console'], | |
122 | consoleType: 'kvm', | |
123 | consoleName: vmname, | |
124 | nodename: nodename, | |
d4333933 DC |
125 | vmid: vmid, |
126 | iconCls: 'fa fa-terminal' | |
156095db DM |
127 | }); |
128 | ||
129 | var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'VM " + vmid + "'") + ")"; | |
130 | ||
131 | Ext.apply(me, { | |
132 | title: Ext.String.format(gettext("Virtual Machine {0} on node {1}"), descr, "'" + nodename + "'"), | |
133 | hstateid: 'kvmtab', | |
889c7083 | 134 | tbar: [ resumeBtn, startBtn, shutdownBtn, resetBtn, |
156095db DM |
135 | removeBtn, migrateBtn, consoleBtn], |
136 | defaults: { statusStore: me.statusStore }, | |
137 | items: [ | |
138 | { | |
6f68dcbe EK |
139 | title: gettext('Summary'), |
140 | xtype: 'pveQemuSummary', | |
c284be32 | 141 | iconCls: 'fa fa-book', |
156095db | 142 | itemId: 'summary' |
156095db DM |
143 | } |
144 | ] | |
145 | }); | |
c5ccc8d0 | 146 | |
1939a006 DC |
147 | if (caps.vms['VM.Console'] && !template) { |
148 | me.items.push({ | |
149 | title: gettext('Console'), | |
150 | itemId: 'console', | |
151 | iconCls: 'fa fa-terminal', | |
152 | xtype: 'pveNoVncConsole', | |
153 | vmid: vmid, | |
154 | consoleType: 'kvm', | |
155 | nodename: nodename | |
156 | }); | |
157 | } | |
158 | ||
159 | me.items.push( | |
160 | { | |
161 | title: gettext('Hardware'), | |
162 | itemId: 'hardware', | |
163 | iconCls: 'fa fa-desktop', | |
164 | xtype: 'PVE.qemu.HardwareView' | |
165 | }, | |
166 | { | |
167 | title: gettext('Options'), | |
168 | iconCls: 'fa fa-gear', | |
169 | itemId: 'options', | |
170 | xtype: 'PVE.qemu.Options' | |
171 | }, | |
172 | { | |
173 | title: gettext('Task History'), | |
174 | itemId: 'tasks', | |
175 | xtype: 'pveNodeTasks', | |
176 | iconCls: 'fa fa-list', | |
177 | vmidFilter: vmid | |
178 | } | |
179 | ); | |
180 | ||
156095db DM |
181 | if (caps.vms['VM.Monitor'] && !template) { |
182 | me.items.push({ | |
183 | title: gettext('Monitor'), | |
c284be32 | 184 | iconCls: 'fa fa-eye', |
156095db DM |
185 | itemId: 'monitor', |
186 | xtype: 'pveQemuMonitor' | |
187 | }); | |
188 | } | |
189 | ||
190 | if (caps.vms['VM.Backup']) { | |
191 | me.items.push({ | |
192 | title: gettext('Backup'), | |
c284be32 | 193 | iconCls: 'fa fa-floppy-o', |
156095db DM |
194 | xtype: 'pveBackupView', |
195 | itemId: 'backup' | |
196 | }); | |
197 | } | |
198 | ||
4a01bc83 | 199 | if (caps.vms['VM.Snapshot'] && !template) { |
156095db DM |
200 | me.items.push({ |
201 | title: gettext('Snapshots'), | |
c284be32 | 202 | iconCls: 'fa fa-history', |
156095db DM |
203 | xtype: 'pveQemuSnapshotTree', |
204 | itemId: 'snapshot' | |
205 | }); | |
206 | } | |
207 | ||
156095db | 208 | if (caps.vms['VM.Console']) { |
a2f35eb2 | 209 | me.items.push( |
156095db | 210 | { |
c284be32 | 211 | xtype: 'pveFirewallRules', |
156095db | 212 | title: gettext('Firewall'), |
c284be32 DC |
213 | iconCls: 'fa fa-shield', |
214 | allow_iface: true, | |
215 | base_url: base_url + '/firewall/rules', | |
216 | list_refs_url: base_url + '/refs', | |
156095db | 217 | itemId: 'firewall' |
c284be32 DC |
218 | }, |
219 | { | |
220 | xtype: 'pveFirewallOptions', | |
221 | groups: ['firewall'], | |
222 | iconCls: 'fa fa-gear', | |
223 | title: gettext('Options'), | |
224 | base_url: base_url + '/firewall/options', | |
225 | fwtype: 'vm', | |
226 | itemId: 'firewall-options' | |
227 | }, | |
228 | { | |
229 | xtype: 'pveFirewallAliases', | |
230 | title: gettext('Alias'), | |
231 | groups: ['firewall'], | |
232 | iconCls: 'fa fa-external-link', | |
233 | base_url: base_url + '/firewall/aliases', | |
234 | itemId: 'firewall-aliases' | |
235 | }, | |
236 | { | |
237 | xtype: 'pveIPSet', | |
238 | title: gettext('IPSet'), | |
239 | groups: ['firewall'], | |
240 | iconCls: 'fa fa-list-ol', | |
241 | base_url: base_url + '/firewall/ipset', | |
242 | list_refs_url: base_url + '/refs', | |
243 | itemId: 'firewall-ipset' | |
244 | }, | |
245 | { | |
246 | title: gettext('Log'), | |
247 | groups: ['firewall'], | |
248 | iconCls: 'fa fa-list', | |
249 | itemId: 'firewall-fwlog', | |
250 | xtype: 'pveLogView', | |
251 | url: '/api2/extjs' + base_url + '/firewall/log' | |
156095db | 252 | } |
a2f35eb2 | 253 | ); |
156095db DM |
254 | } |
255 | ||
256 | if (caps.vms['Permissions.Modify']) { | |
257 | me.items.push({ | |
258 | xtype: 'pveACLView', | |
259 | title: gettext('Permissions'), | |
c284be32 | 260 | iconCls: 'fa fa-unlock', |
156095db DM |
261 | itemId: 'permissions', |
262 | path: '/vms/' + vmid | |
263 | }); | |
264 | } | |
c5ccc8d0 | 265 | |
156095db DM |
266 | me.callParent(); |
267 | ||
540fdc8b | 268 | me.mon(me.statusStore, 'load', function(s, records, success) { |
156095db DM |
269 | var status; |
270 | var qmpstatus; | |
271 | var spice = false; | |
272 | ||
273 | if (!success) { | |
274 | me.workspace.checkVmMigration(me.pveSelNode); | |
275 | status = qmpstatus = 'unknown'; | |
276 | } else { | |
277 | var rec = s.data.get('status'); | |
278 | status = rec ? rec.data.value : 'unknown'; | |
279 | rec = s.data.get('qmpstatus'); | |
280 | qmpstatus = rec ? rec.data.value : 'unknown'; | |
281 | rec = s.data.get('template'); | |
2a727273 DM |
282 | template = rec.data.value || false; |
283 | ||
156095db DM |
284 | spice = s.data.get('spice') ? true : false; |
285 | ||
286 | } | |
287 | ||
288 | if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') { | |
289 | startBtn.setVisible(false); | |
290 | resumeBtn.setVisible(true); | |
291 | } else { | |
292 | startBtn.setVisible(true); | |
293 | resumeBtn.setVisible(false); | |
294 | } | |
295 | ||
296 | consoleBtn.setEnableSpice(spice); | |
297 | ||
298 | startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template); | |
299 | resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running' || template); | |
300 | shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); | |
156095db | 301 | removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped'); |
4365549d | 302 | consoleBtn.setDisabled(template); |
156095db DM |
303 | }); |
304 | ||
305 | me.on('afterrender', function() { | |
306 | me.statusStore.startUpdate(); | |
307 | }); | |
308 | ||
309 | me.on('destroy', function() { | |
310 | me.statusStore.stopUpdate(); | |
311 | }); | |
312 | } | |
313 | }); |