]>
Commit | Line | Data |
---|---|---|
56166a78 DM |
1 | Ext.define('PVE.lxc.Config', { |
2 | extend: 'PVE.panel.Config', | |
3 | alias: 'widget.PVE.lxc.Config', | |
4 | ||
c8802a60 | 5 | onlineHelp: 'chapter_pct', |
7f1ac74c | 6 | |
56166a78 DM |
7 | initComponent: function() { |
8 | var me = this; | |
fe45dd5f | 9 | var vm = me.pveSelNode.data; |
56166a78 | 10 | |
fe45dd5f | 11 | var nodename = vm.node; |
56166a78 DM |
12 | if (!nodename) { |
13 | throw "no node name specified"; | |
14 | } | |
15 | ||
fe45dd5f | 16 | var vmid = vm.vmid; |
56166a78 DM |
17 | if (!vmid) { |
18 | throw "no VM ID specified"; | |
19 | } | |
20 | ||
fe45dd5f | 21 | var template = !!vm.template; |
3a8508a8 | 22 | |
fe45dd5f | 23 | var running = !!vm.uptime; |
9fe20b3f | 24 | |
56166a78 DM |
25 | var caps = Ext.state.Manager.get('GuiCap'); |
26 | ||
27 | var base_url = '/nodes/' + nodename + '/lxc/' + vmid; | |
540fdc8b | 28 | |
9cb193cf | 29 | me.statusStore = Ext.create('Proxmox.data.ObjectStore', { |
56166a78 | 30 | url: '/api2/json' + base_url + '/status/current', |
f6710aac | 31 | interval: 1000, |
56166a78 DM |
32 | }); |
33 | ||
34 | var vm_command = function(cmd, params) { | |
e7ade592 | 35 | Proxmox.Utils.API2Request({ |
56166a78 DM |
36 | params: params, |
37 | url: base_url + "/status/" + cmd, | |
38 | waitMsgTarget: me, | |
39 | method: 'POST', | |
40 | failure: function(response, opts) { | |
41 | Ext.Msg.alert('Error', response.htmlStatus); | |
f6710aac | 42 | }, |
56166a78 DM |
43 | }); |
44 | }; | |
45 | ||
540fdc8b | 46 | var startBtn = Ext.create('Ext.Button', { |
56166a78 | 47 | text: gettext('Start'), |
9fe20b3f | 48 | disabled: !caps.vms['VM.PowerMgmt'] || running, |
768dd5e4 | 49 | hidden: template, |
56166a78 DM |
50 | handler: function() { |
51 | vm_command('start'); | |
d4333933 | 52 | }, |
f6710aac | 53 | iconCls: 'fa fa-play', |
540fdc8b | 54 | }); |
56166a78 | 55 | |
889c7083 | 56 | var shutdownBtn = Ext.create('PVE.button.Split', { |
56166a78 | 57 | text: gettext('Shutdown'), |
9fe20b3f | 58 | disabled: !caps.vms['VM.PowerMgmt'] || !running, |
768dd5e4 | 59 | hidden: template, |
e7ade592 | 60 | confirmMsg: Proxmox.Utils.format_task_description('vzshutdown', vmid), |
56166a78 DM |
61 | handler: function() { |
62 | vm_command('shutdown'); | |
889c7083 DC |
63 | }, |
64 | menu: { | |
8058410f | 65 | items: [{ |
ba3c982e TL |
66 | text: gettext('Reboot'), |
67 | disabled: !caps.vms['VM.PowerMgmt'], | |
68 | confirmMsg: Proxmox.Utils.format_task_description('vzreboot', vmid), | |
69 | tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'), | |
70 | handler: function() { | |
71 | vm_command("reboot"); | |
72 | }, | |
f6710aac | 73 | iconCls: 'fa fa-refresh', |
ba3c982e TL |
74 | }, |
75 | { | |
2f13fde3 OB |
76 | text: gettext('Stop'), |
77 | disabled: !caps.vms['VM.PowerMgmt'], | |
78 | confirmMsg: Proxmox.Utils.format_task_description('vzstop', vmid), | |
79 | tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'), | |
80 | dangerous: true, | |
81 | handler: function() { | |
82 | vm_command("stop"); | |
83 | }, | |
f6710aac TL |
84 | iconCls: 'fa fa-stop', |
85 | }], | |
d4333933 | 86 | }, |
f6710aac | 87 | iconCls: 'fa fa-power-off', |
56166a78 | 88 | }); |
540fdc8b DC |
89 | |
90 | var migrateBtn = Ext.create('Ext.Button', { | |
56166a78 DM |
91 | text: gettext('Migrate'), |
92 | disabled: !caps.vms['VM.Migrate'], | |
3dc5644c | 93 | hidden: PVE.data.ResourceStore.getNodes().length < 2, |
56166a78 | 94 | handler: function() { |
540fdc8b | 95 | var win = Ext.create('PVE.window.Migrate', { |
56166a78 DM |
96 | vmtype: 'lxc', |
97 | nodename: nodename, | |
f6710aac | 98 | vmid: vmid, |
56166a78 DM |
99 | }); |
100 | win.show(); | |
d4333933 | 101 | }, |
f6710aac | 102 | iconCls: 'fa fa-send-o', |
56166a78 DM |
103 | }); |
104 | ||
5720fafa | 105 | var moreBtn = Ext.create('Proxmox.button.Button', { |
66b8fc0b | 106 | text: gettext('More'), |
8058410f TL |
107 | menu: { |
108 | items: [ | |
9bad05bd DC |
109 | { |
110 | text: gettext('Clone'), | |
111 | iconCls: 'fa fa-fw fa-clone', | |
112 | hidden: caps.vms['VM.Clone'] ? false : true, | |
113 | handler: function() { | |
114 | PVE.window.Clone.wrap(nodename, vmid, template, 'lxc'); | |
f6710aac | 115 | }, |
9bad05bd DC |
116 | }, |
117 | { | |
118 | text: gettext('Convert to template'), | |
119 | disabled: template, | |
120 | xtype: 'pveMenuItem', | |
121 | iconCls: 'fa fa-fw fa-file-o', | |
122 | hidden: caps.vms['VM.Allocate'] ? false : true, | |
123 | confirmMsg: Proxmox.Utils.format_task_description('vztemplate', vmid), | |
124 | handler: function() { | |
125 | Proxmox.Utils.API2Request({ | |
126 | url: base_url + '/template', | |
127 | waitMsgTarget: me, | |
128 | method: 'POST', | |
129 | failure: function(response, opts) { | |
130 | Ext.Msg.alert('Error', response.htmlStatus); | |
f6710aac | 131 | }, |
9bad05bd | 132 | }); |
f6710aac | 133 | }, |
9bad05bd | 134 | }, |
66b8fc0b TL |
135 | { |
136 | iconCls: 'fa fa-heartbeat ', | |
137 | hidden: !caps.nodes['Sys.Console'], | |
138 | text: gettext('Manage HA'), | |
139 | handler: function() { | |
fe45dd5f | 140 | var ha = vm.hastate; |
66b8fc0b TL |
141 | Ext.create('PVE.ha.VMResourceEdit', { |
142 | vmid: vmid, | |
143 | guestType: 'ct', | |
f6710aac | 144 | isCreate: (!ha || ha === 'unmanaged'), |
66b8fc0b | 145 | }).show(); |
f6710aac | 146 | }, |
66b8fc0b TL |
147 | }, |
148 | { | |
149 | text: gettext('Remove'), | |
150 | disabled: !caps.vms['VM.Allocate'], | |
151 | itemId: 'removeBtn', | |
152 | handler: function() { | |
153 | Ext.create('PVE.window.SafeDestroy', { | |
154 | url: base_url, | |
f6710aac | 155 | item: { type: 'CT', id: vmid }, |
66b8fc0b TL |
156 | }).show(); |
157 | }, | |
f6710aac TL |
158 | iconCls: 'fa fa-trash-o', |
159 | }, | |
8058410f TL |
160 | ] |
161 | }, | |
56166a78 DM |
162 | }); |
163 | ||
56166a78 DM |
164 | var consoleBtn = Ext.create('PVE.button.ConsoleButton', { |
165 | disabled: !caps.vms['VM.Console'], | |
166 | consoleType: 'lxc', | |
4ad508ef | 167 | consoleName: vm.name, |
768dd5e4 | 168 | hidden: template, |
56166a78 | 169 | nodename: nodename, |
f6710aac | 170 | vmid: vmid, |
56166a78 DM |
171 | }); |
172 | ||
375d2918 DC |
173 | var statusTxt = Ext.create('Ext.toolbar.TextItem', { |
174 | data: { | |
f6710aac | 175 | lock: undefined, |
375d2918 DC |
176 | }, |
177 | tpl: [ | |
178 | '<tpl if="lock">', | |
179 | '<i class="fa fa-lg fa-lock"></i> ({lock})', | |
f6710aac TL |
180 | '</tpl>', |
181 | ], | |
375d2918 DC |
182 | }); |
183 | ||
184 | ||
56166a78 | 185 | Ext.apply(me, { |
4ad508ef | 186 | title: Ext.String.format(gettext("Container {0} on node '{1}'"), vm.text, nodename), |
56166a78 | 187 | hstateid: 'lxctab', |
375d2918 | 188 | tbarSpacing: false, |
8058410f | 189 | tbar: [statusTxt, '->', startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn], |
56166a78 DM |
190 | defaults: { statusStore: me.statusStore }, |
191 | items: [ | |
192 | { | |
8132a620 | 193 | title: gettext('Summary'), |
df0875c2 | 194 | xtype: 'pveGuestSummary', |
e62ebded | 195 | iconCls: 'fa fa-book', |
f6710aac TL |
196 | itemId: 'summary', |
197 | }, | |
198 | ], | |
56166a78 DM |
199 | }); |
200 | ||
768dd5e4 | 201 | if (caps.vms['VM.Console'] && !template) { |
d345d7ad DC |
202 | me.items.push( |
203 | { | |
204 | title: gettext('Console'), | |
d345d7ad DC |
205 | itemId: 'consolejs', |
206 | iconCls: 'fa fa-terminal', | |
207 | xtype: 'pveNoVncConsole', | |
208 | vmid: vmid, | |
209 | consoleType: 'lxc', | |
210 | xtermjs: true, | |
f6710aac TL |
211 | nodename: nodename, |
212 | }, | |
d345d7ad | 213 | ); |
4224e7c4 | 214 | } |
540fdc8b | 215 | |
e72f4285 DC |
216 | me.items.push( |
217 | { | |
218 | title: gettext('Resources'), | |
219 | itemId: 'resources', | |
220 | expandedOnInit: true, | |
221 | iconCls: 'fa fa-cube', | |
f6710aac | 222 | xtype: 'pveLxcRessourceView', |
e72f4285 DC |
223 | }, |
224 | { | |
225 | title: gettext('Network'), | |
226 | iconCls: 'fa fa-exchange', | |
227 | itemId: 'network', | |
f6710aac | 228 | xtype: 'pveLxcNetworkView', |
e72f4285 DC |
229 | }, |
230 | { | |
231 | title: gettext('DNS'), | |
232 | iconCls: 'fa fa-globe', | |
233 | itemId: 'dns', | |
f6710aac | 234 | xtype: 'pveLxcDNS', |
e72f4285 DC |
235 | }, |
236 | { | |
237 | title: gettext('Options'), | |
238 | itemId: 'options', | |
239 | iconCls: 'fa fa-gear', | |
f6710aac | 240 | xtype: 'pveLxcOptions', |
e72f4285 DC |
241 | }, |
242 | { | |
243 | title: gettext('Task History'), | |
244 | itemId: 'tasks', | |
245 | iconCls: 'fa fa-list', | |
6c60ab5e DC |
246 | xtype: 'proxmoxNodeTasks', |
247 | nodename: nodename, | |
f6710aac TL |
248 | vmidFilter: vmid, |
249 | }, | |
e72f4285 DC |
250 | ); |
251 | ||
252 | if (caps.vms['VM.Backup']) { | |
253 | me.items.push({ | |
254 | title: gettext('Backup'), | |
255 | iconCls: 'fa fa-floppy-o', | |
256 | xtype: 'pveBackupView', | |
f6710aac | 257 | itemId: 'backup', |
cb6df20c DC |
258 | }, |
259 | { | |
260 | title: gettext('Replication'), | |
261 | iconCls: 'fa fa-retweet', | |
262 | xtype: 'pveReplicaView', | |
f6710aac | 263 | itemId: 'replication', |
e72f4285 DC |
264 | }); |
265 | } | |
266 | ||
b06d011e DC |
267 | if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback'] || |
268 | caps.vms['VM.Audit']) && !template) { | |
4224e7c4 EK |
269 | me.items.push({ |
270 | title: gettext('Snapshots'), | |
e62ebded | 271 | iconCls: 'fa fa-history', |
5b1b9360 DC |
272 | xtype: 'pveGuestSnapshotTree', |
273 | type: 'lxc', | |
f6710aac | 274 | itemId: 'snapshot', |
4224e7c4 EK |
275 | }); |
276 | } | |
b70496d6 | 277 | |
4224e7c4 EK |
278 | if (caps.vms['VM.Console']) { |
279 | me.items.push( | |
280 | { | |
e62ebded | 281 | xtype: 'pveFirewallRules', |
4224e7c4 | 282 | title: gettext('Firewall'), |
e62ebded DC |
283 | iconCls: 'fa fa-shield', |
284 | allow_iface: true, | |
285 | base_url: base_url + '/firewall/rules', | |
816b62b0 | 286 | list_refs_url: base_url + '/firewall/refs', |
f6710aac | 287 | itemId: 'firewall', |
e62ebded DC |
288 | }, |
289 | { | |
290 | xtype: 'pveFirewallOptions', | |
291 | groups: ['firewall'], | |
292 | iconCls: 'fa fa-gear', | |
c8802a60 | 293 | onlineHelp: 'pve_firewall_vm_container_configuration', |
e62ebded DC |
294 | title: gettext('Options'), |
295 | base_url: base_url + '/firewall/options', | |
296 | fwtype: 'vm', | |
f6710aac | 297 | itemId: 'firewall-options', |
e62ebded DC |
298 | }, |
299 | { | |
300 | xtype: 'pveFirewallAliases', | |
301 | title: gettext('Alias'), | |
302 | groups: ['firewall'], | |
303 | iconCls: 'fa fa-external-link', | |
304 | base_url: base_url + '/firewall/aliases', | |
f6710aac | 305 | itemId: 'firewall-aliases', |
e62ebded DC |
306 | }, |
307 | { | |
308 | xtype: 'pveIPSet', | |
309 | title: gettext('IPSet'), | |
310 | groups: ['firewall'], | |
311 | iconCls: 'fa fa-list-ol', | |
312 | base_url: base_url + '/firewall/ipset', | |
816b62b0 | 313 | list_refs_url: base_url + '/firewall/refs', |
f6710aac | 314 | itemId: 'firewall-ipset', |
e62ebded DC |
315 | }, |
316 | { | |
317 | title: gettext('Log'), | |
318 | groups: ['firewall'], | |
319 | iconCls: 'fa fa-list', | |
c8802a60 | 320 | onlineHelp: 'chapter_pve_firewall', |
e62ebded | 321 | itemId: 'firewall-fwlog', |
0ee5a21e | 322 | xtype: 'proxmoxLogView', |
f6710aac TL |
323 | url: '/api2/extjs' + base_url + '/firewall/log', |
324 | }, | |
4224e7c4 EK |
325 | ); |
326 | } | |
b70496d6 | 327 | |
8132a620 EK |
328 | if (caps.vms['Permissions.Modify']) { |
329 | me.items.push({ | |
330 | xtype: 'pveACLView', | |
331 | title: gettext('Permissions'), | |
332 | itemId: 'permissions', | |
e62ebded | 333 | iconCls: 'fa fa-unlock', |
f6710aac | 334 | path: '/vms/' + vmid, |
8132a620 EK |
335 | }); |
336 | } | |
56166a78 DM |
337 | |
338 | me.callParent(); | |
339 | ||
e341425c | 340 | var prevStatus = 'unknown'; |
540fdc8b | 341 | me.mon(me.statusStore, 'load', function(s, records, success) { |
56166a78 | 342 | var status; |
375d2918 | 343 | var lock; |
56166a78 | 344 | if (!success) { |
56166a78 DM |
345 | status = 'unknown'; |
346 | } else { | |
347 | var rec = s.data.get('status'); | |
348 | status = rec ? rec.data.value : 'unknown'; | |
3a8508a8 DM |
349 | rec = s.data.get('template'); |
350 | template = rec.data.value || false; | |
375d2918 DC |
351 | rec = s.data.get('lock'); |
352 | lock = rec ? rec.data.value : undefined; | |
56166a78 | 353 | } |
375d2918 DC |
354 | |
355 | statusTxt.update({ lock: lock }); | |
356 | ||
3a8508a8 | 357 | startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template); |
56166a78 | 358 | shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); |
66b8fc0b | 359 | me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped'); |
3a8508a8 | 360 | consoleBtn.setDisabled(template); |
e341425c SR |
361 | |
362 | if (prevStatus === 'stopped' && status === 'running') { | |
363 | let con = me.down('#consolejs'); | |
364 | if (con) { | |
365 | con.reload(); | |
366 | } | |
367 | } | |
368 | ||
369 | prevStatus = status; | |
56166a78 DM |
370 | }); |
371 | ||
372 | me.on('afterrender', function() { | |
373 | me.statusStore.startUpdate(); | |
374 | }); | |
375 | ||
376 | me.on('destroy', function() { | |
377 | me.statusStore.stopUpdate(); | |
378 | }); | |
f6710aac | 379 | }, |
56166a78 | 380 | }); |