]> git.proxmox.com Git - pve-manager.git/blob - www/manager/qemu/Config.js
make jslint happy
[pve-manager.git] / www / manager / 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 caps = Ext.state.Manager.get('GuiCap');
19
20 me.statusStore = Ext.create('PVE.data.ObjectStore', {
21 url: "/api2/json/nodes/" + nodename + "/qemu/" + vmid + "/status/current",
22 interval: 1000
23 });
24
25 var vm_command = function(cmd, params) {
26 PVE.Utils.API2Request({
27 params: params,
28 url: '/nodes/' + nodename + '/qemu/' + vmid + "/status/" + cmd,
29 waitMsgTarget: me,
30 method: 'POST',
31 failure: function(response, opts) {
32 Ext.Msg.alert('Error', response.htmlStatus);
33 }
34 });
35 };
36
37 var resumeBtn = Ext.create('Ext.Button', {
38 text: gettext('Resume'),
39 disabled: !caps.vms['VM.PowerMgmt'],
40 visible: false,
41 handler: function() {
42 vm_command('resume');
43 }
44 });
45
46 var startBtn = Ext.create('Ext.Button', {
47 text: gettext('Start'),
48 disabled: !caps.vms['VM.PowerMgmt'],
49 handler: function() {
50 vm_command('start');
51 }
52 });
53
54 var stopBtn = Ext.create('PVE.button.Button', {
55 text: gettext('Stop'),
56 disabled: !caps.vms['VM.PowerMgmt'],
57 confirmMsg: Ext.String.format(gettext("Do you really want to stop VM {0}?"), vmid),
58 handler: function() {
59 vm_command("stop", { timeout: 30 });
60 }
61 });
62
63 var migrateBtn = Ext.create('Ext.Button', {
64 text: gettext('Migrate'),
65 disabled: !caps.vms['VM.Migrate'],
66 handler: function() {
67 var win = Ext.create('PVE.window.Migrate', {
68 vmtype: 'qemu',
69 nodename: nodename,
70 vmid: vmid
71 });
72 win.show();
73 }
74 });
75
76 var resetBtn = Ext.create('PVE.button.Button', {
77 text: gettext('Reset'),
78 disabled: !caps.vms['VM.PowerMgmt'],
79 confirmMsg: Ext.String.format(gettext("Do you really want to reset VM {0}?"), vmid),
80 handler: function() {
81 vm_command("reset");
82 }
83 });
84
85 var shutdownBtn = Ext.create('PVE.button.Button', {
86 text: gettext('Shutdown'),
87 disabled: !caps.vms['VM.PowerMgmt'],
88 confirmMsg: Ext.String.format(gettext("Do you really want to shutdown VM {0}?"), vmid),
89 handler: function() {
90 vm_command('shutdown');
91 }
92 });
93
94 var removeBtn = Ext.create('PVE.button.Button', {
95 text: gettext('Remove'),
96 disabled: !caps.vms['VM.Allocate'],
97 dangerous: true,
98 confirmMsg: Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), vmid),
99 handler: function() {
100 PVE.Utils.API2Request({
101 url: '/nodes/' + nodename + '/qemu/' + vmid,
102 method: 'DELETE',
103 waitMsgTarget: me,
104 failure: function(response, opts) {
105 Ext.Msg.alert('Error', response.htmlStatus);
106 }
107 });
108 }
109 });
110
111 var vmname = me.pveSelNode.data.name;
112
113 var consoleBtn = Ext.create('Ext.Button', {
114 text: gettext('Console'),
115 disabled: !caps.vms['VM.Console'],
116 handler: function() {
117 PVE.Utils.openConoleWindow('kvm', vmid, nodename, vmname);
118 }
119 });
120
121 var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'VM " + vmid + "'") + ")";
122
123 Ext.apply(me, {
124 title: Ext.String.format(gettext("Virtual Machine {0} on node {1}"), descr, "'" + nodename + "'"),
125 hstateid: 'kvmtab',
126 tbar: [ resumeBtn, startBtn, shutdownBtn, stopBtn, resetBtn,
127 removeBtn, migrateBtn, consoleBtn ],
128 defaults: { statusStore: me.statusStore },
129 items: [
130 {
131 title: gettext('Summary'),
132 xtype: 'pveQemuSummary',
133 itemId: 'summary'
134 },
135 {
136 title: gettext('Hardware'),
137 itemId: 'hardware',
138 xtype: 'PVE.qemu.HardwareView'
139 },
140 {
141 title: gettext('Options'),
142 itemId: 'options',
143 xtype: 'PVE.qemu.Options'
144 }
145 ]
146 });
147
148 if (caps.vms['VM.Monitor']) {
149 me.items.push({
150 title: gettext('Monitor'),
151 itemId: 'monitor',
152 xtype: 'pveQemuMonitor'
153 });
154 }
155
156 if (caps.vms['VM.Backup']) {
157 me.items.push({
158 title: gettext('Backup'),
159 xtype: 'pveBackupView',
160 itemId: 'backup'
161 });
162 }
163
164 if (caps.vms['VM.Snapshot']) {
165 me.items.push({
166 title: gettext('Snapshots'),
167 xtype: 'pveQemuSnapshotTree',
168 itemId: 'snapshot'
169 });
170 }
171
172 if (caps.vms['Permissions.Modify']) {
173 me.items.push({
174 xtype: 'pveACLView',
175 title: gettext('Permissions'),
176 itemId: 'permissions',
177 path: '/vms/' + vmid
178 });
179 }
180
181 me.callParent();
182
183 me.statusStore.on('load', function(s, records, success) {
184 var status;
185 var qmpstatus;
186
187 if (!success) {
188 me.workspace.checkVmMigration(me.pveSelNode);
189 status = qmpstatus = 'unknown';
190 } else {
191 var rec = s.data.get('status');
192 status = rec ? rec.data.value : 'unknown';
193 rec = s.data.get('qmpstatus');
194 qmpstatus = rec ? rec.data.value : 'unknown';
195 }
196
197 if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') {
198 startBtn.setVisible(false);
199 resumeBtn.setVisible(true);
200 } else {
201 startBtn.setVisible(true);
202 resumeBtn.setVisible(false);
203 }
204
205 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running');
206 resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
207 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
208 stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped');
209 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
210 });
211
212 me.on('afterrender', function() {
213 me.statusStore.startUpdate();
214 });
215
216 me.on('destroy', function() {
217 me.statusStore.stopUpdate();
218 });
219 }
220 });