]>
Commit | Line | Data |
---|---|---|
5910d3b7 DM |
1 | Ext.define('PVE.qemu.Config', { |
2 | extend: 'PVE.panel.Config', | |
3 | alias: 'widget.PVE.qemu.Config', | |
4 | ||
5 | initComponent: function() { | |
6 | var me = this; | |
7 | ||
8 | var nodename = me.pveSelNode.data.node; | |
9 | if (!nodename) { | |
10 | throw "no node name specified"; | |
11 | } | |
12 | ||
13 | var vmid = me.pveSelNode.data.vmid; | |
14 | if (!vmid) { | |
15 | throw "no VM ID specified"; | |
16 | } | |
17 | ||
59428c5c DM |
18 | var caps = Ext.state.Manager.get('GuiCap'); |
19 | ||
a9a1e2f2 DM |
20 | me.statusStore = Ext.create('PVE.data.ObjectStore', { |
21 | url: "/api2/json/nodes/" + nodename + "/qemu/" + vmid + "/status/current", | |
22 | interval: 1000 | |
23 | }); | |
24 | ||
25 | var vm_command = function(cmd, params) { | |
26 | PVE.Utils.API2Request({ | |
27 | params: params, | |
28 | url: '/nodes/' + nodename + '/qemu/' + vmid + "/status/" + cmd, | |
29 | waitMsgTarget: me, | |
30 | method: 'POST', | |
31 | failure: function(response, opts) { | |
32 | Ext.Msg.alert('Error', response.htmlStatus); | |
33 | } | |
34 | }); | |
35 | }; | |
36 | ||
72937a07 DM |
37 | var resumeBtn = Ext.create('Ext.Button', { |
38 | text: gettext('Resume'), | |
39 | disabled: !caps.vms['VM.PowerMgmt'], | |
40 | visible: false, | |
41 | handler: function() { | |
42 | vm_command('resume'); | |
43 | } | |
44 | }); | |
45 | ||
1fe64d18 | 46 | var startBtn = Ext.create('Ext.Button', { |
50c1c8a5 | 47 | text: gettext('Start'), |
59428c5c | 48 | disabled: !caps.vms['VM.PowerMgmt'], |
a9a1e2f2 DM |
49 | handler: function() { |
50 | vm_command('start'); | |
51 | } | |
52 | }); | |
53 | ||
54 | var stopBtn = Ext.create('PVE.button.Button', { | |
50c1c8a5 | 55 | text: gettext('Stop'), |
59428c5c | 56 | disabled: !caps.vms['VM.PowerMgmt'], |
50c1c8a5 | 57 | confirmMsg: Ext.String.format(gettext("Do you really want to stop VM {0}?"), vmid), |
a9a1e2f2 DM |
58 | handler: function() { |
59 | vm_command("stop", { timeout: 30 }); | |
60 | } | |
61 | }); | |
62 | ||
63 | var migrateBtn = Ext.create('Ext.Button', { | |
50c1c8a5 | 64 | text: gettext('Migrate'), |
59428c5c | 65 | disabled: !caps.vms['VM.Migrate'], |
a9a1e2f2 | 66 | handler: function() { |
8350ac00 DM |
67 | var win = Ext.create('PVE.window.Migrate', { |
68 | vmtype: 'qemu', | |
69 | nodename: nodename, | |
70 | vmid: vmid | |
a9a1e2f2 DM |
71 | }); |
72 | win.show(); | |
73 | } | |
74 | }); | |
75 | ||
76 | var resetBtn = Ext.create('PVE.button.Button', { | |
50c1c8a5 | 77 | text: gettext('Reset'), |
59428c5c | 78 | disabled: !caps.vms['VM.PowerMgmt'], |
50c1c8a5 | 79 | confirmMsg: Ext.String.format(gettext("Do you really want to reset VM {0}?"), vmid), |
a9a1e2f2 DM |
80 | handler: function() { |
81 | vm_command("reset"); | |
82 | } | |
83 | }); | |
84 | ||
85 | var shutdownBtn = Ext.create('PVE.button.Button', { | |
482fa9b4 | 86 | text: gettext('Shutdown'), |
59428c5c | 87 | disabled: !caps.vms['VM.PowerMgmt'], |
50c1c8a5 | 88 | confirmMsg: Ext.String.format(gettext("Do you really want to shutdown VM {0}?"), vmid), |
a9a1e2f2 | 89 | handler: function() { |
bed57d31 | 90 | vm_command('shutdown'); |
a9a1e2f2 DM |
91 | } |
92 | }); | |
93 | ||
94 | var removeBtn = Ext.create('PVE.button.Button', { | |
50c1c8a5 | 95 | text: gettext('Remove'), |
59428c5c | 96 | disabled: !caps.vms['VM.Allocate'], |
f3ddc10d | 97 | dangerous: true, |
50c1c8a5 | 98 | confirmMsg: Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), vmid), |
a9a1e2f2 DM |
99 | handler: function() { |
100 | PVE.Utils.API2Request({ | |
101 | url: '/nodes/' + nodename + '/qemu/' + vmid, | |
102 | method: 'DELETE', | |
103 | waitMsgTarget: me, | |
104 | failure: function(response, opts) { | |
105 | Ext.Msg.alert('Error', response.htmlStatus); | |
106 | } | |
107 | }); | |
108 | } | |
109 | }); | |
110 | ||
47b80718 DM |
111 | var vmname = me.pveSelNode.data.name; |
112 | ||
a9a1e2f2 | 113 | var consoleBtn = Ext.create('Ext.Button', { |
50c1c8a5 | 114 | text: gettext('Console'), |
59428c5c | 115 | disabled: !caps.vms['VM.Console'], |
a9a1e2f2 | 116 | handler: function() { |
47b80718 | 117 | PVE.Utils.openConoleWindow('kvm', vmid, nodename, vmname); |
a9a1e2f2 DM |
118 | } |
119 | }); | |
120 | ||
50c1c8a5 DM |
121 | var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'VM " + vmid + "'") + ")"; |
122 | ||
5910d3b7 | 123 | Ext.apply(me, { |
6c37b50f | 124 | title: Ext.String.format(gettext("Virtual Machine {0} on node {1}"), descr, "'" + nodename + "'"), |
5910d3b7 | 125 | hstateid: 'kvmtab', |
72937a07 | 126 | tbar: [ resumeBtn, startBtn, shutdownBtn, stopBtn, resetBtn, |
47c9c22a | 127 | removeBtn, migrateBtn, consoleBtn ], |
a9a1e2f2 | 128 | defaults: { statusStore: me.statusStore }, |
5910d3b7 DM |
129 | items: [ |
130 | { | |
50c1c8a5 | 131 | title: gettext('Summary'), |
5910d3b7 DM |
132 | xtype: 'pveQemuSummary', |
133 | itemId: 'summary' | |
134 | }, | |
135 | { | |
50c1c8a5 | 136 | title: gettext('Hardware'), |
5910d3b7 DM |
137 | itemId: 'hardware', |
138 | xtype: 'PVE.qemu.HardwareView' | |
139 | }, | |
140 | { | |
50c1c8a5 | 141 | title: gettext('Options'), |
5910d3b7 DM |
142 | itemId: 'options', |
143 | xtype: 'PVE.qemu.Options' | |
e8b4b4ff DM |
144 | }, |
145 | { | |
146 | title: 'Task History', | |
147 | itemId: 'tasks', | |
148 | xtype: 'pveNodeTasks', | |
149 | vmidFilter: vmid | |
5910d3b7 | 150 | } |
5910d3b7 DM |
151 | ] |
152 | }); | |
153 | ||
59428c5c DM |
154 | if (caps.vms['VM.Monitor']) { |
155 | me.items.push({ | |
156 | title: gettext('Monitor'), | |
157 | itemId: 'monitor', | |
158 | xtype: 'pveQemuMonitor' | |
159 | }); | |
160 | } | |
161 | ||
162 | if (caps.vms['VM.Backup']) { | |
163 | me.items.push({ | |
164 | title: gettext('Backup'), | |
165 | xtype: 'pveBackupView', | |
166 | itemId: 'backup' | |
167 | }); | |
168 | } | |
169 | ||
52586927 DM |
170 | if (caps.vms['VM.Snapshot']) { |
171 | me.items.push({ | |
172 | title: gettext('Snapshots'), | |
173 | xtype: 'pveQemuSnapshotTree', | |
174 | itemId: 'snapshot' | |
175 | }); | |
176 | } | |
177 | ||
59428c5c DM |
178 | if (caps.vms['Permissions.Modify']) { |
179 | me.items.push({ | |
180 | xtype: 'pveACLView', | |
181 | title: gettext('Permissions'), | |
182 | itemId: 'permissions', | |
183 | path: '/vms/' + vmid | |
184 | }); | |
185 | } | |
186 | ||
5910d3b7 | 187 | me.callParent(); |
a9a1e2f2 DM |
188 | |
189 | me.statusStore.on('load', function(s, records, success) { | |
190 | var status; | |
72937a07 DM |
191 | var qmpstatus; |
192 | ||
a9a1e2f2 DM |
193 | if (!success) { |
194 | me.workspace.checkVmMigration(me.pveSelNode); | |
72937a07 | 195 | status = qmpstatus = 'unknown'; |
a9a1e2f2 DM |
196 | } else { |
197 | var rec = s.data.get('status'); | |
198 | status = rec ? rec.data.value : 'unknown'; | |
72937a07 DM |
199 | rec = s.data.get('qmpstatus'); |
200 | qmpstatus = rec ? rec.data.value : 'unknown'; | |
201 | } | |
202 | ||
203 | if (qmpstatus === 'prelaunch' || qmpstatus === 'paused') { | |
204 | startBtn.setVisible(false); | |
1fe64d18 | 205 | resumeBtn.setVisible(true); |
72937a07 DM |
206 | } else { |
207 | startBtn.setVisible(true); | |
1fe64d18 | 208 | resumeBtn.setVisible(false); |
a9a1e2f2 DM |
209 | } |
210 | ||
59428c5c DM |
211 | startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running'); |
212 | resetBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); | |
213 | shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); | |
214 | stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped'); | |
215 | removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped'); | |
a9a1e2f2 DM |
216 | }); |
217 | ||
218 | me.on('afterrender', function() { | |
219 | me.statusStore.startUpdate(); | |
220 | }); | |
221 | ||
222 | me.on('destroy', function() { | |
223 | me.statusStore.stopUpdate(); | |
224 | }); | |
5910d3b7 DM |
225 | } |
226 | }); |