]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/qemu/Config.js
use auto-generated block IDs to reference online docu.
[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
156095db
DM
76 var resetBtn = Ext.create('PVE.button.Button', {
77 text: gettext('Reset'),
78 disabled: !caps.vms['VM.PowerMgmt'],
16152937 79 confirmMsg: PVE.Utils.format_task_description('qmreset', vmid),
540fdc8b 80 handler: function() {
156095db 81 vm_command("reset");
d4333933
DC
82 },
83 iconCls: 'fa fa-bolt'
156095db
DM
84 });
85
889c7083 86 var shutdownBtn = Ext.create('PVE.button.Split', {
156095db
DM
87 text: gettext('Shutdown'),
88 disabled: !caps.vms['VM.PowerMgmt'],
16152937 89 confirmMsg: PVE.Utils.format_task_description('qmshutdown', vmid),
156095db
DM
90 handler: function() {
91 vm_command('shutdown');
889c7083
DC
92 },
93 menu: {
94 items: [{
95 text: gettext('Stop'),
96 disabled: !caps.vms['VM.PowerMgmt'],
97 dangerous: true,
98 confirmMsg: PVE.Utils.format_task_description('qmstop', vmid),
99 handler: function() {
100 vm_command("stop", { timeout: 30 });
d4333933 101 },
22f2f9d6 102 iconCls: 'fa fa-stop'
889c7083 103 }]
d4333933
DC
104 },
105 iconCls: 'fa fa-power-off'
156095db
DM
106 });
107
108 var removeBtn = Ext.create('PVE.button.Button', {
109 text: gettext('Remove'),
110 disabled: !caps.vms['VM.Allocate'],
156095db 111 handler: function() {
32f469f3 112 Ext.create('PVE.window.SafeDestroy', {
bcecf280
DM
113 url: base_url,
114 item: { type: 'VM', id: vmid }
32f469f3 115 }).show();
d4333933
DC
116 },
117 iconCls: 'fa fa-trash-o'
156095db
DM
118 });
119
120 var vmname = me.pveSelNode.data.name;
121
122 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
123 disabled: !caps.vms['VM.Console'],
124 consoleType: 'kvm',
125 consoleName: vmname,
126 nodename: nodename,
d4333933
DC
127 vmid: vmid,
128 iconCls: 'fa fa-terminal'
156095db
DM
129 });
130
131 var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'VM " + vmid + "'") + ")";
132
133 Ext.apply(me, {
134 title: Ext.String.format(gettext("Virtual Machine {0} on node {1}"), descr, "'" + nodename + "'"),
135 hstateid: 'kvmtab',
889c7083 136 tbar: [ resumeBtn, startBtn, shutdownBtn, resetBtn,
156095db
DM
137 removeBtn, migrateBtn, consoleBtn],
138 defaults: { statusStore: me.statusStore },
139 items: [
140 {
6f68dcbe
EK
141 title: gettext('Summary'),
142 xtype: 'pveQemuSummary',
c284be32 143 iconCls: 'fa fa-book',
156095db 144 itemId: 'summary'
156095db
DM
145 }
146 ]
147 });
c5ccc8d0 148
1939a006
DC
149 if (caps.vms['VM.Console'] && !template) {
150 me.items.push({
151 title: gettext('Console'),
152 itemId: 'console',
153 iconCls: 'fa fa-terminal',
154 xtype: 'pveNoVncConsole',
155 vmid: vmid,
156 consoleType: 'kvm',
157 nodename: nodename
158 });
159 }
160
161 me.items.push(
162 {
163 title: gettext('Hardware'),
164 itemId: 'hardware',
c8802a60 165 onlineHelp: 'qm_virtual_machines_settings',
1939a006
DC
166 iconCls: 'fa fa-desktop',
167 xtype: 'PVE.qemu.HardwareView'
168 },
169 {
170 title: gettext('Options'),
171 iconCls: 'fa fa-gear',
c8802a60 172 onlineHelp: 'qm_options',
1939a006
DC
173 itemId: 'options',
174 xtype: 'PVE.qemu.Options'
175 },
176 {
177 title: gettext('Task History'),
178 itemId: 'tasks',
179 xtype: 'pveNodeTasks',
180 iconCls: 'fa fa-list',
181 vmidFilter: vmid
182 }
183 );
184
156095db
DM
185 if (caps.vms['VM.Monitor'] && !template) {
186 me.items.push({
187 title: gettext('Monitor'),
c284be32 188 iconCls: 'fa fa-eye',
156095db
DM
189 itemId: 'monitor',
190 xtype: 'pveQemuMonitor'
191 });
192 }
193
194 if (caps.vms['VM.Backup']) {
195 me.items.push({
196 title: gettext('Backup'),
c284be32 197 iconCls: 'fa fa-floppy-o',
156095db 198 xtype: 'pveBackupView',
c8802a60 199 onlineHelp: 'chapter_vzdump',
156095db
DM
200 itemId: 'backup'
201 });
202 }
203
4a01bc83 204 if (caps.vms['VM.Snapshot'] && !template) {
156095db
DM
205 me.items.push({
206 title: gettext('Snapshots'),
c284be32 207 iconCls: 'fa fa-history',
156095db
DM
208 xtype: 'pveQemuSnapshotTree',
209 itemId: 'snapshot'
210 });
211 }
212
156095db 213 if (caps.vms['VM.Console']) {
a2f35eb2 214 me.items.push(
156095db 215 {
c284be32 216 xtype: 'pveFirewallRules',
156095db 217 title: gettext('Firewall'),
c284be32 218 iconCls: 'fa fa-shield',
c8802a60 219 onlineHelp: 'chapter_pve_firewall',
c284be32
DC
220 allow_iface: true,
221 base_url: base_url + '/firewall/rules',
816b62b0 222 list_refs_url: base_url + '/firewall/refs',
156095db 223 itemId: 'firewall'
c284be32
DC
224 },
225 {
226 xtype: 'pveFirewallOptions',
227 groups: ['firewall'],
228 iconCls: 'fa fa-gear',
c8802a60 229 onlineHelp: 'pve_firewall_vm_container_configuration',
c284be32
DC
230 title: gettext('Options'),
231 base_url: base_url + '/firewall/options',
232 fwtype: 'vm',
233 itemId: 'firewall-options'
234 },
235 {
236 xtype: 'pveFirewallAliases',
237 title: gettext('Alias'),
238 groups: ['firewall'],
239 iconCls: 'fa fa-external-link',
c8802a60 240 onlineHelp: 'pve_firewall_ip_aliases',
c284be32
DC
241 base_url: base_url + '/firewall/aliases',
242 itemId: 'firewall-aliases'
243 },
244 {
245 xtype: 'pveIPSet',
246 title: gettext('IPSet'),
247 groups: ['firewall'],
248 iconCls: 'fa fa-list-ol',
c8802a60 249 onlineHelp: 'pve_firewall_ip_sets',
c284be32 250 base_url: base_url + '/firewall/ipset',
816b62b0 251 list_refs_url: base_url + '/firewall/refs',
c284be32
DC
252 itemId: 'firewall-ipset'
253 },
254 {
255 title: gettext('Log'),
256 groups: ['firewall'],
257 iconCls: 'fa fa-list',
c8802a60 258 onlineHelp: 'chapter_pve_firewall',
c284be32
DC
259 itemId: 'firewall-fwlog',
260 xtype: 'pveLogView',
261 url: '/api2/extjs' + base_url + '/firewall/log'
156095db 262 }
a2f35eb2 263 );
156095db
DM
264 }
265
266 if (caps.vms['Permissions.Modify']) {
267 me.items.push({
268 xtype: 'pveACLView',
269 title: gettext('Permissions'),
c284be32 270 iconCls: 'fa fa-unlock',
c8802a60 271 onlineHelp: 'chapter_user_management',
156095db
DM
272 itemId: 'permissions',
273 path: '/vms/' + vmid
274 });
275 }
c5ccc8d0 276
156095db
DM
277 me.callParent();
278
540fdc8b 279 me.mon(me.statusStore, 'load', function(s, records, success) {
156095db
DM
280 var status;
281 var qmpstatus;
282 var spice = false;
283
284 if (!success) {
285 me.workspace.checkVmMigration(me.pveSelNode);
286 status = qmpstatus = 'unknown';
287 } else {
288 var rec = s.data.get('status');
289 status = rec ? rec.data.value : 'unknown';
290 rec = s.data.get('qmpstatus');
291 qmpstatus = rec ? rec.data.value : 'unknown';
292 rec = s.data.get('template');
2a727273
DM
293 template = rec.data.value || false;
294
156095db
DM
295 spice = s.data.get('spice') ? true : false;
296
297 }
298
299 if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') {
300 startBtn.setVisible(false);
301 resumeBtn.setVisible(true);
302 } else {
303 startBtn.setVisible(true);
304 resumeBtn.setVisible(false);
305 }
306
307 consoleBtn.setEnableSpice(spice);
308
309 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
310 resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running' || template);
311 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
156095db 312 removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
4365549d 313 consoleBtn.setDisabled(template);
156095db
DM
314 });
315
316 me.on('afterrender', function() {
317 me.statusStore.startUpdate();
318 });
319
320 me.on('destroy', function() {
321 me.statusStore.stopUpdate();
322 });
323 }
324});