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