]>
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 | ||
3a8508a8 DM |
20 | var template = me.pveSelNode.data.template; |
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 | |
56166a78 DM |
28 | me.statusStore = Ext.create('PVE.data.ObjectStore', { |
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, |
56166a78 DM |
48 | handler: function() { |
49 | vm_command('start'); | |
d4333933 DC |
50 | }, |
51 | iconCls: 'fa fa-play' | |
540fdc8b | 52 | }); |
56166a78 | 53 | |
889c7083 | 54 | var stopBtn = Ext.create('Ext.menu.Item',{ |
56166a78 DM |
55 | text: gettext('Stop'), |
56 | disabled: !caps.vms['VM.PowerMgmt'], | |
e7ade592 | 57 | confirmMsg: Proxmox.Utils.format_task_description('vzstop', vmid), |
889c7083 | 58 | dangerous: true, |
56166a78 DM |
59 | handler: function() { |
60 | vm_command("stop"); | |
d4333933 DC |
61 | }, |
62 | iconCls: 'fa fa-stop' | |
56166a78 | 63 | }); |
540fdc8b | 64 | |
889c7083 | 65 | var shutdownBtn = Ext.create('PVE.button.Split', { |
56166a78 | 66 | text: gettext('Shutdown'), |
9fe20b3f | 67 | disabled: !caps.vms['VM.PowerMgmt'] || !running, |
e7ade592 | 68 | confirmMsg: Proxmox.Utils.format_task_description('vzshutdown', vmid), |
56166a78 DM |
69 | handler: function() { |
70 | vm_command('shutdown'); | |
889c7083 DC |
71 | }, |
72 | menu: { | |
73 | items:[stopBtn] | |
d4333933 DC |
74 | }, |
75 | iconCls: 'fa fa-power-off' | |
56166a78 | 76 | }); |
540fdc8b DC |
77 | |
78 | var migrateBtn = Ext.create('Ext.Button', { | |
56166a78 DM |
79 | text: gettext('Migrate'), |
80 | disabled: !caps.vms['VM.Migrate'], | |
3dc5644c | 81 | hidden: PVE.data.ResourceStore.getNodes().length < 2, |
56166a78 | 82 | handler: function() { |
540fdc8b | 83 | var win = Ext.create('PVE.window.Migrate', { |
56166a78 DM |
84 | vmtype: 'lxc', |
85 | nodename: nodename, | |
86 | vmid: vmid | |
87 | }); | |
88 | win.show(); | |
d4333933 DC |
89 | }, |
90 | iconCls: 'fa fa-send-o' | |
56166a78 DM |
91 | }); |
92 | ||
5720fafa | 93 | var moreBtn = Ext.create('Proxmox.button.Button', { |
66b8fc0b TL |
94 | text: gettext('More'), |
95 | menu: { items: [ | |
96 | { | |
97 | iconCls: 'fa fa-heartbeat ', | |
98 | hidden: !caps.nodes['Sys.Console'], | |
99 | text: gettext('Manage HA'), | |
100 | handler: function() { | |
101 | var ha = me.pveSelNode.data.hastate; | |
102 | Ext.create('PVE.ha.VMResourceEdit', { | |
103 | vmid: vmid, | |
104 | guestType: 'ct', | |
105 | isCreate: (!ha || ha === 'unmanaged') | |
106 | }).show(); | |
107 | } | |
108 | }, | |
109 | { | |
110 | text: gettext('Remove'), | |
111 | disabled: !caps.vms['VM.Allocate'], | |
112 | itemId: 'removeBtn', | |
113 | handler: function() { | |
114 | Ext.create('PVE.window.SafeDestroy', { | |
115 | url: base_url, | |
116 | item: { type: 'CT', id: vmid } | |
117 | }).show(); | |
118 | }, | |
119 | iconCls: 'fa fa-trash-o' | |
120 | } | |
121 | ]} | |
56166a78 DM |
122 | }); |
123 | ||
4ad508ef | 124 | var vm = me.pveSelNode.data; |
56166a78 DM |
125 | |
126 | var consoleBtn = Ext.create('PVE.button.ConsoleButton', { | |
127 | disabled: !caps.vms['VM.Console'], | |
128 | consoleType: 'lxc', | |
4ad508ef | 129 | consoleName: vm.name, |
56166a78 | 130 | nodename: nodename, |
ea541321 | 131 | vmid: vmid |
56166a78 DM |
132 | }); |
133 | ||
56166a78 | 134 | Ext.apply(me, { |
4ad508ef | 135 | title: Ext.String.format(gettext("Container {0} on node '{1}'"), vm.text, nodename), |
56166a78 | 136 | hstateid: 'lxctab', |
66b8fc0b | 137 | tbar: [ startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn ], |
56166a78 DM |
138 | defaults: { statusStore: me.statusStore }, |
139 | items: [ | |
140 | { | |
8132a620 EK |
141 | title: gettext('Summary'), |
142 | xtype: 'pveLxcSummary', | |
e62ebded | 143 | iconCls: 'fa fa-book', |
56166a78 | 144 | itemId: 'summary' |
4224e7c4 | 145 | } |
56166a78 DM |
146 | ] |
147 | }); | |
148 | ||
4224e7c4 | 149 | if (caps.vms['VM.Console']) { |
d345d7ad DC |
150 | me.items.push( |
151 | { | |
152 | title: gettext('Console'), | |
153 | itemId: 'console', | |
154 | iconCls: 'fa fa-terminal', | |
155 | xtype: 'pveNoVncConsole', | |
156 | vmid: vmid, | |
157 | consoleType: 'lxc', | |
158 | nodename: nodename | |
159 | }, | |
160 | { | |
161 | title: gettext('Console (JS)'), | |
162 | itemId: 'consolejs', | |
163 | iconCls: 'fa fa-terminal', | |
164 | xtype: 'pveNoVncConsole', | |
165 | vmid: vmid, | |
166 | consoleType: 'lxc', | |
167 | xtermjs: true, | |
168 | nodename: nodename | |
169 | } | |
170 | ); | |
4224e7c4 | 171 | } |
540fdc8b | 172 | |
e72f4285 DC |
173 | me.items.push( |
174 | { | |
175 | title: gettext('Resources'), | |
176 | itemId: 'resources', | |
177 | expandedOnInit: true, | |
178 | iconCls: 'fa fa-cube', | |
179 | xtype: 'pveLxcRessourceView' | |
180 | }, | |
181 | { | |
182 | title: gettext('Network'), | |
183 | iconCls: 'fa fa-exchange', | |
184 | itemId: 'network', | |
185 | xtype: 'pveLxcNetworkView' | |
186 | }, | |
187 | { | |
188 | title: gettext('DNS'), | |
189 | iconCls: 'fa fa-globe', | |
190 | itemId: 'dns', | |
191 | xtype: 'pveLxcDNS' | |
192 | }, | |
193 | { | |
194 | title: gettext('Options'), | |
195 | itemId: 'options', | |
196 | iconCls: 'fa fa-gear', | |
197 | xtype: 'pveLxcOptions' | |
198 | }, | |
199 | { | |
200 | title: gettext('Task History'), | |
201 | itemId: 'tasks', | |
202 | iconCls: 'fa fa-list', | |
6c60ab5e DC |
203 | xtype: 'proxmoxNodeTasks', |
204 | nodename: nodename, | |
e72f4285 DC |
205 | vmidFilter: vmid |
206 | } | |
207 | ); | |
208 | ||
209 | if (caps.vms['VM.Backup']) { | |
210 | me.items.push({ | |
211 | title: gettext('Backup'), | |
212 | iconCls: 'fa fa-floppy-o', | |
213 | xtype: 'pveBackupView', | |
214 | itemId: 'backup' | |
cb6df20c DC |
215 | }, |
216 | { | |
217 | title: gettext('Replication'), | |
218 | iconCls: 'fa fa-retweet', | |
219 | xtype: 'pveReplicaView', | |
220 | itemId: 'replication' | |
e72f4285 DC |
221 | }); |
222 | } | |
223 | ||
8ed196a4 | 224 | if (caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback']) { |
4224e7c4 EK |
225 | me.items.push({ |
226 | title: gettext('Snapshots'), | |
e62ebded | 227 | iconCls: 'fa fa-history', |
4224e7c4 EK |
228 | xtype: 'pveLxcSnapshotTree', |
229 | itemId: 'snapshot' | |
230 | }); | |
231 | } | |
b70496d6 | 232 | |
4224e7c4 EK |
233 | if (caps.vms['VM.Console']) { |
234 | me.items.push( | |
235 | { | |
e62ebded | 236 | xtype: 'pveFirewallRules', |
4224e7c4 | 237 | title: gettext('Firewall'), |
e62ebded DC |
238 | iconCls: 'fa fa-shield', |
239 | allow_iface: true, | |
240 | base_url: base_url + '/firewall/rules', | |
816b62b0 | 241 | list_refs_url: base_url + '/firewall/refs', |
4224e7c4 | 242 | itemId: 'firewall' |
e62ebded DC |
243 | }, |
244 | { | |
245 | xtype: 'pveFirewallOptions', | |
246 | groups: ['firewall'], | |
247 | iconCls: 'fa fa-gear', | |
c8802a60 | 248 | onlineHelp: 'pve_firewall_vm_container_configuration', |
e62ebded DC |
249 | title: gettext('Options'), |
250 | base_url: base_url + '/firewall/options', | |
251 | fwtype: 'vm', | |
252 | itemId: 'firewall-options' | |
253 | }, | |
254 | { | |
255 | xtype: 'pveFirewallAliases', | |
256 | title: gettext('Alias'), | |
257 | groups: ['firewall'], | |
258 | iconCls: 'fa fa-external-link', | |
259 | base_url: base_url + '/firewall/aliases', | |
260 | itemId: 'firewall-aliases' | |
261 | }, | |
262 | { | |
263 | xtype: 'pveIPSet', | |
264 | title: gettext('IPSet'), | |
265 | groups: ['firewall'], | |
266 | iconCls: 'fa fa-list-ol', | |
267 | base_url: base_url + '/firewall/ipset', | |
816b62b0 | 268 | list_refs_url: base_url + '/firewall/refs', |
e62ebded DC |
269 | itemId: 'firewall-ipset' |
270 | }, | |
271 | { | |
272 | title: gettext('Log'), | |
273 | groups: ['firewall'], | |
274 | iconCls: 'fa fa-list', | |
c8802a60 | 275 | onlineHelp: 'chapter_pve_firewall', |
e62ebded DC |
276 | itemId: 'firewall-fwlog', |
277 | xtype: 'pveLogView', | |
278 | url: '/api2/extjs' + base_url + '/firewall/log' | |
4224e7c4 EK |
279 | } |
280 | ); | |
281 | } | |
b70496d6 | 282 | |
8132a620 EK |
283 | if (caps.vms['Permissions.Modify']) { |
284 | me.items.push({ | |
285 | xtype: 'pveACLView', | |
286 | title: gettext('Permissions'), | |
287 | itemId: 'permissions', | |
e62ebded | 288 | iconCls: 'fa fa-unlock', |
8132a620 EK |
289 | path: '/vms/' + vmid |
290 | }); | |
291 | } | |
56166a78 DM |
292 | |
293 | me.callParent(); | |
294 | ||
540fdc8b | 295 | me.mon(me.statusStore, 'load', function(s, records, success) { |
56166a78 DM |
296 | var status; |
297 | if (!success) { | |
56166a78 DM |
298 | status = 'unknown'; |
299 | } else { | |
300 | var rec = s.data.get('status'); | |
301 | status = rec ? rec.data.value : 'unknown'; | |
3a8508a8 DM |
302 | rec = s.data.get('template'); |
303 | template = rec.data.value || false; | |
56166a78 | 304 | } |
3a8508a8 | 305 | startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template); |
56166a78 DM |
306 | shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); |
307 | stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped'); | |
66b8fc0b | 308 | me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped'); |
3a8508a8 | 309 | consoleBtn.setDisabled(template); |
56166a78 DM |
310 | }); |
311 | ||
312 | me.on('afterrender', function() { | |
313 | me.statusStore.startUpdate(); | |
314 | }); | |
315 | ||
316 | me.on('destroy', function() { | |
317 | me.statusStore.stopUpdate(); | |
318 | }); | |
319 | } | |
320 | }); |