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