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