]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
reorganize qemu items
[pve-manager.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 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 iconCls: 'fa fa-book',
142 itemId: 'summary'
143 },
144 {
145 title: gettext('System'),
146 itemId: 'system',
147 expandedOnInit: true,
148 iconCls: 'fa fa-desktop',
149 xtype: 'PVE.qemu.HardwareView'
150 },
151 {
152 title: gettext('Options'),
153 groups: ['system'],
154 iconCls: 'fa fa-gear',
155 itemId: 'options',
156 xtype: 'PVE.qemu.Options'
157 },
158 {
159 title: gettext('Task History'),
160 itemId: 'tasks',
161 xtype: 'pveNodeTasks',
162 iconCls: 'fa fa-list',
163 vmidFilter: vmid
164 }
165 ]
166 });
167
168 if (caps.vms['VM.Monitor'] && !template) {
169 me.items.push({
170 title: gettext('Monitor'),
171 groups: ['system'],
172 iconCls: 'fa fa-eye',
173 itemId: 'monitor',
174 xtype: 'pveQemuMonitor'
175 });
176 }
177
178 if (caps.vms['VM.Backup']) {
179 me.items.push({
180 title: gettext('Backup'),
181 iconCls: 'fa fa-floppy-o',
182 xtype: 'pveBackupView',
183 itemId: 'backup'
184 });
185 }
186
187 if (caps.vms['VM.Snapshot'] && !template) {
188 me.items.push({
189 title: gettext('Snapshots'),
190 iconCls: 'fa fa-history',
191 xtype: 'pveQemuSnapshotTree',
192 itemId: 'snapshot'
193 });
194 }
195
196 if (caps.vms['VM.Console'] && !template) {
197 me.items.push({
198 title: gettext('Console'),
199 itemId: 'console',
200 iconCls: 'fa fa-terminal',
201 groups: ['system'],
202 xtype: 'pveNoVncConsole',
203 vmid: vmid,
204 consoleType: 'kvm',
205 nodename: nodename
206 });
207 }
208
209 if (caps.vms['VM.Console']) {
210 me.items.push(
211 {
212 xtype: 'pveFirewallRules',
213 title: gettext('Firewall'),
214 iconCls: 'fa fa-shield',
215 allow_iface: true,
216 base_url: base_url + '/firewall/rules',
217 list_refs_url: base_url + '/refs',
218 itemId: 'firewall'
219 },
220 {
221 xtype: 'pveFirewallOptions',
222 groups: ['firewall'],
223 iconCls: 'fa fa-gear',
224 title: gettext('Options'),
225 base_url: base_url + '/firewall/options',
226 fwtype: 'vm',
227 itemId: 'firewall-options'
228 },
229 {
230 xtype: 'pveFirewallAliases',
231 title: gettext('Alias'),
232 groups: ['firewall'],
233 iconCls: 'fa fa-external-link',
234 base_url: base_url + '/firewall/aliases',
235 itemId: 'firewall-aliases'
236 },
237 {
238 xtype: 'pveIPSet',
239 title: gettext('IPSet'),
240 groups: ['firewall'],
241 iconCls: 'fa fa-list-ol',
242 base_url: base_url + '/firewall/ipset',
243 list_refs_url: base_url + '/refs',
244 itemId: 'firewall-ipset'
245 },
246 {
247 title: gettext('Log'),
248 groups: ['firewall'],
249 iconCls: 'fa fa-list',
250 itemId: 'firewall-fwlog',
251 xtype: 'pveLogView',
252 url: '/api2/extjs' + base_url + '/firewall/log'
253 }
254 );
255 }
256
257 if (caps.vms['Permissions.Modify']) {
258 me.items.push({
259 xtype: 'pveACLView',
260 title: gettext('Permissions'),
261 iconCls: 'fa fa-unlock',
262 itemId: 'permissions',
263 path: '/vms/' + vmid
264 });
265 }
266
267 me.callParent();
268
269 me.mon(me.statusStore, 'load', function(s, records, success) {
270 var status;
271 var qmpstatus;
272 var spice = false;
273
274 if (!success) {
275 me.workspace.checkVmMigration(me.pveSelNode);
276 status = qmpstatus = 'unknown';
277 } else {
278 var rec = s.data.get('status');
279 status = rec ? rec.data.value : 'unknown';
280 rec = s.data.get('qmpstatus');
281 qmpstatus = rec ? rec.data.value : 'unknown';
282 rec = s.data.get('template');
283 template = rec.data.value || false;
284
285 spice = s.data.get('spice') ? true : false;
286
287 }
288
289 if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') {
290 startBtn.setVisible(false);
291 resumeBtn.setVisible(true);
292 } else {
293 startBtn.setVisible(true);
294 resumeBtn.setVisible(false);
295 }
296
297 consoleBtn.setEnableSpice(spice);
298
299 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
300 resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running' || template);
301 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
302 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
303 consoleBtn.setDisabled(template);
304 });
305
306 me.on('afterrender', function() {
307 me.statusStore.startUpdate();
308 });
309
310 me.on('destroy', function() {
311 me.statusStore.stopUpdate();
312 });
313 }
314 });