]>
Commit | Line | Data |
---|---|---|
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 | } | |
17 | ||
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; | |
23 | ||
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 | ||
41 | var resumeBtn = Ext.create('Ext.Button', { | |
42 | text: gettext('Resume'), | |
43 | disabled: !caps.vms['VM.PowerMgmt'], | |
44 | hidden: true, | |
45 | handler: function() { | |
46 | vm_command('resume'); | |
47 | }, | |
48 | iconCls: 'fa fa-play' | |
49 | }); | |
50 | ||
51 | var startBtn = Ext.create('Ext.Button', { | |
52 | text: gettext('Start'), | |
53 | disabled: !caps.vms['VM.PowerMgmt'], | |
54 | handler: function() { | |
55 | vm_command('start'); | |
56 | }, | |
57 | iconCls: 'fa fa-play' | |
58 | }); | |
59 | ||
60 | var migrateBtn = Ext.create('Ext.Button', { | |
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(); | |
70 | }, | |
71 | iconCls: 'fa fa-send-o' | |
72 | }); | |
73 | ||
74 | var resetBtn = Ext.create('PVE.button.Button', { | |
75 | text: gettext('Reset'), | |
76 | disabled: !caps.vms['VM.PowerMgmt'], | |
77 | confirmMsg: PVE.Utils.format_task_description('qmreset', vmid), | |
78 | handler: function() { | |
79 | vm_command("reset"); | |
80 | }, | |
81 | iconCls: 'fa fa-bolt' | |
82 | }); | |
83 | ||
84 | var shutdownBtn = Ext.create('PVE.button.Split', { | |
85 | text: gettext('Shutdown'), | |
86 | disabled: !caps.vms['VM.PowerMgmt'], | |
87 | confirmMsg: PVE.Utils.format_task_description('qmshutdown', vmid), | |
88 | handler: function() { | |
89 | vm_command('shutdown'); | |
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 }); | |
99 | }, | |
100 | iconCls: 'fa fa-stop' | |
101 | }] | |
102 | }, | |
103 | iconCls: 'fa fa-power-off' | |
104 | }); | |
105 | ||
106 | var removeBtn = Ext.create('PVE.button.Button', { | |
107 | text: gettext('Remove'), | |
108 | disabled: !caps.vms['VM.Allocate'], | |
109 | handler: function() { | |
110 | Ext.create('PVE.window.SafeDestroy', { | |
111 | url: base_url, | |
112 | item: { type: 'VM', id: vmid } | |
113 | }).show(); | |
114 | }, | |
115 | iconCls: 'fa fa-trash-o' | |
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, | |
125 | vmid: vmid, | |
126 | iconCls: 'fa fa-terminal' | |
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', | |
134 | tbar: [ resumeBtn, startBtn, shutdownBtn, resetBtn, | |
135 | removeBtn, migrateBtn, consoleBtn], | |
136 | defaults: { statusStore: me.statusStore }, | |
137 | items: [ | |
138 | { | |
139 | title: gettext('Summary'), | |
140 | xtype: 'pveQemuSummary', | |
141 | itemId: 'summary' | |
142 | }, | |
143 | { | |
144 | title: gettext('Hardware'), | |
145 | itemId: 'hardware', | |
146 | xtype: 'PVE.qemu.HardwareView' | |
147 | }, | |
148 | { | |
149 | title: gettext('Options'), | |
150 | itemId: 'options', | |
151 | xtype: 'PVE.qemu.Options' | |
152 | }, | |
153 | { | |
154 | title: gettext('Task History'), | |
155 | itemId: 'tasks', | |
156 | xtype: 'pveNodeTasks', | |
157 | vmidFilter: vmid | |
158 | } | |
159 | ] | |
160 | }); | |
161 | ||
162 | if (caps.vms['VM.Monitor'] && !template) { | |
163 | me.items.push({ | |
164 | title: gettext('Monitor'), | |
165 | itemId: 'monitor', | |
166 | xtype: 'pveQemuMonitor' | |
167 | }); | |
168 | } | |
169 | ||
170 | if (caps.vms['VM.Backup']) { | |
171 | me.items.push({ | |
172 | title: gettext('Backup'), | |
173 | xtype: 'pveBackupView', | |
174 | itemId: 'backup' | |
175 | }); | |
176 | } | |
177 | ||
178 | if (caps.vms['VM.Snapshot']) { | |
179 | me.items.push({ | |
180 | title: gettext('Snapshots'), | |
181 | xtype: 'pveQemuSnapshotTree', | |
182 | itemId: 'snapshot' | |
183 | }); | |
184 | } | |
185 | ||
186 | if (caps.vms['VM.Console'] && !template) { | |
187 | me.items.push({ | |
188 | title: gettext('Console'), | |
189 | itemId: 'console', | |
190 | xtype: 'pveNoVncConsole', | |
191 | vmid: vmid, | |
192 | consoleType: 'kvm', | |
193 | nodename: nodename | |
194 | }); | |
195 | } | |
196 | ||
197 | if (caps.vms['VM.Console']) { | |
198 | me.items.push( | |
199 | { | |
200 | xtype: 'pveFirewallPanel', | |
201 | title: gettext('Firewall'), | |
202 | base_url: base_url + '/firewall', | |
203 | fwtype: 'vm', | |
204 | phstateid: me.hstateid, | |
205 | itemId: 'firewall' | |
206 | } | |
207 | ); | |
208 | } | |
209 | ||
210 | if (caps.vms['Permissions.Modify']) { | |
211 | me.items.push({ | |
212 | xtype: 'pveACLView', | |
213 | title: gettext('Permissions'), | |
214 | itemId: 'permissions', | |
215 | path: '/vms/' + vmid | |
216 | }); | |
217 | } | |
218 | ||
219 | me.callParent(); | |
220 | ||
221 | me.mon(me.statusStore, 'load', function(s, records, success) { | |
222 | var status; | |
223 | var qmpstatus; | |
224 | var spice = false; | |
225 | ||
226 | if (!success) { | |
227 | me.workspace.checkVmMigration(me.pveSelNode); | |
228 | status = qmpstatus = 'unknown'; | |
229 | } else { | |
230 | var rec = s.data.get('status'); | |
231 | status = rec ? rec.data.value : 'unknown'; | |
232 | rec = s.data.get('qmpstatus'); | |
233 | qmpstatus = rec ? rec.data.value : 'unknown'; | |
234 | rec = s.data.get('template'); | |
235 | template = rec.data.value || false; | |
236 | ||
237 | spice = s.data.get('spice') ? true : false; | |
238 | ||
239 | } | |
240 | ||
241 | if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') { | |
242 | startBtn.setVisible(false); | |
243 | resumeBtn.setVisible(true); | |
244 | } else { | |
245 | startBtn.setVisible(true); | |
246 | resumeBtn.setVisible(false); | |
247 | } | |
248 | ||
249 | consoleBtn.setEnableSpice(spice); | |
250 | ||
251 | startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template); | |
252 | resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running' || template); | |
253 | shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); | |
254 | removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped'); | |
255 | consoleBtn.setDisabled(template); | |
256 | }); | |
257 | ||
258 | me.on('afterrender', function() { | |
259 | me.statusStore.startUpdate(); | |
260 | }); | |
261 | ||
262 | me.on('destroy', function() { | |
263 | me.statusStore.stopUpdate(); | |
264 | }); | |
265 | } | |
266 | }); |