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