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