]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/Config.js
ui/lxc: cleanup pveSelNode to variable
[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']) && !template) {
266 me.items.push({
267 title: gettext('Snapshots'),
268 iconCls: 'fa fa-history',
269 xtype: 'pveLxcSnapshotTree',
270 itemId: 'snapshot'
271 });
272 }
273
274 if (caps.vms['VM.Console']) {
275 me.items.push(
276 {
277 xtype: 'pveFirewallRules',
278 title: gettext('Firewall'),
279 iconCls: 'fa fa-shield',
280 allow_iface: true,
281 base_url: base_url + '/firewall/rules',
282 list_refs_url: base_url + '/firewall/refs',
283 itemId: 'firewall'
284 },
285 {
286 xtype: 'pveFirewallOptions',
287 groups: ['firewall'],
288 iconCls: 'fa fa-gear',
289 onlineHelp: 'pve_firewall_vm_container_configuration',
290 title: gettext('Options'),
291 base_url: base_url + '/firewall/options',
292 fwtype: 'vm',
293 itemId: 'firewall-options'
294 },
295 {
296 xtype: 'pveFirewallAliases',
297 title: gettext('Alias'),
298 groups: ['firewall'],
299 iconCls: 'fa fa-external-link',
300 base_url: base_url + '/firewall/aliases',
301 itemId: 'firewall-aliases'
302 },
303 {
304 xtype: 'pveIPSet',
305 title: gettext('IPSet'),
306 groups: ['firewall'],
307 iconCls: 'fa fa-list-ol',
308 base_url: base_url + '/firewall/ipset',
309 list_refs_url: base_url + '/firewall/refs',
310 itemId: 'firewall-ipset'
311 },
312 {
313 title: gettext('Log'),
314 groups: ['firewall'],
315 iconCls: 'fa fa-list',
316 onlineHelp: 'chapter_pve_firewall',
317 itemId: 'firewall-fwlog',
318 xtype: 'proxmoxLogView',
319 url: '/api2/extjs' + base_url + '/firewall/log'
320 }
321 );
322 }
323
324 if (caps.vms['Permissions.Modify']) {
325 me.items.push({
326 xtype: 'pveACLView',
327 title: gettext('Permissions'),
328 itemId: 'permissions',
329 iconCls: 'fa fa-unlock',
330 path: '/vms/' + vmid
331 });
332 }
333
334 me.callParent();
335
336 me.mon(me.statusStore, 'load', function(s, records, success) {
337 var status;
338 var lock;
339 if (!success) {
340 status = 'unknown';
341 } else {
342 var rec = s.data.get('status');
343 status = rec ? rec.data.value : 'unknown';
344 rec = s.data.get('template');
345 template = rec.data.value || false;
346 rec = s.data.get('lock');
347 lock = rec ? rec.data.value : undefined;
348 }
349
350 statusTxt.update({ lock: lock });
351
352 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
353 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
354 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
355 consoleBtn.setDisabled(template);
356 });
357
358 me.on('afterrender', function() {
359 me.statusStore.startUpdate();
360 });
361
362 me.on('destroy', function() {
363 me.statusStore.stopUpdate();
364 });
365 }
366 });