]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/qemu/Config.js
add replication grid in datacenter
[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
156095db
DM
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;
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'],
56 handler: function() {
57 vm_command('start');
d4333933 58 },
22f2f9d6 59 iconCls: 'fa fa-play'
540fdc8b
DC
60 });
61
540fdc8b 62 var migrateBtn = Ext.create('Ext.Button', {
156095db
DM
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();
d4333933
DC
72 },
73 iconCls: 'fa fa-send-o'
156095db 74 });
540fdc8b 75
d6dab970
DC
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 }
c8fc7a4e
EK
102 });
103
889c7083 104 var shutdownBtn = Ext.create('PVE.button.Split', {
156095db
DM
105 text: gettext('Shutdown'),
106 disabled: !caps.vms['VM.PowerMgmt'],
16152937 107 confirmMsg: PVE.Utils.format_task_description('qmshutdown', vmid),
156095db
DM
108 handler: function() {
109 vm_command('shutdown');
889c7083
DC
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 });
d4333933 119 },
22f2f9d6 120 iconCls: 'fa fa-stop'
f2fa05d1
DC
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'
889c7083 129 }]
d4333933
DC
130 },
131 iconCls: 'fa fa-power-off'
156095db
DM
132 });
133
134 var removeBtn = Ext.create('PVE.button.Button', {
135 text: gettext('Remove'),
136 disabled: !caps.vms['VM.Allocate'],
156095db 137 handler: function() {
32f469f3 138 Ext.create('PVE.window.SafeDestroy', {
bcecf280
DM
139 url: base_url,
140 item: { type: 'VM', id: vmid }
32f469f3 141 }).show();
d4333933
DC
142 },
143 iconCls: 'fa fa-trash-o'
156095db
DM
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,
d4333933
DC
153 vmid: vmid,
154 iconCls: 'fa fa-terminal'
156095db
DM
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',
f2fa05d1 162 tbar: [ resumeBtn, startBtn, shutdownBtn,
c8fc7a4e 163 removeBtn, migrateBtn, cloneBtn, consoleBtn],
156095db
DM
164 defaults: { statusStore: me.statusStore },
165 items: [
166 {
6f68dcbe
EK
167 title: gettext('Summary'),
168 xtype: 'pveQemuSummary',
c284be32 169 iconCls: 'fa fa-book',
156095db 170 itemId: 'summary'
156095db
DM
171 }
172 ]
173 });
c5ccc8d0 174
1939a006
DC
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
156095db
DM
209 if (caps.vms['VM.Monitor'] && !template) {
210 me.items.push({
211 title: gettext('Monitor'),
c284be32 212 iconCls: 'fa fa-eye',
156095db
DM
213 itemId: 'monitor',
214 xtype: 'pveQemuMonitor'
215 });
216 }
217
218 if (caps.vms['VM.Backup']) {
219 me.items.push({
220 title: gettext('Backup'),
c284be32 221 iconCls: 'fa fa-floppy-o',
156095db
DM
222 xtype: 'pveBackupView',
223 itemId: 'backup'
224 });
225 }
226
4a01bc83 227 if (caps.vms['VM.Snapshot'] && !template) {
156095db
DM
228 me.items.push({
229 title: gettext('Snapshots'),
c284be32 230 iconCls: 'fa fa-history',
156095db
DM
231 xtype: 'pveQemuSnapshotTree',
232 itemId: 'snapshot'
233 });
234 }
235
156095db 236 if (caps.vms['VM.Console']) {
a2f35eb2 237 me.items.push(
156095db 238 {
c284be32 239 xtype: 'pveFirewallRules',
156095db 240 title: gettext('Firewall'),
c284be32
DC
241 iconCls: 'fa fa-shield',
242 allow_iface: true,
243 base_url: base_url + '/firewall/rules',
816b62b0 244 list_refs_url: base_url + '/firewall/refs',
156095db 245 itemId: 'firewall'
c284be32
DC
246 },
247 {
248 xtype: 'pveFirewallOptions',
249 groups: ['firewall'],
250 iconCls: 'fa fa-gear',
c8802a60 251 onlineHelp: 'pve_firewall_vm_container_configuration',
c284be32
DC
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',
816b62b0 271 list_refs_url: base_url + '/firewall/refs',
c284be32
DC
272 itemId: 'firewall-ipset'
273 },
274 {
275 title: gettext('Log'),
276 groups: ['firewall'],
277 iconCls: 'fa fa-list',
c8802a60 278 onlineHelp: 'chapter_pve_firewall',
c284be32
DC
279 itemId: 'firewall-fwlog',
280 xtype: 'pveLogView',
281 url: '/api2/extjs' + base_url + '/firewall/log'
156095db 282 }
a2f35eb2 283 );
156095db
DM
284 }
285
286 if (caps.vms['Permissions.Modify']) {
287 me.items.push({
288 xtype: 'pveACLView',
289 title: gettext('Permissions'),
c284be32 290 iconCls: 'fa fa-unlock',
156095db
DM
291 itemId: 'permissions',
292 path: '/vms/' + vmid
293 });
294 }
c5ccc8d0 295
156095db
DM
296 me.callParent();
297
540fdc8b 298 me.mon(me.statusStore, 'load', function(s, records, success) {
156095db
DM
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');
2a727273
DM
312 template = rec.data.value || false;
313
156095db
DM
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);
156095db 329 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
156095db 330 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
4365549d 331 consoleBtn.setDisabled(template);
156095db
DM
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});