]>
Commit | Line | Data |
---|---|---|
b48c6847 DM |
1 | Ext.define('PVE.lxc.Config', { |
2 | extend: 'PVE.panel.Config', | |
3 | alias: 'widget.PVE.lxc.Config', | |
4 | ||
5 | initComponent: function() { | |
6 | var me = this; | |
7 | ||
8 | var nodename = me.pveSelNode.data.node; | |
9 | if (!nodename) { | |
10 | throw "no node name specified"; | |
11 | } | |
12 | ||
13 | var vmid = me.pveSelNode.data.vmid; | |
14 | if (!vmid) { | |
15 | throw "no VM ID specified"; | |
16 | } | |
17 | ||
18 | var caps = Ext.state.Manager.get('GuiCap'); | |
19 | ||
20 | var base_url = '/nodes/' + nodename + '/lxc/' + vmid; | |
21 | ||
22 | me.statusStore = Ext.create('PVE.data.ObjectStore', { | |
23 | url: '/api2/json' + base_url + '/status/current', | |
24 | interval: 1000 | |
25 | }); | |
26 | ||
27 | var vm_command = function(cmd, params) { | |
28 | PVE.Utils.API2Request({ | |
29 | params: params, | |
30 | url: base_url + "/status/" + cmd, | |
31 | waitMsgTarget: me, | |
32 | method: 'POST', | |
33 | failure: function(response, opts) { | |
34 | Ext.Msg.alert('Error', response.htmlStatus); | |
35 | } | |
36 | }); | |
37 | }; | |
38 | ||
39 | var startBtn = Ext.create('Ext.Button', { | |
40 | text: gettext('Start'), | |
41 | disabled: !caps.vms['VM.PowerMgmt'], | |
42 | handler: function() { | |
43 | vm_command('start'); | |
44 | } | |
45 | }); | |
46 | ||
47 | var umountBtn = Ext.create('Ext.Button', { | |
48 | text: gettext('Unmount'), | |
49 | disabled: true, | |
50 | hidden: true, | |
51 | handler: function() { | |
52 | vm_command('umount'); | |
53 | } | |
54 | }); | |
55 | ||
56 | var stopBtn = Ext.create('PVE.button.Button', { | |
57 | text: gettext('Stop'), | |
58 | disabled: !caps.vms['VM.PowerMgmt'], | |
59 | confirmMsg: Ext.String.format(gettext("Do you really want to stop VM {0}?"), vmid), | |
60 | handler: function() { | |
61 | vm_command("stop"); | |
62 | } | |
63 | }); | |
64 | ||
65 | var shutdownBtn = Ext.create('PVE.button.Button', { | |
66 | text: gettext('Shutdown'), | |
67 | disabled: !caps.vms['VM.PowerMgmt'], | |
68 | confirmMsg: Ext.String.format(gettext("Do you really want to shutdown VM {0}?"), vmid), | |
69 | handler: function() { | |
70 | vm_command('shutdown'); | |
71 | } | |
72 | }); | |
73 | ||
74 | var migrateBtn = Ext.create('Ext.Button', { | |
75 | text: gettext('Migrate'), | |
76 | disabled: !caps.vms['VM.Migrate'], | |
77 | handler: function() { | |
78 | var win = Ext.create('PVE.window.Migrate', { | |
79 | vmtype: 'lxc', | |
80 | nodename: nodename, | |
81 | vmid: vmid | |
82 | }); | |
83 | win.show(); | |
84 | } | |
85 | }); | |
86 | ||
87 | var removeBtn = Ext.create('PVE.button.Button', { | |
88 | text: gettext('Remove'), | |
89 | disabled: !caps.vms['VM.Allocate'], | |
90 | dangerous: true, | |
91 | confirmMsg: Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), vmid), | |
92 | handler: function() { | |
93 | PVE.Utils.API2Request({ | |
94 | url: base_url, | |
95 | method: 'DELETE', | |
96 | waitMsgTarget: me, | |
97 | failure: function(response, opts) { | |
98 | Ext.Msg.alert('Error', response.htmlStatus); | |
99 | } | |
100 | }); | |
101 | } | |
102 | }); | |
103 | ||
104 | var vmname = me.pveSelNode.data.name; | |
105 | ||
106 | var consoleBtn = Ext.create('PVE.button.ConsoleButton', { | |
107 | disabled: !caps.vms['VM.Console'], | |
108 | consoleType: 'lxc', | |
109 | consoleName: vmname, | |
110 | nodename: nodename, | |
111 | vmid: vmid | |
112 | }); | |
113 | ||
114 | var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'CT " + vmid + "'") + ")"; | |
115 | ||
116 | Ext.apply(me, { | |
117 | title: Ext.String.format(gettext("Container {0} on node {1}"), descr, "'" + nodename + "'"), | |
118 | hstateid: 'lxctab', | |
119 | tbar: [ startBtn, shutdownBtn, umountBtn, stopBtn, removeBtn, | |
120 | migrateBtn, consoleBtn ], | |
121 | defaults: { statusStore: me.statusStore }, | |
122 | items: [ | |
123 | { | |
124 | title: gettext('Summary'), | |
125 | xtype: 'pveLxcSummary', | |
126 | itemId: 'summary' | |
127 | }, | |
6dba2f98 DM |
128 | { |
129 | title: gettext('Resources'), | |
130 | itemId: 'resources', | |
131 | xtype: 'pveLxcRessourceView' | |
132 | }, | |
3533a506 DM |
133 | { |
134 | title: gettext('Network'), | |
135 | itemId: 'network', | |
136 | xtype: 'pveLxcNetworkView' | |
137 | }, | |
42fb5a6a DM |
138 | { |
139 | title: gettext('DNS'), | |
140 | itemId: 'dns', | |
141 | xtype: 'pveLxcDNS' | |
142 | }, | |
2c27e4b7 DM |
143 | { |
144 | title: gettext('Options'), | |
145 | itemId: 'options', | |
146 | xtype: 'pveLxcOptions' | |
147 | }, | |
b48c6847 DM |
148 | { |
149 | title: gettext('Task History'), | |
150 | itemId: 'tasks', | |
151 | xtype: 'pveNodeTasks', | |
152 | vmidFilter: vmid | |
153 | } | |
154 | ] | |
155 | }); | |
156 | ||
157 | if (caps.vms['VM.Backup']) { | |
158 | me.items.push({ | |
159 | title: gettext('Backup'), | |
160 | xtype: 'pveBackupView', | |
161 | itemId: 'backup' | |
162 | }); | |
163 | } | |
164 | ||
6a4c551c DM |
165 | if (caps.vms['VM.Console']) { |
166 | me.items.push({ | |
167 | title: gettext('Console'), | |
168 | itemId: 'console', | |
169 | xtype: 'pveNoVncConsole', | |
170 | vmid: vmid, | |
171 | consoleType: 'lxc', | |
172 | nodename: nodename | |
173 | }); | |
174 | } | |
2a30f274 WL |
175 | |
176 | if (caps.vms['VM.Snapshot']) { | |
177 | me.items.push({ | |
178 | title: gettext('Snapshots'), | |
179 | xtype: 'pveLxcSnapshotTree', | |
180 | itemId: 'snapshot' | |
181 | }); | |
182 | } | |
6a4c551c | 183 | |
b48c6847 DM |
184 | if (caps.vms['VM.Console']) { |
185 | me.items.push([ | |
186 | { | |
187 | xtype: 'pveFirewallPanel', | |
188 | title: gettext('Firewall'), | |
189 | base_url: base_url + '/firewall', | |
190 | fwtype: 'vm', | |
191 | phstateid: me.hstateid, | |
192 | itemId: 'firewall' | |
193 | } | |
194 | ]); | |
195 | } | |
196 | ||
197 | if (caps.vms['Permissions.Modify']) { | |
198 | me.items.push({ | |
199 | xtype: 'pveACLView', | |
200 | title: gettext('Permissions'), | |
201 | itemId: 'permissions', | |
202 | path: '/vms/' + vmid | |
203 | }); | |
204 | } | |
205 | ||
206 | me.callParent(); | |
207 | ||
208 | me.statusStore.on('load', function(s, records, success) { | |
209 | var status; | |
210 | if (!success) { | |
211 | me.workspace.checkVmMigration(me.pveSelNode); | |
212 | status = 'unknown'; | |
213 | } else { | |
214 | var rec = s.data.get('status'); | |
215 | status = rec ? rec.data.value : 'unknown'; | |
216 | } | |
217 | startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running'); | |
218 | shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); | |
219 | stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped'); | |
220 | removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped'); | |
221 | ||
222 | if (status === 'mounted') { | |
223 | umountBtn.setDisabled(false); | |
224 | umountBtn.setVisible(true); | |
225 | stopBtn.setVisible(false); | |
226 | } else { | |
227 | umountBtn.setDisabled(true); | |
228 | umountBtn.setVisible(false); | |
229 | stopBtn.setVisible(true); | |
230 | } | |
231 | }); | |
232 | ||
233 | me.on('afterrender', function() { | |
234 | me.statusStore.startUpdate(); | |
235 | }); | |
236 | ||
237 | me.on('destroy', function() { | |
238 | me.statusStore.stopUpdate(); | |
239 | }); | |
240 | } | |
241 | }); |