]>
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 | ||
56166a78 DM |
22 | var caps = Ext.state.Manager.get('GuiCap'); |
23 | ||
24 | var base_url = '/nodes/' + nodename + '/lxc/' + vmid; | |
540fdc8b | 25 | |
56166a78 DM |
26 | me.statusStore = Ext.create('PVE.data.ObjectStore', { |
27 | url: '/api2/json' + base_url + '/status/current', | |
28 | interval: 1000 | |
29 | }); | |
30 | ||
31 | var vm_command = function(cmd, params) { | |
32 | PVE.Utils.API2Request({ | |
33 | params: params, | |
34 | url: base_url + "/status/" + cmd, | |
35 | waitMsgTarget: me, | |
36 | method: 'POST', | |
37 | failure: function(response, opts) { | |
38 | Ext.Msg.alert('Error', response.htmlStatus); | |
39 | } | |
40 | }); | |
41 | }; | |
42 | ||
540fdc8b | 43 | var startBtn = Ext.create('Ext.Button', { |
56166a78 DM |
44 | text: gettext('Start'), |
45 | disabled: !caps.vms['VM.PowerMgmt'], | |
46 | handler: function() { | |
47 | vm_command('start'); | |
d4333933 DC |
48 | }, |
49 | iconCls: 'fa fa-play' | |
540fdc8b | 50 | }); |
56166a78 | 51 | |
540fdc8b | 52 | var umountBtn = Ext.create('Ext.Button', { |
56166a78 DM |
53 | text: gettext('Unmount'), |
54 | disabled: true, | |
55 | hidden: true, | |
56 | handler: function() { | |
57 | vm_command('umount'); | |
540fdc8b DC |
58 | } |
59 | }); | |
60 | ||
889c7083 | 61 | var stopBtn = Ext.create('Ext.menu.Item',{ |
56166a78 DM |
62 | text: gettext('Stop'), |
63 | disabled: !caps.vms['VM.PowerMgmt'], | |
16152937 | 64 | confirmMsg: PVE.Utils.format_task_description('vzstop', vmid), |
889c7083 | 65 | dangerous: true, |
56166a78 DM |
66 | handler: function() { |
67 | vm_command("stop"); | |
d4333933 DC |
68 | }, |
69 | iconCls: 'fa fa-stop' | |
56166a78 | 70 | }); |
540fdc8b | 71 | |
889c7083 | 72 | var shutdownBtn = Ext.create('PVE.button.Split', { |
56166a78 DM |
73 | text: gettext('Shutdown'), |
74 | disabled: !caps.vms['VM.PowerMgmt'], | |
16152937 | 75 | confirmMsg: PVE.Utils.format_task_description('vzshutdown', vmid), |
56166a78 DM |
76 | handler: function() { |
77 | vm_command('shutdown'); | |
889c7083 DC |
78 | }, |
79 | menu: { | |
80 | items:[stopBtn] | |
d4333933 DC |
81 | }, |
82 | iconCls: 'fa fa-power-off' | |
56166a78 | 83 | }); |
540fdc8b DC |
84 | |
85 | var migrateBtn = Ext.create('Ext.Button', { | |
56166a78 DM |
86 | text: gettext('Migrate'), |
87 | disabled: !caps.vms['VM.Migrate'], | |
88 | handler: function() { | |
540fdc8b | 89 | var win = Ext.create('PVE.window.Migrate', { |
56166a78 DM |
90 | vmtype: 'lxc', |
91 | nodename: nodename, | |
92 | vmid: vmid | |
93 | }); | |
94 | win.show(); | |
d4333933 DC |
95 | }, |
96 | iconCls: 'fa fa-send-o' | |
56166a78 DM |
97 | }); |
98 | ||
99 | var removeBtn = Ext.create('PVE.button.Button', { | |
100 | text: gettext('Remove'), | |
101 | disabled: !caps.vms['VM.Allocate'], | |
56166a78 | 102 | handler: function() { |
32f469f3 | 103 | Ext.create('PVE.window.SafeDestroy', { |
bcecf280 DM |
104 | url: base_url, |
105 | item: { type: 'CT', id: vmid } | |
32f469f3 | 106 | }).show(); |
d4333933 DC |
107 | }, |
108 | iconCls: 'fa fa-trash-o' | |
56166a78 DM |
109 | }); |
110 | ||
111 | var vmname = me.pveSelNode.data.name; | |
112 | ||
113 | var consoleBtn = Ext.create('PVE.button.ConsoleButton', { | |
114 | disabled: !caps.vms['VM.Console'], | |
115 | consoleType: 'lxc', | |
116 | consoleName: vmname, | |
117 | nodename: nodename, | |
d4333933 DC |
118 | vmid: vmid, |
119 | iconCls: 'fa fa-terminal' | |
56166a78 DM |
120 | }); |
121 | ||
122 | var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'CT " + vmid + "'") + ")"; | |
123 | ||
124 | Ext.apply(me, { | |
125 | title: Ext.String.format(gettext("Container {0} on node {1}"), descr, "'" + nodename + "'"), | |
126 | hstateid: 'lxctab', | |
889c7083 | 127 | tbar: [ startBtn, shutdownBtn, umountBtn, removeBtn, |
56166a78 DM |
128 | migrateBtn, consoleBtn ], |
129 | defaults: { statusStore: me.statusStore }, | |
130 | items: [ | |
131 | { | |
8132a620 EK |
132 | title: gettext('Summary'), |
133 | xtype: 'pveLxcSummary', | |
e62ebded | 134 | iconCls: 'fa fa-book', |
56166a78 | 135 | itemId: 'summary' |
4224e7c4 | 136 | } |
56166a78 DM |
137 | ] |
138 | }); | |
139 | ||
4224e7c4 EK |
140 | if (caps.vms['VM.Console']) { |
141 | me.items.push({ | |
142 | title: gettext('Console'), | |
143 | itemId: 'console', | |
e62ebded | 144 | iconCls: 'fa fa-terminal', |
4224e7c4 EK |
145 | xtype: 'pveNoVncConsole', |
146 | vmid: vmid, | |
147 | consoleType: 'lxc', | |
148 | nodename: nodename | |
149 | }); | |
150 | } | |
540fdc8b | 151 | |
e72f4285 DC |
152 | me.items.push( |
153 | { | |
154 | title: gettext('Resources'), | |
155 | itemId: 'resources', | |
156 | expandedOnInit: true, | |
157 | iconCls: 'fa fa-cube', | |
158 | xtype: 'pveLxcRessourceView' | |
159 | }, | |
160 | { | |
161 | title: gettext('Network'), | |
162 | iconCls: 'fa fa-exchange', | |
163 | itemId: 'network', | |
164 | xtype: 'pveLxcNetworkView' | |
165 | }, | |
166 | { | |
167 | title: gettext('DNS'), | |
168 | iconCls: 'fa fa-globe', | |
169 | itemId: 'dns', | |
170 | xtype: 'pveLxcDNS' | |
171 | }, | |
172 | { | |
173 | title: gettext('Options'), | |
174 | itemId: 'options', | |
175 | iconCls: 'fa fa-gear', | |
176 | xtype: 'pveLxcOptions' | |
177 | }, | |
178 | { | |
179 | title: gettext('Task History'), | |
180 | itemId: 'tasks', | |
181 | iconCls: 'fa fa-list', | |
182 | xtype: 'pveNodeTasks', | |
183 | vmidFilter: vmid | |
184 | } | |
185 | ); | |
186 | ||
187 | if (caps.vms['VM.Backup']) { | |
188 | me.items.push({ | |
189 | title: gettext('Backup'), | |
190 | iconCls: 'fa fa-floppy-o', | |
191 | xtype: 'pveBackupView', | |
192 | itemId: 'backup' | |
193 | }); | |
194 | } | |
195 | ||
4224e7c4 EK |
196 | if (caps.vms['VM.Snapshot']) { |
197 | me.items.push({ | |
198 | title: gettext('Snapshots'), | |
e62ebded | 199 | iconCls: 'fa fa-history', |
4224e7c4 EK |
200 | xtype: 'pveLxcSnapshotTree', |
201 | itemId: 'snapshot' | |
202 | }); | |
203 | } | |
b70496d6 | 204 | |
4224e7c4 EK |
205 | if (caps.vms['VM.Console']) { |
206 | me.items.push( | |
207 | { | |
e62ebded | 208 | xtype: 'pveFirewallRules', |
4224e7c4 | 209 | title: gettext('Firewall'), |
e62ebded DC |
210 | iconCls: 'fa fa-shield', |
211 | allow_iface: true, | |
212 | base_url: base_url + '/firewall/rules', | |
816b62b0 | 213 | list_refs_url: base_url + '/firewall/refs', |
4224e7c4 | 214 | itemId: 'firewall' |
e62ebded DC |
215 | }, |
216 | { | |
217 | xtype: 'pveFirewallOptions', | |
218 | groups: ['firewall'], | |
219 | iconCls: 'fa fa-gear', | |
c8802a60 | 220 | onlineHelp: 'pve_firewall_vm_container_configuration', |
e62ebded DC |
221 | title: gettext('Options'), |
222 | base_url: base_url + '/firewall/options', | |
223 | fwtype: 'vm', | |
224 | itemId: 'firewall-options' | |
225 | }, | |
226 | { | |
227 | xtype: 'pveFirewallAliases', | |
228 | title: gettext('Alias'), | |
229 | groups: ['firewall'], | |
230 | iconCls: 'fa fa-external-link', | |
231 | base_url: base_url + '/firewall/aliases', | |
232 | itemId: 'firewall-aliases' | |
233 | }, | |
234 | { | |
235 | xtype: 'pveIPSet', | |
236 | title: gettext('IPSet'), | |
237 | groups: ['firewall'], | |
238 | iconCls: 'fa fa-list-ol', | |
239 | base_url: base_url + '/firewall/ipset', | |
816b62b0 | 240 | list_refs_url: base_url + '/firewall/refs', |
e62ebded DC |
241 | itemId: 'firewall-ipset' |
242 | }, | |
243 | { | |
244 | title: gettext('Log'), | |
245 | groups: ['firewall'], | |
246 | iconCls: 'fa fa-list', | |
c8802a60 | 247 | onlineHelp: 'chapter_pve_firewall', |
e62ebded DC |
248 | itemId: 'firewall-fwlog', |
249 | xtype: 'pveLogView', | |
250 | url: '/api2/extjs' + base_url + '/firewall/log' | |
4224e7c4 EK |
251 | } |
252 | ); | |
253 | } | |
b70496d6 | 254 | |
8132a620 EK |
255 | if (caps.vms['Permissions.Modify']) { |
256 | me.items.push({ | |
257 | xtype: 'pveACLView', | |
258 | title: gettext('Permissions'), | |
259 | itemId: 'permissions', | |
e62ebded | 260 | iconCls: 'fa fa-unlock', |
8132a620 EK |
261 | path: '/vms/' + vmid |
262 | }); | |
263 | } | |
56166a78 DM |
264 | |
265 | me.callParent(); | |
266 | ||
540fdc8b | 267 | me.mon(me.statusStore, 'load', function(s, records, success) { |
56166a78 DM |
268 | var status; |
269 | if (!success) { | |
270 | me.workspace.checkVmMigration(me.pveSelNode); | |
271 | status = 'unknown'; | |
272 | } else { | |
273 | var rec = s.data.get('status'); | |
274 | status = rec ? rec.data.value : 'unknown'; | |
3a8508a8 DM |
275 | rec = s.data.get('template'); |
276 | template = rec.data.value || false; | |
56166a78 | 277 | } |
3a8508a8 | 278 | startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template); |
56166a78 DM |
279 | shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); |
280 | stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped'); | |
281 | removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped'); | |
3a8508a8 | 282 | consoleBtn.setDisabled(template); |
56166a78 DM |
283 | |
284 | if (status === 'mounted') { | |
285 | umountBtn.setDisabled(false); | |
286 | umountBtn.setVisible(true); | |
889c7083 | 287 | stopBtn.setDisabled(true); |
56166a78 DM |
288 | } else { |
289 | umountBtn.setDisabled(true); | |
290 | umountBtn.setVisible(false); | |
889c7083 | 291 | stopBtn.setDisabled(false); |
56166a78 DM |
292 | } |
293 | }); | |
294 | ||
295 | me.on('afterrender', function() { | |
296 | me.statusStore.startUpdate(); | |
297 | }); | |
298 | ||
299 | me.on('destroy', function() { | |
300 | me.statusStore.stopUpdate(); | |
301 | }); | |
302 | } | |
303 | }); |