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