]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
1 Ext
.define('PVE.qemu.Config', {
2 extend
: 'PVE.panel.Config',
3 alias
: 'widget.PVE.qemu.Config',
5 onlineHelp
: 'chapter_virtual_machines',
7 initComponent: function() {
9 var vm
= me
.pveSelNode
.data
;
11 var nodename
= vm
.node
;
13 throw "no node name specified";
18 throw "no VM ID specified";
21 var template
= !!vm
.template
;
23 var running
= !!vm
.uptime
;
25 var caps
= Ext
.state
.Manager
.get('GuiCap');
27 var base_url
= '/nodes/' + nodename
+ "/qemu/" + vmid
;
29 me
.statusStore
= Ext
.create('Proxmox.data.ObjectStore', {
30 url
: '/api2/json' + base_url
+ '/status/current',
34 var vm_command = function(cmd
, params
) {
35 Proxmox
.Utils
.API2Request({
37 url
: base_url
+ '/status/' + cmd
,
40 failure: function(response
, opts
) {
41 Ext
.Msg
.alert('Error', response
.htmlStatus
);
46 var resumeBtn
= Ext
.create('Ext.Button', {
47 text
: gettext('Resume'),
48 disabled
: !caps
.vms
['VM.PowerMgmt'],
53 iconCls
: 'fa fa-play',
56 var startBtn
= Ext
.create('Ext.Button', {
57 text
: gettext('Start'),
58 disabled
: !caps
.vms
['VM.PowerMgmt'] || running
,
63 iconCls
: 'fa fa-play',
66 var migrateBtn
= Ext
.create('Ext.Button', {
67 text
: gettext('Migrate'),
68 disabled
: !caps
.vms
['VM.Migrate'],
69 hidden
: PVE
.data
.ResourceStore
.getNodes().length
< 2,
71 var win
= Ext
.create('PVE.window.Migrate', {
78 iconCls
: 'fa fa-send-o',
81 var moreBtn
= Ext
.create('Proxmox.button.Button', {
82 text
: gettext('More'),
86 text
: gettext('Clone'),
87 iconCls
: 'fa fa-fw fa-clone',
88 hidden
: !caps
.vms
['VM.Clone'],
90 PVE
.window
.Clone
.wrap(nodename
, vmid
, template
, 'qemu');
94 text
: gettext('Convert to template'),
97 iconCls
: 'fa fa-fw fa-file-o',
98 hidden
: !caps
.vms
['VM.Allocate'],
99 confirmMsg
: Proxmox
.Utils
.format_task_description('qmtemplate', vmid
),
100 handler: function() {
101 Proxmox
.Utils
.API2Request({
102 url
: base_url
+ '/template',
105 failure: function(response
, opts
) {
106 Ext
.Msg
.alert('Error', response
.htmlStatus
);
112 iconCls
: 'fa fa-heartbeat ',
113 hidden
: !caps
.nodes
['Sys.Console'],
114 text
: gettext('Manage HA'),
115 handler: function() {
117 Ext
.create('PVE.ha.VMResourceEdit', {
119 isCreate
: !ha
|| ha
=== 'unmanaged',
124 text
: gettext('Remove'),
126 disabled
: !caps
.vms
['VM.Allocate'],
127 handler: function() {
128 Ext
.create('PVE.window.SafeDestroy', {
130 item
: { type
: 'VM', id
: vmid
},
133 iconCls
: 'fa fa-trash-o',
139 var shutdownBtn
= Ext
.create('PVE.button.Split', {
140 text
: gettext('Shutdown'),
141 disabled
: !caps
.vms
['VM.PowerMgmt'] || !running
,
143 confirmMsg
: Proxmox
.Utils
.format_task_description('qmshutdown', vmid
),
144 handler: function() {
145 vm_command('shutdown');
149 text
: gettext('Reboot'),
150 disabled
: !caps
.vms
['VM.PowerMgmt'],
151 tooltip
: Ext
.String
.format(gettext('Shutdown, apply pending changes and reboot {0}'), 'VM'),
152 confirmMsg
: Proxmox
.Utils
.format_task_description('qmreboot', vmid
),
153 handler: function() {
154 vm_command("reboot");
156 iconCls
: 'fa fa-refresh',
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");
164 iconCls
: 'fa fa-pause',
166 text
: gettext('Hibernate'),
167 disabled
: !caps
.vms
['VM.PowerMgmt'],
168 confirmMsg
: Proxmox
.Utils
.format_task_description('qmsuspend', vmid
),
169 tooltip
: gettext('Suspend to disk'),
170 handler: function() {
171 vm_command("suspend", { todisk
: 1 });
173 iconCls
: 'fa fa-download',
175 text
: gettext('Stop'),
176 disabled
: !caps
.vms
['VM.PowerMgmt'],
178 tooltip
: Ext
.String
.format(gettext('Stop {0} immediately'), 'VM'),
179 confirmMsg
: Proxmox
.Utils
.format_task_description('qmstop', vmid
),
180 handler: function() {
181 vm_command("stop", { timeout
: 30 });
183 iconCls
: 'fa fa-stop',
185 text
: gettext('Reset'),
186 disabled
: !caps
.vms
['VM.PowerMgmt'],
187 tooltip
: Ext
.String
.format(gettext('Reset {0} immediately'), 'VM'),
188 confirmMsg
: Proxmox
.Utils
.format_task_description('qmreset', vmid
),
189 handler: function() {
192 iconCls
: 'fa fa-bolt',
195 iconCls
: 'fa fa-power-off',
198 var consoleBtn
= Ext
.create('PVE.button.ConsoleButton', {
199 disabled
: !caps
.vms
['VM.Console'],
203 enableXtermjs
: false,
204 consoleName
: vm
.name
,
209 var statusTxt
= Ext
.create('Ext.toolbar.TextItem', {
215 '<i class="fa fa-lg fa-lock"></i> ({lock})',
221 title
: Ext
.String
.format(gettext("Virtual Machine {0} on node '{1}'"), vm
.text
, nodename
),
224 tbar
: [statusTxt
, '->', resumeBtn
, startBtn
, shutdownBtn
, migrateBtn
, consoleBtn
, moreBtn
],
225 defaults
: { statusStore
: me
.statusStore
},
228 title
: gettext('Summary'),
229 xtype
: 'pveGuestSummary',
230 iconCls
: 'fa fa-book',
236 if (caps
.vms
['VM.Console'] && !template
) {
238 title
: gettext('Console'),
240 iconCls
: 'fa fa-terminal',
241 xtype
: 'pveNoVncConsole',
250 title
: gettext('Hardware'),
252 iconCls
: 'fa fa-desktop',
253 xtype
: 'PVE.qemu.HardwareView',
258 iconCls
: 'fa fa-cloud',
262 title
: gettext('Options'),
263 iconCls
: 'fa fa-gear',
265 xtype
: 'PVE.qemu.Options',
268 title
: gettext('Task History'),
270 xtype
: 'proxmoxNodeTasks',
271 iconCls
: 'fa fa-list',
277 if (caps
.vms
['VM.Monitor'] && !template
) {
279 title
: gettext('Monitor'),
280 iconCls
: 'fa fa-eye',
282 xtype
: 'pveQemuMonitor',
286 if (caps
.vms
['VM.Backup']) {
288 title
: gettext('Backup'),
289 iconCls
: 'fa fa-floppy-o',
290 xtype
: 'pveBackupView',
294 title
: gettext('Replication'),
295 iconCls
: 'fa fa-retweet',
296 xtype
: 'pveReplicaView',
297 itemId
: 'replication',
301 if ((caps
.vms
['VM.Snapshot'] || caps
.vms
['VM.Snapshot.Rollback'] ||
302 caps
.vms
['VM.Audit']) && !template
) {
304 title
: gettext('Snapshots'),
305 iconCls
: 'fa fa-history',
307 xtype
: 'pveGuestSnapshotTree',
312 if (caps
.vms
['VM.Console']) {
315 xtype
: 'pveFirewallRules',
316 title
: gettext('Firewall'),
317 iconCls
: 'fa fa-shield',
319 base_url
: base_url
+ '/firewall/rules',
320 list_refs_url
: base_url
+ '/firewall/refs',
324 xtype
: 'pveFirewallOptions',
325 groups
: ['firewall'],
326 iconCls
: 'fa fa-gear',
327 onlineHelp
: 'pve_firewall_vm_container_configuration',
328 title
: gettext('Options'),
329 base_url
: base_url
+ '/firewall/options',
331 itemId
: 'firewall-options',
334 xtype
: 'pveFirewallAliases',
335 title
: gettext('Alias'),
336 groups
: ['firewall'],
337 iconCls
: 'fa fa-external-link',
338 base_url
: base_url
+ '/firewall/aliases',
339 itemId
: 'firewall-aliases',
343 title
: gettext('IPSet'),
344 groups
: ['firewall'],
345 iconCls
: 'fa fa-list-ol',
346 base_url
: base_url
+ '/firewall/ipset',
347 list_refs_url
: base_url
+ '/firewall/refs',
348 itemId
: 'firewall-ipset',
351 title
: gettext('Log'),
352 groups
: ['firewall'],
353 iconCls
: 'fa fa-list',
354 onlineHelp
: 'chapter_pve_firewall',
355 itemId
: 'firewall-fwlog',
356 xtype
: 'proxmoxLogView',
357 url
: '/api2/extjs' + base_url
+ '/firewall/log',
362 if (caps
.vms
['Permissions.Modify']) {
365 title
: gettext('Permissions'),
366 iconCls
: 'fa fa-unlock',
367 itemId
: 'permissions',
368 path
: '/vms/' + vmid
,
374 var prevQMPStatus
= 'unknown';
375 me
.mon(me
.statusStore
, 'load', function(s
, records
, success
) {
383 status
= qmpstatus
= 'unknown';
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');
390 template
= rec
? rec
.data
.value
: false;
391 rec
= s
.data
.get('lock');
392 lock
= rec
? rec
.data
.value
: undefined;
394 spice
= !!s
.data
.get('spice');
395 xtermjs
= !!s
.data
.get('serial');
402 var resume
= ['prelaunch', 'paused', 'suspended'].indexOf(qmpstatus
) !== -1;
404 if (resume
|| lock
=== 'suspended') {
405 startBtn
.setVisible(false);
406 resumeBtn
.setVisible(true);
408 startBtn
.setVisible(true);
409 resumeBtn
.setVisible(false);
412 consoleBtn
.setEnableSpice(spice
);
413 consoleBtn
.setEnableXtermJS(xtermjs
);
415 statusTxt
.update({ lock
: lock
});
417 let guest_running
= status
=== 'running' &&
418 !(qmpstatus
=== "shutdown" || qmpstatus
=== "prelaunch");
419 startBtn
.setDisabled(!caps
.vms
['VM.PowerMgmt'] || template
|| guest_running
);
421 shutdownBtn
.setDisabled(!caps
.vms
['VM.PowerMgmt'] || status
!== 'running');
422 me
.down('#removeBtn').setDisabled(!caps
.vms
['VM.Allocate'] || status
!== 'stopped');
423 consoleBtn
.setDisabled(template
);
425 let wasStopped
= ['prelaunch', 'stopped', 'suspended'].indexOf(prevQMPStatus
) !== -1;
426 if (wasStopped
&& qmpstatus
=== 'running') {
427 let con
= me
.down('#console');
433 prevQMPStatus
= qmpstatus
;
436 me
.on('afterrender', function() {
437 me
.statusStore
.startUpdate();
440 me
.on('destroy', function() {
441 me
.statusStore
.stopUpdate();