]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
gui: show lock in status bar of vms/cts
[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 onlineHelp: 'chapter_virtual_machines',
6
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 }
19
20 var template = !!me.pveSelNode.data.template;
21
22 var running = !!me.pveSelNode.data.uptime;
23
24 var caps = Ext.state.Manager.get('GuiCap');
25
26 var base_url = '/nodes/' + nodename + "/qemu/" + vmid;
27
28 me.statusStore = Ext.create('Proxmox.data.ObjectStore', {
29 url: '/api2/json' + base_url + '/status/current',
30 interval: 1000
31 });
32
33 var vm_command = function(cmd, params) {
34 Proxmox.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
45 var resumeBtn = Ext.create('Ext.Button', {
46 text: gettext('Resume'),
47 disabled: !caps.vms['VM.PowerMgmt'],
48 hidden: true,
49 handler: function() {
50 vm_command('resume');
51 },
52 iconCls: 'fa fa-play'
53 });
54
55 var startBtn = Ext.create('Ext.Button', {
56 text: gettext('Start'),
57 disabled: !caps.vms['VM.PowerMgmt'] || running,
58 hidden: template,
59 handler: function() {
60 vm_command('start');
61 },
62 iconCls: 'fa fa-play'
63 });
64
65 var migrateBtn = Ext.create('Ext.Button', {
66 text: gettext('Migrate'),
67 disabled: !caps.vms['VM.Migrate'],
68 hidden: PVE.data.ResourceStore.getNodes().length < 2,
69 handler: function() {
70 var win = Ext.create('PVE.window.Migrate', {
71 vmtype: 'qemu',
72 nodename: nodename,
73 vmid: vmid
74 });
75 win.show();
76 },
77 iconCls: 'fa fa-send-o'
78 });
79
80 var moreBtn = Ext.create('Proxmox.button.Button', {
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, 'qemu');
89 }
90 },
91 {
92 text: gettext('Convert to template'),
93 disabled: template,
94 xtype: 'pveMenuItem',
95 iconCls: 'fa fa-fw fa-file-o',
96 hidden: caps.vms['VM.Allocate'] ? false : true,
97 confirmMsg: Proxmox.Utils.format_task_description('qmtemplate', vmid),
98 handler: function() {
99 Proxmox.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 }
108 },
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 },
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 ]}
134 });
135
136 var shutdownBtn = Ext.create('PVE.button.Split', {
137 text: gettext('Shutdown'),
138 disabled: !caps.vms['VM.PowerMgmt'] || !running,
139 hidden: template,
140 confirmMsg: Proxmox.Utils.format_task_description('qmshutdown', vmid),
141 handler: function() {
142 vm_command('shutdown');
143 },
144 menu: {
145 items: [{
146 text: gettext('Stop'),
147 disabled: !caps.vms['VM.PowerMgmt'],
148 dangerous: true,
149 confirmMsg: Proxmox.Utils.format_task_description('qmstop', vmid),
150 handler: function() {
151 vm_command("stop", { timeout: 30 });
152 },
153 iconCls: 'fa fa-stop'
154 },{
155 text: gettext('Reset'),
156 disabled: !caps.vms['VM.PowerMgmt'],
157 confirmMsg: Proxmox.Utils.format_task_description('qmreset', vmid),
158 handler: function() {
159 vm_command("reset");
160 },
161 iconCls: 'fa fa-bolt'
162 }]
163 },
164 iconCls: 'fa fa-power-off'
165 });
166
167 var vm = me.pveSelNode.data;
168
169 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
170 disabled: !caps.vms['VM.Console'],
171 hidden: template,
172 consoleType: 'kvm',
173 consoleName: vm.name,
174 nodename: nodename,
175 vmid: vmid
176 });
177
178 var statusTxt = Ext.create('Ext.toolbar.TextItem', {
179 data: {
180 lock: undefined
181 },
182 tpl: [
183 '<tpl if="lock">',
184 '<i class="fa fa-lg fa-lock"></i> ({lock})',
185 '</tpl>'
186 ]
187 });
188
189 Ext.apply(me, {
190 title: Ext.String.format(gettext("Virtual Machine {0} on node '{1}'"), vm.text, nodename),
191 hstateid: 'kvmtab',
192 tbarSpacing: false,
193 tbar: [ statusTxt, '->', resumeBtn, startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn ],
194 defaults: { statusStore: me.statusStore },
195 items: [
196 {
197 title: gettext('Summary'),
198 xtype: 'pveQemuSummary',
199 iconCls: 'fa fa-book',
200 itemId: 'summary'
201 }
202 ]
203 });
204
205 if (caps.vms['VM.Console'] && !template) {
206 me.items.push({
207 title: gettext('Console'),
208 itemId: 'console',
209 iconCls: 'fa fa-terminal',
210 xtype: 'pveNoVncConsole',
211 vmid: vmid,
212 consoleType: 'kvm',
213 nodename: nodename
214 });
215 }
216
217 me.items.push(
218 {
219 title: gettext('Hardware'),
220 itemId: 'hardware',
221 iconCls: 'fa fa-desktop',
222 xtype: 'PVE.qemu.HardwareView'
223 },
224 {
225 title: 'Cloud-Init',
226 itemId: 'cloudinit',
227 iconCls: 'fa fa-cloud',
228 xtype: 'pveCiPanel'
229 },
230 {
231 title: gettext('Options'),
232 iconCls: 'fa fa-gear',
233 itemId: 'options',
234 xtype: 'PVE.qemu.Options'
235 },
236 {
237 title: gettext('Task History'),
238 itemId: 'tasks',
239 xtype: 'proxmoxNodeTasks',
240 iconCls: 'fa fa-list',
241 nodename: nodename,
242 vmidFilter: vmid
243 }
244 );
245
246 if (caps.vms['VM.Monitor'] && !template) {
247 me.items.push({
248 title: gettext('Monitor'),
249 iconCls: 'fa fa-eye',
250 itemId: 'monitor',
251 xtype: 'pveQemuMonitor'
252 });
253 }
254
255 if (caps.vms['VM.Backup']) {
256 me.items.push({
257 title: gettext('Backup'),
258 iconCls: 'fa fa-floppy-o',
259 xtype: 'pveBackupView',
260 itemId: 'backup'
261 },
262 {
263 title: gettext('Replication'),
264 iconCls: 'fa fa-retweet',
265 xtype: 'pveReplicaView',
266 itemId: 'replication'
267 });
268 }
269
270 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback']) && !template) {
271 me.items.push({
272 title: gettext('Snapshots'),
273 iconCls: 'fa fa-history',
274 xtype: 'pveQemuSnapshotTree',
275 itemId: 'snapshot'
276 });
277 }
278
279 if (caps.vms['VM.Console']) {
280 me.items.push(
281 {
282 xtype: 'pveFirewallRules',
283 title: gettext('Firewall'),
284 iconCls: 'fa fa-shield',
285 allow_iface: true,
286 base_url: base_url + '/firewall/rules',
287 list_refs_url: base_url + '/firewall/refs',
288 itemId: 'firewall'
289 },
290 {
291 xtype: 'pveFirewallOptions',
292 groups: ['firewall'],
293 iconCls: 'fa fa-gear',
294 onlineHelp: 'pve_firewall_vm_container_configuration',
295 title: gettext('Options'),
296 base_url: base_url + '/firewall/options',
297 fwtype: 'vm',
298 itemId: 'firewall-options'
299 },
300 {
301 xtype: 'pveFirewallAliases',
302 title: gettext('Alias'),
303 groups: ['firewall'],
304 iconCls: 'fa fa-external-link',
305 base_url: base_url + '/firewall/aliases',
306 itemId: 'firewall-aliases'
307 },
308 {
309 xtype: 'pveIPSet',
310 title: gettext('IPSet'),
311 groups: ['firewall'],
312 iconCls: 'fa fa-list-ol',
313 base_url: base_url + '/firewall/ipset',
314 list_refs_url: base_url + '/firewall/refs',
315 itemId: 'firewall-ipset'
316 },
317 {
318 title: gettext('Log'),
319 groups: ['firewall'],
320 iconCls: 'fa fa-list',
321 onlineHelp: 'chapter_pve_firewall',
322 itemId: 'firewall-fwlog',
323 xtype: 'proxmoxLogView',
324 url: '/api2/extjs' + base_url + '/firewall/log'
325 }
326 );
327 }
328
329 if (caps.vms['Permissions.Modify']) {
330 me.items.push({
331 xtype: 'pveACLView',
332 title: gettext('Permissions'),
333 iconCls: 'fa fa-unlock',
334 itemId: 'permissions',
335 path: '/vms/' + vmid
336 });
337 }
338
339 me.callParent();
340
341 me.mon(me.statusStore, 'load', function(s, records, success) {
342 var status;
343 var qmpstatus;
344 var spice = false;
345 var xtermjs = false;
346 var lock;
347
348 if (!success) {
349 status = qmpstatus = 'unknown';
350 } else {
351 var rec = s.data.get('status');
352 status = rec ? rec.data.value : 'unknown';
353 rec = s.data.get('qmpstatus');
354 qmpstatus = rec ? rec.data.value : 'unknown';
355 rec = s.data.get('template');
356 template = rec.data.value || false;
357 rec = s.data.get('lock');
358 lock = rec ? rec.data.value : undefined;
359
360 spice = s.data.get('spice') ? true : false;
361 xtermjs = s.data.get('serial') ? true : false;
362
363 }
364
365 if (template) {
366 return;
367 }
368
369 if (qmpstatus === 'prelaunch' || qmpstatus === 'paused' || qmpstatus === 'suspended') {
370 startBtn.setVisible(false);
371 resumeBtn.setVisible(true);
372 } else {
373 startBtn.setVisible(true);
374 resumeBtn.setVisible(false);
375 }
376
377 consoleBtn.setEnableSpice(spice);
378 consoleBtn.setEnableXtermJS(xtermjs);
379
380 statusTxt.update({ lock: lock });
381
382 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
383 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
384 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
385 consoleBtn.setDisabled(template);
386 });
387
388 me.on('afterrender', function() {
389 me.statusStore.startUpdate();
390 });
391
392 me.on('destroy', function() {
393 me.statusStore.stopUpdate();
394 });
395 }
396 });