]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/Config.js
use Proxmox.Utils instead of PVE.Utils
[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
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
20 var template = me.pveSelNode.data.template;
21
22 var running = !!me.pveSelNode.data.uptime;
23
24 var caps = Ext.state.Manager.get('GuiCap');
25
26 var base_url = '/nodes/' + nodename + '/lxc/' + vmid;
27
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 Proxmox.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
45 var startBtn = Ext.create('Ext.Button', {
46 text: gettext('Start'),
47 disabled: !caps.vms['VM.PowerMgmt'] || running,
48 handler: function() {
49 vm_command('start');
50 },
51 iconCls: 'fa fa-play'
52 });
53
54 var stopBtn = Ext.create('Ext.menu.Item',{
55 text: gettext('Stop'),
56 disabled: !caps.vms['VM.PowerMgmt'],
57 confirmMsg: Proxmox.Utils.format_task_description('vzstop', vmid),
58 dangerous: true,
59 handler: function() {
60 vm_command("stop");
61 },
62 iconCls: 'fa fa-stop'
63 });
64
65 var shutdownBtn = Ext.create('PVE.button.Split', {
66 text: gettext('Shutdown'),
67 disabled: !caps.vms['VM.PowerMgmt'] || !running,
68 confirmMsg: Proxmox.Utils.format_task_description('vzshutdown', vmid),
69 handler: function() {
70 vm_command('shutdown');
71 },
72 menu: {
73 items:[stopBtn]
74 },
75 iconCls: 'fa fa-power-off'
76 });
77
78 var migrateBtn = Ext.create('Ext.Button', {
79 text: gettext('Migrate'),
80 disabled: !caps.vms['VM.Migrate'],
81 hidden: PVE.data.ResourceStore.getNodes().length < 2,
82 handler: function() {
83 var win = Ext.create('PVE.window.Migrate', {
84 vmtype: 'lxc',
85 nodename: nodename,
86 vmid: vmid
87 });
88 win.show();
89 },
90 iconCls: 'fa fa-send-o'
91 });
92
93 var moreBtn = Ext.create('Proxmox.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 ]}
122 });
123
124 var vm = me.pveSelNode.data;
125
126 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
127 disabled: !caps.vms['VM.Console'],
128 consoleType: 'lxc',
129 consoleName: vm.name,
130 nodename: nodename,
131 vmid: vmid
132 });
133
134 Ext.apply(me, {
135 title: Ext.String.format(gettext("Container {0} on node '{1}'"), vm.text, nodename),
136 hstateid: 'lxctab',
137 tbar: [ startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn ],
138 defaults: { statusStore: me.statusStore },
139 items: [
140 {
141 title: gettext('Summary'),
142 xtype: 'pveLxcSummary',
143 iconCls: 'fa fa-book',
144 itemId: 'summary'
145 }
146 ]
147 });
148
149 if (caps.vms['VM.Console']) {
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 );
171 }
172
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: 'proxmoxNodeTasks',
204 nodename: nodename,
205 vmidFilter: vmid
206 }
207 );
208
209 if (caps.vms['VM.Backup']) {
210 me.items.push({
211 title: gettext('Backup'),
212 iconCls: 'fa fa-floppy-o',
213 xtype: 'pveBackupView',
214 itemId: 'backup'
215 },
216 {
217 title: gettext('Replication'),
218 iconCls: 'fa fa-retweet',
219 xtype: 'pveReplicaView',
220 itemId: 'replication'
221 });
222 }
223
224 if (caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback']) {
225 me.items.push({
226 title: gettext('Snapshots'),
227 iconCls: 'fa fa-history',
228 xtype: 'pveLxcSnapshotTree',
229 itemId: 'snapshot'
230 });
231 }
232
233 if (caps.vms['VM.Console']) {
234 me.items.push(
235 {
236 xtype: 'pveFirewallRules',
237 title: gettext('Firewall'),
238 iconCls: 'fa fa-shield',
239 allow_iface: true,
240 base_url: base_url + '/firewall/rules',
241 list_refs_url: base_url + '/firewall/refs',
242 itemId: 'firewall'
243 },
244 {
245 xtype: 'pveFirewallOptions',
246 groups: ['firewall'],
247 iconCls: 'fa fa-gear',
248 onlineHelp: 'pve_firewall_vm_container_configuration',
249 title: gettext('Options'),
250 base_url: base_url + '/firewall/options',
251 fwtype: 'vm',
252 itemId: 'firewall-options'
253 },
254 {
255 xtype: 'pveFirewallAliases',
256 title: gettext('Alias'),
257 groups: ['firewall'],
258 iconCls: 'fa fa-external-link',
259 base_url: base_url + '/firewall/aliases',
260 itemId: 'firewall-aliases'
261 },
262 {
263 xtype: 'pveIPSet',
264 title: gettext('IPSet'),
265 groups: ['firewall'],
266 iconCls: 'fa fa-list-ol',
267 base_url: base_url + '/firewall/ipset',
268 list_refs_url: base_url + '/firewall/refs',
269 itemId: 'firewall-ipset'
270 },
271 {
272 title: gettext('Log'),
273 groups: ['firewall'],
274 iconCls: 'fa fa-list',
275 onlineHelp: 'chapter_pve_firewall',
276 itemId: 'firewall-fwlog',
277 xtype: 'pveLogView',
278 url: '/api2/extjs' + base_url + '/firewall/log'
279 }
280 );
281 }
282
283 if (caps.vms['Permissions.Modify']) {
284 me.items.push({
285 xtype: 'pveACLView',
286 title: gettext('Permissions'),
287 itemId: 'permissions',
288 iconCls: 'fa fa-unlock',
289 path: '/vms/' + vmid
290 });
291 }
292
293 me.callParent();
294
295 me.mon(me.statusStore, 'load', function(s, records, success) {
296 var status;
297 if (!success) {
298 status = 'unknown';
299 } else {
300 var rec = s.data.get('status');
301 status = rec ? rec.data.value : 'unknown';
302 rec = s.data.get('template');
303 template = rec.data.value || false;
304 }
305 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
306 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
307 stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped');
308 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
309 consoleBtn.setDisabled(template);
310 });
311
312 me.on('afterrender', function() {
313 me.statusStore.startUpdate();
314 });
315
316 me.on('destroy', function() {
317 me.statusStore.stopUpdate();
318 });
319 }
320 });