]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
update shipped appliance info index
[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 canEdit: !!caps.vms['VM.Config.Options'],
226 listeners: {
227 change: function(tags) {
228 Proxmox.Utils.API2Request({
229 url: base_url + '/config',
230 method: 'PUT',
231 params: {
232 tags,
233 },
234 success: function() {
235 me.statusStore.load();
236 },
237 failure: function(response) {
238 Ext.Msg.alert('Error', response.htmlStatus);
239 me.statusStore.load();
240 },
241 });
242 },
243 },
244 });
245
246 let vm_text = `${vm.vmid} (${vm.name})`;
247
248 Ext.apply(me, {
249 title: Ext.String.format(gettext("Virtual Machine {0} on node '{1}'"), vm_text, nodename),
250 hstateid: 'kvmtab',
251 tbarSpacing: false,
252 tbar: [statusTxt, tagsContainer, '->', resumeBtn, startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn],
253 defaults: { statusStore: me.statusStore },
254 items: [
255 {
256 title: gettext('Summary'),
257 xtype: 'pveGuestSummary',
258 iconCls: 'fa fa-book',
259 itemId: 'summary',
260 },
261 ],
262 });
263
264 if (caps.vms['VM.Console'] && !template) {
265 me.items.push({
266 title: gettext('Console'),
267 itemId: 'console',
268 iconCls: 'fa fa-terminal',
269 xtype: 'pveNoVncConsole',
270 vmid: vmid,
271 consoleType: 'kvm',
272 nodename: nodename,
273 });
274 }
275
276 me.items.push(
277 {
278 title: gettext('Hardware'),
279 itemId: 'hardware',
280 iconCls: 'fa fa-desktop',
281 xtype: 'PVE.qemu.HardwareView',
282 },
283 {
284 title: 'Cloud-Init',
285 itemId: 'cloudinit',
286 iconCls: 'fa fa-cloud',
287 xtype: 'pveCiPanel',
288 },
289 {
290 title: gettext('Options'),
291 iconCls: 'fa fa-gear',
292 itemId: 'options',
293 xtype: 'PVE.qemu.Options',
294 },
295 {
296 title: gettext('Task History'),
297 itemId: 'tasks',
298 xtype: 'proxmoxNodeTasks',
299 iconCls: 'fa fa-list-alt',
300 nodename: nodename,
301 preFilter: {
302 vmid,
303 },
304 },
305 );
306
307 if (caps.vms['VM.Monitor'] && !template) {
308 me.items.push({
309 title: gettext('Monitor'),
310 iconCls: 'fa fa-eye',
311 itemId: 'monitor',
312 xtype: 'pveQemuMonitor',
313 });
314 }
315
316 if (caps.vms['VM.Backup']) {
317 me.items.push({
318 title: gettext('Backup'),
319 iconCls: 'fa fa-floppy-o',
320 xtype: 'pveBackupView',
321 itemId: 'backup',
322 },
323 {
324 title: gettext('Replication'),
325 iconCls: 'fa fa-retweet',
326 xtype: 'pveReplicaView',
327 itemId: 'replication',
328 });
329 }
330
331 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback'] ||
332 caps.vms['VM.Audit']) && !template) {
333 me.items.push({
334 title: gettext('Snapshots'),
335 iconCls: 'fa fa-history',
336 type: 'qemu',
337 xtype: 'pveGuestSnapshotTree',
338 itemId: 'snapshot',
339 });
340 }
341
342 if (caps.vms['VM.Console']) {
343 me.items.push(
344 {
345 xtype: 'pveFirewallRules',
346 title: gettext('Firewall'),
347 iconCls: 'fa fa-shield',
348 allow_iface: true,
349 base_url: base_url + '/firewall/rules',
350 list_refs_url: base_url + '/firewall/refs',
351 itemId: 'firewall',
352 },
353 {
354 xtype: 'pveFirewallOptions',
355 groups: ['firewall'],
356 iconCls: 'fa fa-gear',
357 onlineHelp: 'pve_firewall_vm_container_configuration',
358 title: gettext('Options'),
359 base_url: base_url + '/firewall/options',
360 fwtype: 'vm',
361 itemId: 'firewall-options',
362 },
363 {
364 xtype: 'pveFirewallAliases',
365 title: gettext('Alias'),
366 groups: ['firewall'],
367 iconCls: 'fa fa-external-link',
368 base_url: base_url + '/firewall/aliases',
369 itemId: 'firewall-aliases',
370 },
371 {
372 xtype: 'pveIPSet',
373 title: gettext('IPSet'),
374 groups: ['firewall'],
375 iconCls: 'fa fa-list-ol',
376 base_url: base_url + '/firewall/ipset',
377 list_refs_url: base_url + '/firewall/refs',
378 itemId: 'firewall-ipset',
379 },
380 {
381 title: gettext('Log'),
382 groups: ['firewall'],
383 iconCls: 'fa fa-list',
384 onlineHelp: 'chapter_pve_firewall',
385 itemId: 'firewall-fwlog',
386 xtype: 'proxmoxLogView',
387 url: '/api2/extjs' + base_url + '/firewall/log',
388 },
389 );
390 }
391
392 if (caps.vms['Permissions.Modify']) {
393 me.items.push({
394 xtype: 'pveACLView',
395 title: gettext('Permissions'),
396 iconCls: 'fa fa-unlock',
397 itemId: 'permissions',
398 path: '/vms/' + vmid,
399 });
400 }
401
402 me.callParent();
403
404 var prevQMPStatus = 'unknown';
405 me.mon(me.statusStore, 'load', function(s, records, success) {
406 var status;
407 var qmpstatus;
408 var spice = false;
409 var xtermjs = false;
410 var lock;
411 var rec;
412
413 if (!success) {
414 status = qmpstatus = 'unknown';
415 } else {
416 rec = s.data.get('status');
417 status = rec ? rec.data.value : 'unknown';
418 rec = s.data.get('qmpstatus');
419 qmpstatus = rec ? rec.data.value : 'unknown';
420 rec = s.data.get('template');
421 template = rec ? rec.data.value : false;
422 rec = s.data.get('lock');
423 lock = rec ? rec.data.value : undefined;
424
425 spice = !!s.data.get('spice');
426 xtermjs = !!s.data.get('serial');
427 }
428
429 rec = s.data.get('tags');
430 tagsContainer.loadTags(rec?.data?.value);
431
432 if (template) {
433 return;
434 }
435
436 var resume = ['prelaunch', 'paused', 'suspended'].indexOf(qmpstatus) !== -1;
437
438 if (resume || lock === 'suspended') {
439 startBtn.setVisible(false);
440 resumeBtn.setVisible(true);
441 } else {
442 startBtn.setVisible(true);
443 resumeBtn.setVisible(false);
444 }
445
446 consoleBtn.setEnableSpice(spice);
447 consoleBtn.setEnableXtermJS(xtermjs);
448
449 statusTxt.update({ lock: lock });
450
451 let guest_running = status === 'running' &&
452 !(qmpstatus === "shutdown" || qmpstatus === "prelaunch");
453 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || template || guest_running);
454
455 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
456 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
457 consoleBtn.setDisabled(template);
458
459 let wasStopped = ['prelaunch', 'stopped', 'suspended'].indexOf(prevQMPStatus) !== -1;
460 if (wasStopped && qmpstatus === 'running') {
461 let con = me.down('#console');
462 if (con) {
463 con.reload();
464 }
465 }
466
467 prevQMPStatus = qmpstatus;
468 });
469
470 me.on('afterrender', function() {
471 me.statusStore.startUpdate();
472 });
473
474 me.on('destroy', function() {
475 me.statusStore.stopUpdate();
476 });
477 },
478 });