]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/Config.js
ui: eslint: fix trailing comma and comma related whitespaces errors
[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: { items: [
108 {
109 text: gettext('Clone'),
110 iconCls: 'fa fa-fw fa-clone',
111 hidden: caps.vms['VM.Clone'] ? false : true,
112 handler: function() {
113 PVE.window.Clone.wrap(nodename, vmid, template, 'lxc');
114 },
115 },
116 {
117 text: gettext('Convert to template'),
118 disabled: template,
119 xtype: 'pveMenuItem',
120 iconCls: 'fa fa-fw fa-file-o',
121 hidden: caps.vms['VM.Allocate'] ? false : true,
122 confirmMsg: Proxmox.Utils.format_task_description('vztemplate', vmid),
123 handler: function() {
124 Proxmox.Utils.API2Request({
125 url: base_url + '/template',
126 waitMsgTarget: me,
127 method: 'POST',
128 failure: function(response, opts) {
129 Ext.Msg.alert('Error', response.htmlStatus);
130 },
131 });
132 },
133 },
134 {
135 iconCls: 'fa fa-heartbeat ',
136 hidden: !caps.nodes['Sys.Console'],
137 text: gettext('Manage HA'),
138 handler: function() {
139 var ha = vm.hastate;
140 Ext.create('PVE.ha.VMResourceEdit', {
141 vmid: vmid,
142 guestType: 'ct',
143 isCreate: (!ha || ha === 'unmanaged'),
144 }).show();
145 },
146 },
147 {
148 text: gettext('Remove'),
149 disabled: !caps.vms['VM.Allocate'],
150 itemId: 'removeBtn',
151 handler: function() {
152 Ext.create('PVE.window.SafeDestroy', {
153 url: base_url,
154 item: { type: 'CT', id: vmid },
155 }).show();
156 },
157 iconCls: 'fa fa-trash-o',
158 },
159 ]},
160 });
161
162 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
163 disabled: !caps.vms['VM.Console'],
164 consoleType: 'lxc',
165 consoleName: vm.name,
166 hidden: template,
167 nodename: nodename,
168 vmid: vmid,
169 });
170
171 var statusTxt = Ext.create('Ext.toolbar.TextItem', {
172 data: {
173 lock: undefined,
174 },
175 tpl: [
176 '<tpl if="lock">',
177 '<i class="fa fa-lg fa-lock"></i> ({lock})',
178 '</tpl>',
179 ],
180 });
181
182
183 Ext.apply(me, {
184 title: Ext.String.format(gettext("Container {0} on node '{1}'"), vm.text, nodename),
185 hstateid: 'lxctab',
186 tbarSpacing: false,
187 tbar: [ statusTxt, '->', startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn ],
188 defaults: { statusStore: me.statusStore },
189 items: [
190 {
191 title: gettext('Summary'),
192 xtype: 'pveGuestSummary',
193 iconCls: 'fa fa-book',
194 itemId: 'summary',
195 },
196 ],
197 });
198
199 if (caps.vms['VM.Console'] && !template) {
200 me.items.push(
201 {
202 title: gettext('Console'),
203 itemId: 'consolejs',
204 iconCls: 'fa fa-terminal',
205 xtype: 'pveNoVncConsole',
206 vmid: vmid,
207 consoleType: 'lxc',
208 xtermjs: true,
209 nodename: nodename,
210 },
211 );
212 }
213
214 me.items.push(
215 {
216 title: gettext('Resources'),
217 itemId: 'resources',
218 expandedOnInit: true,
219 iconCls: 'fa fa-cube',
220 xtype: 'pveLxcRessourceView',
221 },
222 {
223 title: gettext('Network'),
224 iconCls: 'fa fa-exchange',
225 itemId: 'network',
226 xtype: 'pveLxcNetworkView',
227 },
228 {
229 title: gettext('DNS'),
230 iconCls: 'fa fa-globe',
231 itemId: 'dns',
232 xtype: 'pveLxcDNS',
233 },
234 {
235 title: gettext('Options'),
236 itemId: 'options',
237 iconCls: 'fa fa-gear',
238 xtype: 'pveLxcOptions',
239 },
240 {
241 title: gettext('Task History'),
242 itemId: 'tasks',
243 iconCls: 'fa fa-list',
244 xtype: 'proxmoxNodeTasks',
245 nodename: nodename,
246 vmidFilter: vmid,
247 },
248 );
249
250 if (caps.vms['VM.Backup']) {
251 me.items.push({
252 title: gettext('Backup'),
253 iconCls: 'fa fa-floppy-o',
254 xtype: 'pveBackupView',
255 itemId: 'backup',
256 },
257 {
258 title: gettext('Replication'),
259 iconCls: 'fa fa-retweet',
260 xtype: 'pveReplicaView',
261 itemId: 'replication',
262 });
263 }
264
265 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback'] ||
266 caps.vms['VM.Audit']) && !template) {
267 me.items.push({
268 title: gettext('Snapshots'),
269 iconCls: 'fa fa-history',
270 xtype: 'pveGuestSnapshotTree',
271 type: 'lxc',
272 itemId: 'snapshot',
273 });
274 }
275
276 if (caps.vms['VM.Console']) {
277 me.items.push(
278 {
279 xtype: 'pveFirewallRules',
280 title: gettext('Firewall'),
281 iconCls: 'fa fa-shield',
282 allow_iface: true,
283 base_url: base_url + '/firewall/rules',
284 list_refs_url: base_url + '/firewall/refs',
285 itemId: 'firewall',
286 },
287 {
288 xtype: 'pveFirewallOptions',
289 groups: ['firewall'],
290 iconCls: 'fa fa-gear',
291 onlineHelp: 'pve_firewall_vm_container_configuration',
292 title: gettext('Options'),
293 base_url: base_url + '/firewall/options',
294 fwtype: 'vm',
295 itemId: 'firewall-options',
296 },
297 {
298 xtype: 'pveFirewallAliases',
299 title: gettext('Alias'),
300 groups: ['firewall'],
301 iconCls: 'fa fa-external-link',
302 base_url: base_url + '/firewall/aliases',
303 itemId: 'firewall-aliases',
304 },
305 {
306 xtype: 'pveIPSet',
307 title: gettext('IPSet'),
308 groups: ['firewall'],
309 iconCls: 'fa fa-list-ol',
310 base_url: base_url + '/firewall/ipset',
311 list_refs_url: base_url + '/firewall/refs',
312 itemId: 'firewall-ipset',
313 },
314 {
315 title: gettext('Log'),
316 groups: ['firewall'],
317 iconCls: 'fa fa-list',
318 onlineHelp: 'chapter_pve_firewall',
319 itemId: 'firewall-fwlog',
320 xtype: 'proxmoxLogView',
321 url: '/api2/extjs' + base_url + '/firewall/log',
322 },
323 );
324 }
325
326 if (caps.vms['Permissions.Modify']) {
327 me.items.push({
328 xtype: 'pveACLView',
329 title: gettext('Permissions'),
330 itemId: 'permissions',
331 iconCls: 'fa fa-unlock',
332 path: '/vms/' + vmid,
333 });
334 }
335
336 me.callParent();
337
338 var prevStatus = 'unknown';
339 me.mon(me.statusStore, 'load', function(s, records, success) {
340 var status;
341 var lock;
342 if (!success) {
343 status = 'unknown';
344 } else {
345 var rec = s.data.get('status');
346 status = rec ? rec.data.value : 'unknown';
347 rec = s.data.get('template');
348 template = rec.data.value || false;
349 rec = s.data.get('lock');
350 lock = rec ? rec.data.value : undefined;
351 }
352
353 statusTxt.update({ lock: lock });
354
355 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
356 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
357 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
358 consoleBtn.setDisabled(template);
359
360 if (prevStatus === 'stopped' && status === 'running') {
361 let con = me.down('#consolejs');
362 if (con) {
363 con.reload();
364 }
365 }
366
367 prevStatus = status;
368 });
369
370 me.on('afterrender', function() {
371 me.statusStore.startUpdate();
372 });
373
374 me.on('destroy', function() {
375 me.statusStore.stopUpdate();
376 });
377 },
378 });