]>
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'],
202 consoleName
: vm
.name
,
207 var statusTxt
= Ext
.create('Ext.toolbar.TextItem', {
213 '<i class="fa fa-lg fa-lock"></i> ({lock})',
219 title
: Ext
.String
.format(gettext("Virtual Machine {0} on node '{1}'"), vm
.text
, nodename
),
222 tbar
: [statusTxt
, '->', resumeBtn
, startBtn
, shutdownBtn
, migrateBtn
, consoleBtn
, moreBtn
],
223 defaults
: { statusStore
: me
.statusStore
},
226 title
: gettext('Summary'),
227 xtype
: 'pveGuestSummary',
228 iconCls
: 'fa fa-book',
234 if (caps
.vms
['VM.Console'] && !template
) {
236 title
: gettext('Console'),
238 iconCls
: 'fa fa-terminal',
239 xtype
: 'pveNoVncConsole',
248 title
: gettext('Hardware'),
250 iconCls
: 'fa fa-desktop',
251 xtype
: 'PVE.qemu.HardwareView',
256 iconCls
: 'fa fa-cloud',
260 title
: gettext('Options'),
261 iconCls
: 'fa fa-gear',
263 xtype
: 'PVE.qemu.Options',
266 title
: gettext('Task History'),
268 xtype
: 'proxmoxNodeTasks',
269 iconCls
: 'fa fa-list',
275 if (caps
.vms
['VM.Monitor'] && !template
) {
277 title
: gettext('Monitor'),
278 iconCls
: 'fa fa-eye',
280 xtype
: 'pveQemuMonitor',
284 if (caps
.vms
['VM.Backup']) {
286 title
: gettext('Backup'),
287 iconCls
: 'fa fa-floppy-o',
288 xtype
: 'pveBackupView',
292 title
: gettext('Replication'),
293 iconCls
: 'fa fa-retweet',
294 xtype
: 'pveReplicaView',
295 itemId
: 'replication',
299 if ((caps
.vms
['VM.Snapshot'] || caps
.vms
['VM.Snapshot.Rollback'] ||
300 caps
.vms
['VM.Audit']) && !template
) {
302 title
: gettext('Snapshots'),
303 iconCls
: 'fa fa-history',
305 xtype
: 'pveGuestSnapshotTree',
310 if (caps
.vms
['VM.Console']) {
313 xtype
: 'pveFirewallRules',
314 title
: gettext('Firewall'),
315 iconCls
: 'fa fa-shield',
317 base_url
: base_url
+ '/firewall/rules',
318 list_refs_url
: base_url
+ '/firewall/refs',
322 xtype
: 'pveFirewallOptions',
323 groups
: ['firewall'],
324 iconCls
: 'fa fa-gear',
325 onlineHelp
: 'pve_firewall_vm_container_configuration',
326 title
: gettext('Options'),
327 base_url
: base_url
+ '/firewall/options',
329 itemId
: 'firewall-options',
332 xtype
: 'pveFirewallAliases',
333 title
: gettext('Alias'),
334 groups
: ['firewall'],
335 iconCls
: 'fa fa-external-link',
336 base_url
: base_url
+ '/firewall/aliases',
337 itemId
: 'firewall-aliases',
341 title
: gettext('IPSet'),
342 groups
: ['firewall'],
343 iconCls
: 'fa fa-list-ol',
344 base_url
: base_url
+ '/firewall/ipset',
345 list_refs_url
: base_url
+ '/firewall/refs',
346 itemId
: 'firewall-ipset',
349 title
: gettext('Log'),
350 groups
: ['firewall'],
351 iconCls
: 'fa fa-list',
352 onlineHelp
: 'chapter_pve_firewall',
353 itemId
: 'firewall-fwlog',
354 xtype
: 'proxmoxLogView',
355 url
: '/api2/extjs' + base_url
+ '/firewall/log',
360 if (caps
.vms
['Permissions.Modify']) {
363 title
: gettext('Permissions'),
364 iconCls
: 'fa fa-unlock',
365 itemId
: 'permissions',
366 path
: '/vms/' + vmid
,
372 var prevQMPStatus
= 'unknown';
373 me
.mon(me
.statusStore
, 'load', function(s
, records
, success
) {
381 status
= qmpstatus
= 'unknown';
383 var rec
= s
.data
.get('status');
384 status
= rec
? rec
.data
.value
: 'unknown';
385 rec
= s
.data
.get('qmpstatus');
386 qmpstatus
= rec
? rec
.data
.value
: 'unknown';
387 rec
= s
.data
.get('template');
388 template
= rec
? rec
.data
.value
: false;
389 rec
= s
.data
.get('lock');
390 lock
= rec
? rec
.data
.value
: undefined;
392 spice
= !!s
.data
.get('spice');
393 xtermjs
= !!s
.data
.get('serial');
400 var resume
= ['prelaunch', 'paused', 'suspended'].indexOf(qmpstatus
) !== -1;
402 if (resume
|| lock
=== 'suspended') {
403 startBtn
.setVisible(false);
404 resumeBtn
.setVisible(true);
406 startBtn
.setVisible(true);
407 resumeBtn
.setVisible(false);
410 consoleBtn
.setEnableSpice(spice
);
411 consoleBtn
.setEnableXtermJS(xtermjs
);
413 statusTxt
.update({ lock
: lock
});
415 let guest_running
= status
=== 'running' &&
416 !(qmpstatus
=== "shutdown" || qmpstatus
=== "prelaunch");
417 startBtn
.setDisabled(!caps
.vms
['VM.PowerMgmt'] || template
|| guest_running
);
419 shutdownBtn
.setDisabled(!caps
.vms
['VM.PowerMgmt'] || status
!== 'running');
420 me
.down('#removeBtn').setDisabled(!caps
.vms
['VM.Allocate'] || status
!== 'stopped');
421 consoleBtn
.setDisabled(template
);
423 let wasStopped
= ['prelaunch', 'stopped', 'suspended'].indexOf(prevQMPStatus
) !== -1;
424 if (wasStopped
&& qmpstatus
=== 'running') {
425 let con
= me
.down('#console');
431 prevQMPStatus
= qmpstatus
;
434 me
.on('afterrender', function() {
435 me
.statusStore
.startUpdate();
438 me
.on('destroy', function() {
439 me
.statusStore
.stopUpdate();