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