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