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