]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/qemu/Config.js
lxc: disable console button for templates
[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
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 }
540fdc8b 17
156095db
DM
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;
540fdc8b 23
156095db
DM
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
540fdc8b 41 var resumeBtn = Ext.create('Ext.Button', {
156095db
DM
42 text: gettext('Resume'),
43 disabled: !caps.vms['VM.PowerMgmt'],
44 visible: false,
45 handler: function() {
46 vm_command('resume');
540fdc8b
DC
47 }
48 });
156095db 49
540fdc8b 50 var startBtn = Ext.create('Ext.Button', {
156095db
DM
51 text: gettext('Start'),
52 disabled: !caps.vms['VM.PowerMgmt'],
53 handler: function() {
54 vm_command('start');
540fdc8b
DC
55 }
56 });
57
156095db
DM
58 var stopBtn = Ext.create('PVE.button.Button', {
59 text: gettext('Stop'),
60 disabled: !caps.vms['VM.PowerMgmt'],
61 confirmMsg: Ext.String.format(gettext("Do you really want to stop VM {0}?"), vmid),
62 handler: function() {
63 vm_command("stop", { timeout: 30 });
64 }
65 });
66
540fdc8b 67 var migrateBtn = Ext.create('Ext.Button', {
156095db
DM
68 text: gettext('Migrate'),
69 disabled: !caps.vms['VM.Migrate'],
70 handler: function() {
71 var win = Ext.create('PVE.window.Migrate', {
72 vmtype: 'qemu',
73 nodename: nodename,
74 vmid: vmid
75 });
76 win.show();
540fdc8b 77 }
156095db 78 });
540fdc8b 79
156095db
DM
80 var resetBtn = Ext.create('PVE.button.Button', {
81 text: gettext('Reset'),
82 disabled: !caps.vms['VM.PowerMgmt'],
83 confirmMsg: Ext.String.format(gettext("Do you really want to reset VM {0}?"), vmid),
540fdc8b 84 handler: function() {
156095db
DM
85 vm_command("reset");
86 }
87 });
88
89 var shutdownBtn = Ext.create('PVE.button.Button', {
90 text: gettext('Shutdown'),
91 disabled: !caps.vms['VM.PowerMgmt'],
92 confirmMsg: Ext.String.format(gettext("Do you really want to shutdown VM {0}?"), vmid),
93 handler: function() {
94 vm_command('shutdown');
540fdc8b 95 }
156095db
DM
96 });
97
98 var removeBtn = Ext.create('PVE.button.Button', {
99 text: gettext('Remove'),
100 disabled: !caps.vms['VM.Allocate'],
156095db 101 handler: function() {
32f469f3 102 Ext.create('PVE.window.SafeDestroy', {
bcecf280
DM
103 url: base_url,
104 item: { type: 'VM', id: vmid }
32f469f3 105 }).show();
540fdc8b 106 }
156095db
DM
107 });
108
109 var vmname = me.pveSelNode.data.name;
110
111 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
112 disabled: !caps.vms['VM.Console'],
113 consoleType: 'kvm',
114 consoleName: vmname,
115 nodename: nodename,
116 vmid: vmid
117 });
118
119 var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'VM " + vmid + "'") + ")";
120
121 Ext.apply(me, {
122 title: Ext.String.format(gettext("Virtual Machine {0} on node {1}"), descr, "'" + nodename + "'"),
123 hstateid: 'kvmtab',
540fdc8b 124 tbar: [ resumeBtn, startBtn, shutdownBtn, stopBtn, resetBtn,
156095db
DM
125 removeBtn, migrateBtn, consoleBtn],
126 defaults: { statusStore: me.statusStore },
127 items: [
128 {
6f68dcbe
EK
129 title: gettext('Summary'),
130 xtype: 'pveQemuSummary',
156095db 131 itemId: 'summary'
45b473c6 132 },
156095db
DM
133 {
134 title: gettext('Hardware'),
135 itemId: 'hardware',
136 xtype: 'PVE.qemu.HardwareView'
137 },
138 {
139 title: gettext('Options'),
140 itemId: 'options',
141 xtype: 'PVE.qemu.Options'
142 },
143 {
144 title: gettext('Task History'),
145 itemId: 'tasks',
146 xtype: 'pveNodeTasks',
147 vmidFilter: vmid
148 }
149 ]
150 });
c5ccc8d0 151
156095db
DM
152 if (caps.vms['VM.Monitor'] && !template) {
153 me.items.push({
154 title: gettext('Monitor'),
155 itemId: 'monitor',
156 xtype: 'pveQemuMonitor'
157 });
158 }
159
160 if (caps.vms['VM.Backup']) {
161 me.items.push({
162 title: gettext('Backup'),
163 xtype: 'pveBackupView',
164 itemId: 'backup'
165 });
166 }
167
168 if (caps.vms['VM.Snapshot']) {
169 me.items.push({
170 title: gettext('Snapshots'),
171 xtype: 'pveQemuSnapshotTree',
172 itemId: 'snapshot'
173 });
174 }
175
176 if (caps.vms['VM.Console'] && !template) {
177 me.items.push({
178 title: gettext('Console'),
179 itemId: 'console',
180 xtype: 'pveNoVncConsole',
181 vmid: vmid,
182 consoleType: 'kvm',
183 nodename: nodename
184 });
185 }
186
187 if (caps.vms['VM.Console']) {
a2f35eb2 188 me.items.push(
156095db
DM
189 {
190 xtype: 'pveFirewallPanel',
191 title: gettext('Firewall'),
192 base_url: base_url + '/firewall',
193 fwtype: 'vm',
194 phstateid: me.hstateid,
195 itemId: 'firewall'
196 }
a2f35eb2 197 );
156095db
DM
198 }
199
200 if (caps.vms['Permissions.Modify']) {
201 me.items.push({
202 xtype: 'pveACLView',
203 title: gettext('Permissions'),
204 itemId: 'permissions',
205 path: '/vms/' + vmid
206 });
207 }
c5ccc8d0 208
156095db
DM
209 me.callParent();
210
540fdc8b 211 me.mon(me.statusStore, 'load', function(s, records, success) {
156095db
DM
212 var status;
213 var qmpstatus;
214 var spice = false;
215
216 if (!success) {
217 me.workspace.checkVmMigration(me.pveSelNode);
218 status = qmpstatus = 'unknown';
219 } else {
220 var rec = s.data.get('status');
221 status = rec ? rec.data.value : 'unknown';
222 rec = s.data.get('qmpstatus');
223 qmpstatus = rec ? rec.data.value : 'unknown';
224 rec = s.data.get('template');
225 if(rec.data.value){
226 template = rec.data.value;
227 }
228 spice = s.data.get('spice') ? true : false;
229
230 }
231
232 if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') {
233 startBtn.setVisible(false);
234 resumeBtn.setVisible(true);
235 } else {
236 startBtn.setVisible(true);
237 resumeBtn.setVisible(false);
238 }
239
240 consoleBtn.setEnableSpice(spice);
241
242 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
243 resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running' || template);
244 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
245 stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped');
246 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
4365549d 247 consoleBtn.setDisabled(template);
156095db
DM
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});