]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/lxc/Config.js
ui: utils: refactor mps to mp
[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',
56bc50b8 246 iconCls: 'fa fa-list-alt',
6c60ab5e
DC
247 xtype: 'proxmoxNodeTasks',
248 nodename: nodename,
c313af0f
DC
249 preFilter: {
250 vmid,
251 },
f6710aac 252 },
e72f4285
DC
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',
f6710aac 260 itemId: 'backup',
cb6df20c
DC
261 },
262 {
263 title: gettext('Replication'),
264 iconCls: 'fa fa-retweet',
265 xtype: 'pveReplicaView',
f6710aac 266 itemId: 'replication',
e72f4285
DC
267 });
268 }
269
b06d011e
DC
270 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback'] ||
271 caps.vms['VM.Audit']) && !template) {
4224e7c4
EK
272 me.items.push({
273 title: gettext('Snapshots'),
e62ebded 274 iconCls: 'fa fa-history',
5b1b9360
DC
275 xtype: 'pveGuestSnapshotTree',
276 type: 'lxc',
f6710aac 277 itemId: 'snapshot',
4224e7c4
EK
278 });
279 }
b70496d6 280
4224e7c4
EK
281 if (caps.vms['VM.Console']) {
282 me.items.push(
283 {
e62ebded 284 xtype: 'pveFirewallRules',
4224e7c4 285 title: gettext('Firewall'),
e62ebded
DC
286 iconCls: 'fa fa-shield',
287 allow_iface: true,
288 base_url: base_url + '/firewall/rules',
816b62b0 289 list_refs_url: base_url + '/firewall/refs',
f6710aac 290 itemId: 'firewall',
e62ebded
DC
291 },
292 {
293 xtype: 'pveFirewallOptions',
294 groups: ['firewall'],
295 iconCls: 'fa fa-gear',
c8802a60 296 onlineHelp: 'pve_firewall_vm_container_configuration',
e62ebded
DC
297 title: gettext('Options'),
298 base_url: base_url + '/firewall/options',
299 fwtype: 'vm',
f6710aac 300 itemId: 'firewall-options',
e62ebded
DC
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',
f6710aac 308 itemId: 'firewall-aliases',
e62ebded
DC
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',
816b62b0 316 list_refs_url: base_url + '/firewall/refs',
f6710aac 317 itemId: 'firewall-ipset',
e62ebded
DC
318 },
319 {
320 title: gettext('Log'),
321 groups: ['firewall'],
322 iconCls: 'fa fa-list',
c8802a60 323 onlineHelp: 'chapter_pve_firewall',
e62ebded 324 itemId: 'firewall-fwlog',
0ee5a21e 325 xtype: 'proxmoxLogView',
f6710aac
TL
326 url: '/api2/extjs' + base_url + '/firewall/log',
327 },
4224e7c4
EK
328 );
329 }
b70496d6 330
8132a620
EK
331 if (caps.vms['Permissions.Modify']) {
332 me.items.push({
333 xtype: 'pveACLView',
334 title: gettext('Permissions'),
335 itemId: 'permissions',
e62ebded 336 iconCls: 'fa fa-unlock',
f6710aac 337 path: '/vms/' + vmid,
8132a620
EK
338 });
339 }
56166a78
DM
340
341 me.callParent();
342
e341425c 343 var prevStatus = 'unknown';
540fdc8b 344 me.mon(me.statusStore, 'load', function(s, records, success) {
56166a78 345 var status;
375d2918 346 var lock;
56166a78 347 if (!success) {
56166a78
DM
348 status = 'unknown';
349 } else {
350 var rec = s.data.get('status');
351 status = rec ? rec.data.value : 'unknown';
3a8508a8 352 rec = s.data.get('template');
23b596dc 353 template = rec ? rec.data.value : false;
375d2918
DC
354 rec = s.data.get('lock');
355 lock = rec ? rec.data.value : undefined;
56166a78 356 }
375d2918
DC
357
358 statusTxt.update({ lock: lock });
359
3a8508a8 360 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
56166a78 361 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
66b8fc0b 362 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
3a8508a8 363 consoleBtn.setDisabled(template);
e341425c
SR
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;
56166a78
DM
373 });
374
375 me.on('afterrender', function() {
376 me.statusStore.startUpdate();
377 });
378
379 me.on('destroy', function() {
380 me.statusStore.stopUpdate();
381 });
f6710aac 382 },
56166a78 383});