]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/lxc/Config.js
ui: mpedit: activate backup on MP creation
[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('Proxmox.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 hidden: template,
49 handler: function() {
50 vm_command('start');
51 },
52 iconCls: 'fa fa-play'
53 });
54
55 var shutdownBtn = Ext.create('PVE.button.Split', {
56 text: gettext('Shutdown'),
57 disabled: !caps.vms['VM.PowerMgmt'] || !running,
58 hidden: template,
59 confirmMsg: Proxmox.Utils.format_task_description('vzshutdown', vmid),
60 handler: function() {
61 vm_command('shutdown');
62 },
63 menu: {
64 items:[{
65 text: gettext('Reboot'),
66 disabled: !caps.vms['VM.PowerMgmt'],
67 confirmMsg: Proxmox.Utils.format_task_description('vzreboot', vmid),
68 tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'),
69 handler: function() {
70 vm_command("reboot");
71 },
72 iconCls: 'fa fa-refresh'
73 },
74 {
75 text: gettext('Stop'),
76 disabled: !caps.vms['VM.PowerMgmt'],
77 confirmMsg: Proxmox.Utils.format_task_description('vzstop', vmid),
78 tooltip: Ext.String.format(gettext('Stop {0} immediately'), 'CT'),
79 dangerous: true,
80 handler: function() {
81 vm_command("stop");
82 },
83 iconCls: 'fa fa-stop'
84 }]
85 },
86 iconCls: 'fa fa-power-off'
87 });
88
89 var migrateBtn = Ext.create('Ext.Button', {
90 text: gettext('Migrate'),
91 disabled: !caps.vms['VM.Migrate'],
92 hidden: PVE.data.ResourceStore.getNodes().length < 2,
93 handler: function() {
94 var win = Ext.create('PVE.window.Migrate', {
95 vmtype: 'lxc',
96 nodename: nodename,
97 vmid: vmid
98 });
99 win.show();
100 },
101 iconCls: 'fa fa-send-o'
102 });
103
104 var moreBtn = Ext.create('Proxmox.button.Button', {
105 text: gettext('More'),
106 menu: { items: [
107 {
108 text: gettext('Clone'),
109 iconCls: 'fa fa-fw fa-clone',
110 hidden: caps.vms['VM.Clone'] ? false : true,
111 handler: function() {
112 PVE.window.Clone.wrap(nodename, vmid, template, 'lxc');
113 }
114 },
115 {
116 text: gettext('Convert to template'),
117 disabled: template,
118 xtype: 'pveMenuItem',
119 iconCls: 'fa fa-fw fa-file-o',
120 hidden: caps.vms['VM.Allocate'] ? false : true,
121 confirmMsg: Proxmox.Utils.format_task_description('vztemplate', vmid),
122 handler: function() {
123 Proxmox.Utils.API2Request({
124 url: base_url + '/template',
125 waitMsgTarget: me,
126 method: 'POST',
127 failure: function(response, opts) {
128 Ext.Msg.alert('Error', response.htmlStatus);
129 }
130 });
131 }
132 },
133 {
134 iconCls: 'fa fa-heartbeat ',
135 hidden: !caps.nodes['Sys.Console'],
136 text: gettext('Manage HA'),
137 handler: function() {
138 var ha = me.pveSelNode.data.hastate;
139 Ext.create('PVE.ha.VMResourceEdit', {
140 vmid: vmid,
141 guestType: 'ct',
142 isCreate: (!ha || ha === 'unmanaged')
143 }).show();
144 }
145 },
146 {
147 text: gettext('Remove'),
148 disabled: !caps.vms['VM.Allocate'],
149 itemId: 'removeBtn',
150 handler: function() {
151 Ext.create('PVE.window.SafeDestroy', {
152 url: base_url,
153 item: { type: 'CT', id: vmid }
154 }).show();
155 },
156 iconCls: 'fa fa-trash-o'
157 }
158 ]}
159 });
160
161 var vm = me.pveSelNode.data;
162
163 var consoleBtn = Ext.create('PVE.button.ConsoleButton', {
164 disabled: !caps.vms['VM.Console'],
165 consoleType: 'lxc',
166 consoleName: vm.name,
167 hidden: template,
168 nodename: nodename,
169 vmid: vmid
170 });
171
172 var statusTxt = Ext.create('Ext.toolbar.TextItem', {
173 data: {
174 lock: undefined
175 },
176 tpl: [
177 '<tpl if="lock">',
178 '<i class="fa fa-lg fa-lock"></i> ({lock})',
179 '</tpl>'
180 ]
181 });
182
183
184 Ext.apply(me, {
185 title: Ext.String.format(gettext("Container {0} on node '{1}'"), vm.text, nodename),
186 hstateid: 'lxctab',
187 tbarSpacing: false,
188 tbar: [ statusTxt, '->', startBtn, shutdownBtn, migrateBtn, consoleBtn, moreBtn ],
189 defaults: { statusStore: me.statusStore },
190 items: [
191 {
192 title: gettext('Summary'),
193 xtype: 'pveGuestSummary',
194 iconCls: 'fa fa-book',
195 itemId: 'summary'
196 }
197 ]
198 });
199
200 if (caps.vms['VM.Console'] && !template) {
201 me.items.push(
202 {
203 title: gettext('Console'),
204 itemId: 'consolejs',
205 iconCls: 'fa fa-terminal',
206 xtype: 'pveNoVncConsole',
207 vmid: vmid,
208 consoleType: 'lxc',
209 xtermjs: true,
210 nodename: nodename
211 }
212 );
213 }
214
215 me.items.push(
216 {
217 title: gettext('Resources'),
218 itemId: 'resources',
219 expandedOnInit: true,
220 iconCls: 'fa fa-cube',
221 xtype: 'pveLxcRessourceView'
222 },
223 {
224 title: gettext('Network'),
225 iconCls: 'fa fa-exchange',
226 itemId: 'network',
227 xtype: 'pveLxcNetworkView'
228 },
229 {
230 title: gettext('DNS'),
231 iconCls: 'fa fa-globe',
232 itemId: 'dns',
233 xtype: 'pveLxcDNS'
234 },
235 {
236 title: gettext('Options'),
237 itemId: 'options',
238 iconCls: 'fa fa-gear',
239 xtype: 'pveLxcOptions'
240 },
241 {
242 title: gettext('Task History'),
243 itemId: 'tasks',
244 iconCls: 'fa fa-list',
245 xtype: 'proxmoxNodeTasks',
246 nodename: nodename,
247 vmidFilter: vmid
248 }
249 );
250
251 if (caps.vms['VM.Backup']) {
252 me.items.push({
253 title: gettext('Backup'),
254 iconCls: 'fa fa-floppy-o',
255 xtype: 'pveBackupView',
256 itemId: 'backup'
257 },
258 {
259 title: gettext('Replication'),
260 iconCls: 'fa fa-retweet',
261 xtype: 'pveReplicaView',
262 itemId: 'replication'
263 });
264 }
265
266 if ((caps.vms['VM.Snapshot'] || caps.vms['VM.Snapshot.Rollback']) && !template) {
267 me.items.push({
268 title: gettext('Snapshots'),
269 iconCls: 'fa fa-history',
270 xtype: 'pveLxcSnapshotTree',
271 itemId: 'snapshot'
272 });
273 }
274
275 if (caps.vms['VM.Console']) {
276 me.items.push(
277 {
278 xtype: 'pveFirewallRules',
279 title: gettext('Firewall'),
280 iconCls: 'fa fa-shield',
281 allow_iface: true,
282 base_url: base_url + '/firewall/rules',
283 list_refs_url: base_url + '/firewall/refs',
284 itemId: 'firewall'
285 },
286 {
287 xtype: 'pveFirewallOptions',
288 groups: ['firewall'],
289 iconCls: 'fa fa-gear',
290 onlineHelp: 'pve_firewall_vm_container_configuration',
291 title: gettext('Options'),
292 base_url: base_url + '/firewall/options',
293 fwtype: 'vm',
294 itemId: 'firewall-options'
295 },
296 {
297 xtype: 'pveFirewallAliases',
298 title: gettext('Alias'),
299 groups: ['firewall'],
300 iconCls: 'fa fa-external-link',
301 base_url: base_url + '/firewall/aliases',
302 itemId: 'firewall-aliases'
303 },
304 {
305 xtype: 'pveIPSet',
306 title: gettext('IPSet'),
307 groups: ['firewall'],
308 iconCls: 'fa fa-list-ol',
309 base_url: base_url + '/firewall/ipset',
310 list_refs_url: base_url + '/firewall/refs',
311 itemId: 'firewall-ipset'
312 },
313 {
314 title: gettext('Log'),
315 groups: ['firewall'],
316 iconCls: 'fa fa-list',
317 onlineHelp: 'chapter_pve_firewall',
318 itemId: 'firewall-fwlog',
319 xtype: 'proxmoxLogView',
320 url: '/api2/extjs' + base_url + '/firewall/log'
321 }
322 );
323 }
324
325 if (caps.vms['Permissions.Modify']) {
326 me.items.push({
327 xtype: 'pveACLView',
328 title: gettext('Permissions'),
329 itemId: 'permissions',
330 iconCls: 'fa fa-unlock',
331 path: '/vms/' + vmid
332 });
333 }
334
335 me.callParent();
336
337 me.mon(me.statusStore, 'load', function(s, records, success) {
338 var status;
339 var lock;
340 if (!success) {
341 status = 'unknown';
342 } else {
343 var rec = s.data.get('status');
344 status = rec ? rec.data.value : 'unknown';
345 rec = s.data.get('template');
346 template = rec.data.value || false;
347 rec = s.data.get('lock');
348 lock = rec ? rec.data.value : undefined;
349 }
350
351 statusTxt.update({ lock: lock });
352
353 startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running' || template);
354 shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running');
355 me.down('#removeBtn').setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped');
356 consoleBtn.setDisabled(template);
357 });
358
359 me.on('afterrender', function() {
360 me.statusStore.startUpdate();
361 });
362
363 me.on('destroy', function() {
364 me.statusStore.stopUpdate();
365 });
366 }
367 });