]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
use split button for shutdown/stop for vm/ct
[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 hidden: true,
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 migrateBtn = Ext.create('Ext.Button', {
59 text: gettext('Migrate'),
60 disabled: !caps.vms['VM.Migrate'],
61 handler: function() {
62 var win = Ext.create('PVE.window.Migrate', {
63 vmtype: 'qemu',
64 nodename: nodename,
65 vmid: vmid
66 });
67 win.show();
68 }
69 });
70
71 var resetBtn = Ext.create('PVE.button.Button', {
72 text: gettext('Reset'),
73 disabled: !caps.vms['VM.PowerMgmt'],
74 confirmMsg: PVE.Utils.format_task_description('qmreset', vmid),
75 handler: function() {
76 vm_command("reset");
77 }
78 });
79
80 var shutdownBtn = Ext.create('PVE.button.Split', {
81 text: gettext('Shutdown'),
82 disabled: !caps.vms['VM.PowerMgmt'],
83 confirmMsg: PVE.Utils.format_task_description('qmshutdown', vmid),
84 handler: function() {
85 vm_command('shutdown');
86 },
87 menu: {
88 items: [{
89 text: gettext('Stop'),
90 disabled: !caps.vms['VM.PowerMgmt'],
91 dangerous: true,
92 confirmMsg: PVE.Utils.format_task_description('qmstop', vmid),
93 handler: function() {
94 vm_command("stop", { timeout: 30 });
95 }
96 }]
97 }
98 });
99
100 var removeBtn = Ext.create('PVE.button.Button', {
101 text: gettext('Remove'),
102 disabled: !caps.vms['VM.Allocate'],
103 handler: function() {
104 Ext.create('PVE.window.SafeDestroy', {
105 url: base_url,
106 item: { type: 'VM', id: vmid }
107 }).show();
108 }
109 });
110
111 var vmname = me.pveSelNode.data.name;
112
113 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
114 disabled: !caps.vms['VM.Console'],
115 consoleType: 'kvm',
116 consoleName: vmname,
117 nodename: nodename,
118 vmid: vmid
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, 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 title: gettext('Task History'),
147 itemId: 'tasks',
148 xtype: 'pveNodeTasks',
149 vmidFilter: vmid
150 }
151 ]
152 });
153
154 if (caps.vms['VM.Monitor'] && !template) {
155 me.items.push({
156 title: gettext('Monitor'),
157 itemId: 'monitor',
158 xtype: 'pveQemuMonitor'
159 });
160 }
161
162 if (caps.vms['VM.Backup']) {
163 me.items.push({
164 title: gettext('Backup'),
165 xtype: 'pveBackupView',
166 itemId: 'backup'
167 });
168 }
169
170 if (caps.vms['VM.Snapshot']) {
171 me.items.push({
172 title: gettext('Snapshots'),
173 xtype: 'pveQemuSnapshotTree',
174 itemId: 'snapshot'
175 });
176 }
177
178 if (caps.vms['VM.Console'] && !template) {
179 me.items.push({
180 title: gettext('Console'),
181 itemId: 'console',
182 xtype: 'pveNoVncConsole',
183 vmid: vmid,
184 consoleType: 'kvm',
185 nodename: nodename
186 });
187 }
188
189 if (caps.vms['VM.Console']) {
190 me.items.push(
191 {
192 xtype: 'pveFirewallPanel',
193 title: gettext('Firewall'),
194 base_url: base_url + '/firewall',
195 fwtype: 'vm',
196 phstateid: me.hstateid,
197 itemId: 'firewall'
198 }
199 );
200 }
201
202 if (caps.vms['Permissions.Modify']) {
203 me.items.push({
204 xtype: 'pveACLView',
205 title: gettext('Permissions'),
206 itemId: 'permissions',
207 path: '/vms/' + vmid
208 });
209 }
210
211 me.callParent();
212
213 me.mon(me.statusStore, 'load', function(s, records, success) {
214 var status;
215 var qmpstatus;
216 var spice = false;
217
218 if (!success) {
219 me.workspace.checkVmMigration(me.pveSelNode);
220 status = qmpstatus = 'unknown';
221 } else {
222 var rec = s.data.get('status');
223 status = rec ? rec.data.value : 'unknown';
224 rec = s.data.get('qmpstatus');
225 qmpstatus = rec ? rec.data.value : 'unknown';
226 rec = s.data.get('template');
227 template = rec.data.value || false;
228
229 spice = s.data.get('spice') ? true : false;
230
231 }
232
233 if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') {
234 startBtn.setVisible(false);
235 resumeBtn.setVisible(true);
236 } else {
237 startBtn.setVisible(true);
238 resumeBtn.setVisible(false);
239 }
240
241 consoleBtn.setEnableSpice(spice);
242
243 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
244 resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running' || template);
245 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
246 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
247 consoleBtn.setDisabled(template);
248 });
249
250 me.on('afterrender', function() {
251 me.statusStore.startUpdate();
252 });
253
254 me.on('destroy', function() {
255 me.statusStore.stopUpdate();
256 });
257 }
258 });