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