]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
ui: tree/ResourceTree: show Tags in tree
[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 userCls: 'proxmox-tags-full',
7
8 initComponent: function() {
9 var me = this;
10 var vm = me.pveSelNode.data;
11
12 var nodename = vm.node;
13 if (!nodename) {
14 throw "no node name specified";
15 }
16
17 var vmid = vm.vmid;
18 if (!vmid) {
19 throw "no VM ID specified";
20 }
21
22 var template = !!vm.template;
23
24 var running = !!vm.uptime;
25
26 var caps = Ext.state.Manager.get('GuiCap');
27
28 var base_url = '/nodes/' + nodename + "/qemu/" + vmid;
29
30 me.statusStore = Ext.create('Proxmox.data.ObjectStore', {
31 url: '/api2/json' + base_url + '/status/current',
32 interval: 1000,
33 });
34
35 var vm_command = function(cmd, params) {
36 Proxmox.Utils.API2Request({
37 params: params,
38 url: base_url + '/status/' + cmd,
39 waitMsgTarget: me,
40 method: 'POST',
41 failure: function(response, opts) {
42 Ext.Msg.alert('Error', response.htmlStatus);
43 },
44 });
45 };
46
47 var resumeBtn = Ext.create('Ext.Button', {
48 text: gettext('Resume'),
49 disabled: !caps.vms['VM.PowerMgmt'],
50 hidden: true,
51 handler: function() {
52 vm_command('resume');
53 },
54 iconCls: 'fa fa-play',
55 });
56
57 var startBtn = Ext.create('Ext.Button', {
58 text: gettext('Start'),
59 disabled: !caps.vms['VM.PowerMgmt'] || running,
60 hidden: template,
61 handler: function() {
62 vm_command('start');
63 },
64 iconCls: 'fa fa-play',
65 });
66
67 var migrateBtn = Ext.create('Ext.Button', {
68 text: gettext('Migrate'),
69 disabled: !caps.vms['VM.Migrate'],
70 hidden: PVE.data.ResourceStore.getNodes().length < 2,
71 handler: function() {
72 var win = Ext.create('PVE.window.Migrate', {
73 vmtype: 'qemu',
74 nodename: nodename,
75 vmid: vmid,
76 });
77 win.show();
78 },
79 iconCls: 'fa fa-send-o',
80 });
81
82 var moreBtn = Ext.create('Proxmox.button.Button', {
83 text: gettext('More'),
84 menu: {
85 items: [
86 {
87 text: gettext('Clone'),
88 iconCls: 'fa fa-fw fa-clone',
89 hidden: !caps.vms['VM.Clone'],
90 handler: function() {
91 PVE.window.Clone.wrap(nodename, vmid, template, 'qemu');
92 },
93 },
94 {
95 text: gettext('Convert to template'),
96 disabled: template,
97 xtype: 'pveMenuItem',
98 iconCls: 'fa fa-fw fa-file-o',
99 hidden: !caps.vms['VM.Allocate'],
100 confirmMsg: Proxmox.Utils.format_task_description('qmtemplate', vmid),
101 handler: function() {
102 Proxmox.Utils.API2Request({
103 url: base_url + '/template',
104 waitMsgTarget: me,
105 method: 'POST',
106 failure: function(response, opts) {
107 Ext.Msg.alert('Error', response.htmlStatus);
108 },
109 });
110 },
111 },
112 {
113 iconCls: 'fa fa-heartbeat ',
114 hidden: !caps.nodes['Sys.Console'],
115 text: gettext('Manage HA'),
116 handler: function() {
117 var ha = vm.hastate;
118 Ext.create('PVE.ha.VMResourceEdit', {
119 vmid: vmid,
120 isCreate: !ha || ha === 'unmanaged',
121 }).show();
122 },
123 },
124 {
125 text: gettext('Remove'),
126 itemId: 'removeBtn',
127 disabled: !caps.vms['VM.Allocate'],
128 handler: function() {
129 Ext.create('PVE.window.SafeDestroyGuest', {
130 url: base_url,
131 item: { type: 'VM', id: vmid },
132 taskName: 'qmdestroy',
133 }).show();
134 },
135 iconCls: 'fa fa-trash-o',
136 },
137 ],
138 },
139 });
140
141 var shutdownBtn = Ext.create('PVE.button.Split', {
142 text: gettext('Shutdown'),
143 disabled: !caps.vms['VM.PowerMgmt'] || !running,
144 hidden: template,
145 confirmMsg: Proxmox.Utils.format_task_description('qmshutdown', vmid),
146 handler: function() {
147 vm_command('shutdown');
148 },
149 menu: {
150 items: [{
151 text: gettext('Reboot'),
152 disabled: !caps.vms['VM.PowerMgmt'],
153 tooltip: Ext.String.format(gettext('Shutdown, apply pending changes and reboot {0}'), 'VM'),
154 confirmMsg: Proxmox.Utils.format_task_description('qmreboot', vmid),
155 handler: function() {
156 vm_command("reboot");
157 },
158 iconCls: 'fa fa-refresh',
159 }, {
160 text: gettext('Pause'),
161 disabled: !caps.vms['VM.PowerMgmt'],
162 confirmMsg: Proxmox.Utils.format_task_description('qmpause', vmid),
163 handler: function() {
164 vm_command("suspend");
165 },
166 iconCls: 'fa fa-pause',
167 }, {
168 text: gettext('Hibernate'),
169 disabled: !caps.vms['VM.PowerMgmt'],
170 confirmMsg: Proxmox.Utils.format_task_description('qmsuspend', vmid),
171 tooltip: gettext('Suspend to disk'),
172 handler: function() {
173 vm_command("suspend", { todisk: 1 });
174 },
175 iconCls: 'fa fa-download',
176 }, {
177 text: gettext('Stop'),
178 disabled: !caps.vms['VM.PowerMgmt'],
179 dangerous: true,
180 tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'VM'),
181 confirmMsg: Proxmox.Utils.format_task_description('qmstop', vmid),
182 handler: function() {
183 vm_command("stop", { timeout: 30 });
184 },
185 iconCls: 'fa fa-stop',
186 }, {
187 text: gettext('Reset'),
188 disabled: !caps.vms['VM.PowerMgmt'],
189 tooltip: Ext.String.format(gettext('Reset {0} immediately'), 'VM'),
190 confirmMsg: Proxmox.Utils.format_task_description('qmreset', vmid),
191 handler: function() {
192 vm_command("reset");
193 },
194 iconCls: 'fa fa-bolt',
195 }],
196 },
197 iconCls: 'fa fa-power-off',
198 });
199
200 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
201 disabled: !caps.vms['VM.Console'],
202 hidden: template,
203 consoleType: 'kvm',
204 // disable spice/xterm for default action until status api call succeeded
205 enableSpice: false,
206 enableXtermjs: false,
207 consoleName: vm.name,
208 nodename: nodename,
209 vmid: vmid,
210 });
211
212 var statusTxt = Ext.create('Ext.toolbar.TextItem', {
213 data: {
214 lock: undefined,
215 },
216 tpl: [
217 '<tpl if="lock">',
218 '<i class="fa fa-lg fa-lock"></i> ({lock})',
219 '</tpl>',
220 ],
221 });
222
223 let tagsContainer = Ext.create('PVE.panel.TagEditContainer', {
224 tags: vm.tags,
225 listeners: {
226 change: function(tags) {
227 Proxmox.Utils.API2Request({
228 url: base_url + '/config',
229 method: 'PUT',
230 params: {
231 tags,
232 },
233 success: function() {
234 me.statusStore.load();
235 },
236 failure: function(response) {
237 Ext.Msg.alert('Error', response.htmlStatus);
238 me.statusStore.load();
239 },
240 });
241 },
242 },
243 });
244
245 let vm_text = `${vm.vmid} (${vm.name})`;
246
247 Ext.apply(me, {
248 title: Ext.String.format(gettext("Virtual Machine {0} on node '{1}'"), vm_text, nodename),
249 hstateid: 'kvmtab',
250 tbarSpacing: false,
251 tbar: [statusTxt, tagsContainer, '->', resumeBtn, startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn],
252 defaults: { statusStore: me.statusStore },
253 items: [
254 {
255 title: gettext('Summary'),
256 xtype: 'pveGuestSummary',
257 iconCls: 'fa fa-book',
258 itemId: 'summary',
259 },
260 ],
261 });
262
263 if (caps.vms['VM.Console'] && !template) {
264 me.items.push({
265 title: gettext('Console'),
266 itemId: 'console',
267 iconCls: 'fa fa-terminal',
268 xtype: 'pveNoVncConsole',
269 vmid: vmid,
270 consoleType: 'kvm',
271 nodename: nodename,
272 });
273 }
274
275 me.items.push(
276 {
277 title: gettext('Hardware'),
278 itemId: 'hardware',
279 iconCls: 'fa fa-desktop',
280 xtype: 'PVE.qemu.HardwareView',
281 },
282 {
283 title: 'Cloud-Init',
284 itemId: 'cloudinit',
285 iconCls: 'fa fa-cloud',
286 xtype: 'pveCiPanel',
287 },
288 {
289 title: gettext('Options'),
290 iconCls: 'fa fa-gear',
291 itemId: 'options',
292 xtype: 'PVE.qemu.Options',
293 },
294 {
295 title: gettext('Task History'),
296 itemId: 'tasks',
297 xtype: 'proxmoxNodeTasks',
298 iconCls: 'fa fa-list-alt',
299 nodename: nodename,
300 preFilter: {
301 vmid,
302 },
303 },
304 );
305
306 if (caps.vms['VM.Monitor'] && !template) {
307 me.items.push({
308 title: gettext('Monitor'),
309 iconCls: 'fa fa-eye',
310 itemId: 'monitor',
311 xtype: 'pveQemuMonitor',
312 });
313 }
314
315 if (caps.vms['VM.Backup']) {
316 me.items.push({
317 title: gettext('Backup'),
318 iconCls: 'fa fa-floppy-o',
319 xtype: 'pveBackupView',
320 itemId: 'backup',
321 },
322 {
323 title: gettext('Replication'),
324 iconCls: 'fa fa-retweet',
325 xtype: 'pveReplicaView',
326 itemId: 'replication',
327 });
328 }
329
330 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback'] ||
331 caps.vms['VM.Audit']) && !template) {
332 me.items.push({
333 title: gettext('Snapshots'),
334 iconCls: 'fa fa-history',
335 type: 'qemu',
336 xtype: 'pveGuestSnapshotTree',
337 itemId: 'snapshot',
338 });
339 }
340
341 if (caps.vms['VM.Console']) {
342 me.items.push(
343 {
344 xtype: 'pveFirewallRules',
345 title: gettext('Firewall'),
346 iconCls: 'fa fa-shield',
347 allow_iface: true,
348 base_url: base_url + '/firewall/rules',
349 list_refs_url: base_url + '/firewall/refs',
350 itemId: 'firewall',
351 },
352 {
353 xtype: 'pveFirewallOptions',
354 groups: ['firewall'],
355 iconCls: 'fa fa-gear',
356 onlineHelp: 'pve_firewall_vm_container_configuration',
357 title: gettext('Options'),
358 base_url: base_url + '/firewall/options',
359 fwtype: 'vm',
360 itemId: 'firewall-options',
361 },
362 {
363 xtype: 'pveFirewallAliases',
364 title: gettext('Alias'),
365 groups: ['firewall'],
366 iconCls: 'fa fa-external-link',
367 base_url: base_url + '/firewall/aliases',
368 itemId: 'firewall-aliases',
369 },
370 {
371 xtype: 'pveIPSet',
372 title: gettext('IPSet'),
373 groups: ['firewall'],
374 iconCls: 'fa fa-list-ol',
375 base_url: base_url + '/firewall/ipset',
376 list_refs_url: base_url + '/firewall/refs',
377 itemId: 'firewall-ipset',
378 },
379 {
380 title: gettext('Log'),
381 groups: ['firewall'],
382 iconCls: 'fa fa-list',
383 onlineHelp: 'chapter_pve_firewall',
384 itemId: 'firewall-fwlog',
385 xtype: 'proxmoxLogView',
386 url: '/api2/extjs' + base_url + '/firewall/log',
387 },
388 );
389 }
390
391 if (caps.vms['Permissions.Modify']) {
392 me.items.push({
393 xtype: 'pveACLView',
394 title: gettext('Permissions'),
395 iconCls: 'fa fa-unlock',
396 itemId: 'permissions',
397 path: '/vms/' + vmid,
398 });
399 }
400
401 me.callParent();
402
403 var prevQMPStatus = 'unknown';
404 me.mon(me.statusStore, 'load', function(s, records, success) {
405 var status;
406 var qmpstatus;
407 var spice = false;
408 var xtermjs = false;
409 var lock;
410 var rec;
411
412 if (!success) {
413 status = qmpstatus = 'unknown';
414 } else {
415 rec = s.data.get('status');
416 status = rec ? rec.data.value : 'unknown';
417 rec = s.data.get('qmpstatus');
418 qmpstatus = rec ? rec.data.value : 'unknown';
419 rec = s.data.get('template');
420 template = rec ? rec.data.value : false;
421 rec = s.data.get('lock');
422 lock = rec ? rec.data.value : undefined;
423
424 spice = !!s.data.get('spice');
425 xtermjs = !!s.data.get('serial');
426 }
427
428 rec = s.data.get('tags');
429 tagsContainer.loadTags(rec?.data?.value);
430
431 if (template) {
432 return;
433 }
434
435 var resume = ['prelaunch', 'paused', 'suspended'].indexOf(qmpstatus) !== -1;
436
437 if (resume || lock === 'suspended') {
438 startBtn.setVisible(false);
439 resumeBtn.setVisible(true);
440 } else {
441 startBtn.setVisible(true);
442 resumeBtn.setVisible(false);
443 }
444
445 consoleBtn.setEnableSpice(spice);
446 consoleBtn.setEnableXtermJS(xtermjs);
447
448 statusTxt.update({ lock: lock });
449
450 let guest_running = status === 'running' &&
451 !(qmpstatus === "shutdown" || qmpstatus === "prelaunch");
452 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || template || guest_running);
453
454 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
455 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
456 consoleBtn.setDisabled(template);
457
458 let wasStopped = ['prelaunch', 'stopped', 'suspended'].indexOf(prevQMPStatus) !== -1;
459 if (wasStopped && qmpstatus === 'running') {
460 let con = me.down('#console');
461 if (con) {
462 con.reload();
463 }
464 }
465
466 prevQMPStatus = qmpstatus;
467 });
468
469 me.on('afterrender', function() {
470 me.statusStore.startUpdate();
471 });
472
473 me.on('destroy', function() {
474 me.statusStore.stopUpdate();
475 });
476 },
477 });