]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/qemu/Config.js
ui: add PVE.menu.Item
[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;
9
10 var nodename = me.pveSelNode.data.node;
11 if (!nodename) {
12 throw "no node name specified";
13 }
14
15 var vmid = me.pveSelNode.data.vmid;
16 if (!vmid) {
17 throw "no VM ID specified";
18 }
540fdc8b 19
6ecdb340 20 var template = !!me.pveSelNode.data.template;
156095db
DM
21
22 var caps = Ext.state.Manager.get('GuiCap');
23
24 var base_url = '/nodes/' + nodename + "/qemu/" + vmid;
540fdc8b 25
156095db
DM
26 me.statusStore = Ext.create('PVE.data.ObjectStore', {
27 url: '/api2/json' + base_url + '/status/current',
28 interval: 1000
29 });
30
31 var vm_command = function(cmd, params) {
32 PVE.Utils.API2Request({
33 params: params,
34 url: base_url + '/status/' + cmd,
35 waitMsgTarget: me,
36 method: 'POST',
37 failure: function(response, opts) {
38 Ext.Msg.alert('Error', response.htmlStatus);
39 }
40 });
41 };
42
540fdc8b 43 var resumeBtn = Ext.create('Ext.Button', {
156095db
DM
44 text: gettext('Resume'),
45 disabled: !caps.vms['VM.PowerMgmt'],
394a9983 46 hidden: true,
156095db
DM
47 handler: function() {
48 vm_command('resume');
d4333933
DC
49 },
50 iconCls: 'fa fa-play'
540fdc8b 51 });
156095db 52
540fdc8b 53 var startBtn = Ext.create('Ext.Button', {
156095db
DM
54 text: gettext('Start'),
55 disabled: !caps.vms['VM.PowerMgmt'],
6ecdb340 56 hidden: template,
156095db
DM
57 handler: function() {
58 vm_command('start');
d4333933 59 },
22f2f9d6 60 iconCls: 'fa fa-play'
540fdc8b
DC
61 });
62
540fdc8b 63 var migrateBtn = Ext.create('Ext.Button', {
156095db
DM
64 text: gettext('Migrate'),
65 disabled: !caps.vms['VM.Migrate'],
6ecdb340 66 hidden: PVE.data.ResourceStore.getNodes().length < 2,
156095db
DM
67 handler: function() {
68 var win = Ext.create('PVE.window.Migrate', {
69 vmtype: 'qemu',
70 nodename: nodename,
71 vmid: vmid
72 });
73 win.show();
d4333933
DC
74 },
75 iconCls: 'fa fa-send-o'
156095db 76 });
540fdc8b 77
d6dab970
DC
78 var cloneBtn = Ext.create('PVE.button.Split', {
79 text: gettext('Clone'),
80 iconCls: 'fa fa-fw fa-clone',
81 hidden: caps.vms['VM.Clone'] ? false : true,
82 handler: function() {
83 PVE.window.Clone.wrap(nodename, vmid, template);
84 },
85 menu: {
86 items: [{
87 text: gettext('Convert to template'),
88 disabled: template,
89 iconCls: 'fa fa-fw fa-file-o',
90 hidden: caps.vms['VM.Allocate'] ? false : true,
91 confirmMsg: PVE.Utils.format_task_description('qmtemplate', vmid),
92 handler: function() {
93 PVE.Utils.API2Request({
94 url: base_url + '/template',
95 waitMsgTarget: me,
96 method: 'POST',
97 failure: function(response, opts) {
98 Ext.Msg.alert('Error', response.htmlStatus);
99 }
100 });
101 }
102 }]
103 }
c8fc7a4e
EK
104 });
105
889c7083 106 var shutdownBtn = Ext.create('PVE.button.Split', {
156095db
DM
107 text: gettext('Shutdown'),
108 disabled: !caps.vms['VM.PowerMgmt'],
6ecdb340 109 hidden: template,
16152937 110 confirmMsg: PVE.Utils.format_task_description('qmshutdown', vmid),
156095db
DM
111 handler: function() {
112 vm_command('shutdown');
889c7083
DC
113 },
114 menu: {
115 items: [{
116 text: gettext('Stop'),
117 disabled: !caps.vms['VM.PowerMgmt'],
118 dangerous: true,
119 confirmMsg: PVE.Utils.format_task_description('qmstop', vmid),
120 handler: function() {
121 vm_command("stop", { timeout: 30 });
d4333933 122 },
22f2f9d6 123 iconCls: 'fa fa-stop'
f2fa05d1
DC
124 },{
125 text: gettext('Reset'),
126 disabled: !caps.vms['VM.PowerMgmt'],
127 confirmMsg: PVE.Utils.format_task_description('qmreset', vmid),
128 handler: function() {
129 vm_command("reset");
130 },
131 iconCls: 'fa fa-bolt'
889c7083 132 }]
d4333933
DC
133 },
134 iconCls: 'fa fa-power-off'
156095db
DM
135 });
136
137 var removeBtn = Ext.create('PVE.button.Button', {
138 text: gettext('Remove'),
139 disabled: !caps.vms['VM.Allocate'],
156095db 140 handler: function() {
32f469f3 141 Ext.create('PVE.window.SafeDestroy', {
bcecf280
DM
142 url: base_url,
143 item: { type: 'VM', id: vmid }
32f469f3 144 }).show();
d4333933
DC
145 },
146 iconCls: 'fa fa-trash-o'
156095db
DM
147 });
148
4ad508ef 149 var vm = me.pveSelNode.data;
156095db
DM
150
151 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
152 disabled: !caps.vms['VM.Console'],
6ecdb340 153 hidden: template,
156095db 154 consoleType: 'kvm',
4ad508ef 155 consoleName: vm.name,
156095db 156 nodename: nodename,
d4333933
DC
157 vmid: vmid,
158 iconCls: 'fa fa-terminal'
156095db
DM
159 });
160
156095db 161 Ext.apply(me, {
4ad508ef 162 title: Ext.String.format(gettext("Virtual Machine {0} on node '{1}'"), vm.text, nodename),
156095db 163 hstateid: 'kvmtab',
f2fa05d1 164 tbar: [ resumeBtn, startBtn, shutdownBtn,
c8fc7a4e 165 removeBtn, migrateBtn, cloneBtn, consoleBtn],
156095db
DM
166 defaults: { statusStore: me.statusStore },
167 items: [
168 {
6f68dcbe
EK
169 title: gettext('Summary'),
170 xtype: 'pveQemuSummary',
c284be32 171 iconCls: 'fa fa-book',
156095db 172 itemId: 'summary'
156095db
DM
173 }
174 ]
175 });
c5ccc8d0 176
1939a006
DC
177 if (caps.vms['VM.Console'] && !template) {
178 me.items.push({
179 title: gettext('Console'),
180 itemId: 'console',
181 iconCls: 'fa fa-terminal',
182 xtype: 'pveNoVncConsole',
183 vmid: vmid,
184 consoleType: 'kvm',
185 nodename: nodename
186 });
187 }
188
189 me.items.push(
190 {
191 title: gettext('Hardware'),
192 itemId: 'hardware',
193 iconCls: 'fa fa-desktop',
194 xtype: 'PVE.qemu.HardwareView'
195 },
196 {
197 title: gettext('Options'),
198 iconCls: 'fa fa-gear',
199 itemId: 'options',
200 xtype: 'PVE.qemu.Options'
201 },
202 {
203 title: gettext('Task History'),
204 itemId: 'tasks',
205 xtype: 'pveNodeTasks',
206 iconCls: 'fa fa-list',
207 vmidFilter: vmid
208 }
209 );
210
156095db
DM
211 if (caps.vms['VM.Monitor'] && !template) {
212 me.items.push({
213 title: gettext('Monitor'),
c284be32 214 iconCls: 'fa fa-eye',
156095db
DM
215 itemId: 'monitor',
216 xtype: 'pveQemuMonitor'
217 });
218 }
219
220 if (caps.vms['VM.Backup']) {
221 me.items.push({
222 title: gettext('Backup'),
c284be32 223 iconCls: 'fa fa-floppy-o',
156095db
DM
224 xtype: 'pveBackupView',
225 itemId: 'backup'
cb6df20c
DC
226 },
227 {
228 title: gettext('Replication'),
229 iconCls: 'fa fa-retweet',
230 xtype: 'pveReplicaView',
231 itemId: 'replication'
156095db
DM
232 });
233 }
234
8ed196a4 235 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback']) && !template) {
156095db
DM
236 me.items.push({
237 title: gettext('Snapshots'),
c284be32 238 iconCls: 'fa fa-history',
156095db
DM
239 xtype: 'pveQemuSnapshotTree',
240 itemId: 'snapshot'
241 });
242 }
243
156095db 244 if (caps.vms['VM.Console']) {
a2f35eb2 245 me.items.push(
156095db 246 {
c284be32 247 xtype: 'pveFirewallRules',
156095db 248 title: gettext('Firewall'),
c284be32
DC
249 iconCls: 'fa fa-shield',
250 allow_iface: true,
251 base_url: base_url + '/firewall/rules',
816b62b0 252 list_refs_url: base_url + '/firewall/refs',
156095db 253 itemId: 'firewall'
c284be32
DC
254 },
255 {
256 xtype: 'pveFirewallOptions',
257 groups: ['firewall'],
258 iconCls: 'fa fa-gear',
c8802a60 259 onlineHelp: 'pve_firewall_vm_container_configuration',
c284be32
DC
260 title: gettext('Options'),
261 base_url: base_url + '/firewall/options',
262 fwtype: 'vm',
263 itemId: 'firewall-options'
264 },
265 {
266 xtype: 'pveFirewallAliases',
267 title: gettext('Alias'),
268 groups: ['firewall'],
269 iconCls: 'fa fa-external-link',
270 base_url: base_url + '/firewall/aliases',
271 itemId: 'firewall-aliases'
272 },
273 {
274 xtype: 'pveIPSet',
275 title: gettext('IPSet'),
276 groups: ['firewall'],
277 iconCls: 'fa fa-list-ol',
278 base_url: base_url + '/firewall/ipset',
816b62b0 279 list_refs_url: base_url + '/firewall/refs',
c284be32
DC
280 itemId: 'firewall-ipset'
281 },
282 {
283 title: gettext('Log'),
284 groups: ['firewall'],
285 iconCls: 'fa fa-list',
c8802a60 286 onlineHelp: 'chapter_pve_firewall',
c284be32
DC
287 itemId: 'firewall-fwlog',
288 xtype: 'pveLogView',
289 url: '/api2/extjs' + base_url + '/firewall/log'
156095db 290 }
a2f35eb2 291 );
156095db
DM
292 }
293
294 if (caps.vms['Permissions.Modify']) {
295 me.items.push({
296 xtype: 'pveACLView',
297 title: gettext('Permissions'),
c284be32 298 iconCls: 'fa fa-unlock',
156095db
DM
299 itemId: 'permissions',
300 path: '/vms/' + vmid
301 });
302 }
c5ccc8d0 303
156095db
DM
304 me.callParent();
305
540fdc8b 306 me.mon(me.statusStore, 'load', function(s, records, success) {
156095db
DM
307 var status;
308 var qmpstatus;
309 var spice = false;
310
311 if (!success) {
156095db
DM
312 status = qmpstatus = 'unknown';
313 } else {
314 var rec = s.data.get('status');
315 status = rec ? rec.data.value : 'unknown';
316 rec = s.data.get('qmpstatus');
317 qmpstatus = rec ? rec.data.value : 'unknown';
318 rec = s.data.get('template');
2a727273
DM
319 template = rec.data.value || false;
320
156095db
DM
321 spice = s.data.get('spice') ? true : false;
322
323 }
324
6ecdb340
DC
325 if (template) {
326 return;
327 }
328
1d0293b8 329 if (qmpstatus === 'prelaunch' || qmpstatus === 'paused' || qmpstatus === 'suspended') {
156095db
DM
330 startBtn.setVisible(false);
331 resumeBtn.setVisible(true);
332 } else {
333 startBtn.setVisible(true);
334 resumeBtn.setVisible(false);
335 }
336
337 consoleBtn.setEnableSpice(spice);
338
339 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
156095db 340 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
156095db 341 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
4365549d 342 consoleBtn.setDisabled(template);
156095db
DM
343 });
344
345 me.on('afterrender', function() {
346 me.statusStore.startUpdate();
347 });
348
349 me.on('destroy', function() {
350 me.statusStore.stopUpdate();
351 });
352 }
353});