]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/Config.js
add replication grid to lxc/qemu/node
[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 title: gettext('Replication'),
227 iconCls: 'fa fa-retweet',
228 xtype: 'pveReplicaView',
229 itemId: 'replication'
230 });
231 }
232
233 if (caps.vms['VM.Snapshot'] && !template) {
234 me.items.push({
235 title: gettext('Snapshots'),
236 iconCls: 'fa fa-history',
237 xtype: 'pveQemuSnapshotTree',
238 itemId: 'snapshot'
239 });
240 }
241
242 if (caps.vms['VM.Console']) {
243 me.items.push(
244 {
245 xtype: 'pveFirewallRules',
246 title: gettext('Firewall'),
247 iconCls: 'fa fa-shield',
248 allow_iface: true,
249 base_url: base_url + '/firewall/rules',
250 list_refs_url: base_url + '/firewall/refs',
251 itemId: 'firewall'
252 },
253 {
254 xtype: 'pveFirewallOptions',
255 groups: ['firewall'],
256 iconCls: 'fa fa-gear',
257 onlineHelp: 'pve_firewall_vm_container_configuration',
258 title: gettext('Options'),
259 base_url: base_url + '/firewall/options',
260 fwtype: 'vm',
261 itemId: 'firewall-options'
262 },
263 {
264 xtype: 'pveFirewallAliases',
265 title: gettext('Alias'),
266 groups: ['firewall'],
267 iconCls: 'fa fa-external-link',
268 base_url: base_url + '/firewall/aliases',
269 itemId: 'firewall-aliases'
270 },
271 {
272 xtype: 'pveIPSet',
273 title: gettext('IPSet'),
274 groups: ['firewall'],
275 iconCls: 'fa fa-list-ol',
276 base_url: base_url + '/firewall/ipset',
277 list_refs_url: base_url + '/firewall/refs',
278 itemId: 'firewall-ipset'
279 },
280 {
281 title: gettext('Log'),
282 groups: ['firewall'],
283 iconCls: 'fa fa-list',
284 onlineHelp: 'chapter_pve_firewall',
285 itemId: 'firewall-fwlog',
286 xtype: 'pveLogView',
287 url: '/api2/extjs' + base_url + '/firewall/log'
288 }
289 );
290 }
291
292 if (caps.vms['Permissions.Modify']) {
293 me.items.push({
294 xtype: 'pveACLView',
295 title: gettext('Permissions'),
296 iconCls: 'fa fa-unlock',
297 itemId: 'permissions',
298 path: '/vms/' + vmid
299 });
300 }
301
302 me.callParent();
303
304 me.mon(me.statusStore, 'load', function(s, records, success) {
305 var status;
306 var qmpstatus;
307 var spice = false;
308
309 if (!success) {
310 me.workspace.checkVmMigration(me.pveSelNode);
311 status = qmpstatus = 'unknown';
312 } else {
313 var rec = s.data.get('status');
314 status = rec ? rec.data.value : 'unknown';
315 rec = s.data.get('qmpstatus');
316 qmpstatus = rec ? rec.data.value : 'unknown';
317 rec = s.data.get('template');
318 template = rec.data.value || false;
319
320 spice = s.data.get('spice') ? true : false;
321
322 }
323
324 if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') {
325 startBtn.setVisible(false);
326 resumeBtn.setVisible(true);
327 } else {
328 startBtn.setVisible(true);
329 resumeBtn.setVisible(false);
330 }
331
332 consoleBtn.setEnableSpice(spice);
333
334 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
335 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
336 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
337 consoleBtn.setDisabled(template);
338 });
339
340 me.on('afterrender', function() {
341 me.statusStore.startUpdate();
342 });
343
344 me.on('destroy', function() {
345 me.statusStore.stopUpdate();
346 });
347 }
348 });