]>
Commit | Line | Data |
---|---|---|
a58001dd DM |
1 | Ext.define('Proxmox.node.NetworkEdit', { |
2 | extend: 'Proxmox.window.Edit', | |
3 | alias: ['widget.proxmoxNodeNetworkEdit'], | |
4 | ||
01031528 | 5 | initComponent: function() { |
05a977a2 | 6 | let me = this; |
a58001dd DM |
7 | |
8 | if (!me.nodename) { | |
9 | throw "no node name specified"; | |
10 | } | |
11 | ||
12 | if (!me.iftype) { | |
13 | throw "no network device type specified"; | |
14 | } | |
15 | ||
b33f451f | 16 | me.isCreate = !me.iface; |
a58001dd | 17 | |
05a977a2 | 18 | let iface_vtype; |
a58001dd DM |
19 | |
20 | if (me.iftype === 'bridge') { | |
21 | iface_vtype = 'BridgeName'; | |
22 | } else if (me.iftype === 'bond') { | |
23 | iface_vtype = 'BondName'; | |
b33f451f | 24 | } else if (me.iftype === 'eth' && !me.isCreate) { |
a58001dd | 25 | iface_vtype = 'InterfaceName'; |
8aefd47c AD |
26 | } else if (me.iftype === 'vlan') { |
27 | iface_vtype = 'VlanName'; | |
a58001dd DM |
28 | } else if (me.iftype === 'OVSBridge') { |
29 | iface_vtype = 'BridgeName'; | |
30 | } else if (me.iftype === 'OVSBond') { | |
31 | iface_vtype = 'BondName'; | |
32 | } else if (me.iftype === 'OVSIntPort') { | |
33 | iface_vtype = 'InterfaceName'; | |
34 | } else if (me.iftype === 'OVSPort') { | |
35 | iface_vtype = 'InterfaceName'; | |
36 | } else { | |
37 | console.log(me.iftype); | |
38 | throw "unknown network device type specified"; | |
39 | } | |
40 | ||
41 | me.subject = Proxmox.Utils.render_network_iface_type(me.iftype); | |
42 | ||
5c833def TL |
43 | let column1 = [], |
44 | column2 = [], | |
1aaba242 | 45 | columnB = [], |
5c833def TL |
46 | advancedColumn1 = [], |
47 | advancedColumn2 = []; | |
a58001dd | 48 | |
5c833def | 49 | if (!(me.iftype === 'OVSIntPort' || me.iftype === 'OVSPort' || me.iftype === 'OVSBond')) { |
a58001dd | 50 | column2.push({ |
fccec7c6 | 51 | xtype: 'proxmoxcheckbox', |
a58001dd DM |
52 | fieldLabel: gettext('Autostart'), |
53 | name: 'autostart', | |
54 | uncheckedValue: 0, | |
01031528 | 55 | checked: me.isCreate ? true : undefined, |
a58001dd DM |
56 | }); |
57 | } | |
58 | ||
59 | if (me.iftype === 'bridge') { | |
60 | column2.push({ | |
fccec7c6 | 61 | xtype: 'proxmoxcheckbox', |
a58001dd DM |
62 | fieldLabel: gettext('VLAN aware'), |
63 | name: 'bridge_vlan_aware', | |
01031528 | 64 | deleteEmpty: !me.isCreate, |
a58001dd DM |
65 | }); |
66 | column2.push({ | |
67 | xtype: 'textfield', | |
68 | fieldLabel: gettext('Bridge ports'), | |
01031528 | 69 | name: 'bridge_ports', |
a58001dd DM |
70 | }); |
71 | } else if (me.iftype === 'OVSBridge') { | |
72 | column2.push({ | |
73 | xtype: 'textfield', | |
74 | fieldLabel: gettext('Bridge ports'), | |
01031528 | 75 | name: 'ovs_ports', |
a58001dd DM |
76 | }); |
77 | column2.push({ | |
78 | xtype: 'textfield', | |
79 | fieldLabel: gettext('OVS options'), | |
01031528 | 80 | name: 'ovs_options', |
a58001dd DM |
81 | }); |
82 | } else if (me.iftype === 'OVSPort' || me.iftype === 'OVSIntPort') { | |
83 | column2.push({ | |
b33f451f | 84 | xtype: me.isCreate ? 'PVE.form.BridgeSelector' : 'displayfield', |
a58001dd DM |
85 | fieldLabel: Proxmox.Utils.render_network_iface_type('OVSBridge'), |
86 | allowBlank: false, | |
87 | nodename: me.nodename, | |
88 | bridgeType: 'OVSBridge', | |
01031528 | 89 | name: 'ovs_bridge', |
a58001dd DM |
90 | }); |
91 | column2.push({ | |
92 | xtype: 'pveVlanField', | |
b33f451f | 93 | deleteEmpty: !me.isCreate, |
a58001dd | 94 | name: 'ovs_tag', |
01031528 | 95 | value: '', |
a58001dd DM |
96 | }); |
97 | column2.push({ | |
98 | xtype: 'textfield', | |
99 | fieldLabel: gettext('OVS options'), | |
01031528 | 100 | name: 'ovs_options', |
a58001dd | 101 | }); |
8aefd47c | 102 | } else if (me.iftype === 'vlan') { |
ea7da80c | 103 | if (!me.isCreate) { |
ea7da80c TL |
104 | me.disablevlanid = false; |
105 | me.disablevlanrawdevice = false; | |
106 | me.vlanrawdevicevalue = ''; | |
107 | me.vlanidvalue = ''; | |
8aefd47c | 108 | |
ea7da80c TL |
109 | if (Proxmox.Utils.VlanInterface_match.test(me.iface)) { |
110 | me.disablevlanid = true; | |
111 | me.disablevlanrawdevice = true; | |
05a977a2 | 112 | let arr = Proxmox.Utils.VlanInterface_match.exec(me.iface); |
ea7da80c TL |
113 | me.vlanrawdevicevalue = arr[1]; |
114 | me.vlanidvalue = arr[2]; | |
ea7da80c TL |
115 | } else if (Proxmox.Utils.Vlan_match.test(me.iface)) { |
116 | me.disablevlanid = true; | |
05a977a2 | 117 | let arr = Proxmox.Utils.Vlan_match.exec(me.iface); |
ea7da80c TL |
118 | me.vlanidvalue = arr[1]; |
119 | } | |
120 | } else { | |
ea7da80c TL |
121 | me.disablevlanid = true; |
122 | me.disablevlanrawdevice = true; | |
8aefd47c AD |
123 | } |
124 | ||
125 | column2.push({ | |
126 | xtype: 'textfield', | |
127 | fieldLabel: gettext('Vlan raw device'), | |
128 | name: 'vlan-raw-device', | |
ea7da80c | 129 | value: me.vlanrawdevicevalue, |
01031528 | 130 | disabled: me.disablevlanrawdevice, |
8aefd47c AD |
131 | }); |
132 | ||
133 | column2.push({ | |
134 | xtype: 'pveVlanField', | |
135 | name: 'vlan-id', | |
ea7da80c | 136 | value: me.vlanidvalue, |
01031528 | 137 | disabled: me.disablevlanid, |
1aaba242 | 138 | }); |
8aefd47c | 139 | |
1aaba242 TL |
140 | columnB.push({ |
141 | xtype: 'label', | |
142 | userCls: 'pmx-hint', | |
143 | text: 'Either add the VLAN number to an existing interface name, or choose your own name and set the VLAN raw device (for the latter ifupdown1 supports vlanXY naming only)', | |
8aefd47c | 144 | }); |
a58001dd DM |
145 | } else if (me.iftype === 'bond') { |
146 | column2.push({ | |
147 | xtype: 'textfield', | |
148 | fieldLabel: gettext('Slaves'), | |
01031528 | 149 | name: 'slaves', |
a58001dd DM |
150 | }); |
151 | ||
05a977a2 | 152 | let policySelector = Ext.createWidget('bondPolicySelector', { |
a58001dd DM |
153 | fieldLabel: gettext('Hash policy'), |
154 | name: 'bond_xmit_hash_policy', | |
b33f451f | 155 | deleteEmpty: !me.isCreate, |
01031528 | 156 | disabled: true, |
a58001dd DM |
157 | }); |
158 | ||
05a977a2 | 159 | let primaryfield = Ext.createWidget('textfield', { |
b154853a AD |
160 | fieldLabel: gettext('bond-primary'), |
161 | name: 'bond-primary', | |
162 | value: '', | |
01031528 | 163 | disabled: true, |
b154853a AD |
164 | }); |
165 | ||
a58001dd DM |
166 | column2.push({ |
167 | xtype: 'bondModeSelector', | |
168 | fieldLabel: gettext('Mode'), | |
169 | name: 'bond_mode', | |
b33f451f | 170 | value: me.isCreate ? 'balance-rr' : undefined, |
a58001dd DM |
171 | listeners: { |
172 | change: function(f, value) { | |
173 | if (value === 'balance-xor' || | |
174 | value === '802.3ad') { | |
175 | policySelector.setDisabled(false); | |
b154853a AD |
176 | primaryfield.setDisabled(true); |
177 | primaryfield.setValue(''); | |
178 | } else if (value === 'active-backup') { | |
179 | primaryfield.setDisabled(false); | |
180 | policySelector.setDisabled(true); | |
181 | policySelector.setValue(''); | |
a58001dd DM |
182 | } else { |
183 | policySelector.setDisabled(true); | |
184 | policySelector.setValue(''); | |
b154853a AD |
185 | primaryfield.setDisabled(true); |
186 | primaryfield.setValue(''); | |
a58001dd | 187 | } |
01031528 | 188 | }, |
a58001dd | 189 | }, |
01031528 | 190 | allowBlank: false, |
a58001dd DM |
191 | }); |
192 | ||
193 | column2.push(policySelector); | |
b154853a | 194 | column2.push(primaryfield); |
a58001dd DM |
195 | } else if (me.iftype === 'OVSBond') { |
196 | column2.push({ | |
b33f451f | 197 | xtype: me.isCreate ? 'PVE.form.BridgeSelector' : 'displayfield', |
a58001dd DM |
198 | fieldLabel: Proxmox.Utils.render_network_iface_type('OVSBridge'), |
199 | allowBlank: false, | |
200 | nodename: me.nodename, | |
201 | bridgeType: 'OVSBridge', | |
01031528 | 202 | name: 'ovs_bridge', |
a58001dd DM |
203 | }); |
204 | column2.push({ | |
205 | xtype: 'pveVlanField', | |
b33f451f | 206 | deleteEmpty: !me.isCreate, |
a58001dd | 207 | name: 'ovs_tag', |
01031528 | 208 | value: '', |
a58001dd DM |
209 | }); |
210 | column2.push({ | |
211 | xtype: 'textfield', | |
212 | fieldLabel: gettext('OVS options'), | |
01031528 | 213 | name: 'ovs_options', |
a58001dd DM |
214 | }); |
215 | } | |
216 | ||
217 | column2.push({ | |
218 | xtype: 'textfield', | |
219 | fieldLabel: gettext('Comment'), | |
220 | allowBlank: true, | |
221 | nodename: me.nodename, | |
01031528 | 222 | name: 'comments', |
a58001dd DM |
223 | }); |
224 | ||
05a977a2 TL |
225 | let url; |
226 | let method; | |
a58001dd | 227 | |
b33f451f | 228 | if (me.isCreate) { |
a58001dd DM |
229 | url = "/api2/extjs/nodes/" + me.nodename + "/network"; |
230 | method = 'POST'; | |
231 | } else { | |
232 | url = "/api2/extjs/nodes/" + me.nodename + "/network/" + me.iface; | |
233 | method = 'PUT'; | |
234 | } | |
235 | ||
5c833def | 236 | column1.push({ |
ea7da80c TL |
237 | xtype: 'hiddenfield', |
238 | name: 'type', | |
01031528 | 239 | value: me.iftype, |
ea7da80c TL |
240 | }, |
241 | { | |
242 | xtype: me.isCreate ? 'textfield' : 'displayfield', | |
243 | fieldLabel: gettext('Name'), | |
244 | name: 'iface', | |
245 | value: me.iface, | |
246 | vtype: iface_vtype, | |
247 | allowBlank: false, | |
248 | listeners: { | |
249 | change: function(f, value) { | |
250 | if (me.isCreate && iface_vtype === 'VlanName') { | |
05a977a2 TL |
251 | let vlanidField = me.down('field[name=vlan-id]'); |
252 | let vlanrawdeviceField = me.down('field[name=vlan-raw-device]'); | |
ea7da80c TL |
253 | if (Proxmox.Utils.VlanInterface_match.test(value)) { |
254 | vlanidField.setDisabled(true); | |
255 | vlanrawdeviceField.setDisabled(true); | |
256 | } else if (Proxmox.Utils.Vlan_match.test(value)) { | |
257 | vlanidField.setDisabled(true); | |
258 | vlanrawdeviceField.setDisabled(false); | |
259 | } else { | |
260 | vlanidField.setDisabled(false); | |
261 | vlanrawdeviceField.setDisabled(false); | |
262 | } | |
263 | } | |
01031528 TL |
264 | }, |
265 | }, | |
5c833def | 266 | }); |
a58001dd DM |
267 | |
268 | if (me.iftype === 'OVSBond') { | |
269 | column1.push( | |
270 | { | |
271 | xtype: 'bondModeSelector', | |
272 | fieldLabel: gettext('Mode'), | |
273 | name: 'bond_mode', | |
274 | openvswitch: true, | |
b33f451f | 275 | value: me.isCreate ? 'active-backup' : undefined, |
01031528 | 276 | allowBlank: false, |
a58001dd DM |
277 | }, |
278 | { | |
279 | xtype: 'textfield', | |
280 | fieldLabel: gettext('Slaves'), | |
01031528 TL |
281 | name: 'ovs_bonds', |
282 | }, | |
a58001dd DM |
283 | ); |
284 | } else { | |
a58001dd DM |
285 | column1.push( |
286 | { | |
a0ec1620 | 287 | xtype: 'proxmoxtextfield', |
b33f451f | 288 | deleteEmpty: !me.isCreate, |
8e2d096c DC |
289 | fieldLabel: 'IPv4/CIDR', |
290 | vtype: 'IPCIDRAddress', | |
01031528 | 291 | name: 'cidr', |
a58001dd DM |
292 | }, |
293 | { | |
a0ec1620 | 294 | xtype: 'proxmoxtextfield', |
b33f451f | 295 | deleteEmpty: !me.isCreate, |
8e2d096c | 296 | fieldLabel: gettext('Gateway') + ' (IPv4)', |
a58001dd | 297 | vtype: 'IPAddress', |
01031528 | 298 | name: 'gateway', |
a58001dd DM |
299 | }, |
300 | { | |
a0ec1620 | 301 | xtype: 'proxmoxtextfield', |
b33f451f | 302 | deleteEmpty: !me.isCreate, |
8e2d096c DC |
303 | fieldLabel: 'IPv6/CIDR', |
304 | vtype: 'IP6CIDRAddress', | |
01031528 | 305 | name: 'cidr6', |
a58001dd DM |
306 | }, |
307 | { | |
a0ec1620 | 308 | xtype: 'proxmoxtextfield', |
b33f451f | 309 | deleteEmpty: !me.isCreate, |
8e2d096c | 310 | fieldLabel: gettext('Gateway') + ' (IPv6)', |
a58001dd | 311 | vtype: 'IP6Address', |
01031528 | 312 | name: 'gateway6', |
aedaf2b6 | 313 | }, |
5c833def | 314 | ); |
01031528 | 315 | advancedColumn1.push( |
aedaf2b6 AD |
316 | { |
317 | xtype: 'proxmoxintegerfield', | |
318 | minValue: 1280, | |
319 | maxValue: 65520, | |
320 | deleteEmpty: !me.isCreate, | |
5c833def | 321 | emptyText: 1500, |
aedaf2b6 | 322 | fieldLabel: 'MTU', |
01031528 | 323 | name: 'mtu', |
5c833def | 324 | }, |
a58001dd DM |
325 | ); |
326 | } | |
327 | ||
328 | Ext.applyIf(me, { | |
329 | url: url, | |
330 | method: method, | |
331 | items: { | |
332 | xtype: 'inputpanel', | |
333 | column1: column1, | |
5c833def | 334 | column2: column2, |
1aaba242 | 335 | columnB: columnB, |
5c833def TL |
336 | advancedColumn1: advancedColumn1, |
337 | advancedColumn2: advancedColumn2, | |
01031528 | 338 | }, |
a58001dd DM |
339 | }); |
340 | ||
341 | me.callParent(); | |
342 | ||
b33f451f | 343 | if (me.isCreate) { |
a58001dd DM |
344 | me.down('field[name=iface]').setValue(me.iface_default); |
345 | } else { | |
346 | me.load({ | |
347 | success: function(response, options) { | |
05a977a2 | 348 | let data = response.result.data; |
a58001dd | 349 | if (data.type !== me.iftype) { |
05a977a2 | 350 | let msg = "Got unexpected device type"; |
a58001dd DM |
351 | Ext.Msg.alert(gettext('Error'), msg, function() { |
352 | me.close(); | |
353 | }); | |
354 | return; | |
355 | } | |
356 | me.setValues(data); | |
357 | me.isValid(); // trigger validation | |
01031528 | 358 | }, |
a58001dd DM |
359 | }); |
360 | } | |
01031528 | 361 | }, |
a58001dd | 362 | }); |