]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
Fix Qemu summary view:
[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 visible: false,
45 handler: function() {
46 vm_command('resume');
47 }
48 });
49
50 var startBtn = Ext.create('Ext.Button', {
51 text: gettext('Start'),
52 disabled: !caps.vms['VM.PowerMgmt'],
53 handler: function() {
54 vm_command('start');
55 }
56 });
57
58 var stopBtn = Ext.create('PVE.button.Button', {
59 text: gettext('Stop'),
60 disabled: !caps.vms['VM.PowerMgmt'],
61 confirmMsg: Ext.String.format(gettext("Do you really want to stop VM {0}?"), vmid),
62 handler: function() {
63 vm_command("stop", { timeout: 30 });
64 }
65 });
66
67 var migrateBtn = Ext.create('Ext.Button', {
68 text: gettext('Migrate'),
69 disabled: !caps.vms['VM.Migrate'],
70 handler: function() {
71 var win = Ext.create('PVE.window.Migrate', {
72 vmtype: 'qemu',
73 nodename: nodename,
74 vmid: vmid
75 });
76 win.show();
77 }
78 });
79
80 var resetBtn = Ext.create('PVE.button.Button', {
81 text: gettext('Reset'),
82 disabled: !caps.vms['VM.PowerMgmt'],
83 confirmMsg: Ext.String.format(gettext("Do you really want to reset VM {0}?"), vmid),
84 handler: function() {
85 vm_command("reset");
86 }
87 });
88
89 var shutdownBtn = Ext.create('PVE.button.Button', {
90 text: gettext('Shutdown'),
91 disabled: !caps.vms['VM.PowerMgmt'],
92 confirmMsg: Ext.String.format(gettext("Do you really want to shutdown VM {0}?"), vmid),
93 handler: function() {
94 vm_command('shutdown');
95 }
96 });
97
98 var removeBtn = Ext.create('PVE.button.Button', {
99 text: gettext('Remove'),
100 disabled: !caps.vms['VM.Allocate'],
101 dangerous: true,
102 confirmMsg: Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), vmid),
103 handler: function() {
104 PVE.Utils.API2Request({
105 url: base_url,
106 method: 'DELETE',
107 waitMsgTarget: me,
108 failure: function(response, opts) {
109 Ext.Msg.alert('Error', response.htmlStatus);
110 }
111 });
112 }
113 });
114
115 var vmname = me.pveSelNode.data.name;
116
117 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
118 disabled: !caps.vms['VM.Console'],
119 consoleType: 'kvm',
120 consoleName: vmname,
121 nodename: nodename,
122 vmid: vmid
123 });
124
125 var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'VM " + vmid + "'") + ")";
126
127 Ext.apply(me, {
128 title: Ext.String.format(gettext("Virtual Machine {0} on node {1}"), descr, "'" + nodename + "'"),
129 hstateid: 'kvmtab',
130 tbar: [ resumeBtn, startBtn, shutdownBtn, stopBtn, resetBtn,
131 removeBtn, migrateBtn, consoleBtn],
132 defaults: { statusStore: me.statusStore },
133 items: [
134 {
135 title: gettext('Summary'),
136 xtype: 'pveQemuSummary',
137 itemId: 'summary'
138 } ]
139 });
140 /*
141 {
142 title: gettext('Hardware'),
143 itemId: 'hardware',
144 xtype: 'PVE.qemu.HardwareView'
145 },
146 {
147 title: gettext('Options'),
148 itemId: 'options',
149 xtype: 'PVE.qemu.Options'
150 },
151 {
152 title: gettext('Task History'),
153 itemId: 'tasks',
154 xtype: 'pveNodeTasks',
155 vmidFilter: vmid
156 }
157 ]
158 });
159
160 if (caps.vms['VM.Monitor'] && !template) {
161 me.items.push({
162 title: gettext('Monitor'),
163 itemId: 'monitor',
164 xtype: 'pveQemuMonitor'
165 });
166 }
167
168 if (caps.vms['VM.Backup']) {
169 me.items.push({
170 title: gettext('Backup'),
171 xtype: 'pveBackupView',
172 itemId: 'backup'
173 });
174 }
175
176 if (caps.vms['VM.Snapshot']) {
177 me.items.push({
178 title: gettext('Snapshots'),
179 xtype: 'pveQemuSnapshotTree',
180 itemId: 'snapshot'
181 });
182 }
183
184 if (caps.vms['VM.Console'] && !template) {
185 me.items.push({
186 title: gettext('Console'),
187 itemId: 'console',
188 xtype: 'pveNoVncConsole',
189 vmid: vmid,
190 consoleType: 'kvm',
191 nodename: nodename
192 });
193 }
194
195 if (caps.vms['VM.Console']) {
196 me.items.push(
197 {
198 xtype: 'pveFirewallPanel',
199 title: gettext('Firewall'),
200 base_url: base_url + '/firewall',
201 fwtype: 'vm',
202 phstateid: me.hstateid,
203 itemId: 'firewall'
204 }
205 );
206 }
207
208 if (caps.vms['Permissions.Modify']) {
209 me.items.push({
210 xtype: 'pveACLView',
211 title: gettext('Permissions'),
212 itemId: 'permissions',
213 path: '/vms/' + vmid
214 });
215 }
216 */
217 me.callParent();
218
219 me.mon(me.statusStore, 'load', function(s, records, success) {
220 var status;
221 var qmpstatus;
222 var spice = false;
223
224 if (!success) {
225 me.workspace.checkVmMigration(me.pveSelNode);
226 status = qmpstatus = 'unknown';
227 } else {
228 var rec = s.data.get('status');
229 status = rec ? rec.data.value : 'unknown';
230 rec = s.data.get('qmpstatus');
231 qmpstatus = rec ? rec.data.value : 'unknown';
232 rec = s.data.get('template');
233 if(rec.data.value){
234 template = rec.data.value;
235 }
236 spice = s.data.get('spice') ? true : false;
237
238 }
239
240 if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') {
241 startBtn.setVisible(false);
242 resumeBtn.setVisible(true);
243 } else {
244 startBtn.setVisible(true);
245 resumeBtn.setVisible(false);
246 }
247
248 consoleBtn.setEnableSpice(spice);
249
250 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
251 resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running' || template);
252 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
253 stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped');
254 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
255 });
256
257 me.on('afterrender', function() {
258 me.statusStore.startUpdate();
259 });
260
261 me.on('destroy', function() {
262 me.statusStore.stopUpdate();
263 });
264 }
265 });