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