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