]>
Commit | Line | Data |
---|---|---|
6521f904 DM |
1 | Ext.define('PVE.openvz.Config', { |
2 | extend: 'PVE.panel.Config', | |
3 | alias: 'widget.PVE.openvz.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 | ||
8fb7d745 DM |
18 | var caps = Ext.state.Manager.get('GuiCap'); |
19 | ||
87233e4d DM |
20 | var base_url = '/nodes/' + nodename + '/openvz/' + vmid; |
21 | ||
3732a665 | 22 | me.statusStore = Ext.create('PVE.data.ObjectStore', { |
87233e4d | 23 | url: '/api2/json' + base_url + '/status/current', |
3732a665 DM |
24 | interval: 1000 |
25 | }); | |
26 | ||
27 | var vm_command = function(cmd, params) { | |
28 | PVE.Utils.API2Request({ | |
29 | params: params, | |
87233e4d | 30 | url: base_url + "/status/" + cmd, |
3732a665 DM |
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', { | |
a2dca26b | 40 | text: gettext('Start'), |
8fb7d745 | 41 | disabled: !caps.vms['VM.PowerMgmt'], |
3732a665 DM |
42 | handler: function() { |
43 | vm_command('start'); | |
44 | } | |
45 | }); | |
8710f280 DM |
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 | }); | |
3732a665 DM |
55 | |
56 | var stopBtn = Ext.create('PVE.button.Button', { | |
a2dca26b | 57 | text: gettext('Stop'), |
8fb7d745 | 58 | disabled: !caps.vms['VM.PowerMgmt'], |
a2dca26b | 59 | confirmMsg: Ext.String.format(gettext("Do you really want to stop VM {0}?"), vmid), |
3732a665 | 60 | handler: function() { |
51ed1415 | 61 | vm_command("stop"); |
3732a665 DM |
62 | } |
63 | }); | |
64 | ||
65 | var shutdownBtn = Ext.create('PVE.button.Button', { | |
a2dca26b | 66 | text: gettext('Shutdown'), |
8fb7d745 | 67 | disabled: !caps.vms['VM.PowerMgmt'], |
a2dca26b | 68 | confirmMsg: Ext.String.format(gettext("Do you really want to shutdown VM {0}?"), vmid), |
3732a665 | 69 | handler: function() { |
51ed1415 | 70 | vm_command('shutdown'); |
3732a665 DM |
71 | } |
72 | }); | |
73 | ||
7e79e293 | 74 | var migrateBtn = Ext.create('Ext.Button', { |
a2dca26b | 75 | text: gettext('Migrate'), |
8fb7d745 | 76 | disabled: !caps.vms['VM.Migrate'], |
7e79e293 DM |
77 | handler: function() { |
78 | var win = Ext.create('PVE.window.Migrate', { | |
79 | vmtype: 'openvz', | |
80 | nodename: nodename, | |
81 | vmid: vmid | |
82 | }); | |
83 | win.show(); | |
84 | } | |
85 | }); | |
86 | ||
3732a665 | 87 | var removeBtn = Ext.create('PVE.button.Button', { |
a2dca26b | 88 | text: gettext('Remove'), |
8fb7d745 | 89 | disabled: !caps.vms['VM.Allocate'], |
ddb20c58 | 90 | dangerous: true, |
a2dca26b | 91 | confirmMsg: Ext.String.format(gettext('Are you sure you want to remove VM {0}? This will permanently erase all VM data.'), vmid), |
3732a665 DM |
92 | handler: function() { |
93 | PVE.Utils.API2Request({ | |
87233e4d | 94 | url: base_url, |
3732a665 DM |
95 | method: 'DELETE', |
96 | waitMsgTarget: me, | |
97 | failure: function(response, opts) { | |
98 | Ext.Msg.alert('Error', response.htmlStatus); | |
99 | } | |
100 | }); | |
101 | } | |
102 | }); | |
103 | ||
fb3feb55 DM |
104 | var vmname = me.pveSelNode.data.name; |
105 | ||
ed51f6d6 | 106 | var consoleBtn = Ext.create('PVE.button.ConsoleButton', { |
8fb7d745 | 107 | disabled: !caps.vms['VM.Console'], |
ed51f6d6 DM |
108 | consoleType: 'openvz', |
109 | consoleName: vmname, | |
110 | nodename: nodename, | |
111 | vmid: vmid | |
3732a665 DM |
112 | }); |
113 | ||
a2dca26b DM |
114 | var descr = vmid + " (" + (vmname ? "'" + vmname + "' " : "'CT " + vmid + "'") + ")"; |
115 | ||
6521f904 | 116 | Ext.apply(me, { |
a2dca26b | 117 | title: Ext.String.format(gettext("Container {0} on node {1}"), descr, "'" + nodename + "'"), |
6521f904 | 118 | hstateid: 'ovztab', |
8710f280 | 119 | tbar: [ startBtn, shutdownBtn, umountBtn, stopBtn, removeBtn, |
10f62558 | 120 | migrateBtn, consoleBtn ], |
3732a665 | 121 | defaults: { statusStore: me.statusStore }, |
6521f904 DM |
122 | items: [ |
123 | { | |
a2dca26b | 124 | title: gettext('Summary'), |
ce8395e5 | 125 | xtype: 'pveOpenVZSummary', |
a2f57991 | 126 | itemId: 'summary' |
6521f904 | 127 | }, |
d9f0ffa9 | 128 | { |
a2dca26b DM |
129 | title: gettext('Resources'), |
130 | itemId: 'resources', | |
d9f0ffa9 DM |
131 | xtype: 'pveOpenVZRessourceView' |
132 | }, | |
9021b40c | 133 | { |
a2dca26b | 134 | title: gettext('Network'), |
9021b40c DM |
135 | itemId: 'network', |
136 | xtype: 'pveOpenVZNetworkView' | |
137 | }, | |
7690de6e | 138 | { |
0070ee37 | 139 | title: gettext('DNS'), |
7690de6e DM |
140 | itemId: 'dns', |
141 | xtype: 'pveOpenVZDNS' | |
142 | }, | |
6521f904 | 143 | { |
a2dca26b | 144 | title: gettext('Options'), |
6521f904 | 145 | itemId: 'options', |
337dca7c | 146 | xtype: 'pveOpenVZOptions' |
6521f904 | 147 | }, |
5614bec0 | 148 | { |
0070ee37 | 149 | title: gettext('Task History'), |
5614bec0 DM |
150 | itemId: 'tasks', |
151 | xtype: 'pveNodeTasks', | |
152 | vmidFilter: vmid | |
153 | }, | |
9056e748 DM |
154 | { |
155 | title: 'UBC', | |
156 | itemId: 'ubc', | |
157 | xtype: 'pveBeanCounterGrid', | |
87233e4d | 158 | url: '/api2/json' + base_url + '/status/ubc' |
6521f904 | 159 | } |
6521f904 DM |
160 | ] |
161 | }); | |
162 | ||
8fb7d745 DM |
163 | if (caps.vms['VM.Backup']) { |
164 | me.items.push({ | |
165 | title: gettext('Backup'), | |
166 | xtype: 'pveBackupView', | |
167 | itemId: 'backup' | |
168 | }); | |
169 | } | |
170 | ||
87233e4d DM |
171 | if (caps.vms['VM.Console']) { |
172 | me.items.push([ | |
173 | { | |
174 | xtype: 'pveFirewallPanel', | |
175 | title: gettext('Firewall'), | |
176 | base_url: base_url + '/firewall', | |
177 | fwtype: 'vm', | |
178 | phstateid: me.hstateid, | |
179 | itemId: 'firewall' | |
180 | } | |
181 | ]); | |
182 | } | |
183 | ||
8fb7d745 DM |
184 | if (caps.vms['Permissions.Modify']) { |
185 | me.items.push({ | |
186 | xtype: 'pveACLView', | |
187 | title: gettext('Permissions'), | |
188 | itemId: 'permissions', | |
189 | path: '/vms/' + vmid | |
190 | }); | |
191 | } | |
192 | ||
6521f904 | 193 | me.callParent(); |
3732a665 DM |
194 | |
195 | me.statusStore.on('load', function(s, records, success) { | |
196 | var status; | |
197 | if (!success) { | |
198 | me.workspace.checkVmMigration(me.pveSelNode); | |
199 | status = 'unknown'; | |
200 | } else { | |
201 | var rec = s.data.get('status'); | |
202 | status = rec ? rec.data.value : 'unknown'; | |
203 | } | |
8fb7d745 DM |
204 | startBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'running'); |
205 | shutdownBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status !== 'running'); | |
206 | stopBtn.setDisabled(!caps.vms['VM.PowerMgmt'] || status === 'stopped'); | |
207 | removeBtn.setDisabled(!caps.vms['VM.Allocate'] || status !== 'stopped'); | |
8710f280 DM |
208 | |
209 | if (status === 'mounted') { | |
210 | umountBtn.setDisabled(false); | |
211 | umountBtn.setVisible(true); | |
212 | stopBtn.setVisible(false); | |
213 | } else { | |
214 | umountBtn.setDisabled(true); | |
215 | umountBtn.setVisible(false); | |
216 | stopBtn.setVisible(true); | |
217 | } | |
3732a665 DM |
218 | }); |
219 | ||
220 | me.on('afterrender', function() { | |
221 | me.statusStore.startUpdate(); | |
222 | }); | |
223 | ||
224 | me.on('destroy', function() { | |
225 | me.statusStore.stopUpdate(); | |
226 | }); | |
227 | } | |
6521f904 | 228 | }); |