]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/qemu/Config.js
Move the snapshot API test to a static function
[pve-manager.git] / www / manager6 / qemu / Config.js
CommitLineData
156095db
DM
1Ext.define('PVE.qemu.Config', {
2 extend: 'PVE.panel.Config',
3 alias: 'widget.PVE.qemu.Config',
4
c8802a60 5 onlineHelp: 'chapter_virtual_machines',
3c724630 6
156095db
DM
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 }
540fdc8b 19
156095db
DM
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;
540fdc8b 25
156095db
DM
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
540fdc8b 43 var resumeBtn = Ext.create('Ext.Button', {
156095db
DM
44 text: gettext('Resume'),
45 disabled: !caps.vms['VM.PowerMgmt'],
394a9983 46 hidden: true,
156095db
DM
47 handler: function() {
48 vm_command('resume');
d4333933
DC
49 },
50 iconCls: 'fa fa-play'
540fdc8b 51 });
156095db 52
540fdc8b 53 var startBtn = Ext.create('Ext.Button', {
156095db
DM
54 text: gettext('Start'),
55 disabled: !caps.vms['VM.PowerMgmt'],
56 handler: function() {
57 vm_command('start');
d4333933 58 },
22f2f9d6 59 iconCls: 'fa fa-play'
540fdc8b
DC
60 });
61
540fdc8b 62 var migrateBtn = Ext.create('Ext.Button', {
156095db
DM
63 text: gettext('Migrate'),
64 disabled: !caps.vms['VM.Migrate'],
65 handler: function() {
66 var win = Ext.create('PVE.window.Migrate', {
67 vmtype: 'qemu',
68 nodename: nodename,
69 vmid: vmid
70 });
71 win.show();
d4333933
DC
72 },
73 iconCls: 'fa fa-send-o'
156095db 74 });
540fdc8b 75
156095db
DM
76 var resetBtn = Ext.create('PVE.button.Button', {
77 text: gettext('Reset'),
78 disabled: !caps.vms['VM.PowerMgmt'],
16152937 79 confirmMsg: PVE.Utils.format_task_description('qmreset', vmid),
540fdc8b 80 handler: function() {
156095db 81 vm_command("reset");
d4333933
DC
82 },
83 iconCls: 'fa fa-bolt'
156095db
DM
84 });
85
889c7083 86 var shutdownBtn = Ext.create('PVE.button.Split', {
156095db
DM
87 text: gettext('Shutdown'),
88 disabled: !caps.vms['VM.PowerMgmt'],
16152937 89 confirmMsg: PVE.Utils.format_task_description('qmshutdown', vmid),
156095db
DM
90 handler: function() {
91 vm_command('shutdown');
889c7083
DC
92 },
93 menu: {
94 items: [{
95 text: gettext('Stop'),
96 disabled: !caps.vms['VM.PowerMgmt'],
97 dangerous: true,
98 confirmMsg: PVE.Utils.format_task_description('qmstop', vmid),
99 handler: function() {
100 vm_command("stop", { timeout: 30 });
d4333933 101 },
22f2f9d6 102 iconCls: 'fa fa-stop'
889c7083 103 }]
d4333933
DC
104 },
105 iconCls: 'fa fa-power-off'
156095db
DM
106 });
107
108 var removeBtn = Ext.create('PVE.button.Button', {
109 text: gettext('Remove'),
110 disabled: !caps.vms['VM.Allocate'],
156095db 111 handler: function() {
32f469f3 112 Ext.create('PVE.window.SafeDestroy', {
bcecf280
DM
113 url: base_url,
114 item: { type: 'VM', id: vmid }
32f469f3 115 }).show();
d4333933
DC
116 },
117 iconCls: 'fa fa-trash-o'
156095db
DM
118 });
119
120 var vmname = me.pveSelNode.data.name;
121
122 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
123 disabled: !caps.vms['VM.Console'],
124 consoleType: 'kvm',
125 consoleName: vmname,
126 nodename: nodename,
d4333933
DC
127 vmid: vmid,
128 iconCls: 'fa fa-terminal'
156095db
DM
129 });
130
131 var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'VM " + vmid + "'") + ")";
132
133 Ext.apply(me, {
134 title: Ext.String.format(gettext("Virtual Machine {0} on node {1}"), descr, "'" + nodename + "'"),
135 hstateid: 'kvmtab',
889c7083 136 tbar: [ resumeBtn, startBtn, shutdownBtn, resetBtn,
156095db
DM
137 removeBtn, migrateBtn, consoleBtn],
138 defaults: { statusStore: me.statusStore },
139 items: [
140 {
6f68dcbe
EK
141 title: gettext('Summary'),
142 xtype: 'pveQemuSummary',
c284be32 143 iconCls: 'fa fa-book',
156095db 144 itemId: 'summary'
156095db
DM
145 }
146 ]
147 });
c5ccc8d0 148
1939a006
DC
149 if (caps.vms['VM.Console'] && !template) {
150 me.items.push({
151 title: gettext('Console'),
152 itemId: 'console',
153 iconCls: 'fa fa-terminal',
154 xtype: 'pveNoVncConsole',
155 vmid: vmid,
156 consoleType: 'kvm',
157 nodename: nodename
158 });
159 }
160
161 me.items.push(
162 {
163 title: gettext('Hardware'),
164 itemId: 'hardware',
165 iconCls: 'fa fa-desktop',
166 xtype: 'PVE.qemu.HardwareView'
167 },
168 {
169 title: gettext('Options'),
170 iconCls: 'fa fa-gear',
171 itemId: 'options',
172 xtype: 'PVE.qemu.Options'
173 },
174 {
175 title: gettext('Task History'),
176 itemId: 'tasks',
177 xtype: 'pveNodeTasks',
178 iconCls: 'fa fa-list',
179 vmidFilter: vmid
180 }
181 );
182
156095db
DM
183 if (caps.vms['VM.Monitor'] && !template) {
184 me.items.push({
185 title: gettext('Monitor'),
c284be32 186 iconCls: 'fa fa-eye',
156095db
DM
187 itemId: 'monitor',
188 xtype: 'pveQemuMonitor'
189 });
190 }
191
192 if (caps.vms['VM.Backup']) {
193 me.items.push({
194 title: gettext('Backup'),
c284be32 195 iconCls: 'fa fa-floppy-o',
156095db
DM
196 xtype: 'pveBackupView',
197 itemId: 'backup'
198 });
199 }
200
4a01bc83 201 if (caps.vms['VM.Snapshot'] && !template) {
156095db
DM
202 me.items.push({
203 title: gettext('Snapshots'),
c284be32 204 iconCls: 'fa fa-history',
156095db
DM
205 xtype: 'pveQemuSnapshotTree',
206 itemId: 'snapshot'
207 });
208 }
209
156095db 210 if (caps.vms['VM.Console']) {
a2f35eb2 211 me.items.push(
156095db 212 {
c284be32 213 xtype: 'pveFirewallRules',
156095db 214 title: gettext('Firewall'),
c284be32
DC
215 iconCls: 'fa fa-shield',
216 allow_iface: true,
217 base_url: base_url + '/firewall/rules',
816b62b0 218 list_refs_url: base_url + '/firewall/refs',
156095db 219 itemId: 'firewall'
c284be32
DC
220 },
221 {
222 xtype: 'pveFirewallOptions',
223 groups: ['firewall'],
224 iconCls: 'fa fa-gear',
c8802a60 225 onlineHelp: 'pve_firewall_vm_container_configuration',
c284be32
DC
226 title: gettext('Options'),
227 base_url: base_url + '/firewall/options',
228 fwtype: 'vm',
229 itemId: 'firewall-options'
230 },
231 {
232 xtype: 'pveFirewallAliases',
233 title: gettext('Alias'),
234 groups: ['firewall'],
235 iconCls: 'fa fa-external-link',
236 base_url: base_url + '/firewall/aliases',
237 itemId: 'firewall-aliases'
238 },
239 {
240 xtype: 'pveIPSet',
241 title: gettext('IPSet'),
242 groups: ['firewall'],
243 iconCls: 'fa fa-list-ol',
244 base_url: base_url + '/firewall/ipset',
816b62b0 245 list_refs_url: base_url + '/firewall/refs',
c284be32
DC
246 itemId: 'firewall-ipset'
247 },
248 {
249 title: gettext('Log'),
250 groups: ['firewall'],
251 iconCls: 'fa fa-list',
c8802a60 252 onlineHelp: 'chapter_pve_firewall',
c284be32
DC
253 itemId: 'firewall-fwlog',
254 xtype: 'pveLogView',
255 url: '/api2/extjs' + base_url + '/firewall/log'
156095db 256 }
a2f35eb2 257 );
156095db
DM
258 }
259
260 if (caps.vms['Permissions.Modify']) {
261 me.items.push({
262 xtype: 'pveACLView',
263 title: gettext('Permissions'),
c284be32 264 iconCls: 'fa fa-unlock',
156095db
DM
265 itemId: 'permissions',
266 path: '/vms/' + vmid
267 });
268 }
c5ccc8d0 269
156095db
DM
270 me.callParent();
271
540fdc8b 272 me.mon(me.statusStore, 'load', function(s, records, success) {
156095db
DM
273 var status;
274 var qmpstatus;
275 var spice = false;
276
277 if (!success) {
278 me.workspace.checkVmMigration(me.pveSelNode);
279 status = qmpstatus = 'unknown';
280 } else {
281 var rec = s.data.get('status');
282 status = rec ? rec.data.value : 'unknown';
283 rec = s.data.get('qmpstatus');
284 qmpstatus = rec ? rec.data.value : 'unknown';
285 rec = s.data.get('template');
2a727273
DM
286 template = rec.data.value || false;
287
156095db
DM
288 spice = s.data.get('spice') ? true : false;
289
290 }
291
292 if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') {
293 startBtn.setVisible(false);
294 resumeBtn.setVisible(true);
295 } else {
296 startBtn.setVisible(true);
297 resumeBtn.setVisible(false);
298 }
299
300 consoleBtn.setEnableSpice(spice);
301
302 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
303 resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running' || template);
304 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
156095db 305 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
4365549d 306 consoleBtn.setDisabled(template);
156095db
DM
307 });
308
309 me.on('afterrender', function() {
310 me.statusStore.startUpdate();
311 });
312
313 me.on('destroy', function() {
314 me.statusStore.stopUpdate();
315 });
316 }
317});