]>
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'],
56 var startBtn
= Ext
.create('Ext.Button', {
57 text
: gettext('Start'),
58 disabled
: !caps
.vms
['VM.PowerMgmt'] || running
,
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'),
85 text
: gettext('Clone'),
86 iconCls
: 'fa fa-fw fa-clone',
87 hidden
: caps
.vms
['VM.Clone'] ? false : true,
89 PVE
.window
.Clone
.wrap(nodename
, vmid
, template
, 'qemu');
93 text
: gettext('Convert to template'),
96 iconCls
: 'fa fa-fw fa-file-o',
97 hidden
: caps
.vms
['VM.Allocate'] ? false : true,
98 confirmMsg
: Proxmox
.Utils
.format_task_description('qmtemplate', vmid
),
100 Proxmox
.Utils
.API2Request({
101 url
: base_url
+ '/template',
104 failure: function(response
, opts
) {
105 Ext
.Msg
.alert('Error', response
.htmlStatus
);
111 iconCls
: 'fa fa-heartbeat ',
112 hidden
: !caps
.nodes
['Sys.Console'],
113 text
: gettext('Manage HA'),
114 handler: function() {
116 Ext
.create('PVE.ha.VMResourceEdit', {
118 isCreate
: (!ha
|| ha
=== 'unmanaged')
123 text
: gettext('Remove'),
125 disabled
: !caps
.vms
['VM.Allocate'],
126 handler: function() {
127 Ext
.create('PVE.window.SafeDestroy', {
129 item
: { type
: 'VM', id
: vmid
}
132 iconCls
: 'fa fa-trash-o'
137 var shutdownBtn
= Ext
.create('PVE.button.Split', {
138 text
: gettext('Shutdown'),
139 disabled
: !caps
.vms
['VM.PowerMgmt'] || !running
,
141 confirmMsg
: Proxmox
.Utils
.format_task_description('qmshutdown', vmid
),
142 handler: function() {
143 vm_command('shutdown');
147 text
: gettext('Reboot'),
148 disabled
: !caps
.vms
['VM.PowerMgmt'],
149 tooltip
: Ext
.String
.format(gettext('Shutdown, apply pending changes and reboot {0}'), 'VM'),
150 confirmMsg
: Proxmox
.Utils
.format_task_description('qmreboot', vmid
),
151 handler: function() {
152 vm_command("reboot");
154 iconCls
: 'fa fa-refresh'
156 text
: gettext('Pause'),
157 disabled
: !caps
.vms
['VM.PowerMgmt'],
158 confirmMsg
: Proxmox
.Utils
.format_task_description('qmpause', vmid
),
159 handler: function() {
160 vm_command("suspend");
162 iconCls
: 'fa fa-pause'
164 text
: gettext('Hibernate'),
165 disabled
: !caps
.vms
['VM.PowerMgmt'],
166 confirmMsg
: Proxmox
.Utils
.format_task_description('qmsuspend', vmid
),
167 tooltip
: gettext('Suspend to disk'),
168 handler: function() {
169 vm_command("suspend", { todisk
: 1 });
171 iconCls
: 'fa fa-download'
173 text
: gettext('Stop'),
174 disabled
: !caps
.vms
['VM.PowerMgmt'],
176 tooltip
: Ext
.String
.format(gettext('Stop {0} immediately'), 'VM'),
177 confirmMsg
: Proxmox
.Utils
.format_task_description('qmstop', vmid
),
178 handler: function() {
179 vm_command("stop", { timeout
: 30 });
181 iconCls
: 'fa fa-stop'
183 text
: gettext('Reset'),
184 disabled
: !caps
.vms
['VM.PowerMgmt'],
185 tooltip
: Ext
.String
.format(gettext('Reset {0} immediately'), 'VM'),
186 confirmMsg
: Proxmox
.Utils
.format_task_description('qmreset', vmid
),
187 handler: function() {
190 iconCls
: 'fa fa-bolt'
193 iconCls
: 'fa fa-power-off'
196 var consoleBtn
= Ext
.create('PVE.button.ConsoleButton', {
197 disabled
: !caps
.vms
['VM.Console'],
200 consoleName
: vm
.name
,
205 var statusTxt
= Ext
.create('Ext.toolbar.TextItem', {
211 '<i class="fa fa-lg fa-lock"></i> ({lock})',
217 title
: Ext
.String
.format(gettext("Virtual Machine {0} on node '{1}'"), vm
.text
, nodename
),
220 tbar
: [ statusTxt
, '->', resumeBtn
, startBtn
, shutdownBtn
, migrateBtn
, consoleBtn
, moreBtn
],
221 defaults
: { statusStore
: me
.statusStore
},
224 title
: gettext('Summary'),
225 xtype
: 'pveGuestSummary',
226 iconCls
: 'fa fa-book',
232 if (caps
.vms
['VM.Console'] && !template
) {
234 title
: gettext('Console'),
236 iconCls
: 'fa fa-terminal',
237 xtype
: 'pveNoVncConsole',
246 title
: gettext('Hardware'),
248 iconCls
: 'fa fa-desktop',
249 xtype
: 'PVE.qemu.HardwareView'
254 iconCls
: 'fa fa-cloud',
258 title
: gettext('Options'),
259 iconCls
: 'fa fa-gear',
261 xtype
: 'PVE.qemu.Options'
264 title
: gettext('Task History'),
266 xtype
: 'proxmoxNodeTasks',
267 iconCls
: 'fa fa-list',
273 if (caps
.vms
['VM.Monitor'] && !template
) {
275 title
: gettext('Monitor'),
276 iconCls
: 'fa fa-eye',
278 xtype
: 'pveQemuMonitor'
282 if (caps
.vms
['VM.Backup']) {
284 title
: gettext('Backup'),
285 iconCls
: 'fa fa-floppy-o',
286 xtype
: 'pveBackupView',
290 title
: gettext('Replication'),
291 iconCls
: 'fa fa-retweet',
292 xtype
: 'pveReplicaView',
293 itemId
: 'replication'
297 if ((caps
.vms
['VM.Snapshot'] || caps
.vms
['VM.Snapshot.Rollback'] ||
298 caps
.vms
['VM.Audit']) && !template
) {
300 title
: gettext('Snapshots'),
301 iconCls
: 'fa fa-history',
303 xtype
: 'pveGuestSnapshotTree',
308 if (caps
.vms
['VM.Console']) {
311 xtype
: 'pveFirewallRules',
312 title
: gettext('Firewall'),
313 iconCls
: 'fa fa-shield',
315 base_url
: base_url
+ '/firewall/rules',
316 list_refs_url
: base_url
+ '/firewall/refs',
320 xtype
: 'pveFirewallOptions',
321 groups
: ['firewall'],
322 iconCls
: 'fa fa-gear',
323 onlineHelp
: 'pve_firewall_vm_container_configuration',
324 title
: gettext('Options'),
325 base_url
: base_url
+ '/firewall/options',
327 itemId
: 'firewall-options'
330 xtype
: 'pveFirewallAliases',
331 title
: gettext('Alias'),
332 groups
: ['firewall'],
333 iconCls
: 'fa fa-external-link',
334 base_url
: base_url
+ '/firewall/aliases',
335 itemId
: 'firewall-aliases'
339 title
: gettext('IPSet'),
340 groups
: ['firewall'],
341 iconCls
: 'fa fa-list-ol',
342 base_url
: base_url
+ '/firewall/ipset',
343 list_refs_url
: base_url
+ '/firewall/refs',
344 itemId
: 'firewall-ipset'
347 title
: gettext('Log'),
348 groups
: ['firewall'],
349 iconCls
: 'fa fa-list',
350 onlineHelp
: 'chapter_pve_firewall',
351 itemId
: 'firewall-fwlog',
352 xtype
: 'proxmoxLogView',
353 url
: '/api2/extjs' + base_url
+ '/firewall/log'
358 if (caps
.vms
['Permissions.Modify']) {
361 title
: gettext('Permissions'),
362 iconCls
: 'fa fa-unlock',
363 itemId
: 'permissions',
370 var prevQMPStatus
= 'unknown';
371 me
.mon(me
.statusStore
, 'load', function(s
, records
, success
) {
379 status
= qmpstatus
= 'unknown';
381 var rec
= s
.data
.get('status');
382 status
= rec
? rec
.data
.value
: 'unknown';
383 rec
= s
.data
.get('qmpstatus');
384 qmpstatus
= rec
? rec
.data
.value
: 'unknown';
385 rec
= s
.data
.get('template');
386 template
= rec
.data
.value
|| false;
387 rec
= s
.data
.get('lock');
388 lock
= rec
? rec
.data
.value
: undefined;
390 spice
= s
.data
.get('spice') ? true : false;
391 xtermjs
= s
.data
.get('serial') ? true : false;
399 var resume
= (['prelaunch', 'paused', 'suspended'].indexOf(qmpstatus
) !== -1);
401 if (resume
|| lock
=== 'suspended') {
402 startBtn
.setVisible(false);
403 resumeBtn
.setVisible(true);
405 startBtn
.setVisible(true);
406 resumeBtn
.setVisible(false);
409 consoleBtn
.setEnableSpice(spice
);
410 consoleBtn
.setEnableXtermJS(xtermjs
);
412 statusTxt
.update({ lock
: lock
});
414 let guest_running
= status
=== 'running' &&
415 !(qmpstatus
=== "shutdown" || qmpstatus
=== "prelaunch");
416 startBtn
.setDisabled(!caps
.vms
['VM.PowerMgmt'] || template
|| guest_running
);
418 shutdownBtn
.setDisabled(!caps
.vms
['VM.PowerMgmt'] || status
!== 'running');
419 me
.down('#removeBtn').setDisabled(!caps
.vms
['VM.Allocate'] || status
!== 'stopped');
420 consoleBtn
.setDisabled(template
);
422 let wasStopped
= ['prelaunch', 'stopped', 'suspended'].indexOf(prevQMPStatus
) !== -1;
423 if (wasStopped
&& qmpstatus
=== 'running') {
424 let con
= me
.down('#console');
430 prevQMPStatus
= qmpstatus
;
433 me
.on('afterrender', function() {
434 me
.statusStore
.startUpdate();
437 me
.on('destroy', function() {
438 me
.statusStore
.stopUpdate();